| 1 | /* |
| 2 | Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy |
| 3 | |
| 4 | The software in this package is distributed under the GNU General |
| 5 | Public License version 2 (with a special exception described below). |
| 6 | |
| 7 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 8 | in the file COPYING.GPL. |
| 9 | |
| 10 | As a special exception, if other files instantiate templates or use macros |
| 11 | or inline functions from this file, or you compile this file and link it |
| 12 | with other works to produce a work based on this file, this file |
| 13 | does not by itself cause the resulting work to be covered |
| 14 | by the GNU General Public License. |
| 15 | |
| 16 | However the source code for this file must still be made available |
| 17 | in accordance with section (3) of the GNU General Public License. |
| 18 | |
| 19 | This exception does not invalidate any other reasons why a work based |
| 20 | on this file might be covered by the GNU General Public License. |
| 21 | */ |
| 22 | #ifndef __LIBT2N_COMMAND_CLIENT |
| 23 | #define __LIBT2N_COMMAND_CLIENT |
| 24 | |
| 25 | #include <functional> |
| 26 | #include <string> |
| 27 | |
| 28 | #include "client.hxx" |
| 29 | #include "container.hxx" |
| 30 | |
| 31 | namespace libt2n |
| 32 | { |
| 33 | |
| 34 | /// a client sending out commands to a server |
| 35 | class command_client |
| 36 | { |
| 37 | public: |
| 38 | static const long long command_timeout_usec_default=90000000; |
| 39 | static const long long hello_timeout_usec_default=30000000; |
| 40 | |
| 41 | private: |
| 42 | client_connection *c; |
| 43 | |
| 44 | long long hello_timeout_usec; |
| 45 | long long command_timeout_usec; |
| 46 | |
| 47 | void read_hello(); |
| 48 | std::string read_packet(const long long &usec_timeout); |
| 49 | bool check_hello(const std::string& hellostr); |
| 50 | |
| 51 | t2n_exception *constructorException; |
| 52 | |
| 53 | public: |
| 54 | command_client(client_connection* _c, |
| 55 | long long _command_timeout_usec=command_timeout_usec_default, |
| 56 | long long _hello_timeout_usec=hello_timeout_usec_default); |
| 57 | virtual ~command_client(); |
| 58 | |
| 59 | void replace_connection(client_connection* _c); |
| 60 | |
| 61 | void send_command(command* cmd, result_container &res); |
| 62 | |
| 63 | void set_command_timeout_usec(long long _command_timeout_usec=command_timeout_usec_default) |
| 64 | { command_timeout_usec=_command_timeout_usec; } |
| 65 | void set_hello_timeout_usec(long long _hello_timeout_usec=hello_timeout_usec_default) |
| 66 | { hello_timeout_usec=_hello_timeout_usec; } |
| 67 | long long get_command_timeout_usec(void) |
| 68 | { return command_timeout_usec; } |
| 69 | long long get_hello_timeout_usec(void) |
| 70 | { return hello_timeout_usec; } |
| 71 | bool is_connection_closed(void) |
| 72 | { return c->is_closed(); } |
| 73 | t2n_exception* get_constuctor_exception(void) |
| 74 | { return constructorException; } |
| 75 | }; |
| 76 | |
| 77 | } |
| 78 | |
| 79 | #endif |
| 80 | |