Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * blackboard_thread.cpp - Fawkes Example Plugin BlackBoard Thread 00004 * 00005 * Created: Wed Jun 20 16:37:40 2007 00006 * Copyright 2007-2008 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 <plugins/examples/basics/blackboard_thread.h> 00024 #include <interfaces/TestInterface.h> 00025 00026 using namespace fawkes; 00027 00028 00029 /** @class ExampleBlackBoardThread <plugins/examples/basics/blackboard_thread.h> 00030 * Simple demonstration for a thread using the BlackBoard. 00031 * 00032 * @author Tim Niemueller 00033 */ 00034 00035 00036 /** Constructor. 00037 * @param reader set to true, to make this bb thread to open the test interface 00038 * read-only, false to open it as a writer 00039 */ 00040 ExampleBlackBoardThread::ExampleBlackBoardThread(bool reader) 00041 : Thread("ExampleBlackBoardThread", Thread::OPMODE_WAITFORWAKEUP), 00042 BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_THINK) 00043 { 00044 this->reader = reader; 00045 } 00046 00047 00048 /** Destructor. */ 00049 ExampleBlackBoardThread::~ExampleBlackBoardThread() 00050 { 00051 } 00052 00053 00054 void 00055 ExampleBlackBoardThread::finalize() 00056 { 00057 logger->log_debug(name(), "Closing test interface"); 00058 try { 00059 blackboard->close(test_interface); 00060 } catch (Exception &e) { 00061 logger->log_error(name(), "Could not close kicker interface"); 00062 logger->log_error(name(), e); 00063 } 00064 } 00065 00066 00067 /** Initialize thread. 00068 * Here, the device and the BB-interface are opened. 00069 */ 00070 void 00071 ExampleBlackBoardThread::init() 00072 { 00073 logger->log_debug(name(), "Opening test interface"); 00074 try { 00075 if ( reader ) { 00076 test_interface = blackboard->open_for_reading<TestInterface>("Test"); 00077 } else { 00078 test_interface = blackboard->open_for_writing<TestInterface>("Test"); 00079 } 00080 } catch (Exception& e) { 00081 e.append("Opening test interface for writing failed"); 00082 throw; 00083 } 00084 } 00085 00086 /** Thread loop. 00087 * Parse messages from the interface and update values in the interface. 00088 */ 00089 void 00090 ExampleBlackBoardThread::loop() 00091 { 00092 // nothin' 00093 }