Bump year in copyright msg in source
[metaproxy-moved-to-github.git] / src / package.hpp
index 719aaf5..de006bb 100644 (file)
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2009 Index Data
 
-#ifndef PACKAGE_HPP
-#define PACKAGE_HPP
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
 
-#include <stdexcept>
-#include <yaz++/gdu.h>
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef YP2_PACKAGE_HPP
+#define YP2_PACKAGE_HPP
+
+#include <iosfwd>
+
+#include <yazpp/gdu.h>
 
 #include "router.hpp"
 #include "filter.hpp"
 #include "session.hpp"
+#include "origin.hpp"
+
+namespace metaproxy_1 {
+    class Package;
+}
+
+
+namespace std 
+{
+    std::ostream& operator<<(std::ostream& os, metaproxy_1::Package& p);
+}
+
+namespace metaproxy_1 {
 
-namespace yp2 {
-    
-    class Origin {
-        enum origin_t {
-            API,
-            UNIX,
-            TCPIP
-        } type;
-        std::string address; // UNIX+TCPIP
-        int port;            // TCPIP only
-    public:
-        Origin() : type(API) {};
-    };
-    
     class Package {
     public:
+        Package();
+
+        ~Package();
         
-        Package(yp2::Session &session, yp2::Origin &origin) 
-            : m_session(session), m_origin(origin),
-              m_filter(0), m_router(0), m_data(0)  {}
-        
+        Package(metaproxy_1::Session &session, 
+                const metaproxy_1::Origin &origin);
+
+        /// shallow copy constructor which only copies the filter chain info
+        Package & copy_filter(const Package &p);
+
         /// send Package to it's next Filter defined in Router
-        Package & move() {
-            m_filter = m_router->move(m_filter, this);
-            if (m_filter)
-                return m_filter->process(*this);
-            else
-                return *this;
-        }
+        void move();
+
+        /// send Package to other route
+        void move(std::string route);
         
         /// access session - left val in assignment
-        yp2::Session & session() {
-            return m_session;
-        }
+        metaproxy_1::Session & session();
         
         /// get function - right val in assignment
-        unsigned int data() const {
-            return m_data;
-        }
+        Origin origin() const;
         
         /// set function - left val in assignment
-        unsigned int & data() {
-            return m_data;
-        }
+        Origin & origin();
         
         /// set function - can be chained
-        Package & data(const unsigned int & data){
-            m_data = data;
-            return *this;
-        }
-        
-        
-        /// get function - right val in assignment
-        Origin origin() const {
-            return m_origin;
-        }
-        
-        /// set function - left val in assignment
-        Origin & origin() {
-            return m_origin;
-        }
-        
+        Package & origin(const Origin & origin);
+
         /// set function - can be chained
-        Package & origin(const Origin & origin){
-            m_origin = origin;
-            return *this;
-        }
-        
-        Package & router(const Router &router){
-            m_filter = 0;
-            m_router = &router;
-            return *this;
-        }
+        Package & router(const Router &router);
+
+        yazpp_1::GDU &request();
+
+        yazpp_1::GDU &response();
                 
+        /// get function - right val in assignment
+        Session session() const;
+        
     private:
         Session m_session;
         Origin m_origin;
-        
-        const Filter *m_filter;
-        const Router *m_router;
-        unsigned int m_data;
+
+        RoutePos *m_route_pos;
+
+        //int m_data;
         
         yazpp_1::GDU m_request_gdu;
         yazpp_1::GDU m_response_gdu;
     };
 }
 
+
+
 #endif
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+