interface_importer.h

00001 
00002 /***************************************************************************
00003  *  interfaceimporter.h - Fawkes Lua Interface Importer
00004  *
00005  *  Created: Thu Jan 01 14:28:47 2009
00006  *  Copyright  2006-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
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 /* just to make Emacs auto-indent happy */
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   /** Map of varname to interface instance. */
00065   typedef fawkes::LockMap<std::string, fawkes::Interface *>  InterfaceMap;
00066   /** Map of varname to list of interfaces */
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 } // end of namespace fawkes
00119 
00120 #endif

Generated on Tue Feb 22 13:31:27 2011 for Fawkes API by  doxygen 1.4.7