Fawkes API Fawkes Development Version
|
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 using namespace firevision; 00033 00034 /** @class FountainThread <apps/fountain/fountain_thread.h> 00035 * Fountain main thread. 00036 * @author Tim Niemueller 00037 */ 00038 00039 /** Constructor. */ 00040 FountainThread::FountainThread() 00041 : Thread("FountainThread", OPMODE_WAITFORWAKEUP) 00042 { 00043 __fuse_server = NULL; 00044 __service = NULL; 00045 } 00046 00047 00048 /** Destructor. */ 00049 FountainThread::~FountainThread() 00050 { 00051 if ( __fuse_server ) { 00052 thread_collector->remove(__fuse_server); 00053 delete __fuse_server; 00054 __fuse_server = NULL; 00055 } 00056 delete __service; 00057 __service = NULL; 00058 } 00059 00060 00061 void 00062 FountainThread::init() 00063 { 00064 // Start FUSE server 00065 unsigned int port = 0; 00066 try { 00067 port = config->get_uint("/firevision/fountain/tcp_port"); 00068 if ( port > 0xFFFF ) { 00069 throw OutOfBoundsException("Network port out of bounds", port, 0, 0xFFFF); 00070 } 00071 __fuse_server = new FuseServer(port, thread_collector); 00072 thread_collector->add(__fuse_server); 00073 } catch (Exception &e) { 00074 e.print_trace(); 00075 throw; 00076 } 00077 00078 // Announce service 00079 std::string sname = "Fountain on "; 00080 sname += nnresolver->short_hostname(); 00081 __service = new NetworkService(sname.c_str(), "_fountain._tcp", port); 00082 service_publisher->publish_service(__service); 00083 } 00084 00085 00086 void 00087 FountainThread::finalize() 00088 { 00089 service_publisher->unpublish_service(__service); 00090 00091 thread_collector->remove(__fuse_server); 00092 delete __fuse_server; 00093 __fuse_server = NULL; 00094 delete __service; 00095 __service = NULL; 00096 } 00097 00098 00099 void 00100 FountainThread::loop() 00101 { 00102 // do nothing, but implement to not exit 00103 printf("Sucker Loop\n"); 00104 }