fountain_thread.cpp
00001 00002 /*************************************************************************** 00003 * fountain_thread.h - Fountain main thread 00004 * 00005 * Created: Fri Nov 16 11:22:30 2007 00006 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include <apps/fountain/fountain_thread.h> 00024 00025 #include <core/exceptions/software.h> 00026 #include <fvutils/net/fuse_server.h> 00027 00028 #include <string> 00029 #include <cstdio> 00030 00031 using namespace fawkes; 00032 00033 /** @class FountainThread <apps/fountain/fountain_thread.h> 00034 * Fountain main thread. 00035 * @author Tim Niemueller 00036 */ 00037 00038 /** Constructor. */ 00039 FountainThread::FountainThread() 00040 : Thread("FountainThread", OPMODE_WAITFORWAKEUP) 00041 { 00042 __fuse_server = NULL; 00043 __service = NULL; 00044 } 00045 00046 00047 /** Destructor. */ 00048 FountainThread::~FountainThread() 00049 { 00050 if ( __fuse_server ) { 00051 thread_collector->remove(__fuse_server); 00052 delete __fuse_server; 00053 __fuse_server = NULL; 00054 } 00055 delete __service; 00056 __service = NULL; 00057 } 00058 00059 00060 void 00061 FountainThread::init() 00062 { 00063 // Start FUSE server 00064 unsigned int port = 0; 00065 try { 00066 port = config->get_uint("/firevision/fountain/tcp_port"); 00067 if ( port > 0xFFFF ) { 00068 throw OutOfBoundsException("Network port out of bounds", port, 0, 0xFFFF); 00069 } 00070 __fuse_server = new FuseServer(port, thread_collector); 00071 thread_collector->add(__fuse_server); 00072 } catch (Exception &e) { 00073 e.print_trace(); 00074 throw; 00075 } 00076 00077 // Announce service 00078 std::string sname = "Fountain on "; 00079 sname += nnresolver->short_hostname(); 00080 __service = new NetworkService(sname.c_str(), "_fountain._tcp", port); 00081 service_publisher->publish_service(__service); 00082 } 00083 00084 00085 void 00086 FountainThread::finalize() 00087 { 00088 service_publisher->unpublish_service(__service); 00089 00090 thread_collector->remove(__fuse_server); 00091 delete __fuse_server; 00092 __fuse_server = NULL; 00093 delete __service; 00094 __service = NULL; 00095 } 00096 00097 00098 void 00099 FountainThread::loop() 00100 { 00101 // do nothing, but implement to not exit 00102 printf("Sucker Loop\n"); 00103 }

