Subversion Repositories HomeAutomation

Rev

Rev 1633 | Rev 1644 | 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 CONTROL_MANAGER_H
  22. #define CONTROL_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 "common/common.h"
  35.  
  36. #include "Node.h"
  37. #include "Module.h"
  38. #include "can/Message.h"
  39.  
  40. namespace atom {
  41. namespace control {
  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(unsigned int node_id, bool available)> SignalOnNodeChange;
  50.     typedef boost::signals2::signal<void(std::string full_id, bool available)> SignalOnModuleChange;
  51.     typedef boost::signals2::signal<void(std::string full_id, std::string command, common::StringMap variables)> SignalOnModuleMessage;
  52.    
  53.     virtual ~Manager();
  54.    
  55.     static Pointer Instance();
  56.     static void Create();
  57.     static void Delete();
  58.    
  59.     void ConnectSlots(const SignalOnNodeChange::slot_type& signal_on_node_change_, const SignalOnModuleChange::slot_type& slot_on_module_change, const SignalOnModuleMessage::slot_type& slot_on_module_message);
  60.    
  61.     void SendMessage(std::string full_id, std::string command, common::StringMap variables);
  62.     bool IsModuleAvailable(std::string full_id);
  63.     bool ProgramNode(Node::Id node_id, bool is_bios, std::string filename);
  64.    
  65. private:
  66.     static Pointer instance_;
  67.    
  68.     timer::TimerId timer_id_;
  69.    
  70.     NodeList nodes_;
  71.     ModuleList modules_;
  72.     Node::Id active_programming_node_id_;
  73.    
  74.     SignalOnNodeChange signal_on_node_change_;
  75.     SignalOnModuleChange signal_on_module_change_;
  76.     SignalOnModuleMessage signal_on_module_message_;
  77.    
  78.     Manager();
  79.    
  80.     void SlotOnMessageHandler(broker::Message::Pointer message);
  81.     void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
  82.     void SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state);
  83.    
  84.     void SendMessageHandler(std::string full_id, std::string command, common::StringMap variables);
  85.    
  86.     Node::Pointer GetNode(Node::Id node_id);
  87.     Module::Pointer GetModule(Module::Id module_id, std::string module_name, std::string class_name);
  88.     void RemoveModules(Node::Id node_id);
  89.     unsigned int GetNumberOfModules(Node::Id node_id);
  90.    
  91.     logging::Logger LOG;
  92. };
  93.  
  94. }; // namespace control
  95. }; // namespace atom
  96.  
  97. #endif // CONTROL_MANAGER_H
  98.