server.h Source File (original) (raw)
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef MPS_Server_H
00038 #define MPS_Server_H
00039
00040 namespace MPS {
00041
00042 class Server;
00043 class InterfaceServer;
00044
00045
00046
00047
00048
00049 class Server {
00050 private:
00051 typedef map<string, string> boundNames_t;
00052 boundNames_t boundNames;
00053
00054 string objectName;
00055
00056 friend class Transport;
00057
00058
00059 void bindName(Address const &addr) {
00060 boundNames[addr.getTransport()] = addr.getResolvedName();
00061 }
00062
00063
00064 void unbindName(string const &transport) {
00065 boundNames.erase(transport);
00066 }
00067
00068 protected:
00069
00070 Server(string const &_o)
00071 : objectName(_o)
00072 {}
00073
00074 public:
00075 virtual ~Server() {}
00076
00077
00078 string const &getObjectName() const { return objectName; }
00079
00080
00081
00082 vector getBoundNames() const;
00083
00084
00085
00086
00087
00088 string getBoundName(string const &transportName) const {
00089 boundNames_t::const_iterator i = boundNames.find(transportName);
00090 return (i == boundNames.end()) ? "" : (*i).second;
00091 }
00092
00093
00094 virtual void dispatch(InputStream &request, OutputStream &reply) = 0;
00095 };
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 class InterfaceServer: public Server {
00107 public:
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 typedef void (*request_handler_t)(ref const &__impl,
00125 InputStream &__input,
00126 OutputStream &__output);
00127
00128 private:
00129 friend class Transport;
00130
00131 typedef vector requesthandlervec_t;
00132
00133 ref __impl;
00134 requesthandlervec_t methods;
00135
00136 public:
00137
00138 InterfaceServer(string const &objectName, ref const &impl)
00139 : Server(objectName),
00140 __impl(impl),
00141 methods()
00142 {
00143 __impl->_setInterfaceServer(this);
00144 }
00145
00146 protected:
00147
00148 void registerMethod(int methodIndex, string const &methodName, request_handler_t handler);
00149
00150 public:
00151 virtual void dispatch(InputStream &request, OutputStream &reply);
00152 };
00153
00154 }
00155
00156 #endif