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
33namespace fawkes {
34
35class BlackBoard;
36class Configuration;
37class Interface;
38class Logger;
39class LuaContext;
40
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) noexcept;
52
53 private:
55 std::string varname_;
56 };
57
59
60public:
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
93private:
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
102private:
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
BlackBoard interface observer.
The BlackBoard abstract class.
Definition: blackboard.h:46
Interface for configuration handling.
Definition: config.h:68
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Interface for logging.
Definition: logger.h:42
Lua context watcher.
Lua C++ wrapper.
Definition: context.h:44
Lua interface importer.
LuaInterfaceImporter::InterfaceMap & reading_interfaces()
Get interface map of reading interfaces.
void read()
Read from all reading interfaces.
void add_interface(std::string varname, Interface *interface)
Add a single interface to be pushed to the context.
LuaInterfaceImporter::InterfaceMap & writing_interfaces()
Get interface map of writing interfaces.
void close_writing_interfaces()
Close interfaces for writing.
LuaInterfaceImporter(LuaContext *context_, BlackBoard *blackboard, Configuration *config, Logger *logger)
Constructor.
void push_interfaces()
Push interfaces to Lua environment.
void lua_restarted(LuaContext *context)
Lua restart event.
void read_from_buffer()
Update interfaces from internal buffers.
void read_to_buffer()
Read from all reading interfaces into a buffer.
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.
void write()
Write all writing interfaces.
void open_reading_interfaces(std::string &prefix)
Open interfaces for reading.
fawkes::LockMap< std::string, std::list< fawkes::Interface * > > InterfaceListMap
Map of varname to list of interfaces.
Fawkes library namespace.