Subversion Repositories HomeAutomation

Rev

Rev 1644 | Rev 1887 | Go to most recent revision | 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 "logging/Logger.h"
31
#include "broker/Subscriber.h"
32
 
1601 runge 33
#include "timer/Subscriber.h"
1642 runge 34
#include "common/common.h"
1601 runge 35
 
1598 runge 36
#include "Node.h"
37
#include "Module.h"
1642 runge 38
#include "can/Message.h"
1644 runge 39
#include "common/common.h"
1598 runge 40
 
41
namespace atom {
1642 runge 42
namespace control {
1598 runge 43
 
1601 runge 44
class Manager : public broker::Subscriber, public timer::Subscriber
1598 runge 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;
1657 runge 50
    typedef boost::signals2::signal<void(Node::Id, bool available)> SignalOnNodeChange;
1602 runge 51
    typedef boost::signals2::signal<void(std::string full_id, bool available)> SignalOnModuleChange;
1642 runge 52
    typedef boost::signals2::signal<void(std::string full_id, std::string command, common::StringMap variables)> SignalOnModuleMessage;
1598 runge 53
 
54
    virtual ~Manager();
55
 
56
    static Pointer Instance();
1599 runge 57
    static void Create();
1598 runge 58
    static void Delete();
59
 
1657 runge 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);
1602 runge 63
 
1642 runge 64
    void SendMessage(std::string full_id, std::string command, common::StringMap variables);
1644 runge 65
    common::StringList GetAvailableModules();
1657 runge 66
 
67
    common::StringList GetAvailableNodes();
1642 runge 68
    bool ProgramNode(Node::Id node_id, bool is_bios, std::string filename);
1657 runge 69
    bool ResetNode(Node::Id node_id);
1602 runge 70
 
1598 runge 71
private:
72
    static Pointer instance_;
73
 
1601 runge 74
    timer::TimerId timer_id_;
75
 
1598 runge 76
    NodeList nodes_;
77
    ModuleList modules_;
1633 runge 78
    Node::Id active_programming_node_id_;
1598 runge 79
 
1614 runge 80
    SignalOnNodeChange signal_on_node_change_;
1602 runge 81
    SignalOnModuleChange signal_on_module_change_;
82
    SignalOnModuleMessage signal_on_module_message_;
83
 
1598 runge 84
    Manager();
85
 
86
    void SlotOnMessageHandler(broker::Message::Pointer message);
1601 runge 87
    void SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat);
1627 runge 88
    void SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state);
1598 runge 89
 
1642 runge 90
    void SendMessageHandler(std::string full_id, std::string command, common::StringMap variables);
1604 runge 91
 
1598 runge 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
    logging::Logger LOG;
98
};
99
 
1642 runge 100
}; // namespace control
1598 runge 101
}; // namespace atom
102
 
1642 runge 103
#endif // CONTROL_MANAGER_H