Go to the documentation of this file.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 #ifndef AbstractSkelH
00033 #define AbstractSkelH
00034
00035 #include <zeusbase/System/Thread.h>
00036 #include <zeusbase/System/ZVariant.h>
00037 #include <zeusbase/System/ByteArray.hpp>
00038 #include <zeusbase/Net/ServerSocket.h>
00039 #include <zeusbase/Remote/RemoteDefines.hpp>
00040 #include <zeusbase/Remote/RemoteMethodCall.h>
00041 #include <zeusbase/Remote/RemoteReference.h>
00042 #include <zeusbase/Remote/Interfaces/IRemoteObject.hpp>
00043
00044
00050
00051 #define SKEL_DECL(classid, objectid) \
00052 class classid : public TAbstractSkel \
00053 { \
00054 public : \
00055 classid(objectid& rInstance)\
00056 : TAbstractSkel(), \
00057 m_rInstance(rInstance)\
00058 { \
00059 } \
00060 \
00061 protected: \
00062 virtual ~classid() \
00063 { \
00064 } \
00065 virtual Retval dispatchCommand(const IRemoteMethodCall& rMethod, IRemoteMethodCall*& rMethodreturn); \
00066 \
00067 private: \
00068 objectid& m_rInstance; \
00069 }; \
00070
00071
00072
00076
00077 #define SKEL_REMOTEREF(__param) pRemote##__param
00078
00079
00080
00084
00085 #define SKEL_DISPATCH_START(classid) \
00086 Retval classid::dispatchCommand(const IRemoteMethodCall& rMethod, IRemoteMethodCall*& rpMethodreturn) \
00087 { \
00088 Retval retValue = RET_NOERROR; \
00089 \
00090 TSingleLinkedList<IZUnknown*> lstParams; \
00091 TString strMethodName; \
00092 TRemoteMethodCall* pReturnCall = new TRemoteMethodCall(strMethodName); \
00093 TZVariant* pVarRetval = new TZVariant(); \
00094 rMethod.getMethodName(strMethodName);
00095
00096
00102
00103 #define SKEL_DISP_SWITCH(__name) \
00104 if (strMethodName == __name) \
00105 {
00106
00107
00110
00111 #define SKEL_DISP_SWITCH_END }
00112
00113
00114
00130
00131 #define SKEL_READ_PARAM(__name, __param) \
00132 TString strParam##__param = __name; \
00133 if (rMethod.getParameterByName(strParam##__param, __param) ==RET_NOERROR) \
00134 { \
00135 lstParams.add(__param); \
00136 } \
00137 else \
00138 { \
00139 retValue = RET_REQUEST_FAILED; \
00140 } \
00141
00142
00148
00149 #define SKEL_READ_PARAM_REMOTEREF(__name, __param) \
00150 SKEL_READ_PARAM(__name, __param) \
00151 ISerializable* pSerial##__param = NULL; \
00152 IRemoteObject* SKEL_REMOTEREF(__param) = NULL; \
00153 if (__param != NULL && __param->getObject(pSerial##__param) == RET_NOERROR) \
00154 { \
00155 if (pSerial##__param->askForInterface(INTERFACE_IRemoteObject, ICAST(SKEL_REMOTEREF(__param))) == RET_NOERROR) \
00156 { \
00157 lstParams.add(SKEL_REMOTEREF(__param)); \
00158 } \
00159 else \
00160 { \
00161 retValue = RET_REQUEST_FAILED; \
00162 } \
00163 pSerial##__param->release(); \
00164 } \
00165 else \
00166 { \
00167 retValue = RET_REQUEST_FAILED; \
00168 } \
00169
00170
00173
00174 #define SKEL_REMOTEREF_CHECK(__param) (SKEL_REMOTEREF(__param) != NULL)
00175
00176
00179
00180 #define SKEL_DISPATCH_END \
00181 while(lstParams.getCount() > 0) \
00182 { \
00183 lstParams[0]->release(); \
00184 lstParams.deleteItem(0); \
00185 } \
00186 rpMethodreturn = pReturnCall; \
00187 rpMethodreturn->setReturnValue(*pVarRetval); \
00188 pVarRetval->release(); \
00189 return retValue; \
00190 }
00191
00192 BEGIN_NAMESPACE_Zeus
00193
00194 class TCCTPRequest;
00195 class TCCTPResponse;
00196 class TCriticalSection;
00197
00198
00205
00206 zeusbase_class TAbstractSkel : public TThread
00207 {
00208 public:
00209 TAbstractSkel(bool bHighPerformance = false);
00210
00211 virtual Retval startSkeleton(IString& rAddress, Uint& rPort, bool bDynamic);
00212 virtual void kill(Float64 dTimeOut = 5.0);
00213 virtual void execute();
00214 void dispatch1(const TCCTPRequest& request, TCCTPResponse& response);
00215 void processAsynchronousCalls();
00216
00217 Retval getClientSocket(Uint uiThreadID, TSocket*& rpSocket) const;
00218 bool isRunning() const;
00219 void setCleanFlag();
00220 void setUseRemoteObjectAsReferencesOnly(bool bFlag);
00221
00222 protected:
00223
00225
00226 #ifdef _MSC_VER
00227 public:
00228 #endif
00229
00230
00231
00232
00233
00234
00235 class TClientHandlerThread : public TThread
00236 {
00237 public :
00238 TClientHandlerThread(TAbstractSkel& rParent, TSocket& rSocket);
00239
00240 Retval getSocket(TSocket*& rpSocket) const;
00241
00242 virtual void kill(Float64 dTimeOut = 5.0);
00243 virtual void execute();
00244
00245 protected:
00246 virtual ~TClientHandlerThread();
00247
00248 TAbstractSkel& m_rParent;
00249 TSocket& m_rClientSocket;
00250 };
00252
00253 #ifdef _MSC_VER
00254 protected:
00255 #endif
00256
00257
00259 TSingleLinkedList<TClientHandlerThread*> m_lstClients;
00261 TCriticalSection& m_rLock;
00263 TAutoPtr<TServerSocket> m_ptrSocket;
00265 bool m_bCleanFlag;
00267 bool m_bUseRemoteObjectAsReferencesOnly;
00268
00269 virtual ~TAbstractSkel();
00270 virtual Retval dispatchCommand(const IRemoteMethodCall& rMethod, IRemoteMethodCall*& rpMethodreturn) = 0;
00271 inline virtual void dispatchAsynchCommand(const IRemoteMethodCall& ) { }
00272 virtual void startNewHandler(TSocket& rClient);
00273
00274 Retval postAsynchronMethod(const IRemoteMethodCall& rMethod);
00275
00276 private:
00278 bool m_bHighPerformance;
00280 TSingleLinkedList<IRemoteMethodCall*> m_lstAsynchCall;
00281 };
00282
00283
00284
00288
00289 inline bool TAbstractSkel::isRunning() const
00290 {
00291 return (this->isAlive() && m_ptrSocket != NULL && m_ptrSocket->isBound());
00292 }
00293
00294
00299
00300 inline void TAbstractSkel::setUseRemoteObjectAsReferencesOnly(bool bFlag)
00301 {
00302 m_bUseRemoteObjectAsReferencesOnly = bFlag;
00303 }
00304
00305
00310
00311 namespace TAbstractSkelObjectRelease
00312 {
00313
00314
00317
00318 template <class T> inline void releaseInstances(T& rObject)
00319 {
00320 rObject.release();
00321 }
00322
00323
00326
00327 template <class T> inline void releaseInstances(T*& rpObject)
00328 {
00329 if (rpObject != NULL)
00330 {
00331 rpObject->release();
00332 rpObject = NULL;
00333 }
00334 }
00335
00336
00339
00340 template <> void inline releaseInstances(IRemoteObjectList& rObjectList)
00341 {
00342 while(rObjectList.getCount() > 0)
00343 {
00344 rObjectList.getItem(0)->release();
00345 rObjectList.deleteItem(0);
00346 }
00347 }
00348
00349
00352
00353 template <> void inline releaseInstances(IStringList& ) {}
00354 }
00355
00356 END_NAMESPACE_Zeus
00357
00358 #endif
00359