Subversion Repositories HomeAutomation

Rev

Rev 1971 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1598 runge 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
 
1642 runge 21
#ifndef CONTROL_MANAGER_H
22
#define CONTROL_MANAGER_H
1598 runge 23
 
24
#include <map>
1602 runge 25
#include <string>
1598 runge 26
 
27
#include <boost/shared_ptr.hpp>
28
#include <boost/signals2.hpp>
29
 
30
#include "broker/Subscriber.h"
31
 
1601 runge 32
#include "timer/Subscriber.h"
1642 runge 33
#include "common/common.h"
1601 runge 34
 
1598 runge 35
#include "Node.h"
36
#include "Module.h"
1642 runge 37
#include "can/Message.h"
1644 runge 38
#include "common/common.h"
1598 runge 39
 
40
namespace atom {
1642 runge 41
namespace control {
1598 runge 42
 
1601 runge 43
class Manager : public broker::Subscriber, public timer::Subscriber
1598 runge 44
{
45
public:
1971 runge 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();
2164 arune 67
  unsigned int GetProgramProgress(Node::Id node_id);
1971 runge 68
  bool ProgramNode(Node::Id node_id, bool is_bios, std::string filename);
69
  bool ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data);
70
  bool ResetNode(Node::Id node_id);
71
  Node::Information GetNodeInformation(Node::Id node_id);
1598 runge 72
 
73
private:
74
    static Pointer instance_;
75
 
1971 runge 76
    timer::TimerId  timer_id_;
77
    NodeList        nodes_;
78
    ModuleList      modules_;
79
    Node::Id        active_programming_node_id_;
1601 runge 80
 
1971 runge 81
    SignalOnNodeChange    signal_on_node_change_;
82
    SignalOnModuleChange  signal_on_module_change_;
1602 runge 83
    SignalOnModuleMessage signal_on_module_message_;
84
 
1598 runge 85
    Manager();
86
 
87
    void SlotOnMessageHandler(broker::Message::Pointer message);
1601 runge 88
    void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
1627 runge 89
    void SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state);
1598 runge 90
 
1642 runge 91
    void SendMessageHandler(std::string full_id, std::string command, common::StringMap variables);
1604 runge 92
 
1598 runge 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
 
1642 runge 99
}; // namespace control
1598 runge 100
}; // namespace atom
101
 
1642 runge 102
#endif // CONTROL_MANAGER_H