Fawkes API  Fawkes Development Version
interface_importer.h
1 
2 /***************************************************************************
3  * interfaceimporter.h - Fawkes Lua Interface Importer
4  *
5  * Created: Thu Jan 01 14:28:47 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _LUA_INTERFACEIMPORTER_H_
24 #define _LUA_INTERFACEIMPORTER_H_
25 
26 #include <blackboard/interface_observer.h>
27 #include <core/utils/lock_map.h>
28 #include <lua/context_watcher.h>
29 
30 #include <list>
31 #include <string>
32 
33 namespace fawkes {
34 
35 class BlackBoard;
36 class Configuration;
37 class Interface;
38 class Logger;
39 class LuaContext;
40 
41 class LuaInterfaceImporter : public LuaContextWatcher
42 {
43  class InterfaceObserver : public BlackBoardInterfaceObserver
44  {
45  public:
46  InterfaceObserver(LuaInterfaceImporter *lii,
47  std::string varname,
48  const char * type,
49  const char * id_pattern);
50 
51  virtual void bb_interface_created(const char *type, const char *id) throw();
52 
53  private:
55  std::string varname_;
56  };
57 
59 
60 public:
61  /** Map of varname to interface instance. */
63  /** Map of varname to list of interfaces */
65 
67  BlackBoard * blackboard,
68  Configuration *config,
69  Logger * logger);
71 
72  void open_reading_interfaces(std::string &prefix);
73  void open_writing_interfaces(std::string &prefix);
74 
75  void add_interface(std::string varname, Interface *interface);
76 
79 
82 
83  void push_interfaces();
84 
85  void read_to_buffer();
86  void read_from_buffer();
87 
88  void read();
89  void write();
90 
91  void lua_restarted(LuaContext *context);
92 
93 private:
94  void open_interfaces(std::string &prefix, InterfaceMap &imap, bool write);
95  void push_interfaces(LuaContext *context);
96  void push_interfaces_varname(LuaContext *context, InterfaceMap &imap);
97  void push_interfaces_uid(LuaContext *context, InterfaceMap &imap);
98  void push_multi_interfaces_varname(LuaContext *context, InterfaceListMap &imap);
99 
100  void add_observed_interface(std::string varname, const char *type, const char *id);
101 
102 private:
103  LuaContext * context_;
104  BlackBoard * blackboard_;
105  Configuration *config_;
106  Logger * logger_;
107 
108  bool two_stage_;
109 
110  InterfaceMap reading_ifs_;
111  InterfaceListMap reading_multi_ifs_;
112  InterfaceMap writing_ifs_;
113  ObserverMap observers_;
114 
115  InterfaceMap ext_rifs_;
116  InterfaceMap ext_wifs_;
117 
118  bool interfaces_pushed_;
119 };
120 
121 } // end of namespace fawkes
122 
123 #endif
fawkes::LuaInterfaceImporter::writing_interfaces
LuaInterfaceImporter::InterfaceMap & writing_interfaces()
Get interface map of writing interfaces.
Definition: interface_importer.cpp:290
fawkes::LockMap< std::string, InterfaceObserver * >
fawkes::LuaInterfaceImporter::write
void write()
Write all writing interfaces.
Definition: interface_importer.cpp:340
fawkes::LuaInterfaceImporter::add_interface
void add_interface(std::string varname, Interface *interface)
Add a single interface to be pushed to the context.
Definition: interface_importer.cpp:206
fawkes::LuaInterfaceImporter::reading_interfaces
LuaInterfaceImporter::InterfaceMap & reading_interfaces()
Get interface map of reading interfaces.
Definition: interface_importer.cpp:281
fawkes::LuaContext
Definition: context.h:49
fawkes::LuaInterfaceImporter::open_reading_interfaces
void open_reading_interfaces(std::string &prefix)
Open interfaces for reading.
Definition: interface_importer.cpp:182
fawkes::LuaInterfaceImporter
Definition: interface_importer.h:47
fawkes::BlackBoard
Definition: blackboard.h:50
fawkes::LuaInterfaceImporter::read_to_buffer
void read_to_buffer()
Read from all reading interfaces into a buffer.
Definition: interface_importer.cpp:307
fawkes::LuaInterfaceImporter::read
void read()
Read from all reading interfaces.
Definition: interface_importer.cpp:297
fawkes::Configuration
Definition: config.h:70
fawkes::LuaInterfaceImporter::close_writing_interfaces
void close_writing_interfaces()
Close interfaces for writing.
Definition: interface_importer.cpp:269
fawkes::Logger
Definition: logger.h:41
fawkes
fawkes::LuaInterfaceImporter::InterfaceMap
fawkes::LockMap< std::string, fawkes::Interface * > InterfaceMap
Map of varname to interface instance.
Definition: interface_importer.h:68
fawkes::LuaInterfaceImporter::LuaInterfaceImporter
LuaInterfaceImporter(LuaContext *context_, BlackBoard *blackboard, Configuration *config, Logger *logger)
Constructor.
Definition: interface_importer.cpp:58
fawkes::Interface
Definition: interface.h:78
fawkes::LuaInterfaceImporter::~LuaInterfaceImporter
~LuaInterfaceImporter()
Destructor.
Definition: interface_importer.cpp:74
fawkes::LuaInterfaceImporter::open_writing_interfaces
void open_writing_interfaces(std::string &prefix)
Open interfaces for writing.
Definition: interface_importer.cpp:191
fawkes::LuaInterfaceImporter::close_reading_interfaces
void close_reading_interfaces()
Close interfaces for reading.
Definition: interface_importer.cpp:245
fawkes::LuaInterfaceImporter::read_from_buffer
void read_from_buffer()
Update interfaces from internal buffers.
Definition: interface_importer.cpp:326
fawkes::LuaInterfaceImporter::push_interfaces
void push_interfaces()
Push interfaces to Lua environment.
Definition: interface_importer.cpp:428
fawkes::LuaInterfaceImporter::InterfaceListMap
fawkes::LockMap< std::string, std::list< fawkes::Interface * > > InterfaceListMap
Map of varname to list of interfaces.
Definition: interface_importer.h:70
fawkes::LuaInterfaceImporter::lua_restarted
void lua_restarted(LuaContext *context)
Definition: interface_importer.cpp:435