Subversion Repositories HomeAutomation

Rev

Rev 1602 | Rev 1614 | 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.     bool IsModuleAvailable(std::string full_id);
  62.    
  63. private:
  64.     static Pointer instance_;
  65.    
  66.     timer::TimerId timer_id_;
  67.    
  68.     NodeList nodes_;
  69.     ModuleList modules_;
  70.    
  71.     SignalOnModuleChange signal_on_module_change_;
  72.     SignalOnModuleMessage signal_on_module_message_;
  73.    
  74.     Manager();
  75.    
  76.     void SlotOnMessageHandler(broker::Message::Pointer message);
  77.     void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
  78.    
  79.     void SendMessageHandler(std::string full_id, std::string command, type::StringMap variables);
  80.    
  81.     Node::Pointer GetNode(Node::Id node_id);
  82.     Module::Pointer GetModule(Module::Id module_id, std::string module_name, std::string class_name);
  83.     void RemoveModules(Node::Id node_id);
  84.     void RequestModules(Node::Id node_id);
  85.     unsigned int GetNumberOfModules(Node::Id node_id);
  86.    
  87.     logging::Logger LOG;
  88. };
  89.  
  90. }; // namespace can
  91. }; // namespace atom
  92.  
  93. #endif // CAN_MANAGER_H
  94.