Subversion Repositories HomeAutomation

Rev

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

Rev 1592 Rev 1593
Line 2... Line 2...
2
 
2
 
3
#include <boost/bind.hpp>
3
#include <boost/bind.hpp>
4
 
4
 
5
#include "net/Manager.h"
5
#include "net/Manager.h"
6
#include "net/Types.h"
6
#include "net/Types.h"
-
 
7
 
-
 
8
#include "timer/Manager.h"
-
 
9
#include "timer/Types.h"
-
 
10
 
7
 
11
 
8
using namespace atom;
12
using namespace atom;
-
 
13
 
9
 
14
 
10
net::Manager::Pointer NM = net::Manager::Instance();
15
net::Manager::Pointer NM = net::Manager::Instance();
11
 
16
 
-
 
17
net::ServerId server_id = 0;
-
 
18
timer::TimerId timer_id;
-
 
19
 
12
void Main_SlotOnNewState(net::ClientId client_id, net::ClientState client_state)
20
void Main_SlotOnNewState(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state)
13
{
21
{
14
    std::cout << "client:" << client_id << " - New state: " << client_state << std::endl;
22
    std::cout << "client:" << client_id << " - New state: " << client_state << std::endl;
15
}
23
}
16
 
24
 
17
void Main_SlotOnNewData(net::ClientId client_id, net::Buffer data)
25
void Main_SlotOnNewData(net::ClientId client_id, net::ServerId server_id, net::Buffer data)
18
{
26
{
19
    std::string s(data.data());
27
    std::string s(data.data());
20
   
28
   
21
    std::cout << "client:" << client_id << " - New data: " << s << std::endl;
29
    std::cout << "client:" << client_id << " - New data: " << s << std::endl;
22
   
30
   
23
    net::Buffer out_data = data;
31
    net::Buffer out_data;
24
   
32
   
-
 
33
    strncpy(out_data.c_array(), data.data(), out_data.size());
25
   
34
   
26
    NM->SendTo(client_id, out_data);
35
    NM->SendTo(client_id, out_data);
-
 
36
}
-
 
37
 
-
 
38
void Main_SlotOnTimeout(timer::TimerId timer_id)
-
 
39
{
-
 
40
    std::cout << "timer:" << timer_id << " - expired" << std::endl;
-
 
41
   
-
 
42
    std::string out_string = "Timeout!";
-
 
43
   
-
 
44
    net::Buffer out_data;
-
 
45
   
-
 
46
    strncpy(out_data.c_array(), out_string.data(), out_data.size());
-
 
47
   
-
 
48
    NM->SendToAll(server_id, out_data);
27
}
49
}
28
 
50
 
29
int main(int argc, char **argv)
51
int main(int argc, char **argv)
30
{
52
{
31
    std::cout << "connect slots" << std::endl;
53
    std::cout << "connect slots" << std::endl;
32
   
54
   
-
 
55
    timer::Manager::Pointer TM = timer::Manager::Instance();
-
 
56
   
-
 
57
   
-
 
58
    //TM->Set(10000, true);
-
 
59
   
33
    NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2), boost::bind(&Main_SlotOnNewData, _1, _2));
60
    TM->ConnectSlots(boost::bind(&Main_SlotOnTimeout, _1));
34
   
61
   
-
 
62
   
35
    std::cout << "connect" << std::endl;
63
    std::cout << "connect slots2" << std::endl;
-
 
64
    NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2, _3), boost::bind(&Main_SlotOnNewData, _1, _2, _3));
-
 
65
   
36
   
66
   
37
    try
67
    try
38
    {
68
    {
39
        net::ServerId server_id = NM->StartServer(net::PROTOCOL_TCP, 2000);
69
        server_id = NM->StartServer(net::PROTOCOL_TCP, 2000);
-
 
70
   
-
 
71
        timer_id = TM->Set(10000, true);
-
 
72
       
40
        /*
73
        /*
41
        net::ClientId client_id_udp = NM->Connect(net::PROTOCOL_UDP, "192.168.1.250", 1100);
74
        net::ClientId client_id_udp = NM->Connect(net::PROTOCOL_UDP, "192.168.1.250", 1100);
42
       
75
       
43
        std::cout << "connected" << std::endl;
76
        std::cout << "connected" << std::endl;
44
       
77