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 AbstractStubH
00033 #define AbstractStubH
00034
00035 #include <zeusbase/System/ZObject.h>
00036 #include <zeusbase/System/ZVariant.h>
00037 #include <zeusbase/System/ByteArray.hpp>
00038 #include <zeusbase/System/Stack.hpp>
00039 #include <zeusbase/System/StringList.h>
00040 #include <zeusbase/Remote/RemoteDefines.hpp>
00041 #include <zeusbase/Remote/RemoteMethodCall.h>
00042 #include <zeusbase/Remote/RemoteReference.h>
00043 #include <zeusbase/Remote/Interfaces/IRemoteObjectStub.hpp>
00044
00045 BEGIN_NAMESPACE_Zeus
00046
00047
00053
00054 #define STUB_CLASS_DECL(classid, classname) \
00055 public: \
00056 static Retval MQUALIFIER createObject(Uint , IInputStream* pStream, IZUnknown*& rpObj) \
00057 { \
00058 Retval retValue = RET_REQUEST_FAILED; \
00059 \
00060 if (pStream == NULL)\
00061 { \
00062 rpObj = (IRemoteObject*)new classid();\
00063 retValue = RET_NOERROR;\
00064 } \
00065 return retValue;\
00066 } \
00067 \
00068 static void autoreg(bool reg)\
00069 { \
00070 static Uint classid##Handle = 0;\
00071 TString strClassName(classname); \
00072 if (reg) \
00073 { \
00074 classid##Handle = ZObjectFactory.registerClass(strClassName, createObject); \
00075 } \
00076 else \
00077 { \
00078 ZObjectFactory.unregisterClass(strClassName, classid##Handle); \
00079 } \
00080 } \
00081
00082
00083
00088
00089 #define STUB_DELEGATION(name, method) \
00090 method \
00091 { \
00092 Retval retValue = RET_REQUEST_FAILED; \
00093 TRemoteMethodCall* pMethod = new TRemoteMethodCall(name); \
00094 TStack<IZUnknown*> lstOutReferences;
00095
00096
00102
00103 #define STUB_PARAM(__name, __param) \
00104 { \
00105 TZVariant* pVar = new TZVariant(__name, __param); \
00106 pMethod->addParameter(*pVar); \
00107 pVar->release(); \
00108 }
00109
00110
00120
00121 #define STUB_PARAM_REMOTEREF(__name, __param) \
00122 { \
00123 TRemoteReference* pRef = new TRemoteReference(__param); \
00124 STUB_PARAM(__name, *pRef); \
00125 pRef->release(); \
00126 }
00127
00128
00129
00137
00138 #define STUB_RETURN_START \
00139 IRemoteMethodCall* pMethodReturn = NULL; \
00140 retValue = this->sendMethod(*pMethod, pMethodReturn);\
00141 \
00142 if (retValue == RET_NOERROR) \
00143 { \
00144
00145
00150
00151 #define STUB_RETPARAM_STRING(__name, __param) \
00152 if (retValue == RET_NOERROR) \
00153 { \
00154 TString strName(__name); \
00155 IZVariant* pVariant; \
00156 if (pMethodReturn->getParameterByName(strName, pVariant) == RET_NOERROR) \
00157 { \
00158 TString strData; \
00159 if (pVariant->getString(strData) == RET_NOERROR) \
00160 { \
00161 __param.assignStr(strData); \
00162 retValue = RET_NOERROR; \
00163 } \
00164 else \
00165 { \
00166 retValue = RET_REQUEST_FAILED; \
00167 } \
00168 pVariant->release(); \
00169 } \
00170 else \
00171 { \
00172 retValue = RET_REMOTEPROTOCOL_ERROR; \
00173 } \
00174 }
00175
00176
00181
00182 #define STUB_RETPARAM_STRING_PTR(__name, __param) \
00183 if (retValue == RET_NOERROR) \
00184 { \
00185 TString strName(__name); \
00186 IZVariant* pVariant; \
00187 if (pMethodReturn->getParameterByName(strName, pVariant) == RET_NOERROR) \
00188 { \
00189 TString strData; \
00190 if (pVariant->getString(strData) == RET_NOERROR) \
00191 { \
00192 __param->assignStr(strData); \
00193 retValue = RET_NOERROR; \
00194 } \
00195 else \
00196 { \
00197 retValue = RET_REQUEST_FAILED; \
00198 } \
00199 pVariant->release(); \
00200 } \
00201 else \
00202 { \
00203 retValue = RET_REMOTEPROTOCOL_ERROR; \
00204 } \
00205 }
00206
00207
00212
00213 #define STUB_RETPARAM_STRINGLIST(__name, __param) \
00214 if (retValue == RET_NOERROR) \
00215 { \
00216 TString strCountName = RPARAM_LIST_COUNT(__name); \
00217 IZVariant* pCountVariant; \
00218 if (pMethodReturn->getParameterByName(strCountName, pCountVariant) == RET_NOERROR) \
00219 { \
00220 Int iCount = 0; \
00221 pCountVariant->getInt32(iCount); \
00222 for(Int i = 0; (i < iCount && retValue == RET_NOERROR); i++) \
00223 { \
00224 TString strParamName = RPARAM_LIST_ITEM(__name, i); \
00225 TString strParamValue; \
00226 IString* pParamValuePtr = &strParamValue; \
00227 STUB_RETPARAM_STRING_PTR(strParamName, pParamValuePtr); \
00228 if (retValue == RET_NOERROR) \
00229 { \
00230 __param->add(strParamValue);\
00231 } \
00232 } \
00233 if (retValue != RET_NOERROR) \
00234 { \
00235 __param->clear(); \
00236 } \
00237 pCountVariant->release(); \
00238 } \
00239 else \
00240 { \
00241 retValue = RET_REMOTEPROTOCOL_ERROR; \
00242 } \
00243 }
00244
00245
00246 #define STUB_CREATE_STUB(__object, __stub) \
00247 TRemoteReference* pRef = (TRemoteReference*)__object; \
00248 if (pRef->createStub(&__stub) == RET_NOERROR) \
00249 { \
00250 lstOutReferences.push(__stub); \
00251 } \
00252 else \
00253 { \
00254 retValue = RET_UNREGISTERED_CLASS; \
00255 } \
00256
00257
00258
00266
00267 #define STUB_RETPARAM_REMOTEREF(__name, __param) \
00268 if (retValue == RET_NOERROR) \
00269 { \
00270 TString strName(__name); \
00271 IZVariant* pVariant; \
00272 if (pMethodReturn->getParameterByName(strName, pVariant) == RET_NOERROR) \
00273 { \
00274 ISerializable* pObject = NULL; \
00275 if (pVariant->getObject(pObject) == RET_NOERROR) \
00276 { \
00277 STUB_CREATE_STUB(pObject, *__param); \
00278 pObject->release(); \
00279 } \
00280 else \
00281 { \
00282 retValue = RET_REQUEST_FAILED; \
00283 } \
00284 pVariant->release(); \
00285 } \
00286 else \
00287 { \
00288 retValue = RET_REMOTEPROTOCOL_ERROR; \
00289 } \
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299 \
00300
00301
00309
00310 #define STUB_RETPARAM_REMOTEREFLIST(__name, __param) \
00311 if (retValue == RET_NOERROR) \
00312 { \
00313 TString strName(__name); \
00314 IZVariant* pVariant; \
00315 if (pMethodReturn->getParameterByName(strName, pVariant) == RET_NOERROR) \
00316 { \
00317 TSingleLinkedList<ISerializable*> lstObjects; \
00318 if (pVariant->getObjectList(lstObjects) == RET_NOERROR) \
00319 { \
00320 TIterator<ISerializable*> It = lstObjects.getIterator(); \
00321 while (It.hasNextItem()) \
00322 { \
00323 IRemoteObject* pStub = NULL;\
00324 ISerializable* pObject = It.getNextItem(); \
00325 STUB_CREATE_STUB(pObject, pStub); \
00326 if (pStub != NULL) \
00327 { \
00328 __param->add(pStub);\
00329 } \
00330 } \
00331 \
00332 while(lstObjects.getCount() > 0) \
00333 { \
00334 lstObjects[0]->release(); \
00335 lstObjects.deleteItem(0); \
00336 } \
00337 if (__param->getCount() > 0) \
00338 { \
00339 retValue = RET_NOERROR; \
00340 } \
00341 } \
00342 else \
00343 { \
00344 retValue = RET_REQUEST_FAILED; \
00345 } \
00346 pVariant->release(); \
00347 } \
00348 else \
00349 { \
00350 retValue = RET_REMOTEPROTOCOL_ERROR; \
00351 } \
00352 }
00353
00354
00358
00359 #define STUB_RETVALUE_LONG(__retvar) \
00360 if (retValue == RET_NOERROR) \
00361 { \
00362 IZVariant* pRetVar = NULL; \
00363 if (pMethodReturn->getReturnValue(pRetVar) == RET_NOERROR) \
00364 { \
00365 if (pRetVar->getType() == IZVariant::etInt32) \
00366 { \
00367 Int iVal = 0;\
00368 pRetVar->getInt32(iVal); \
00369 __retvar = iVal; \
00370 } \
00371 else \
00372 { \
00373 retValue = RET_REMOTEPROTOCOL_ERROR; \
00374 } \
00375 pRetVar->release(); \
00376 } \
00377 }
00378
00379
00383
00384 #define STUB_RETVALUE_DOUBLE(__retvar) \
00385 if (retValue == RET_NOERROR) \
00386 { \
00387 IZVariant* pRetVar = NULL; \
00388 if (pMethodReturn->getReturnValue(pRetVar) == RET_NOERROR) \
00389 { \
00390 if (pRetVar->getType() == IZVariant::etFloat64) \
00391 { \
00392 pRetVar->getFloat64(__retvar); \
00393 } \
00394 else \
00395 { \
00396 retValue = RET_REMOTEPROTOCOL_ERROR; \
00397 } \
00398 pRetVar->release(); \
00399 } \
00400 }
00401
00402
00403
00407
00408 #define STUB_RETURN_END(__retvar) \
00409 pMethodReturn->release(); \
00410 } \
00411 pMethod->release(); \
00412 if (retValue != RET_NOERROR)\
00413 { \
00414 while(!lstOutReferences.isEmpty()) \
00415 { \
00416 lstOutReferences.pop()->release(); \
00417 } \
00418 } \
00419 return __retvar; \
00420 }
00421
00422
00425
00426 #define STUB_RETURN_ERRORCODE \
00427 STUB_RETURN_START \
00428 STUB_RETVALUE_LONG(retValue) \
00429 STUB_RETURN_END(retValue)
00430
00431
00434
00435 #define STUB_RETURN_VOID \
00436 pMethodReturn->release(); \
00437 } \
00438 pMethod->release(); \
00439 }
00440
00441 class TSocket;
00442
00443
00447
00448 zeusbase_class TAbstractStub : public TZObject, public IRemoteObjectStub
00449 {
00450 public :
00451 TAbstractStub(bool bHighPerformance = false);
00452
00453
00454 virtual void MQUALIFIER setClassName(const IString& rName);
00455 virtual void MQUALIFIER setCodeModuleName(const IString& rName);
00456 virtual Retval MQUALIFIER connect(const IString& rAddress, Uint uiPort);
00457
00458
00459 virtual void MQUALIFIER getClassName(IString& rName) const;
00460 virtual void MQUALIFIER getCodeModuleName(IString& rName) const;
00461 virtual Retval MQUALIFIER getConnectionParam(IString& rAddress, Uint& uiPort) const;
00462
00463
00464 MEMORY_MANAGER_DECL
00465
00466 protected:
00468 TSocket* m_pSocket;
00470 TString m_strCodeModule;
00472 TString m_strClassName;
00474 TString m_strAddress;
00476 Uint m_uiPort;
00477
00478 virtual ~TAbstractStub();
00479
00480 Retval sendMethod(TRemoteMethodCall& rMethod, IRemoteMethodCall*& rpMethodreturn) const;
00481 Retval getMethodReturn(IRemoteMethodCall*& rpMethodreturn) const;
00482 void disconnect();
00483
00484 private:
00485 virtual Retval MQUALIFIER createStub(IRemoteObject*& ) { return RET_METHOD_NOT_IMPL; }
00486
00488 bool m_bHighPerformance;
00489 };
00490
00491
00492
00495
00496 inline void MQUALIFIER TAbstractStub::setClassName(const IString& rName)
00497 {
00498 m_strClassName = rName;
00499 }
00500
00501
00504
00505 inline void MQUALIFIER TAbstractStub::setCodeModuleName(const IString& rName)
00506 {
00507 m_strCodeModule = rName;
00508 }
00509
00510
00511
00514
00515 inline void MQUALIFIER TAbstractStub::getClassName(IString& rName) const
00516 {
00517 rName.assignStr(m_strClassName);
00518 }
00519
00520
00523
00524 inline void MQUALIFIER TAbstractStub::getCodeModuleName(IString& rName) const
00525 {
00526 rName.assignStr(m_strCodeModule);
00527 }
00528
00529
00532
00533 inline Retval MQUALIFIER TAbstractStub::getConnectionParam(IString& rAddress, Uint& uiPort) const
00534 {
00535 rAddress.assignStr(m_strAddress);
00536 uiPort = m_uiPort;
00537 return RET_NOERROR;
00538 }
00539
00540 END_NAMESPACE_Zeus
00541
00542
00543 #endif