Fawkes API
Fawkes Development Version
|
This thread creates an ECLiPSe context in which the Readylog interpreter and the program are loaded. More...
#include "eclipse_thread.h"
Public Member Functions | |
EclipseAgentThread () | |
Constructor. | |
virtual | ~EclipseAgentThread () |
Destructor. | |
virtual void | init () |
Initialize the thread. | |
virtual void | finalize () |
Finalize the thread. | |
virtual void | once () |
Execute an action exactly once. | |
void | post_event (const char *) |
Post an event to the ECLiPSe context. | |
void | read_interfaces () |
Read all registered interfaces. | |
void | write_interfaces () |
Write the registered interface that have been opened for writing. | |
fawkes::Interface * | get_registered_interface (const char *id) |
Get the registered interface with the given id. | |
fawkes::Logger * | get_logger () |
Get the logger. | |
Static Public Member Functions | |
static EclipseAgentThread * | instance () |
Get the EclipseAgentThread instance. |
This thread creates an ECLiPSe context in which the Readylog interpreter and the program are loaded.
EclipseAgentThread::EclipseAgentThread | ( | ) |
Constructor.
Definition at line 51 of file eclipse_thread.cpp.
EclipseAgentThread::~EclipseAgentThread | ( | ) | [virtual] |
Destructor.
Definition at line 59 of file eclipse_thread.cpp.
void EclipseAgentThread::finalize | ( | ) | [virtual] |
Finalize the thread.
This method is executed just before the thread is canceled and destroyed. It is always preceeded by a call to prepare_finalize(). If this is not the case this is a failure. The condition can be checked with the boolean variable finalize_prepared.
This method is meant to be used in conjunction with aspects and to cover thread inter-dependencies. This routine MUST bring the thread into a safe state such that it may be canceled and destroyed afterwards. If there is any reason that this cannot happen make your prepare_finalize() reports so.
This method is called by the thread manager just before the thread is being cancelled. Here you can do whatever steps are necessary just before the thread is cancelled. Note that you thread is still running and might be in the middle of a loop, so it is not a good place to give up on all resources used. Mind segmentation faults that could happen. Protect the area with a mutex that you lock at the beginning of your loop and free in the end, and that you lock at the beginning of finalize and then never unlock. Also not that the finalization may be canceled afterwards. The next thing that happens is that either the thread is canceled and destroyed or that the finalization is canceled and the thread has to run again.
Finalize is called on a thread just before it is deleted. It is guaranteed to be called on a fully initialized thread (if no exception is thrown in init()) (this guarantee holds in the Fawkes framework).
The default implementation does nothing besides throwing an exception if prepare_finalize() has not been called.
Exception | thrown if prepare_finalize() has not been called. |
Reimplemented from fawkes::Thread.
Definition at line 160 of file eclipse_thread.cpp.
fawkes::Logger * EclipseAgentThread::get_logger | ( | ) |
Get the logger.
Definition at line 386 of file eclipse_thread.cpp.
References fawkes::LoggingAspect::logger.
fawkes::Interface * EclipseAgentThread::get_registered_interface | ( | const char * | id | ) |
Get the registered interface with the given id.
id | the interface id |
Definition at line 373 of file eclipse_thread.cpp.
void EclipseAgentThread::init | ( | ) | [virtual] |
Initialize the thread.
This method is meant to be used in conjunction with aspects. Some parts of the initialization may only happen after some aspect of the thread has been initialized. Implement the init method with these actions. It is guaranteed to be called just after all aspects have been initialized and only once in the lifetime of the thread. Throw an exception if any problem occurs and the thread should not run.
Just because your init() routine suceeds and everything looks fine for this thread does not automatically imply that it will run. If it belongs to a group of threads in a ThreadList and any of the other threads fail to initialize then no thread from this group is run and thus this thread will never run. In that situation finalize() is called for this very instance, prepare_finalize() however is not called.
Reimplemented from fawkes::Thread.
Definition at line 64 of file eclipse_thread.cpp.
References fawkes::ConfigurableAspect::config, fawkes::Configuration::get_string(), fawkes::LoggingAspect::logger, fawkes::Logger::log_info(), fawkes::Thread::name(), fawkes::Configuration::search(), fawkes::Configuration::ValueIterator::next(), fawkes::Configuration::ValueIterator::is_string(), fawkes::Configuration::ValueIterator::get_string(), fawkes::Logger::log_debug(), fawkes::BlackBoardAspect::blackboard, fawkes::BlackBoard::open_for_reading(), fawkes::BlackBoard::open_for_writing(), and fawkes::Exception::append().
EclipseAgentThread * EclipseAgentThread::instance | ( | ) | [static] |
Get the EclipseAgentThread instance.
Definition at line 395 of file eclipse_thread.cpp.
void EclipseAgentThread::once | ( | ) | [virtual] |
Execute an action exactly once.
This code is executed once and only once right after the thread is started before loop() is called. This is useful if you want to implement an one-shot background job. Just implement once() and leave once() untouched. Start the thread and detach it and it will just do its job and then die automatically. If you use set_delete_on_exit(true) even the Thread instance will be automatically deleted.
Reimplemented from fawkes::Thread.
Definition at line 166 of file eclipse_thread.cpp.
void EclipseAgentThread::post_event | ( | const char * | event | ) |
Post an event to the ECLiPSe context.
event | the name of the event |
Definition at line 177 of file eclipse_thread.cpp.
Referenced by AgentControlThread::prepare_finalize_user(), and AgentControlThread::loop().
void EclipseAgentThread::read_interfaces | ( | ) |
Read all registered interfaces.
Definition at line 189 of file eclipse_thread.cpp.
Referenced by AgentControlThread::loop().
void EclipseAgentThread::write_interfaces | ( | ) |
Write the registered interface that have been opened for writing.
Definition at line 204 of file eclipse_thread.cpp.
Referenced by AgentControlThread::loop().