X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fclient_wrapper.hxx;h=50d5df69fd6dfd970e173e5c32d76d995cacca6e;hp=14dabfb1343e4984a47cf0fed6e4fe6607e1ef88;hb=44b4600fd51677e54dd167734ca9252b58237cda;hpb=e162ddf298a2e8c3756c55995897374ef614cbcd diff --git a/src/client_wrapper.hxx b/src/client_wrapper.hxx index 14dabfb..50d5df6 100644 --- a/src/client_wrapper.hxx +++ b/src/client_wrapper.hxx @@ -1,21 +1,24 @@ -/*************************************************************************** - * Copyright (C) 2008 by Gerd v. Egidy and Reinhard Pfau * - * 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. * - ***************************************************************************/ +/* +Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy + +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ #ifndef __LIBT2N_CLIENT_WRAPPER #define __LIBT2N_CLIENT_WRAPPER @@ -55,9 +58,10 @@ class ConnectionWrapper public: ConnectionWrapper() - : log_level(none), logstream(NULL), - command_timeout_usec(command_client::command_timeout_usec_default), - hello_timeout_usec(command_client::hello_timeout_usec_default) + : command_timeout_usec(command_client::command_timeout_usec_default), + hello_timeout_usec(command_client::hello_timeout_usec_default), + log_level(none), + logstream(NULL) { } virtual ~ConnectionWrapper() @@ -101,7 +105,7 @@ class ConnectionWrapper void set_hello_timeout_usec(long long _hello_timeout_usec) { hello_timeout_usec=_hello_timeout_usec; } - void set_logging(std::ostream *_logstream, log_level_values _log_level); + virtual void set_logging(std::ostream *_logstream, log_level_values _log_level); std::ostream* get_logstream(log_level_values level); }; @@ -169,6 +173,13 @@ class T2nSingletonWrapperMessages calls using this connection with an error-handling strategy (e.g. to reconnect when the connection broke). The source looks very complicated due to heavy use of templates, look at the 3rd codegen example to see how to use it. + + @par Example + Calling remote methods is usually done via t2n_exec, this saves you from always + specifying which T2nSingletonWrapper-template to use when calling T2nSingletonWrapper::exec + @code + t2n_exec(&cmd_group_t2nexample_client::testfunc)("the answer is %d",42) + @endcode */ template< class Client > class T2nSingletonWrapper : public T2nSingletonWrapperMessages @@ -179,6 +190,7 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages static std::auto_ptr SingletonObject; static std::auto_ptr WrappedConnection; + /// @cond // create a prep-method for each possible number of parameters #define _GEN_ARG(z,n,d) Arg ## n arg ##n #define _GEN_PREP(z,n,d) \ @@ -200,6 +212,7 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages #undef _GEN_PREP #undef _GEN_ARG + /// @endcond T2nSingletonWrapper(std::auto_ptr stub) { @@ -241,6 +254,9 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages public: + /** @brief tell the wrapper which connection to use + @param wrappedConnection the connection to establish when needed + */ static void set_connection(std::auto_ptr wrappedConnection) { WrappedConnection=wrappedConnection; @@ -249,15 +265,19 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages if (SingletonObject.get() != NULL) SingletonObject.reset(); } + + /// return a pointer to the ConnectionWrapper currently in use static ConnectionWrapper* get_connection_wrapper(void) { return WrappedConnection.get(); } + /// manually establish the connection without actually executing a call static void ensure_singleton_there(void) { if (SingletonObject.get() == NULL) init(); } + /// @cond // create an exec-method for each possible number of parameters #define _GEN_PLACEHOLDER(z,n,d) BOOST_PP_CAT(_,BOOST_PP_ADD(n,1)) #define _GEN_EXEC(z,n,d) \ @@ -282,9 +302,11 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages #undef _GEN_EXEC #undef _GEN_PLACEHOLDER + /// @endcond }; +/// @cond // create an t2n_exec-method for each possible number of parameters #define _GEN_EXEC(z,n,d) \ template< class Client, typename R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,typename Arg) > \ @@ -300,6 +322,7 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages #undef _GEN_EXEC #undef _GEN_PLACEHOLDER +/// @endcond } #endif