Subversion Repositories HomeAutomation

Rev

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

Rev 1593 Rev 1594
Line 1... Line 1...
1
#include <iostream>
1
#include <iostream>
-
 
2
#include <fstream>
-
 
3
#include <vector>
-
 
4
#include <string>
2
 
5
 
3
#include <boost/bind.hpp>
6
#include <boost/bind.hpp>
-
 
7
#include <boost/program_options.hpp>
4
 
8
 
5
#include "net/Manager.h"
9
#include "net/Manager.h"
6
#include "net/Types.h"
10
#include "net/Types.h"
7
 
11
 
8
#include "timer/Manager.h"
12
#include "timer/Manager.h"
9
#include "timer/Types.h"
13
#include "timer/Types.h"
10
 
14
 
-
 
15
#include "config/Manager.h"
-
 
16
 
-
 
17
#include "logging/Logger.h"
11
 
18
 
12
using namespace atom;
19
using namespace atom;
13
 
20
 
14
 
21
 
15
net::Manager::Pointer NM = net::Manager::Instance();
22
net::Manager::Pointer NM = net::Manager::Instance();
Line 25... Line 32...
25
void Main_SlotOnNewData(net::ClientId client_id, net::ServerId server_id, net::Buffer data)
32
void Main_SlotOnNewData(net::ClientId client_id, net::ServerId server_id, net::Buffer data)
26
{
33
{
27
    std::string s(data.data());
34
    std::string s(data.data());
28
   
35
   
29
    std::cout << "client:" << client_id << " - New data: " << s << std::endl;
36
    std::cout << "client:" << client_id << " - New data: " << s << std::endl;
30
   
37
   
31
    net::Buffer out_data;
38
    net::Buffer out_data;
32
   
39
   
33
    strncpy(out_data.c_array(), data.data(), out_data.size());
40
    strncpy(out_data.c_array(), data.data(), out_data.size());
34
   
41
   
35
    NM->SendTo(client_id, out_data);
42
    NM->SendTo(client_id, out_data);
36
}
43
}
37
 
44
 
38
void Main_SlotOnTimeout(timer::TimerId timer_id)
45
void Main_SlotOnTimeout(timer::TimerId timer_id)
39
{
46
{
40
    std::cout << "timer:" << timer_id << " - expired" << std::endl;
47
    std::cout << "timer:" << timer_id << " - expired" << std::endl;
41
   
48
   
42
    std::string out_string = "Timeout!";
49
    std::string out_string = "Timeout!";
43
   
50
   
44
    net::Buffer out_data;
51
    net::Buffer out_data;
45
   
52
   
46
    strncpy(out_data.c_array(), out_string.data(), out_data.size());
53
    strncpy(out_data.c_array(), out_string.data(), out_data.size());
47
   
54
   
48
    NM->SendToAll(server_id, out_data);
55
    NM->SendToAll(server_id, out_data);
49
}
56
}
50
 
57
 
