Subversion Repositories HomeAutomation

Rev

Rev 1599 | Rev 1642 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1599 Rev 1601
Line 22... Line 22...
22
#define NET_MANAGER_H
22
#define NET_MANAGER_H
23
 
23
 
24
#include <string>
24
#include <string>
25
#include <map>
25
#include <map>
26
 
26
 
27
#include <boost/asio.hpp>
-
 
28
#include <boost/signals2.hpp>
27
#include <boost/signals2.hpp>
29
#include <boost/shared_ptr.hpp>
28
#include <boost/shared_ptr.hpp>
-
 
29
 
30
#include <boost/thread.hpp>
30
#include "common/IoService.h"
31
#include <boost/thread/mutex.hpp>
-
 
32
 
31
 
33
#include "types.h"
32
#include "types.h"
34
#include "Client.h"
33
#include "Client.h"
35
#include "TcpClient.h"
34
#include "TcpClient.h"
36
#include "UdpClient.h"
35
#include "UdpClient.h"
37
#include "SerialClient.h"
36
#include "SerialClient.h"
38
 
37
 
39
namespace atom {
38
namespace atom {
40
namespace net {
39
namespace net {
41
 
40
 
42
class Manager
41
class Manager : virtual common::IoService
43
{
42
{
44
public:
43
public:
45
    typedef boost::shared_ptr<Manager> Pointer;
44
    typedef boost::shared_ptr<Manager> Pointer;
46
 
45
 
47
    typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState;
46
    typedef boost::signals2::signal<void(ClientId, ServerId, ClientState)> SignalOnNewState;
Line 52... Line 51...
52
    static Pointer Instance();
51
    static Pointer Instance();
53
    static void Create();
52
    static void Create();
54
    static void Delete();
53
    static void Delete();
55
   
54
   
56
    void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
55
    void ConnectSlots(const SignalOnNewState::slot_type& slot_on_new_state, const SignalOnNewData::slot_type& slot_on_new_data);
57
   
56
   
58
    ServerId StartServer(Protocol protocol, unsigned int port);
57
    ServerId StartServer(Protocol protocol, unsigned int port);
59
    ClientId Connect(Protocol protocol, std::string address, unsigned int port_or_baud);
58
    ClientId Connect(Protocol protocol, std::string address, unsigned int port_or_baud);
60
   
59
   
61
    void StopServer(ServerId server_id);
60
    void StopServer(ServerId server_id);
62
    void Disconnect(ClientId client_id);
61
    void Disconnect(ClientId client_id);
Line 66... Line 65...
66
 
65
 
67
private:
66
private:
68
    typedef std::map<ClientId, Client::Pointer> ClientList;
67
    typedef std::map<ClientId, Client::Pointer> ClientList;
69
 
68
 
70
    static Pointer instance_;
69
    static Pointer instance_;
71
   
-
 
72
    boost::thread thread_;
-
 
73
    boost::asio::io_service io_service_;
-
 
74
    boost::asio::io_service::work io_service_work_;
-
 
75
   
70
   
76
    ClientList clients_;
71
    ClientList clients_;
77
   
72
   
78
    SignalOnNewState signal_on_new_state_;
73
    SignalOnNewState signal_on_new_state_;
79
    SignalOnNewData signal_on_new_data_;
74
    SignalOnNewData signal_on_new_data_;