Subversion Repositories HomeAutomation

Rev

Rev 1322 | Rev 1328 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

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