FFL  1.0
Finfly Foundation Library
request.h
00001 /* $Id: request.h 2926 2013-02-05 19:07:32Z roma $ */
00002 
00003 #include <map>
00004 
00005 #include "../ipc/socket.h"
00006 #include "logbook.h"
00007 
00008 namespace ffl
00009 {
00010 
00011         namespace cssc
00012         {
00013 
00025                 class request
00026                 {
00027                 public:
00028 
00029                         request() throw(){}
00030 
00031                         request(ipc::socket& _s, long _t = -1) throw(...);
00032 
00033                         request(const std::string& _name) throw(...):Name(_name){}
00034 
00035                         ~request();
00036 
00037                         void reply(ipc::socket& _s, long _t = -1) throw(...);
00038 
00039                         void execute(ipc::socket& _s, logbook& _log, long _iotimeout = -1, long _rqtimeout = -1) throw(...);
00040 
00041                         class argument
00042                         {
00043                         public:
00044 
00045                                 typedef std::map<std::string, argument*> set;
00046 
00047                                 enum type
00048                                 {
00049                                         NONE    = 0,
00050                                         TABLE,
00051                                 };
00052 
00053                                 argument(set& _s, const std::string& _n):Set(_s)
00054                                 {
00055                                         It = _s.insert(std::pair<std::string, argument*>(_n, this)).first;
00056                                 }
00057 
00058                                 virtual ~argument(){}
00059 
00060                                 virtual type typeof() throw() = 0;
00061 
00062                                 void send(ipc::socket& _s, long _t) throw(...)
00063                                 {
00064                                         _s.put(typeof(), _t);
00065                                         send_value(_s, _t);
00066                                 }
00067 
00068                                 static void send(ipc::socket& _s, const set& _v, long _t = -1) throw(...);
00069 
00070                                 void receive(ipc::socket& _s, long _t) throw(...)
00071                                 {
00072                                         receive_value(_s, _t);
00073                                 }
00074 
00075                                 static void receive(ipc::socket& _s, set& _v, long _t = -1) throw(...);
00076 
00077                                 virtual argument* clone(set& _s) throw(...) = 0;
00078 
00079                                 static void erase(set& _v) throw();
00080 
00081                         protected:
00082 
00083                                 virtual void send_value(ipc::socket& _s, long _t) throw(...) = 0;
00084 
00085                                 virtual void receive_value(ipc::socket& _s, long _t) throw(...) = 0;
00086 
00087                                 set::iterator It;
00088 
00089                                 set& Set;
00090 
00091                         };
00092 
00093                         class argument_of_table:public argument
00094                         {
00095                         public:
00096 
00097                                 argument_of_table(set& _s, const std::string& _n):argument(_s, _n){}
00098 
00099                                 argument_of_table(set& _s, const std::string& _n, const co_table& _t):argument(_s, _n)
00100                                 {
00101                                         Value.copy(_t);
00102                                 }
00103 
00104                                 type typeof() throw(){return TABLE;}
00105 
00106                                 co_table Value;
00107 
00108                                 argument* clone(set& _s) throw(...)
00109                                 {
00110                                         return new argument_of_table(_s, It->first, Value);
00111                                 }
00112 
00113                         private:
00114 
00115                                 class transfer:public co_table_transfer
00116                                 {
00117                                 public:
00118 
00119                                         transfer(ipc::socket& _s, long _timeout):Socket(_s), IOTimeout(_timeout){}
00120 
00121                                 private:
00122 
00123                                         ipc::socket& Socket;
00124 
00125                                         long IOTimeout;
00126 
00127                                         void do_write(void *_buf, int _size)
00128                                         {
00129                                                 Socket.write((const char*)_buf, _size, IOTimeout);
00130                                         }
00131 
00132                                         void do_read(void *_buf, int _size)
00133                                         {
00134                                                 Socket.read((char*)_buf, _size, IOTimeout);
00135                                         }
00136 
00137                                 };
00138 
00139                                 void send_value(ipc::socket& _s, long _t) throw(...)
00140                                 {
00141                                         Value.write(transfer(_s, _t));
00142                                 }
00143 
00144                                 void receive_value(ipc::socket& _s, long _t) throw(...)
00145                                 {
00146                                         Value.read(transfer(_s, _t));
00147                                 }
00148 
00149                         };
00150 
00155                         argument::set In;
00156 
00161                         argument::set Out;
00162 
00164                         std::string Name;       
00165 
00166                 protected:
00167 
00170                         virtual void just_begin() throw(){}
00171 
00174                         virtual void just_ended() throw(){}
00175 
00180                         virtual bool checkpoint() throw(){return true;} 
00181 
00182                 };
00183 
00184         }
00185 
00186 }
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Макросы