1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2011 Index Data
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
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
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
20 #include <metaproxy/package.hpp>
21 #include <yaz/snprintf.h>
26 namespace mp = metaproxy_1;
28 namespace metaproxy_1 {
29 class Package::PackageLogger : boost::noncopyable {
35 mp::Package::Package()
40 mp::Package::~Package()
45 mp::Package::Package(mp::Session &session, const mp::Origin &origin)
46 : m_session(session), m_origin(origin),
51 mp::Package & mp::Package::copy_filter(const Package &p)
53 p_logger = p.p_logger;
58 void mp::Package::copy_route(const Package &p)
61 m_route_pos = p.m_route_pos->clone();
64 void mp::Package::move()
68 const filter::Base *next_filter = m_route_pos->move(0);
70 next_filter->process(*this);
74 void mp::Package::move(std::string route)
78 const char *r_cstr = route.length() ? route.c_str() : 0;
79 const filter::Base *next_filter = m_route_pos->move(r_cstr);
81 next_filter->process(*this);
86 mp::Session & mp::Package::session()
91 mp::Origin mp::Package::origin() const
96 mp::Origin & mp::Package::origin()
101 mp::Package & mp::Package::router(const mp::Router &router)
103 m_route_pos = router.createpos();
107 yazpp_1::GDU &mp::Package::request()
109 return m_request_gdu;
113 yazpp_1::GDU &mp::Package::response()
115 return m_response_gdu;
118 mp::Session mp::Package::session() const
123 std::ostream& std::operator<<(std::ostream& os, const mp::Package& p)
125 os << p.origin() << " ";
126 os << p.session().id();
130 void mp::Package::log(const char *module, int level, const char *fmt, ...)
137 yaz_vsnprintf(buf + 1, sizeof(buf)-30, fmt, ap);
139 std::ostringstream os;
141 os << module << " " << *this << buf;
144 yaz_log(level, "%s", os.str().c_str());
147 p_logger->str += std::string(module) + std::string(buf) + std::string("\n");
150 void mp::Package::log_enable(void)
152 p_logger.reset(new PackageLogger);
155 void mp::Package::log_write(const char *buf, size_t sz)
158 p_logger->str += std::string(buf, sz);
161 void mp::Package::log_reset(std::string &res)
166 // p_logger->str.clear();
174 * c-file-style: "Stroustrup"
175 * indent-tabs-mode: nil
177 * vim: shiftwidth=4 tabstop=8 expandtab