Year 2007.
[metaproxy-moved-to-github.git] / src / ex_router_flexml.cpp
index a1c1a0d..dfe11b7 100644 (file)
@@ -1,54 +1,90 @@
-/* $Id: ex_router_flexml.cpp,v 1.1 2005-10-26 14:12:00 marc Exp $
-   Copyright (c) 2005, Index Data.
+/* $Id: ex_router_flexml.cpp,v 1.10 2007-01-25 14:05:54 adam Exp $
+   Copyright (c) 2005-2007, Index Data.
 
-%LICENSE%
+   See the LICENSE file for details
  */
 
+#include "config.hpp"
+
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+
 #include <iostream>
 #include <stdexcept>
 
-#include "config.hpp"
 #include "filter.hpp"
+#include "package.hpp"
 #include "router_flexml.hpp"
+#include "factory_static.hpp"
+
+namespace mp = metaproxy_1;
 
 int main(int argc, char **argv)
 {
-   //try 
-   //{
-   
-        std::string xmlconf = "<?xml version=\"1.0\"?>\n"
-            "<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
-            "<start route=\"start\"/>\n"
-            "<filters>\n"
-            "<filter id=\"front_default\" type=\"frontend-net\">\n"
-            "<port>210</port>\n"
-            "</filter>\n"
-            "<filter id=\"log_cout\" type=\"log\">\n"
-            "<logfile>mylog.log</logfile>\n"
-            "</filter>\n"
-            "</filters>\n"
-            "<routes>\n"  
-            "<route id=\"start\">\n"
-            "<filter refid=\"front_default\"/>\n"
-            "<filter refid=\"log_cout\"/>\n"
-            "</route>\n"
-            "</routes>\n"
-            "</yp2>\n";
+    try 
+    {
+        po::options_description desc("Allowed options");
+        desc.add_options()
+            ("help", "produce help message")
+            ("config", po::value< std::vector<std::string> >(), "xml config")
+            ;
         
-        yp2::RouterFleXML rflexml(xmlconf);
+        po::positional_options_description p;
+        p.add("config", -1);
         
+        po::variables_map vm;        
+        po::store(po::command_line_parser(argc, argv).
+                  options(desc).positional(p).run(), vm);
+        po::notify(vm);    
+        
+        if (vm.count("help")) {
+            std::cout << desc << "\n";
+            return 1;
+        }
+        
+        xmlDocPtr doc = 0;
+        if (vm.count("config"))
+        {
+            std::vector<std::string> config_fnames = 
+                vm["config"].as< std::vector<std::string> >();
 
+            if (config_fnames.size() != 1)
+            {
+                std::cerr << "Only one configuration must be given\n";
+                std::exit(1);
+            }
+            
+            doc = xmlParseFile(config_fnames[0].c_str());
+            if (!doc)
+            {
+                std::cerr << "xmlParseFile failed\n";
+                std::exit(1);
+            }
+        }
+        else
+        {
+            std::cerr << "No configuration given\n";
+            std::exit(1);
+        }
+        if (doc)
+        {
+            mp::FactoryStatic factory;
+            mp::RouterFleXML router(doc, factory);
 
-        // }
-        //catch ( ... ) {
-        //std::cerr << "Unknown Exception" << std::endl;
-        //throw();
-        //std::exit(1);
-        //}
-   std::exit(0);
-}
-
+           mp::Package pack;
+        
+            pack.router(router).move();
 
+            xmlFreeDoc(doc);
+        }
+    }
+    catch ( ... ) {
+        std::cerr << "Unknown Exception" << std::endl;
+        throw;
+        std::exit(1);
+    }
+    std::exit(0);
+}
 
 
 /*