Added ex_filter_frontend_net noinst program
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 14 Oct 2005 11:18:59 +0000 (11:18 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 14 Oct 2005 11:18:59 +0000 (11:18 +0000)
src/Makefile.am
src/ex_filter_frontend_net.cpp [new file with mode: 0644]

index 1587d49..cf719f3 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am,v 1.17 2005-10-13 20:06:45 adam Exp $
+## $Id: Makefile.am,v 1.18 2005-10-14 11:18:59 adam Exp $
 
 MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
 
@@ -18,13 +18,9 @@ libyp2_la_SOURCES = filter_frontend_net.cpp filter_frontend_net.hpp \
 LDADD= libyp2.la $(YAZPPLALIB) $(XSLT_LIBS)
 
 bin_PROGRAMS =
-noinst_PROGRAMS = p2 
+noinst_PROGRAMS = ex_filter_frontend_net
 
-p2_SOURCES=p2_frontend.cpp p2_msg.cpp p2.cpp p2_frontend.h \
- p2_config.cpp p2_config.h \
- p2_backend.h p2_backend_dummy.cpp \
- p2_modules.cpp p2_modules.h \
- p2_xmlerror.cpp p2_xmlerror.h
+ex_filter_frontend_net_SOURCES = ex_filter_frontend_net.cpp
 
 # Rules for test programs..
 
diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp
new file mode 100644 (file)
index 0000000..4478afb
--- /dev/null
@@ -0,0 +1,75 @@
+
+#include <cstdlib>
+#include <iostream>
+#include <stdexcept>
+
+#include "config.hpp"
+
+#include "filter_frontend_net.hpp"
+
+#include "router.hpp"
+#include "session.hpp"
+#include "package.hpp"
+
+class FilterInit: public yp2::Filter {
+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)
+        {
+            // std::cout << "Got PDU. Sending init response\n";
+            ODR odr = odr_createmem(ODR_ENCODE);
+            Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
+            
+            apdu->u.initResponse->implementationName = "YP2/YAZ";
+            
+            package.response() = apdu;
+            odr_destroy(odr);
+        }
+        return package.move();
+    };
+};
+
+int main(int argc, char **argv)
+{
+    try 
+    {
+        {
+           yp2::RouterChain router;
+
+            // put in frontend first
+            yp2::FilterFrontendNet filter_front;
+            filter_front.listen_address() = "tcp:@:9999";
+            //filter_front.listen_duration() = 1;  // listen a short time only
+           router.rule(filter_front);
+
+            // put in a backend
+            FilterInit filter_init;
+           router.rule(filter_init);
+
+            yp2::Session session;
+            yp2::Origin origin;
+           yp2::Package pack(session, origin);
+           
+           pack.router(router).move(); 
+        }
+    }
+    catch ( ... ) {
+        std::cerr << "unknown exception\n";
+        std::exit(1);
+    }
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */