# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = @top_srcdir@/doc @top_srcdir@/src @top_srcdir@/codegen
+INPUT = @top_srcdir@/doc @top_srcdir@/src @top_srcdir@/codegen/codegen-stubhead.hxx
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# the library search path.
lib_LTLIBRARIES = libt2n.la
-libt2n_la_SOURCES = server.cpp socket_server.cpp client.cpp connection.cpp \
- socket_handler.cpp socket_client.cpp command_server.cpp command_client.cpp \
- t2n_exception.cpp command.cpp container.cpp
+libt2n_la_SOURCES = client.cpp command.cpp command_client.cpp \
+ command_server.cpp connection.cpp container.cpp server.cpp socket_client.cpp \
+ socket_handler.cpp socket_server.cpp t2n_exception.cpp client_wrapper.cpp
+
+# Note: If you specify a:b:c as the version in the next line,
+# the library that is made has version (a-c).c.b. In this
+# example, the version is 2.1.2. (3:2:1)
+libt2n_la_LDFLAGS = -version-info 1:0:0
+
+pkginclude_HEADERS = client.hxx client_wrapper.hxx command.hxx \
+ command_client.hxx command_server.hxx connection.hxx container.hxx log.hxx server.hxx \
+ socket_client.hxx socket_handler.hxx socket_server.hxx t2n_exception.hxx types.hxx \
+ wrapper_handler_socket.hxx
-pkginclude_HEADERS = server.hxx socket_server.hxx t2n_exception.hxx client.hxx \
- socket_client.hxx connection.hxx types.hxx socket_handler.hxx command.hxx container.hxx \
- command_client.hxx command_server.hxx log.hxx
{
client_connection::client_connection()
- : connection(), callbacks(__events_end)
+ : connection()
{
set_logging(NULL,none);
}
-client_connection::~client_connection()
-{
- // we want the connection_closed callbacks to be called before
- close();
-
- do_callbacks(connection_deleted);
-}
-
-void client_connection::close()
-{
- if (!is_closed())
- {
- connection::close();
- do_callbacks(connection_closed);
- }
-}
-
-/// add a callback
-/**
- @param event event the function will be called at
- @param func functor (see boost function) that will be called
- @note use boost::bind to bind to member functions and parameters like this:
- @verbatim
- // in this example 17 is a fixed parameter that is always added to the call
- c.add_callback(connection_closed,bind(&my_class::func_to_call_back, boost::ref(*this), 17));
- @endverbatim
-*/
-void client_connection::add_callback(callback_event_type event, const boost::function<void ()>& func)
-{
- callbacks[event].push_back(func);
-}
-
-
-
-void client_connection::do_callbacks(callback_event_type event)
-{
- std::list<boost::function<void ()> >::iterator i,ie=callbacks[event].end();
- for (i=callbacks[event].begin(); i != ie; i++)
- (*i)();
-}
-
/// get pointer to logging stream, returns NULL if no logging needed
std::ostream* client_connection::get_logstream(log_level_values level)
{
#define __LIBT2N_CLIENT
#include <string>
-#include <vector>
-#include <list>
-
-#include <boost/function.hpp>
+#include <iostream>
#include "connection.hxx"
#include "types.hxx"
log_level_values log_level;
std::ostream *logstream;
- /// vector initialized for all callback-types, all elements in each list will be called
- std::vector<std::list<boost::function<void ()> > > callbacks;
-
- protected:
- void do_callbacks(callback_event_type event);
-
public:
client_connection();
- virtual ~client_connection();
-
- void close();
-
void set_logging(std::ostream *_logstream, log_level_values _log_level);
std::ostream* get_logstream(log_level_values level);
-
- void add_callback(callback_event_type event, const boost::function<void ()>& func);
};
}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Gerd v. Egidy *
+ * gve@intra2net.com *
+ * *
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library 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 Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <iostream>
+#include <string>
+
+#include <functional>
+
+#include <boost/any.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+
+#include "../codegen/codegen-stubhead.hxx"
+
+
+#include <client_wrapper.hxx>
+
+#include <wrapper_handler_socket.hxx>
+
+namespace libt2n
+{
+
+class testme : public command_client
+{
+ public:
+
+ testme(client_connection &x, long long a, long long b)
+ : command_client(x,100000,10000)
+ { }
+
+ void helloworld(const std::string& text)
+ {
+ std::cout << "Hello world, " << text << std::endl;
+ }
+};
+
+const char* T2nSingletonWrapperMessages::NotInitializedMessage = "T2nSingletonWrapper used before setting initializing connection";
+
+typedef T2nSingletonWrapper<testme> wraptype;
+
+template<>
+std::auto_ptr<wraptype> wraptype::SingletonObject = std::auto_ptr<wraptype>();
+
+template<>
+std::auto_ptr<ConnectionWrapper> wraptype::WrappedConnection = std::auto_ptr<ConnectionWrapper>();
+
+void test(void)
+{
+
+
+ t2n_exec(&testme::helloworld)("gurke");
+
+}
+
+}
#undef _GEN_PREP
#undef _GEN_ARG
- T2nSingletonWrapper()
+ T2nSingletonWrapper(std::auto_ptr<Client> stub)
+ {
+ Stub=stub;
+ }
+
+ static void init()
{
if (WrappedConnection.get() == NULL)
throw std::logic_error(NotInitializedMessage);
- Stub=std::auto_ptr<Client>(new Client(*(WrappedConnection->get_connection()),
+ std::auto_ptr<Client> stub(new Client(*(WrappedConnection->get_connection()),
WrappedConnection->get_command_timeout_usec(),
WrappedConnection->get_hello_timeout_usec()));
+
+ SingletonObject=std::auto_ptr<T2nSingletonWrapper>(new T2nSingletonWrapper(stub));
}
template< typename R >
static void ensure_singleton_there(void)
{
if (SingletonObject.get() == NULL)
- SingletonObject=std::auto_ptr<T2nSingletonWrapper>(new T2nSingletonWrapper());
+ init();
}
// create an exec-method for each possible number of parameters
virtual ~command_client() {}
void send_command(command* cmd, result_container &res);
+
+ void set_command_timeout_usec(long long _command_timeout_usec=command_timeout_usec_default)
+ { command_timeout_usec=_command_timeout_usec; }
+ void set_hello_timeout_usec(long long _hello_timeout_usec=hello_timeout_usec_default)
+ { hello_timeout_usec=_hello_timeout_usec; }
+ long long get_command_timeout_usec(void)
+ { return command_timeout_usec; }
+ long long get_hello_timeout_usec(void)
+ { return hello_timeout_usec; }
};
}
namespace libt2n
{
+connection::~connection()
+{
+ // we want the connection_closed callbacks to be called before
+ close();
+
+ do_callbacks(connection_deleted);
+}
+
+void connection::close()
+{
+ if (!is_closed())
+ {
+ closed=true;
+ do_callbacks(connection_closed);
+ }
+}
+
connection::packet_size_indicator connection::bytes_available()
{
// no size information -> no packet
real_write(send_data);
}
+/** @brief add a callback
+
+ @param event event the function will be called at
+ @param func functor (see boost function) that will be called
+
+ @note use boost::bind to bind to member functions and parameters like this:
+ 17 is a fixed parameter that is always added to the call
+ c.add_callback(connection_closed,bind(&my_class::func_to_call_back, boost::ref(*this), 17));
+*/
+void connection::add_callback(callback_event_type event, const boost::function<void ()>& func)
+{
+ if (event == new_connection)
+ throw std::logic_error("new_connection callback not allowed for server_connections");
+
+ callbacks[event].push_back(func);
+}
+
+/** @brief an event has occured, execute the callbacks that are registered for this event
+
+ @param event event type that has occured
+*/
+void connection::do_callbacks(callback_event_type event)
+{
+ std::list<boost::function<void ()> >::iterator i,ie=callbacks[event].end();
+ for (i=callbacks[event].begin(); i != ie; i++)
+ (*i)();
+}
+
+/** @brief get the callbacks in place for one event
+
+ @param event event the callbacks should be registered for
+ @return std::list of functors (boost::function) with the callbacks
+
+ @note if you want to get the callbacks for all events, loop from 0 to __events_end
+*/
+std::list<boost::function<void ()> > connection::get_callback_list(callback_event_type event)
+{
+ return callbacks[event];
+}
+
+
}
#define __LIBT2N_CONNECTION
#include <string>
+#include <vector>
+#include <list>
+#include <iostream>
+
+#include <boost/function.hpp>
#include <netinet/in.h>
private:
bool closed;
+ /// vector initialized for all callback-types, all elements in each list will be called
+ std::vector<std::list<boost::function<void ()> > > callbacks;
+
protected:
connection()
- { closed=false; }
+ : callbacks(__events_end), closed(false)
+ { }
std::string buffer;
virtual std::ostream* get_logstream(log_level_values level)=0;
+ void do_callbacks(callback_event_type event);
+
public:
- virtual ~connection()
- { close(); }
+ virtual ~connection();
/// is this connection closed or not
bool is_closed()
{ return closed; }
/// close this connection
- virtual void close()
- { closed=true; }
+ virtual void close();
/** @brief look for new data and store it in the local buffer
@param usec_timeout wait until new data is found, max timeout usecs.
{ return bytes_available(); }
void write(const std::string& data);
+
+ void add_callback(callback_event_type event, const boost::function<void ()>& func);
+
+ std::list<boost::function<void ()> > get_callback_list(callback_event_type event);
};
}
{
server_connection::server_connection(int _timeout)
- : connection(), callbacks(__events_end)
+ : connection()
{
set_timeout(_timeout);
reset_timeout();
my_server=0;
}
-server_connection::~server_connection()
-{
- // we want the connection_closed callbacks to be called before
- close();
-
- do_callbacks(connection_deleted);
-}
-
-void server_connection::close()
-{
- if (!is_closed())
- {
- connection::close();
- do_callbacks(connection_closed);
- }
-}
-
/// get pointer to logging stream, returns NULL if no logging needed
std::ostream* server_connection::get_logstream(log_level_values level)
{
last_action_time=time(NULL);
}
-/** @brief add a callback
-
- @param event event the function will be called at
- @param func functor (see boost function) that will be called
-
- @note use boost::bind to bind to member functions and parameters like this:
- 17 is a fixed parameter that is always added to the call
- c.add_callback(connection_closed,bind(&my_class::func_to_call_back, boost::ref(*this), 17));
-*/
void server_connection::add_callback(callback_event_type event, const boost::function<void ()>& func)
{
if (event == new_connection)
throw std::logic_error("new_connection callback not allowed for server_connections");
- callbacks[event].push_back(func);
-}
-
-void server_connection::do_callbacks(callback_event_type event)
-{
- std::list<boost::function<void ()> >::iterator i,ie=callbacks[event].end();
- for (i=callbacks[event].begin(); i != ie; i++)
- (*i)();
+ connection::add_callback(event,func);
}
server::server()
void set_id(unsigned int _connection_id)
{ connection_id=_connection_id; }
- /// vector initialized for all callback-types, all elements in each list will be called
- std::vector<std::list<boost::function<void ()> > > callbacks;
-
protected:
server *my_server;
std::ostream* get_logstream(log_level_values level);
- void do_callbacks(callback_event_type event);
-
public:
- virtual ~server_connection();
-
void check_timeout();
void reset_timeout();
void set_timeout(int _timeout)
unsigned int get_id()
{ return connection_id; }
- void close();
-
void add_callback(callback_event_type event, const boost::function<void ()>& func);
};