Subversion Repositories HomeAutomation

Rev

Rev 1887 | 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 "broker/Subscriber.h"
  31.  
  32. #include "timer/Subscriber.h"
  33. #include "common/common.h"
  34.  
  35. #include "Node.h"
  36. #include "Module.h"
  37. #include "can/Message.h"
  38. #include "common/common.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(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 ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_);
  60.   void ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change);
  61.   void ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message);
  62.  
  63.   void SendMessage(std::string full_id, std::string command, common::StringMap variables);
  64.   common::StringList GetAvailableModules();
  65.  
  66.   common::StringList GetAvailableNodes();
  67.   bool ProgramNode(Node::Id node_id, bool is_bios, std::string filename);
  68.   bool ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data);
  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.     NodeList        nodes_;
  77.     ModuleList      modules_;
  78.     Node::Id        active_programming_node_id_;
  79.    
  80.     SignalOnNodeChange    signal_on_node_change_;
  81.     SignalOnModuleChange  signal_on_module_change_;
  82.     SignalOnModuleMessage signal_on_module_message_;
  83.    
  84.     Manager();
  85.    
  86.     void SlotOnMessageHandler(broker::Message::Pointer message);
  87.     void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
  88.     void SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state);
  89.    
  90.     void SendMessageHandler(std::string full_id, std::string command, common::StringMap variables);
  91.    
  92.     Node::Pointer GetNode(Node::Id node_id);
  93.     Module::Pointer GetModule(Module::Id module_id, std::string module_name, std::string class_name);
  94.     void RemoveModules(Node::Id node_id);
  95.     unsigned int GetNumberOfModules(Node::Id node_id);
  96. };
  97.  
  98. }; // namespace control
  99. }; // namespace atom
  100.  
  101. #endif // CONTROL_MANAGER_H
  102.