Same header and footer for all files. Header includes copyright +
[metaproxy-moved-to-github.git] / src / ex_filter_frontend_net.cpp
index f8cbf5a..76264f9 100644 (file)
@@ -1,25 +1,34 @@
+/* $Id: ex_filter_frontend_net.cpp,v 1.7 2005-10-15 14:09:09 adam Exp $
+   Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
 
 #include <cstdlib>
 #include <iostream>
 #include <stdexcept>
 
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+
 #include "config.hpp"
 
 #include "filter_frontend_net.hpp"
+#include "filter_log.hpp"
 
 #include "router.hpp"
 #include "session.hpp"
 #include "package.hpp"
 
-class FilterInit: public yp2::Filter {
+class FilterInit: public yp2::filter::Base {
 public:
     void process(yp2::Package & package) const {
-
+        
         if (package.session().is_closed())
         {
             // std::cout << "Got Close.\n";
         }
-       
+        
         Z_GDU *gdu = package.request().get();
         if (gdu)
         {
@@ -51,7 +60,7 @@ public:
                 break;
             } 
             odr_destroy(odr);
-       }
+        }
         return package.move();
     };
 };
@@ -60,18 +69,52 @@ int main(int argc, char **argv)
 {
     try 
     {
+        po::options_description desc("Allowed options");
+        desc.add_options()
+            ("help", "produce help message")
+            ("duration", po::value<int>(),
+             "number of seconds for server to exist")
+            ("port", po::value< std::vector<std::string> >(), "listener port")
+            ;
+
+        po::positional_options_description p;
+        p.add("port", -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;
+        }
+
+        if (vm.count("port"))
         {
+            std::vector<std::string> ports = 
+                vm["port"].as< std::vector<std::string> >();
+
+            for (size_t i = 0; i<ports.size(); i++)
+                std::cout << "port " << i << " " << ports[i] << "\n";
+
            yp2::RouterChain router;
 
-            // put in frontend first
-            yp2::FilterFrontendNet filter_front;
-            filter_front.listen_address() = "tcp:@:9999";
+            // put frontend filter in router
+            yp2::filter::FrontendNet filter_front;
+            filter_front.ports() = ports;
 
             // 0=no time, >0 timeout in seconds
-            filter_front.listen_duration() = 0;
+            if (vm.count("duration")) {
+                filter_front.listen_duration() = vm["duration"].as<int>();
+            }
            router.rule(filter_front);
 
-            // put in a backend
+            // put log filter in router
+            yp2::filter::Log filter_log;
+            router.rule(filter_log);
+
+            // put backend init filter in router
             FilterInit filter_init;
            router.rule(filter_init);
 
@@ -86,12 +129,14 @@ int main(int argc, char **argv)
         std::cerr << "unknown exception\n";
         std::exit(1);
     }
+    std::exit(0);
 }
 
 /*
  * Local variables:
  * c-basic-offset: 4
  * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */