1 /***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
27 client_connection::client_connection()
28 : connection(), callbacks(__events_end)
30 set_logging(NULL,none);
33 client_connection::~client_connection()
35 // we want the connection_closed callbacks to be called before
38 do_callbacks(connection_deleted);
41 void client_connection::close()
46 do_callbacks(connection_closed);
52 @param event event the function will be called at
53 @param func functor (see boost function) that will be called
54 @note use boost::bind to bind to member functions and parameters like this:
56 // in this example 17 is a fixed parameter that is always added to the call
57 c.add_callback(connection_closed,bind(&my_class::func_to_call_back, boost::ref(*this), 17));
60 void client_connection::add_callback(callback_event_type event, const boost::function<void ()>& func)
62 callbacks[event].push_back(func);
67 void client_connection::do_callbacks(callback_event_type event)
69 std::list<boost::function<void ()> >::iterator i,ie=callbacks[event].end();
70 for (i=callbacks[event].begin(); i != ie; i++)
74 /// get pointer to logging stream, returns NULL if no logging needed
75 std::ostream* client_connection::get_logstream(log_level_values level)
77 if (logstream && log_level >= level)
83 /// activate logging to the given stream. everything above the given level is logged.
84 void client_connection::set_logging(std::ostream *_logstream, log_level_values _log_level)