51
int main(int argc, char **argv)
58
int main(int argc, char **argv)
52
{
59
{
-
 
60
    logging::Logger LOG("Main");
-
 
61
 
-
 
62
    config::Manager::Pointer CM = config::Manager::Instance();
-
 
63
   
-
 
64
    if (!CM->Set(argc, argv))
-
 
65
    {
-
 
66
        return 0;
-
 
67
    }
-
 
68
   
-
 
69
    if (CM->Exist("MonitorPort"))
-
 
70
    {
-
 
71
        LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(CM->GetAsInt("MonitorPort")));
-
 
72
    }
-
 
73
   
-
 
74
    if (CM->Exist("CanNet"))
-
 
75
    {
-
 
76
        std::vector<std::string> cannets = CM->GetAsStringVector("CanNet");
-
 
77
       
-
 
78
        for (int n = 0; n < cannets.size(); n++)
-
 
79
        {
-
 
80
            LOG.Info("CanNet[" + boost::lexical_cast<std::string>(n) + "]=" + cannets[n]);
-
 
81
        }
-
 
82
       
-
 
83
    }
-
 
84
    LOG.Info("Done!");
-
 
85
   
-
 
86
    return 0;
-
 
87
   
-
 
88
    // Declare a group of options that will be
-
 
89
    // allowed only on command line
-
 
90
    boost::program_options::options_description generic("Generic options");
-
 
91
    generic.add_options()   ("version,v", "print version string")
-
 
92
    ("help", "produce help message");
-
 
93
   
53
    std::cout << "connect slots" << std::endl;
94
    // Declare a group of options that will be
-
 
95
    // allowed both on command line and in
-
 
96
    // config file
-
 
97
    boost::program_options::options_description config("Configuration");
-
 
98
    config.add_options()
-
 
99
                        ("MonitorPort", boost::program_options::value<int>()->default_value(2000), "TCP port to expose for monitoring")
-
 
100
                        ("CommandPort", boost::program_options::value<int>()->default_value(2001), "TCP port to expose for monitoring")
-
 
101
                        ("LogFile", boost::program_options::value<std::string>(), "File to log output to")
-
 
102
                        ("ScriptsPath", boost::program_options::value<std::string>(), "File to log output to")
-
 
103
                        ("ProtocolFile", boost::program_options::value<std::string>(), "File to log output to")
-
 
104
                        ("DaemonMode,D", "File to log output to")
-
 
105
                        ("CanNet_1", boost::program_options::value<std::vector<std::string> >(), "include path");
-
 
106
   
-
 
107
   LOG.Debug("a");
-
 
108
    boost::program_options::options_description cmdline_options;
-
 
109
    cmdline_options.add(generic).add(config);
-
 
110
   
-
 
111
    boost::program_options::options_description config_file_options;
-
 
112
    config_file_options.add(config);
-
 
113
   
-
 
114
    boost::program_options::options_description visible("Allowed options");
-
 
115
    visible.add(generic).add(config);
-
 
116
   
-
 
117
       
-
 
118
    boost::program_options::variables_map vm;
-
 
119
    store(boost::program_options::command_line_parser(argc, argv).options(cmdline_options).run(), vm);
-
 
120
    LOG.Debug("b");
-
 
121
    std::ifstream ifs("atom.conf");
-
 
122
    store(parse_config_file(ifs, config_file_options), vm);
-
 
123
    notify(vm);
-
 
124
   
-
 
125
    LOG.Debug("c");
-
 
126
   
-
 
127
    if (vm.count("help"))
-
 
128
    {
-
 
129
        LOG.Info("Help");
-
 
130
    }
-
 
131
   
-
 
132
    if (vm.count("MonitorPort"))
-
 
133
    {
-
 
134
        LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(vm["MonitorPort"].as<int>()));
-
 
135
    }
-
 
136
   
-
 
137
    if (vm.count("LogFile"))
-
 
138
    {
-
 
139
        LOG.Info("LogFile: " + vm["LogFile"].as<std::string>());
-
 
140
    }
-
 
141
   
-
 
142
    if (vm.count("DaemonMode"))
-
 
143
    {
-
 
144
        LOG.Info("DaemonMode: " + vm["DaemonMode"].as<std::string>());
-
 
145
    }
-
 
146
 
-
 
147
   
-
 
148
   
-
 
149
   
-
 
150
   
-
 
151
   
-
 
152
   
-
 
153
   
-
 
154
   
-
 
155
   
-
 
156
   
-
 
157
    net::Manager::Delete();
-
 
158
   
-
 
159
   
-
 
160
   
-
 
161
   
-
 
162
    return 0;
54
   
163
   
-
 
164
    LOG.Error("test sdsdsds sds ");
-
 
165
    return 0;
55
    timer::Manager::Pointer TM = timer::Manager::Instance();
166
    timer::Manager::Pointer TM = timer::Manager::Instance();
56
   
167
   
57
   
168
   
58
    //TM->Set(10000, true);
169
    //TM->Set(10000, true);
59
   
170