X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fclient_wrapper.hxx;h=672308e7cd17484e3f46393eec95a8de654aa52f;hp=0822af073b47e77b978b17e8f7de7908193a9e56;hb=4c3662a0b083759056b93c21e747e5551a8ddfcc;hpb=0ea6d528901a0eeb0fce1c2a71ae69c277798142 diff --git a/src/client_wrapper.hxx b/src/client_wrapper.hxx index 0822af0..672308e 100644 --- a/src/client_wrapper.hxx +++ b/src/client_wrapper.hxx @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -39,27 +38,47 @@ namespace libt2n class ConnectionWrapper { - public: + private: + long long command_timeout_usec; + long long hello_timeout_usec; - virtual client_connection* get_connection()=0; + protected: + log_level_values log_level; + std::ostream *logstream; + void set_logging_on_connection(client_connection& c); - virtual long long get_command_timeout_usec(void) - { - return command_client::command_timeout_usec_default; - } + 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) + { } - virtual long long get_hello_timeout_usec(void) - { - return command_client::hello_timeout_usec_default; - } + virtual ~ConnectionWrapper() + { } + + virtual client_connection* get_connection()=0; virtual void handle(command_client* stubBase, boost::function< void() > f) { f(); } - virtual ~ConnectionWrapper() - { } + long long get_command_timeout_usec(void) + { return command_timeout_usec; } + + void set_command_timeout_usec(long long _command_timeout_usec) + { command_timeout_usec=_command_timeout_usec; } + + long long get_hello_timeout_usec(void) + { return hello_timeout_usec; } + + 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); + + std::ostream* get_logstream(log_level_values level); }; // contains the internal stuff needed for T2nWrapper @@ -150,14 +169,21 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages #undef _GEN_PREP #undef _GEN_ARG - T2nSingletonWrapper() + T2nSingletonWrapper(std::auto_ptr stub) + { + Stub=stub; + } + + static void init() { if (WrappedConnection.get() == NULL) throw std::logic_error(NotInitializedMessage); - Stub=std::auto_ptr(new Client(*(WrappedConnection->get_connection()), + std::auto_ptr stub(new Client(*(WrappedConnection->get_connection()), WrappedConnection->get_command_timeout_usec(), WrappedConnection->get_hello_timeout_usec())); + + SingletonObject=std::auto_ptr(new T2nSingletonWrapper(stub)); } template< typename R > @@ -182,13 +208,13 @@ class T2nSingletonWrapper : public T2nSingletonWrapperMessages if (SingletonObject.get() != NULL) SingletonObject.reset(); } - static ConnectionWrapper* get_connection(void) + static ConnectionWrapper* get_connection_wrapper(void) { return WrappedConnection.get(); } static void ensure_singleton_there(void) { if (SingletonObject.get() == NULL) - SingletonObject=std::auto_ptr(new T2nSingletonWrapper()); + init(); } // create an exec-method for each possible number of parameters