Subversion Repositories HomeAutomation

Rev

Rev 1601 | Rev 1939 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1592 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
 
21
#ifndef NET_MANAGER_H
22
#define NET_MANAGER_H
23
 
24
#include <string>
25
#include <map>
26
 
27
#include <boost/signals2.hpp>
1593 runge 28
#include <boost/shared_ptr.hpp>
1592 runge 29
 
1601 runge 30
#include "common/IoService.h"
31
 
1595 runge 32
#include "types.h"
1592 runge 33
#include "Client.h"
34
#include "TcpClient.h"
35
#include "UdpClient.h"
36
#include "SerialClient.h"
37
 
38
namespace atom {
39
namespace net {
40
 
1601 runge 41
class Manager : virtual common::IoService
1592 runge 42
{
43
public:
44
    typedef boost::shared_ptr<Manager> Pointer;
45
 
1593 runge 46
    typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState;
1642 runge 47
    typedef boost::signals2::signal<void(ClientId, ServerId, common::Byteset)> SignalOnNewData;
1592 runge 48
 
49
    virtual ~Manager();
1599 runge 50
 
1592 runge 51
    static Pointer Instance();
1599 runge 52
    static void Create();
1592 runge 53
    static void Delete();
54
 
55
    void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
56
 
57
    ServerId StartServer(Protocol protocol, unsigned int port);
58
    ClientId Connect(Protocol protocol, std::string address, unsigned int port_or_baud);
59
 
60
    void StopServer(ServerId server_id);
61
    void Disconnect(ClientId client_id);
62
 
1642 runge 63
    void SendToAll(ServerId server_id, common::Byteset data);
64
    void SendTo(ClientId client_id, common::Byteset data);
1592 runge 65
 
66
private:
67
    typedef std::map<ClientId, Client::Pointer> ClientList;
68
 
69
    static Pointer instance_;
70
 
71
    ClientList clients_;
72
 
73
    SignalOnNewState signal_on_new_state_;
74
    SignalOnNewData signal_on_new_data_;
75
 
76
    Manager();
77
 
1593 runge 78
    void SlotOnNewState(ClientId client_id, ServerId server_id, ClientState client_state);
1642 runge 79
    void SlotOnNewData(ClientId client_id, ServerId server_id, common::Byteset data);
1592 runge 80
 
81
    void StopServerHandler(ServerId server_id);
82
    void DisconnectHandler(ClientId client_id);
83
 
1642 runge 84
    void SendToAllHandler(ServerId server_id, common::Byteset data);
85
    void SendToHandler(ClientId client_id, common::Byteset data);
1592 runge 86
 
87
    ClientId GetFreeClientId();
88
    ServerId GetFreeServerId();
89
};
90
 
91
}; // namespace net
92
}; // namespace atom
93
 
94
#endif // NET_MANAGER_H