Classes | Public Types | Public Member Functions

fawkes::LuaInterfaceImporter Class Reference

Lua interface importer. More...

#include <>>

Inheritance diagram for fawkes::LuaInterfaceImporter:
Inheritance graph
[legend]

List of all members.

Classes

class  InterfaceObserver

Public Types

typedef fawkes::LockMap
< std::string,
fawkes::Interface * > 
InterfaceMap
 Map of varname to interface instance.
typedef fawkes::LockMap
< std::string, std::list
< fawkes::Interface * > > 
InterfaceListMap
 Map of varname to list of interfaces.

Public Member Functions

 LuaInterfaceImporter (LuaContext *__context, BlackBoard *blackboard, Configuration *config, Logger *logger)
 Constructor.
 ~LuaInterfaceImporter ()
 Destructor.
void open_reading_interfaces (std::string &prefix)
 Open interfaces for reading.
void open_writing_interfaces (std::string &prefix)
 Open interfaces for writing.
void add_interface (std::string varname, Interface *interface)
 Add a single interface to be pushed to the context.
void close_reading_interfaces ()
 Close interfaces for reading.
void close_writing_interfaces ()
 Close interfaces for writing.
LuaInterfaceImporter::InterfaceMapwriting_interfaces ()
 Get interface map of writing interfaces.
LuaInterfaceImporter::InterfaceMapreading_interfaces ()
 Get interface map of reading interfaces.
void push_interfaces ()
 Push interfaces to Lua environment.
void read ()
 Read from all reading interfaces.
void write ()
 Write all writing interfaces.
void lua_restarted (LuaContext *context)
 Lua restart event.

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

Map of varname to list of interfaces.

Definition at line 67 of file interface_importer.h.

Map of varname to interface instance.

Definition at line 65 of file interface_importer.h.


Constructor & Destructor Documentation

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

Constructor.

Parameters:
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 (  ) 

Member Function Documentation

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:
varname the variable name of the interface
interface the interface to push

Definition at line 192 of file interface_importer.cpp.

References fawkes::Interface::is_writer().

void fawkes::LuaInterfaceImporter::close_reading_interfaces (  ) 

Close interfaces for reading.

Definition at line 231 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 255 of file interface_importer.cpp.

References fawkes::BlackBoard::close().

Referenced by ~LuaInterfaceImporter().

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:
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 391 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.

Parameters:
prefix configuration prefix for the interface list

Definition at line 167 of file interface_importer.cpp.

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

Open interfaces for writing.

Parameters:
prefix configuration prefix for the interface list

Definition at line 176 of file interface_importer.cpp.

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 383 of file interface_importer.cpp.

Referenced by lua_restarted().

void fawkes::LuaInterfaceImporter::read (  ) 

Read from all reading interfaces.

Definition at line 285 of file interface_importer.cpp.

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

Get interface map of reading interfaces.

Returns:
interface map of reading interfaces

Definition at line 267 of file interface_importer.cpp.

void fawkes::LuaInterfaceImporter::write (  ) 

Write all writing interfaces.

Definition at line 294 of file interface_importer.cpp.

References fawkes::Exception::append(), and fawkes::Exception::print_trace().

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

Get interface map of writing interfaces.

Returns:
interface map of writing interfaces

Definition at line 277 of file interface_importer.cpp.


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