f76a4d6c729901051a0d7ebed4569c04f4f498bd
[metaproxy-moved-to-github.git] / src / origin.cpp
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 #include "config.hpp"
20 #include <metaproxy/origin.hpp>
21
22 #include <iostream>
23
24 namespace mp = metaproxy_1;
25
26 mp::Origin::Origin(std::string listen_host, 
27                    unsigned int listen_port) 
28     : m_type(API), m_address(""), m_origin_id(0),
29       m_listen_host(listen_host), m_listen_port(listen_port), m_max_sockets(0)
30 {
31 }
32
33 std::string mp::Origin::listen_host() const
34 {
35     return m_listen_host;
36 };
37
38 std::string & mp::Origin::listen_host()
39 {
40     return m_listen_host;
41 };
42
43 unsigned int mp::Origin::listen_port() const
44 {
45     return m_listen_port;
46 };
47
48 unsigned int & mp::Origin::listen_port()
49 {
50     return m_listen_port;
51 };
52
53 void mp::Origin::set_max_sockets(int max_sockets)
54 {
55     m_max_sockets = max_sockets;
56 }
57
58 int mp::Origin::get_max_sockets()
59 {
60     return m_max_sockets;
61 }
62
63 void mp::Origin::set_tcpip_address(std::string addr, unsigned long s)
64 {
65     m_type = TCPIP;
66     m_address = addr;
67     m_origin_id = s;
68 }
69
70 void mp::Origin::set_custom_session(const std::string &s)
71 {
72     m_custom_session = s;
73 }
74
75 std::string mp::Origin::get_address()
76 {
77     return m_address;
78 }
79
80 std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o)
81 {
82     if (o.m_address.length())
83         os << o.m_address;
84     else
85         os << "0";
86     os << ":" << o.m_origin_id;
87     if (o.m_custom_session.length())
88         os << ":" << o.m_custom_session;
89     return os;
90 }
91                 
92 /*
93  * Local variables:
94  * c-basic-offset: 4
95  * c-file-style: "Stroustrup"
96  * indent-tabs-mode: nil
97  * End:
98  * vim: shiftwidth=4 tabstop=8 expandtab
99  */
100