Subversion Repositories HomeAutomation

Rev

Rev 1601 | Rev 1604 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  *
  3.  *  Copyright (C) 2010  Mattias Runge
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License along
  16.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  17.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  *
  19.  */
  20.  
  21. #ifndef CAN_MANAGER_H
  22. #define CAN_MANAGER_H
  23.  
  24. #include <map>
  25. #include <string>
  26.  
  27. #include <boost/shared_ptr.hpp>
  28. #include <boost/signals2.hpp>
  29.  
  30. #include "logging/Logger.h"
  31. #include "broker/Subscriber.h"
  32.  
  33. #include "timer/Subscriber.h"
  34. #include "type/common.h"
  35.  
  36. #include "Node.h"
  37. #include "Module.h"
  38. #include "Message.h"
  39.  
  40. namespace atom {
  41. namespace can {
  42.  
  43. class Manager : public broker::Subscriber, public timer::Subscriber
  44. {
  45. public:
  46.     typedef boost::shared_ptr<Manager> Pointer;
  47.     typedef std::map<Node::Id, Node::Pointer> NodeList;
  48.     typedef std::map<Module::FullId, Module::Pointer> ModuleList;
  49.     typedef boost::signals2::signal<void(std::string full_id, bool available)> SignalOnModuleChange;
  50.     typedef boost::signals2::signal<void(std::string full_id, std::string command, type::StringMap variables)> SignalOnModuleMessage;
  51.    
  52.     virtual ~Manager();
  53.    
  54.     static Pointer Instance();
  55.     static void Create();
  56.     static void Delete();
  57.    
  58.     void ConnectSlots(const SignalOnModuleChange::slot_type& slot_on_module_change, const SignalOnModuleMessage::slot_type& slot_on_module_message);
  59.    
  60.     void SendMessage(std::string full_id, std::string command, type::StringMap variables);
  61.    
  62. private:
  63.     static Pointer instance_;
  64.    
  65.     timer::TimerId timer_id_;
  66.    
  67.     NodeList nodes_;
  68.     ModuleList modules_;
  69.    
  70.     SignalOnModuleChange signal_on_module_change_;
  71.     SignalOnModuleMessage signal_on_module_message_;
  72.    
  73.     Manager();
  74.    
  75.     void SlotOnMessageHandler(broker::Message::Pointer message);
  76.     void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
  77.    
  78.     Node::Pointer GetNode(Node::Id node_id);
  79.     Module::Pointer GetModule(Module::Id module_id, std::string module_name, std::string class_name);
  80.     void RemoveModules(Node::Id node_id);
  81.     void RequestModules(Node::Id node_id);
  82.     unsigned int GetNumberOfModules(Node::Id node_id);
  83.    
  84.     logging::Logger LOG;
  85. };
  86.  
  87. }; // namespace can
  88. }; // namespace atom
  89.  
  90. #endif // CAN_MANAGER_H
  91.