interface_importer.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __LUA_INTERFACEIMPORTER_H_
00024 #define __LUA_INTERFACEIMPORTER_H_
00025
00026 #include <lua/context_watcher.h>
00027
00028 #include <core/utils/lock_map.h>
00029 #include <blackboard/interface_observer.h>
00030
00031 #include <string>
00032 #include <list>
00033
00034 namespace fawkes {
00035 #if 0
00036 }
00037 #endif
00038
00039 class BlackBoard;
00040 class Configuration;
00041 class Interface;
00042 class Logger;
00043 class LuaContext;
00044
00045 class LuaInterfaceImporter : public LuaContextWatcher
00046 {
00047
00048 class InterfaceObserver : public BlackBoardInterfaceObserver
00049 {
00050 public:
00051 InterfaceObserver(LuaInterfaceImporter *lii, std::string varname,
00052 const char *type, const char *id_pattern);
00053
00054 virtual void bb_interface_created(const char *type, const char *id) throw();
00055
00056 private:
00057 LuaInterfaceImporter *__lii;
00058 std::string __varname;
00059 };
00060
00061 typedef fawkes::LockMap<std::string, InterfaceObserver *> ObserverMap;
00062
00063 public:
00064
00065 typedef fawkes::LockMap<std::string, fawkes::Interface *> InterfaceMap;
00066
00067 typedef fawkes::LockMap<std::string, std::list<fawkes::Interface *> > InterfaceListMap;
00068
00069 LuaInterfaceImporter(LuaContext *__context, BlackBoard *blackboard,
00070 Configuration *config, Logger *logger);
00071 ~LuaInterfaceImporter();
00072
00073 void open_reading_interfaces(std::string &prefix);
00074 void open_writing_interfaces(std::string &prefix);
00075
00076 void add_interface(std::string varname, Interface *interface);
00077
00078 void close_reading_interfaces();
00079 void close_writing_interfaces();
00080
00081 LuaInterfaceImporter::InterfaceMap & writing_interfaces();
00082 LuaInterfaceImporter::InterfaceMap & reading_interfaces();
00083
00084 void push_interfaces();
00085
00086 void read();
00087 void write();
00088
00089 void lua_restarted(LuaContext *context);
00090
00091 private:
00092 void open_interfaces(std::string &prefix, InterfaceMap &imap, bool write);
00093 void push_interfaces(LuaContext *context);
00094 void push_interfaces_varname(LuaContext *context, InterfaceMap &imap);
00095 void push_interfaces_uid(LuaContext *context, InterfaceMap &imap);
00096 void push_multi_interfaces_varname(LuaContext *context, InterfaceListMap &imap);
00097
00098 void add_observed_interface(std::string varname,
00099 const char *type, const char *id);
00100
00101 private:
00102 LuaContext *__context;
00103 BlackBoard *__blackboard;
00104 Configuration *__config;
00105 Logger *__logger;
00106
00107 InterfaceMap __reading_ifs;
00108 InterfaceListMap __reading_multi_ifs;
00109 InterfaceMap __writing_ifs;
00110 ObserverMap __observers;
00111
00112 InterfaceMap __ext_rifs;
00113 InterfaceMap __ext_wifs;
00114
00115 bool __interfaces_pushed;
00116 };
00117
00118 }
00119
00120 #endif