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 <lua/context_watcher.h>
27 
28 #include <core/utils/lock_map.h>
29 #include <blackboard/interface_observer.h>
30 
31 #include <string>
32 #include <list>
33 
34 namespace fawkes {
35 #if 0 /* just to make Emacs auto-indent happy */
36 }
37 #endif
38 
39 class BlackBoard;
40 class Configuration;
41 class Interface;
42 class Logger;
43 class LuaContext;
44 
46 {
47 
48  class InterfaceObserver : public BlackBoardInterfaceObserver
49  {
50  public:
51  InterfaceObserver(LuaInterfaceImporter *lii, std::string varname,
52  const char *type, const char *id_pattern);
53 
54  virtual void bb_interface_created(const char *type, const char *id) throw();
55 
56  private:
57  LuaInterfaceImporter *__lii;
58  std::string __varname;
59  };
60 
62 
63  public:
64  /** Map of varname to interface instance. */
66  /** Map of varname to list of interfaces */
68 
69  LuaInterfaceImporter(LuaContext *__context, BlackBoard *blackboard,
70  Configuration *config, Logger *logger);
72 
73  void open_reading_interfaces(std::string &prefix);
74  void open_writing_interfaces(std::string &prefix);
75 
76  void add_interface(std::string varname, Interface *interface);
77 
80 
83 
84  void push_interfaces();
85 
86  void read_to_buffer();
87  void read_from_buffer();
88 
89  void read();
90  void write();
91 
92  void lua_restarted(LuaContext *context);
93 
94  private:
95  void open_interfaces(std::string &prefix, InterfaceMap &imap, bool write);
96  void push_interfaces(LuaContext *context);
97  void push_interfaces_varname(LuaContext *context, InterfaceMap &imap);
98  void push_interfaces_uid(LuaContext *context, InterfaceMap &imap);
99  void push_multi_interfaces_varname(LuaContext *context, InterfaceListMap &imap);
100 
101  void add_observed_interface(std::string varname,
102  const char *type, const char *id);
103 
104  private:
105  LuaContext *__context;
106  BlackBoard *__blackboard;
107  Configuration *__config;
108  Logger *__logger;
109 
110  bool __two_stage;
111 
112  InterfaceMap __reading_ifs;
113  InterfaceListMap __reading_multi_ifs;
114  InterfaceMap __writing_ifs;
115  ObserverMap __observers;
116 
117  InterfaceMap __ext_rifs;
118  InterfaceMap __ext_wifs;
119 
120  bool __interfaces_pushed;
121 };
122 
123 } // end of namespace fawkes
124 
125 #endif
LuaInterfaceImporter::InterfaceMap & reading_interfaces()
Get interface map of reading interfaces.
Lua context watcher.
LuaInterfaceImporter(LuaContext *__context, BlackBoard *blackboard, Configuration *config, Logger *logger)
Constructor.
Fawkes library namespace.
void read_to_buffer()
Read from all reading interfaces into a buffer.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void open_writing_interfaces(std::string &prefix)
Open interfaces for writing.
void close_reading_interfaces()
Close interfaces for reading.
fawkes::LockMap< std::string, fawkes::Interface * > InterfaceMap
Map of varname to interface instance.
Lua interface importer.
void open_reading_interfaces(std::string &prefix)
Open interfaces for reading.
Lua C++ wrapper.
Definition: context.h:47
void read_from_buffer()
Update interfaces from internal buffers.
void add_interface(std::string varname, Interface *interface)
Add a single interface to be pushed to the context.
BlackBoard interface observer.
void read()
Read from all reading interfaces.
LuaInterfaceImporter::InterfaceMap & writing_interfaces()
Get interface map of writing interfaces.
void close_writing_interfaces()
Close interfaces for writing.
fawkes::LockMap< std::string, std::list< fawkes::Interface * > > InterfaceListMap
Map of varname to list of interfaces.
void write()
Write all writing interfaces.
The BlackBoard abstract class.
Definition: blackboard.h:48
Interface for configuration handling.
Definition: config.h:67
void lua_restarted(LuaContext *context)
Lua restart event.
void push_interfaces()
Push interfaces to Lua environment.
Interface for logging.
Definition: logger.h:34