First go at Package logger
[metaproxy-moved-to-github.git] / include / metaproxy / package.hpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2011 Index Data
3
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef YP2_PACKAGE_HPP
20 #define YP2_PACKAGE_HPP
21
22 #include <iosfwd>
23
24 #include <yazpp/gdu.h>
25
26 #include "router.hpp"
27 #include "filter.hpp"
28 #include "session.hpp"
29 #include "origin.hpp"
30
31 namespace metaproxy_1 {
32     class Package;
33 }
34
35
36 namespace std 
37 {
38     std::ostream& operator<<(std::ostream& os, const metaproxy_1::Package& p);
39 }
40
41 namespace metaproxy_1 {
42
43     class Package {
44     public:
45         Package();
46
47         ~Package();
48         
49         Package(metaproxy_1::Session &session, 
50                 const metaproxy_1::Origin &origin);
51
52         /// shallow copy constructor which only copies the filter chain info
53         Package & copy_filter(const Package &p);
54
55         /// send Package to it's next Filter defined in Router
56         void move();
57
58         /// send Package to other route
59         void move(std::string route);
60         
61         /// access session - left val in assignment
62         metaproxy_1::Session & session();
63         
64         /// get function - right val in assignment
65         Origin origin() const;
66        
67         /// set function - left val in assignment
68         Origin & origin();
69         
70         /// set function - can be chained
71         Package & router(const Router &router);
72
73         yazpp_1::GDU &request();
74
75         yazpp_1::GDU &response();
76                 
77         /// get function - right val in assignment
78         Session session() const;
79
80         void log(const char *module, int level, const char *fmt, ...);
81         
82         void reset_log(std::string &res);
83
84         class PackageLogger;
85         typedef boost::shared_ptr<PackageLogger> PackageLoggerPtr;
86
87     private:
88         Session m_session;
89         Origin m_origin;
90
91         RoutePos *m_route_pos;
92
93         PackageLoggerPtr p_logger;
94         
95         yazpp_1::GDU m_request_gdu;
96         yazpp_1::GDU m_response_gdu;
97     };
98 }
99
100 #endif
101 /*
102  * Local variables:
103  * c-basic-offset: 4
104  * c-file-style: "Stroustrup"
105  * indent-tabs-mode: nil
106  * End:
107  * vim: shiftwidth=4 tabstop=8 expandtab
108  */
109