Fawkes API  Fawkes Development Version
fawkes::LuaInterfaceImporter Class Reference

Lua interface importer. More...

#include <>>

Inheritance diagram for fawkes::LuaInterfaceImporter:

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::InterfaceMapwriting_interfaces ()
 Get interface map of writing interfaces. More...
 
LuaInterfaceImporter::InterfaceMapreading_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...
 
- Public Member Functions inherited from fawkes::LuaContextWatcher
virtual ~LuaContextWatcher ()
 Virtual empty destructor. More...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 45 of file interface_importer.h.

Member Typedef Documentation

◆ InterfaceListMap

Map of varname to list of interfaces.

Definition at line 67 of file interface_importer.h.

◆ InterfaceMap

Map of varname to interface instance.

Definition at line 65 of file interface_importer.h.

Constructor & Destructor Documentation

◆ LuaInterfaceImporter()

fawkes::LuaInterfaceImporter::LuaInterfaceImporter ( LuaContext context,
BlackBoard blackboard,
Configuration config,
Logger logger 
)

Constructor.

Parameters
contextLua context
blackboardBlackBoard
configconfiguration
loggerLogger

Definition at line 56 of file interface_importer.cpp.

References fawkes::LuaContext::add_watcher().

◆ ~LuaInterfaceImporter()

Member Function Documentation

◆ add_interface()

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.

Parameters
varnamethe variable name of the interface
interfacethe 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().

◆ close_reading_interfaces()

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().

◆ close_writing_interfaces()

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().

◆ lua_restarted()

void fawkes::LuaInterfaceImporter::lua_restarted ( LuaContext context)
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.

Parameters
contextThis 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().

◆ open_reading_interfaces()

void fawkes::LuaInterfaceImporter::open_reading_interfaces ( std::string &  prefix)

Open interfaces for reading.

Parameters
prefixconfiguration prefix for the interface list

Definition at line 172 of file interface_importer.cpp.

Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().

◆ open_writing_interfaces()

void fawkes::LuaInterfaceImporter::open_writing_interfaces ( std::string &  prefix)

Open interfaces for writing.

Parameters
prefixconfiguration prefix for the interface list

Definition at line 181 of file interface_importer.cpp.

Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().

◆ push_interfaces()

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().

◆ read()

void fawkes::LuaInterfaceImporter::read ( )

Read from all reading interfaces.

Definition at line 290 of file interface_importer.cpp.

Referenced by LuaAgentPeriodicExecutionThread::loop().

◆ read_from_buffer()

void fawkes::LuaInterfaceImporter::read_from_buffer ( )

Update interfaces from internal buffers.

Exceptions
Exceptionthrown if read_to_buffer() was not called before.

Definition at line 320 of file interface_importer.cpp.

Referenced by LuaAgentContinuousExecutionThread::read_interfaces().

◆ read_to_buffer()

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().

◆ reading_interfaces()

LuaInterfaceImporter::InterfaceMap & fawkes::LuaInterfaceImporter::reading_interfaces ( )

Get interface map of reading interfaces.

Returns
interface map of reading interfaces

Definition at line 272 of file interface_importer.cpp.

◆ write()

◆ writing_interfaces()

LuaInterfaceImporter::InterfaceMap & fawkes::LuaInterfaceImporter::writing_interfaces ( )

Get interface map of writing interfaces.

Returns
interface map of writing interfaces

Definition at line 282 of file interface_importer.cpp.


The documentation for this class was generated from the following files: