Rev 1318 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1318 | Rev 1319 | ||
|---|---|---|---|
| 1 | //============================================================================ |
1 | //============================================================================ |
| 2 | // Name : Atom.cpp |
2 | // Name : Atom.cpp |
| 3 | // Author : Mattias Runge |
3 | // Author : Mattias Runge |
| 4 | // Version : 2.0 |
4 | // Version : 2.0 |
| 5 | // Copyright : GPL |
5 | // Copyright : GPL |
| 6 | //============================================================================ |
6 | //============================================================================ |
| 7 | 7 | ||
| 8 | #include <iostream> |
8 | #include <iostream> |
| 9 | #include <istream> |
9 | #include <istream> |
| 10 | #include <ostream> |
10 | #include <ostream> |
| 11 | #include <string> |
11 | #include <string> |
| 12 | #include <fstream> |
12 | #include <fstream> |
| 13 | #include <iterator> |
13 | #include <iterator> |
| 14 | 14 | ||
| 15 | #include <stdio.h> |
15 | #include <stdio.h> |
| 16 | 16 | ||
| 17 | #include "version.h" |
17 | #include "version.h" |
| 18 | #include <boost/asio.hpp> |
18 | #include <boost/asio.hpp> |
| 19 | #include <boost/bind.hpp> |
19 | #include <boost/bind.hpp> |
| 20 | #include <boost/foreach.hpp> |
20 | #include <boost/foreach.hpp> |
| 21 | #include <boost/program_options.hpp> |
21 | #include <boost/program_options.hpp> |
| 22 | #include "broker/Broker.h" |
22 | #include "broker/Broker.h" |
| 23 | #include "message/Message.h" |
23 | #include "message/Message.h" |
| 24 | #include "subscribers/monitor/Monitor.h" |
24 | #include "subscribers/monitor/Monitor.h" |
| 25 | #include "subscribers/cannet/CanNet.h" |
25 | #include "subscribers/cannet/CanNet.h" |
| 26 | #include "xml/Node.h" |
26 | #include "xml/Node.h" |
| 27 | #include "thread/Thread.h" |
27 | #include "thread/Thread.h" |
| 28 | #include "utils/BitBuffer.h" |
- | |
| 29 | #include "net/UdpServer.h" |
28 | #include "net/UdpServer.h" |
| 30 | #include "xml/Node.h" |
29 | #include "xml/Node.h" |
| 31 | #include "protocol/Protocol.h" |
30 | #include "protocol/Protocol.h" |
| 32 | #include "log/Logger.h" |
31 | #include "log/Logger.h" |
| 33 | 32 | ||
| 34 | namespace po = boost::program_options; |
33 | namespace po = boost::program_options; |
| 35 | 34 | ||
| 36 | #define foreach BOOST_FOREACH |
35 | #define foreach BOOST_FOREACH |
| 37 | #define reverse_foreach BOOST_REVERSE_FOREACH |
36 | #define reverse_foreach BOOST_REVERSE_FOREACH |
| 38 | using namespace std; |
37 | using namespace std; |
| 39 | 38 | ||
| 40 | 39 | ||
| 41 | using namespace atom; |
40 | using namespace atom; |
| 42 | 41 | ||
| 43 | int main(int argc, char* argv[]) |
42 | int main(int argc, char* argv[]) |
| 44 | { |
43 | { |
| 45 | log::Logger LOG; |
44 | log::Logger LOG; |
| 46 | LOG.setName("Main"); |
45 | LOG.setName("Main"); |
| 47 | 46 | ||
| 48 | LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")"); |
47 | LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")"); |
| 49 | LOG.info("Written by Mattias Runge 2009"); |
48 | LOG.info("Written by Mattias Runge 2009"); |
| 50 | 49 | ||
| 51 | 50 | ||
| 52 | 51 | ||
| 53 | Protocol::pointer protocol = Protocol::getInstance(); |
52 | Protocol::pointer protocol = Protocol::getInstance(); |
| 54 | protocol->load("../../Configuration/protocol.xml"); |
53 | protocol->load("../../Configuration/protocol.xml"); |
| 55 | cout << protocol->getRootNode().toString() << endl; |
54 | cout << protocol->getRootNode().toString() << endl; |
| 56 | 55 | ||
| 57 | 56 | ||
| 58 | broker::Broker::pointer broker = broker::Broker::getInstance(); |
57 | broker::Broker::pointer broker = broker::Broker::getInstance(); |
| 59 | 58 | ||
| 60 | subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker)); |
59 | subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker)); |
| 61 | subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100)); |
60 | subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100)); |
| 62 | 61 | ||
| 63 | 62 | ||
| 64 | sleep(10000000); |
63 | sleep(10000000); |
| 65 | 64 | ||
| 66 | 65 | ||
| 67 | return 0; |
66 | return 0; |
| 68 | //udpSubscriber->write(utils::BitBuffer(startPacket)); |
67 | //udpSubscriber->write(utils::BitBuffer(startPacket)); |
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | cout << "ABC123" << endl; |
70 | cout << "ABC123" << endl; |
| 72 | 71 | ||
| 73 | return 0; |
72 | return 0; |
| 74 | /*sleep(1); |
73 | /*sleep(1); |
| 75 | 74 | ||
| 76 | messagebroker::Message message(""); |
75 | messagebroker::Message message(""); |
| 77 | 76 | ||
| 78 | 77 | ||
| 79 | message.data = "test1"; |
78 | message.data = "test1"; |
| 80 | broker.put(message); |
79 | broker.put(message); |
| 81 | 80 | ||
| 82 | message.setOrigin(monitorSubscriber); |
81 | message.setOrigin(monitorSubscriber); |
| 83 | message.data = "test2"; |
82 | message.data = "test2"; |
| 84 | broker.put(message); |
83 | broker.put(message); |
| 85 | sleep(1); |
84 | sleep(1); |
| 86 | delete monitorSubscriber; |
85 | delete monitorSubscriber; |
| 87 | 86 | ||
| 88 | message.data = "test3"; |
87 | message.data = "test3"; |
| 89 | broker.put(message); |
88 | broker.put(message); |
| 90 | sleep(1); |
89 | sleep(1); |
| 91 | delete udpSubscriber; |
90 | delete udpSubscriber; |
| 92 | 91 | ||
| 93 | 92 | ||
| 94 | try |
93 | try |
| 95 | { |
94 | { |
| 96 | // Declare a group of options that will be |
95 | // Declare a group of options that will be |
| 97 | // allowed only on command line |
96 | // allowed only on command line |
| 98 | po::options_description generic("Generic options"); |
97 | po::options_description generic("Generic options"); |
| 99 | generic.add_options() ("version,v", "print version string") |
98 | generic.add_options() ("version,v", "print version string") |
| 100 | ("help", "produce help message"); |
99 | ("help", "produce help message"); |
| 101 | 100 | ||
| 102 | // Declare a group of options that will be |
101 | // Declare a group of options that will be |
| 103 | // allowed both on command line and in |
102 | // allowed both on command line and in |
| 104 | // config file |
103 | // config file |
| 105 | po::options_description config("Configuration"); |
104 | po::options_description config("Configuration"); |
| 106 | config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level") |
105 | config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level") |
| 107 | ("include-path,I", po::value<vector<string> >()->composing(), "include path"); |
106 | ("include-path,I", po::value<vector<string> >()->composing(), "include path"); |
| 108 | 107 | ||
| 109 | // Hidden options, will be allowed both on command line and |
108 | // Hidden options, will be allowed both on command line and |
| 110 | // in config file, but will not be shown to the user. |
109 | // in config file, but will not be shown to the user. |
| 111 | po::options_description hidden("Hidden options"); |
110 | po::options_description hidden("Hidden options"); |
| 112 | hidden.add_options()("input-file", po::value<vector<string> >(), "input file"); |
111 | hidden.add_options()("input-file", po::value<vector<string> >(), "input file"); |
| 113 | 112 | ||
| 114 | po::options_description cmdline_options; |
113 | po::options_description cmdline_options; |
| 115 | cmdline_options.add(generic).add(config).add(hidden); |
114 | cmdline_options.add(generic).add(config).add(hidden); |
| 116 | 115 | ||
| 117 | po::options_description config_file_options; |
116 | po::options_description config_file_options; |
| 118 | config_file_options.add(config).add(hidden); |
117 | config_file_options.add(config).add(hidden); |
| 119 | 118 | ||
| 120 | po::options_description visible("Allowed options"); |
119 | po::options_description visible("Allowed options"); |
| 121 | visible.add(generic).add(config); |
120 | visible.add(generic).add(config); |
| 122 | 121 | ||
| 123 | po::positional_options_description p; |
122 | po::positional_options_description p; |
| 124 | p.add("input-file", -1); |
123 | p.add("input-file", -1); |
| 125 | 124 | ||
| 126 | po::variables_map vm; |
125 | po::variables_map vm; |
| 127 | store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
126 | store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
| 128 | 127 | ||
| 129 | ifstream ifs("multiple_sources.cfg"); |
128 | ifstream ifs("multiple_sources.cfg"); |
| 130 | store(parse_config_file(ifs, config_file_options), vm); |
129 | store(parse_config_file(ifs, config_file_options), vm); |
| 131 | notify(vm); |
130 | notify(vm); |
| 132 | 131 | ||
| 133 | if (vm.count("help")) |
132 | if (vm.count("help")) |
| 134 | { |
133 | { |
| 135 | cout << visible << "\n"; |
134 | cout << visible << "\n"; |
| 136 | return 0; |
135 | return 0; |
| 137 | } |
136 | } |
| 138 | 137 | ||
| 139 | if (vm.count("version")) |
138 | if (vm.count("version")) |
| 140 | { |
139 | { |
| 141 | cout << "Multiple sources example, version 1.0\n"; |
140 | cout << "Multiple sources example, version 1.0\n"; |
| 142 | return 0; |
141 | return 0; |
| 143 | } |
142 | } |
| 144 | 143 | ||
| 145 | if (vm.count("include-path")) |
144 | if (vm.count("include-path")) |
| 146 | { |
145 | { |
| 147 | //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n"; |
146 | //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n"; |
| 148 | } |
147 | } |
| 149 | 148 | ||
| 150 | if (vm.count("input-file")) |
149 | if (vm.count("input-file")) |
| 151 | { |
150 | { |
| 152 | //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n"; |
151 | //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n"; |
| 153 | } |
152 | } |
| 154 | 153 | ||
| 155 | //cout << "Optimization level is " << opt << "\n"; |
154 | //cout << "Optimization level is " << opt << "\n"; |
| 156 | 155 | ||
| 157 | */ |
156 | */ |
| 158 | /*if (argc != 3) |
157 | /*if (argc != 3) |
| 159 | { |
158 | { |
| 160 | std::cout << "Usage: async_client <server> <path>\n"; |
159 | std::cout << "Usage: async_client <server> <path>\n"; |
| 161 | std::cout << "Example:\n"; |
160 | std::cout << "Example:\n"; |
| 162 | std::cout << " async_client www.boost.org /LICENSE_1_0.txt\n"; |
161 | std::cout << " async_client www.boost.org /LICENSE_1_0.txt\n"; |
| 163 | return 1; |
162 | return 1; |
| 164 | } |
163 | } |
| 165 | 164 | ||
| 166 | boost::asio::io_service io_service; |
165 | boost::asio::io_service io_service; |
| 167 | client c(io_service, argv[1], argv[2]); |
166 | client c(io_service, argv[1], argv[2]); |
| 168 | io_service.run();*/ |
167 | io_service.run();*/ |
| 169 | /* |
168 | /* |
| 170 | std::string hello( "Hello, world!" ); |
169 | std::string hello( "Hello, world!" ); |
| 171 | 170 | ||
| 172 | foreach( char ch, hello ) |
171 | foreach( char ch, hello ) |
| 173 | { |
172 | { |
| 174 | std::cout << ch; |
173 | std::cout << ch; |
| 175 | } |
174 | } |
| 176 | 175 | ||
| 177 | } |
176 | } |
| 178 | catch (std::exception& e) |
177 | catch (std::exception& e) |
| 179 | { |
178 | { |
| 180 | std::cout << "Exception: " << e.what() << "\n"; |
179 | std::cout << "Exception: " << e.what() << "\n"; |
| 181 | } |
180 | } |
| 182 | */ |
181 | */ |
| 183 | return 0; |
182 | return 0; |
| 184 | } |
183 | } |
| 185 | 184 | ||