Subversion Repositories HomeAutomation

Rev

Rev 1657 | Rev 1971 | 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. #include "common/common.h"
  40.  
  41. namespace atom {
  42. namespace control {
  43.  
  44. class Manager : public broker::Subscriber, public timer::Subscriber
  45. {
  46. public:
  47.     typedef boost::shared_ptr<Manager> Pointer;
  48.     typedef std::map<Node::Id, Node::Pointer> NodeList;
  49.     typedef std::map<Module::FullId, Module::Pointer> ModuleList;
  50.     typedef boost::signals2::signal<void(Node::Id, bool available)> SignalOnNodeChange;
  51.     typedef boost::signals2::signal<void(std::string full_id, bool available)> SignalOnModuleChange;
  52.     typedef boost::signals2::signal<void(std::string full_id, std::string command, common::StringMap variables)> SignalOnModuleMessage;
  53.    
  54.     virtual ~Manager();
  55.    
  56.     static Pointer Instance();
  57.     static void Create();
  58.     static void Delete();
  59.    
  60.     void ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_);
  61.     void ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change);
  62.     void ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message);
  63.    
  64.     void SendMessage(std::string full_id, std::string command, common::StringMap variables);
  65.     common::StringList GetAvailableModules();
  66.    
  67.     common::StringList GetAvailableNodes();
  68.     bool ProgramNode(Node::Id node_id, bool is_bios, std::string filename);
  69.     bool ResetNode(Node::Id node_id);
  70.     Node::Information GetNodeInformation(Node::Id node_id);
  71.    
  72. private:
  73.     static Pointer instance_;
  74.    
  75.     timer::TimerId timer_id_;
  76.    
  77.     NodeList nodes_;
  78.     ModuleList modules_;
  79.     Node::Id active_programming_node_id_;
  80.    
  81.     SignalOnNodeChange signal_on_node_change_;
  82.     SignalOnModuleChange signal_on_module_change_;
  83.     SignalOnModuleMessage signal_on_module_message_;
  84.    
  85.     Manager();
  86.    
  87.     void SlotOnMessageHandler(broker::Message::Pointer message);
  88.     void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
  89.     void SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state);
  90.    
  91.     void SendMessageHandler(std::string full_id, std::string command, common::StringMap variables);
  92.    
  93.     Node::Pointer GetNode(Node::Id node_id);
  94.     Module::Pointer GetModule(Module::Id module_id, std::string module_name, std::string class_name);
  95.     void RemoveModules(Node::Id node_id);
  96.     unsigned int GetNumberOfModules(Node::Id node_id);
  97.    
  98.     logging::Logger LOG;
  99. };
  100.  
  101. }; // namespace control
  102. }; // namespace atom
  103.  
  104. #endif // CONTROL_MANAGER_H
  105.