Rev 1326 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1326 | Rev 1328 | ||
|---|---|---|---|
| 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/Header.h" |
23 | #include "message/Header.h" |
| 24 | #include "message/Message.h" |
24 | #include "message/Message.h" |
| 25 | #include "subscribers/monitor/Monitor.h" |
25 | #include "subscribers/monitor/Monitor.h" |
| 26 | #include "subscribers/cannet/CanNet.h" |
26 | #include "subscribers/cannet/CanNet.h" |
| 27 | #include "xml/Node.h" |
27 | #include "xml/Node.h" |
| 28 | #include "thread/Thread.h" |
28 | #include "thread/Thread.h" |
| 29 | #include "net/UdpServer.h" |
29 | #include "net/UdpServer.h" |
| 30 | #include "xml/Node.h" |
30 | #include "xml/Node.h" |
| 31 | #include "protocol/Protocol.h" |
31 | #include "protocol/Protocol.h" |
| 32 | #include "log/Logger.h" |
32 | #include "log/Logger.h" |
| 33 | #include "Exception.hpp" |
33 | #include "Exception.hpp" |
| 34 | 34 | ||
| 35 | namespace po = boost::program_options; |
35 | namespace po = boost::program_options; |
| 36 | 36 | ||
| 37 | #define foreach BOOST_FOREACH |
37 | #define foreach BOOST_FOREACH |
| 38 | #define reverse_foreach BOOST_REVERSE_FOREACH |
38 | #define reverse_foreach BOOST_REVERSE_FOREACH |
| 39 | using namespace std; |
39 | using namespace std; |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | using namespace atom; |
42 | using namespace atom; |
| - | 43 | /* |
|
| - | 44 | # |
|
| - | 45 | #include <unistd.h> |
|
| 43 | 46 | ||
| - | 47 | # |
|
| - | 48 | #include <stdlib.h>// for MAX_PATH |
|
| - | 49 | # |
|
| - | 50 | #include <iostream> // for cout and cin |
|
| - | 51 | # |
|
| - | 52 | ||
| - | 53 | # |
|
| - | 54 | using namespace std; |
|
| - | 55 | # |
|
| - | 56 | // function to return the current working directory |
|
| - | 57 | # |
|
| - | 58 | // this is generally the application path |
|
| - | 59 | # |
|
| - | 60 | void GetCurrentPath(char* buffer) |
|
| - | 61 | # |
|
| - | 62 | { |
|
| - | 63 | # |
|
| - | 64 | getcwd(buffer, 1024); |
|
| - | 65 | # |
|
| - | 66 | } |
|
| - | 67 | # |
|
| - | 68 | ||
| - | 69 | # |
|
| - | 70 | int main() |
|
| - | 71 | # |
|
| - | 72 | { |
|
| - | 73 | # |
|
| - | 74 | ||
| - | 75 | # |
|
| - | 76 | // _MAX_PATH is the maximum length allowed for a path |
|
| - | 77 | # |
|
| - | 78 | char CurrentPath[1024]; |
|
| - | 79 | # |
|
| - | 80 | // use the function to get the path |
|
| - | 81 | # |
|
| - | 82 | GetCurrentPath(CurrentPath); |
|
| - | 83 | # |
|
| - | 84 | ||
| - | 85 | # |
|
| - | 86 | // display the path for demo purposes only |
|
| - | 87 | # |
|
| - | 88 | char temp[1024]; |
|
| - | 89 | # |
|
| - | 90 | cout << CurrentPath << endl; |
|
| - | 91 | # |
|
| - | 92 | cout << "Press Enter to continue"; |
|
| - | 93 | # |
|
| - | 94 | cin.getline(temp,1024); |
|
| - | 95 | # |
|
| - | 96 | return 0; |
|
| - | 97 | # |
|
| - | 98 | } |
|
| - | 99 | */ |
|
| 44 | int main(int argc, char* argv[]) |
100 | int main(int argc, char* argv[]) |
| 45 | { |
101 | { |
| 46 | try |
102 | try |
| 47 | { |
103 | { |
| 48 | log::Logger LOG; |
104 | log::Logger LOG; |
| 49 | LOG.setName("Main"); |
105 | LOG.setName("Main"); |
| 50 | 106 | ||
| 51 | LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")"); |
107 | LOG.info("Atom (" + string(AutoVersion::FULLVERSION_STRING) + " " + string(AutoVersion::STATUS) + ")"); |
| 52 | LOG.info("Written by Mattias Runge 2009"); |
108 | LOG.info("Written by Mattias Runge 2009"); |
| 53 | 109 | ||
| 54 | Protocol::getInstance()->load("../../Configuration/protocol.xml", "../../Configuration/protocol-cache.xml"); |
110 | Protocol::getInstance()->load("../../Configuration/protocol.xml", "../../Configuration/protocol-cache.xml"); |
| 55 | 111 | ||
| 56 | broker::Broker::pointer broker = broker::Broker::getInstance(); |
112 | broker::Broker::pointer broker = broker::Broker::getInstance(); |
| 57 | 113 | ||
| 58 | subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker)); |
114 | subscribers::Monitor::pointer monitorSubscriber(new subscribers::Monitor(broker)); |
| 59 |
|
115 | subscribers::CanNet::pointer canNetSubscriber(new subscribers::CanNet(broker, "192.168.1.250", 1100)); |
| 60 | 116 | ||
| 61 | LOG. |
117 | /*LOG.info("Will now try to send a message..."); |
| 62 | 118 | ||
| 63 | message::Header header(0, "irTranceiver", "temperature"); |
119 | message::Header header(0, "irTranceiver", "temperature"); |
| 64 | 120 | ||
| 65 | LOG.info("Header constructed..."); |
121 | LOG.info("Header constructed..."); |
| 66 | 122 | ||
| 67 | message::Message::pointer message(new message::Message(header)); |
123 | message::Message::pointer message(new message::Message(header)); |
| 68 | 124 | ||
| 69 | LOG.info("Message constructed..."); |
125 | LOG.info("Message constructed..."); |
| 70 | 126 | ||
| 71 | broker |
127 | broker->put(message);*/ |
| 72 | 128 | ||
| 73 | sleep(10000000); |
129 | sleep(10000000); |
| 74 | } |
130 | } |
| 75 | catch (Exception * e) |
131 | catch (Exception * e) |
| 76 | { |
132 | { |
| 77 | cout << "Exception: " << e->getDescription() << endl; |
133 | cout << "Exception: " << e->getDescription() << endl; |
| 78 | } |
134 | } |
| 79 | 135 | ||
| 80 | 136 | ||
| 81 | 137 | ||
| 82 | 138 | ||
| 83 | return 0; |
139 | return 0; |
| 84 | //udpSubscriber->write(utils::BitBuffer(startPacket)); |
140 | //udpSubscriber->write(utils::BitBuffer(startPacket)); |
| 85 | 141 | ||
| 86 | 142 | ||
| 87 | cout << "ABC123" << endl; |
143 | cout << "ABC123" << endl; |
| 88 | 144 | ||
| 89 | return 0; |
145 | return 0; |
| 90 | /*sleep(1); |
146 | /*sleep(1); |
| 91 | 147 | ||
| 92 | messagebroker::Message message(""); |
148 | messagebroker::Message message(""); |
| 93 | 149 | ||
| 94 | 150 | ||
| 95 | message.data = "test1"; |
151 | message.data = "test1"; |
| 96 | broker.put(message); |
152 | broker.put(message); |
| 97 | 153 | ||
| 98 | message.setOrigin(monitorSubscriber); |
154 | message.setOrigin(monitorSubscriber); |
| 99 | message.data = "test2"; |
155 | message.data = "test2"; |
| 100 | broker.put(message); |
156 | broker.put(message); |
| 101 | sleep(1); |
157 | sleep(1); |
| 102 | delete monitorSubscriber; |
158 | delete monitorSubscriber; |
| 103 | 159 | ||
| 104 | message.data = "test3"; |
160 | message.data = "test3"; |
| 105 | broker.put(message); |
161 | broker.put(message); |
| 106 | sleep(1); |
162 | sleep(1); |
| 107 | delete udpSubscriber; |
163 | delete udpSubscriber; |
| 108 | 164 | ||
| 109 | 165 | ||
| 110 | try |
166 | try |
| 111 | { |
167 | { |
| 112 | // Declare a group of options that will be |
168 | // Declare a group of options that will be |
| 113 | // allowed only on command line |
169 | // allowed only on command line |
| 114 | po::options_description generic("Generic options"); |
170 | po::options_description generic("Generic options"); |
| 115 | generic.add_options() ("version,v", "print version string") |
171 | generic.add_options() ("version,v", "print version string") |
| 116 | ("help", "produce help message"); |
172 | ("help", "produce help message"); |
| 117 | 173 | ||
| 118 | // Declare a group of options that will be |
174 | // Declare a group of options that will be |
| 119 | // allowed both on command line and in |
175 | // allowed both on command line and in |
| 120 | // config file |
176 | // config file |
| 121 | po::options_description config("Configuration"); |
177 | po::options_description config("Configuration"); |
| 122 | config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level") |
178 | config.add_options()("optimization", po::value<int>()->default_value(10), "optimization level") |
| 123 | ("include-path,I", po::value<vector<string> >()->composing(), "include path"); |
179 | ("include-path,I", po::value<vector<string> >()->composing(), "include path"); |
| 124 | 180 | ||
| 125 | // Hidden options, will be allowed both on command line and |
181 | // Hidden options, will be allowed both on command line and |
| 126 | // in config file, but will not be shown to the user. |
182 | // in config file, but will not be shown to the user. |
| 127 | po::options_description hidden("Hidden options"); |
183 | po::options_description hidden("Hidden options"); |
| 128 | hidden.add_options()("input-file", po::value<vector<string> >(), "input file"); |
184 | hidden.add_options()("input-file", po::value<vector<string> >(), "input file"); |
| 129 | 185 | ||
| 130 | po::options_description cmdline_options; |
186 | po::options_description cmdline_options; |
| 131 | cmdline_options.add(generic).add(config).add(hidden); |
187 | cmdline_options.add(generic).add(config).add(hidden); |
| 132 | 188 | ||
| 133 | po::options_description config_file_options; |
189 | po::options_description config_file_options; |
| 134 | config_file_options.add(config).add(hidden); |
190 | config_file_options.add(config).add(hidden); |
| 135 | 191 | ||
| 136 | po::options_description visible("Allowed options"); |
192 | po::options_description visible("Allowed options"); |
| 137 | visible.add(generic).add(config); |
193 | visible.add(generic).add(config); |
| 138 | 194 | ||
| 139 | po::positional_options_description p; |
195 | po::positional_options_description p; |
| 140 | p.add("input-file", -1); |
196 | p.add("input-file", -1); |
| 141 | 197 | ||
| 142 | po::variables_map vm; |
198 | po::variables_map vm; |
| 143 | store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
199 | store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
| 144 | 200 | ||
| 145 | ifstream ifs("multiple_sources.cfg"); |
201 | ifstream ifs("multiple_sources.cfg"); |
| 146 | store(parse_config_file(ifs, config_file_options), vm); |
202 | store(parse_config_file(ifs, config_file_options), vm); |
| 147 | notify(vm); |
203 | notify(vm); |
| 148 | 204 | ||
| 149 | if (vm.count("help")) |
205 | if (vm.count("help")) |
| 150 | { |
206 | { |
| 151 | cout << visible << "\n"; |
207 | cout << visible << "\n"; |
| 152 | return 0; |
208 | return 0; |
| 153 | } |
209 | } |
| 154 | 210 | ||
| 155 | if (vm.count("version")) |
211 | if (vm.count("version")) |
| 156 | { |
212 | { |
| 157 | cout << "Multiple sources example, version 1.0\n"; |
213 | cout << "Multiple sources example, version 1.0\n"; |
| 158 | return 0; |
214 | return 0; |
| 159 | } |
215 | } |
| 160 | 216 | ||
| 161 | if (vm.count("include-path")) |
217 | if (vm.count("include-path")) |
| 162 | { |
218 | { |
| 163 | //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n"; |
219 | //cout << "Include paths are: " << vm["include-path"].as<vector<string>>() << "\n"; |
| 164 | } |
220 | } |
| 165 | 221 | ||
| 166 | if (vm.count("input-file")) |
222 | if (vm.count("input-file")) |
| 167 | { |
223 | { |
| 168 | //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n"; |
224 | //cout << "Input files are: " << vm["input-file"].as<vector<string>>() << "\n"; |
| 169 | } |
225 | } |
| 170 | 226 | ||
| 171 | //cout << "Optimization level is " << opt << "\n"; |
227 | //cout << "Optimization level is " << opt << "\n"; |
| 172 | 228 | ||
| 173 | */ |
229 | */ |
| 174 | /*if (argc != 3) |
230 | /*if (argc != 3) |
| 175 | { |
231 | { |
| 176 | std::cout << "Usage: async_client <server> <path>\n"; |
232 | std::cout << "Usage: async_client <server> <path>\n"; |
| 177 | std::cout << "Example:\n"; |
233 | std::cout << "Example:\n"; |
| 178 | std::cout << " async_client www.boost.org /LICENSE_1_0.txt\n"; |
234 | std::cout << " async_client www.boost.org /LICENSE_1_0.txt\n"; |
| 179 | return 1; |
235 | return 1; |
| 180 | } |
236 | } |
| 181 | 237 | ||
| 182 | boost::asio::io_service io_service; |
238 | boost::asio::io_service io_service; |
| 183 | client c(io_service, argv[1], argv[2]); |
239 | client c(io_service, argv[1], argv[2]); |
| 184 | io_service.run();*/ |
240 | io_service.run();*/ |
| 185 | /* |
241 | /* |
| 186 | std::string hello( "Hello, world!" ); |
242 | std::string hello( "Hello, world!" ); |
| 187 | 243 | ||
| 188 | foreach( char ch, hello ) |
244 | foreach( char ch, hello ) |
| 189 | { |
245 | { |
| 190 | std::cout << ch; |
246 | std::cout << ch; |
| 191 | } |
247 | } |
| 192 | 248 | ||
| 193 | } |
249 | } |
| 194 | catch (std::exception& e) |
250 | catch (std::exception& e) |
| 195 | { |
251 | { |
| 196 | std::cout << "Exception: " << e.what() << "\n"; |
252 | std::cout << "Exception: " << e.what() << "\n"; |
| 197 | } |
253 | } |
| 198 | */ |
254 | */ |
| 199 | return 0; |
255 | return 0; |
| 200 | } |
256 | } |
| 201 | 257 | ||