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