Fawkes API
Fawkes Development Version
|
Lua interface importer. More...
#include <>>
Public Types | |
typedef fawkes::LockMap< std::string, fawkes::Interface * > | InterfaceMap |
Map of varname to interface instance. More... | |
typedef fawkes::LockMap< std::string, std::list< fawkes::Interface * > > | InterfaceListMap |
Map of varname to list of interfaces. More... | |
Public Member Functions | |
LuaInterfaceImporter (LuaContext *__context, BlackBoard *blackboard, Configuration *config, Logger *logger) | |
Constructor. More... | |
~LuaInterfaceImporter () | |
Destructor. More... | |
void | open_reading_interfaces (std::string &prefix) |
Open interfaces for reading. More... | |
void | open_writing_interfaces (std::string &prefix) |
Open interfaces for writing. More... | |
void | add_interface (std::string varname, Interface *interface) |
Add a single interface to be pushed to the context. More... | |
void | close_reading_interfaces () |
Close interfaces for reading. More... | |
void | close_writing_interfaces () |
Close interfaces for writing. More... | |
LuaInterfaceImporter::InterfaceMap & | writing_interfaces () |
Get interface map of writing interfaces. More... | |
LuaInterfaceImporter::InterfaceMap & | reading_interfaces () |
Get interface map of reading interfaces. More... | |
void | push_interfaces () |
Push interfaces to Lua environment. More... | |
void | read_to_buffer () |
Read from all reading interfaces into a buffer. More... | |
void | read_from_buffer () |
Update interfaces from internal buffers. More... | |
void | read () |
Read from all reading interfaces. More... | |
void | write () |
Write all writing interfaces. More... | |
void | lua_restarted (LuaContext *context) |
Lua restart event. More... | |
![]() | |
virtual | ~LuaContextWatcher () |
Virtual empty destructor. More... | |
Lua interface importer.
The Lua interface importer reads a list from the configuration for a given prefix and exports them to the Lua environment. The configuration entries have the form "/this/is/the/prefix/variablename" -> Interface UID. The interfaces are exported as a table assigned to the global variable named "interfaces". This table has four entries, reading and writing to tables with variablename to interface mappings and reading_by_uid and writing_by_uid with mappings from the interface UID to the interface.
Definition at line 45 of file interface_importer.h.
typedef fawkes::LockMap<std::string, std::list<fawkes::Interface *> > fawkes::LuaInterfaceImporter::InterfaceListMap |
Map of varname to list of interfaces.
Definition at line 67 of file interface_importer.h.
typedef fawkes::LockMap<std::string, fawkes::Interface *> fawkes::LuaInterfaceImporter::InterfaceMap |
Map of varname to interface instance.
Definition at line 65 of file interface_importer.h.
fawkes::LuaInterfaceImporter::LuaInterfaceImporter | ( | LuaContext * | context, |
BlackBoard * | blackboard, | ||
Configuration * | config, | ||
Logger * | logger | ||
) |
Constructor.
context | Lua context |
blackboard | BlackBoard |
config | configuration |
logger | Logger |
Definition at line 56 of file interface_importer.cpp.
References fawkes::LuaContext::add_watcher().
fawkes::LuaInterfaceImporter::~LuaInterfaceImporter | ( | ) |
Destructor.
Definition at line 73 of file interface_importer.cpp.
References close_reading_interfaces(), close_writing_interfaces(), fawkes::Configuration::ValueIterator::get_string(), fawkes::Logger::log_info(), fawkes::Configuration::ValueIterator::next(), fawkes::BlackBoard::open_for_reading(), fawkes::BlackBoard::open_for_writing(), fawkes::BlackBoard::open_multiple_for_reading(), fawkes::Configuration::ValueIterator::path(), fawkes::BlackBoard::register_observer(), fawkes::LuaContext::remove_watcher(), fawkes::Interface::resize_buffers(), fawkes::Configuration::search(), fawkes::Configuration::ValueIterator::type(), and write().
void fawkes::LuaInterfaceImporter::add_interface | ( | std::string | varname, |
Interface * | interface | ||
) |
Add a single interface to be pushed to the context.
The given interface is pushed with the given variable name to the context, on explicit push_interfaces() and on the next LuaContext restart. However, the interface is not owned by the importer and thus neither is the interface read during read() nor is it written during write(). It is also not automatically closed in the destructor.
varname | the variable name of the interface |
interface | the interface to push |
Definition at line 197 of file interface_importer.cpp.
References fawkes::LuaContext::add_package(), fawkes::LuaContext::get_field(), fawkes::LuaContext::get_global(), fawkes::Interface::is_writer(), fawkes::Logger::log_warn(), fawkes::BlackBoard::open_for_reading(), fawkes::LuaContext::pop(), fawkes::LuaContext::push_usertype(), fawkes::LuaContext::raw_seti(), and fawkes::LuaContext::set_field().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaInterfaceImporter::close_reading_interfaces | ( | ) |
Close interfaces for reading.
Definition at line 236 of file interface_importer.cpp.
References fawkes::BlackBoard::close(), and fawkes::BlackBoard::unregister_observer().
Referenced by ~LuaInterfaceImporter().
void fawkes::LuaInterfaceImporter::close_writing_interfaces | ( | ) |
Close interfaces for writing.
Definition at line 260 of file interface_importer.cpp.
References fawkes::BlackBoard::close().
Referenced by ~LuaInterfaceImporter().
|
virtual |
Lua restart event.
This is called when the LuaContext has been restarted, for example when file watching is enabled and a file changed. It is executed after all packages have been loaded and variables have been set, but before the start script is run. The implementation may throw an exception if anything prevents it from using the new context properly.
context | This is a temporary LuaContext that is valid as long as the method is executed. It is a wrapper context around the new Lua state, just before the start script is run and it the calling context is switched to the new state (if no error occurs). |
Implements fawkes::LuaContextWatcher.
Definition at line 431 of file interface_importer.cpp.
References fawkes::Logger::log_warn(), and push_interfaces().
void fawkes::LuaInterfaceImporter::open_reading_interfaces | ( | std::string & | prefix | ) |
Open interfaces for reading.
prefix | configuration prefix for the interface list |
Definition at line 172 of file interface_importer.cpp.
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaInterfaceImporter::open_writing_interfaces | ( | std::string & | prefix | ) |
Open interfaces for writing.
prefix | configuration prefix for the interface list |
Definition at line 181 of file interface_importer.cpp.
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaInterfaceImporter::push_interfaces | ( | ) |
Push interfaces to Lua environment.
The interfaces are pushed to the interfaces table described in the class documentation. Note that you need to do this only once. The table is automatically re-pushed on a Lua restart event.
Definition at line 423 of file interface_importer.cpp.
Referenced by LuaAgentPeriodicExecutionThread::init(), LuaAgentContinuousExecutionThread::init(), lua_restarted(), and write().
void fawkes::LuaInterfaceImporter::read | ( | ) |
Read from all reading interfaces.
Definition at line 290 of file interface_importer.cpp.
Referenced by LuaAgentPeriodicExecutionThread::loop().
void fawkes::LuaInterfaceImporter::read_from_buffer | ( | ) |
Update interfaces from internal buffers.
Exception | thrown if read_to_buffer() was not called before. |
Definition at line 320 of file interface_importer.cpp.
Referenced by LuaAgentContinuousExecutionThread::read_interfaces().
void fawkes::LuaInterfaceImporter::read_to_buffer | ( | ) |
Read from all reading interfaces into a buffer.
Definition at line 301 of file interface_importer.cpp.
Referenced by LuaAgentContinuousExecutionThread::init(), and LuaAgentContinuousExecutionThread::loop().
LuaInterfaceImporter::InterfaceMap & fawkes::LuaInterfaceImporter::reading_interfaces | ( | ) |
Get interface map of reading interfaces.
Definition at line 272 of file interface_importer.cpp.
void fawkes::LuaInterfaceImporter::write | ( | ) |
Write all writing interfaces.
Definition at line 334 of file interface_importer.cpp.
References fawkes::LuaContext::add_package(), fawkes::Exception::append(), fawkes::LuaContext::create_table(), fawkes::Exception::print_trace(), push_interfaces(), fawkes::LuaContext::push_usertype(), fawkes::LuaContext::raw_seti(), fawkes::LuaContext::set_field(), and fawkes::LuaContext::set_global().
Referenced by LuaAgentPeriodicExecutionThread::loop(), LuaAgentContinuousExecutionThread::write_interfaces(), and ~LuaInterfaceImporter().
LuaInterfaceImporter::InterfaceMap & fawkes::LuaInterfaceImporter::writing_interfaces | ( | ) |
Get interface map of writing interfaces.
Definition at line 282 of file interface_importer.cpp.