00001 /*************************************************************************** 00002 * Copyright (C) 2006 by Gerd v. Egidy * 00003 * gve@intra2net.com * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License version * 00007 * 2.1 as published by the Free Software Foundation. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU Lesser General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU Lesser General Public * 00015 * License along with this program; if not, write to the * 00016 * Free Software Foundation, Inc., * 00017 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00018 ***************************************************************************/ 00019 #ifndef __LIBT2N_COMMAND_CLIENT 00020 #define __LIBT2N_COMMAND_CLIENT 00021 00022 #include <functional> 00023 #include <string> 00024 00025 #include "client.hxx" 00026 #include "container.hxx" 00027 00028 namespace libt2n 00029 { 00030 00032 class command_client 00033 { 00034 public: 00035 static const long long command_timeout_usec_default=90000000; 00036 static const long long hello_timeout_usec_default=30000000; 00037 00038 private: 00039 client_connection *c; 00040 00041 long long hello_timeout_usec; 00042 long long command_timeout_usec; 00043 00044 void read_hello(); 00045 std::string read_packet(const long long &usec_timeout); 00046 bool check_hello(const std::string& hellostr); 00047 00048 std::auto_ptr<t2n_exception> constructorException; 00049 00050 public: 00051 command_client(client_connection* _c, 00052 long long _command_timeout_usec=command_timeout_usec_default, 00053 long long _hello_timeout_usec=hello_timeout_usec_default); 00054 virtual ~command_client() {} 00055 00056 void replace_connection(client_connection* _c); 00057 00058 void send_command(command* cmd, result_container &res); 00059 00060 void set_command_timeout_usec(long long _command_timeout_usec=command_timeout_usec_default) 00061 { command_timeout_usec=_command_timeout_usec; } 00062 void set_hello_timeout_usec(long long _hello_timeout_usec=hello_timeout_usec_default) 00063 { hello_timeout_usec=_hello_timeout_usec; } 00064 long long get_command_timeout_usec(void) 00065 { return command_timeout_usec; } 00066 long long get_hello_timeout_usec(void) 00067 { return hello_timeout_usec; } 00068 bool is_connection_closed(void) 00069 { return c->is_closed(); } 00070 t2n_exception* get_constuctor_exception(void) 00071 { return constructorException.get(); } 00072 }; 00073 00074 } 00075 00076 #endif 00077
1.5.6