00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00047 #ifndef _OSRTCONTEXT_H_
00048 #define _OSRTCONTEXT_H_
00049
00050 #include "rtxsrc/rtxContext.h"
00051 #include "rtxsrc/rtxDiag.h"
00052 #include "rtxsrc/rtxError.h"
00053 #include "rtxsrc/rtxMemory.h"
00054
00055 #if defined(_MSC_VER)
00056
00057 #pragma warning(disable: 4514)
00058 #endif
00059
00065 class EXTRTCLASS OSRTContext {
00066 private:
00067 EXTRTMETHOD OSRTContext (OSCTXT*);
00068
00069 protected:
00074 OSCTXT mCtxt;
00075
00079 OSUINT32 mCount;
00080
00084 OSBOOL mbInitialized;
00085
00091 int mStatus;
00092
00093 public:
00098 EXTRTMETHOD OSRTContext ();
00099
00103 virtual EXTRTMETHOD ~OSRTContext ();
00104
00110 inline OSCTXT* getPtr () { return &mCtxt; }
00111
00112 inline const OSCTXT* getPtr () const { return &mCtxt; }
00113
00117 EXTRTMETHOD OSUINT32 getRefCount();
00118
00125 inline int getStatus () const {
00126 return (0 == mStatus) ? rtxErrGetLastError (&mCtxt) : mStatus;
00127 }
00128
00133 inline OSBOOL isInitialized () { return mbInitialized; }
00134
00138 EXTRTMETHOD void _ref();
00139
00143 EXTRTMETHOD void _unref();
00144
00153 EXTRTMETHOD char* getErrorInfo ();
00154
00167 EXTRTMETHOD char* getErrorInfo (size_t* pBufSize);
00168
00185 EXTRTMETHOD char* getErrorInfo (char* pBuf, size_t& bufSize);
00186
00196 inline void* memAlloc (size_t numocts) {
00197 return rtxMemAlloc (&mCtxt, numocts);
00198 }
00199
00206 inline void memFreeAll () {
00207 rtxMemFree (&mCtxt);
00208 }
00209
00218 inline void memFreePtr (void* ptr) {
00219 rtxMemFreePtr (&mCtxt, ptr);
00220 }
00221
00231 inline void* memRealloc (void* ptr, size_t numocts) {
00232 return rtxMemRealloc (&mCtxt, ptr, numocts);
00233 }
00234
00239 inline void memReset () {
00240 rtxMemReset (&mCtxt);
00241 }
00242
00247 inline void printErrorInfo () {
00248 rtxErrPrint (&mCtxt);
00249 }
00250
00255 inline void resetErrorInfo () {
00256 rtxErrReset (&mCtxt);
00257 }
00258
00265 inline OSBOOL setDiag (OSBOOL value=TRUE) {
00266 return rtxSetDiag (&mCtxt, value);
00267 }
00268
00279 virtual EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, size_t keylen);
00280
00287 inline int setStatus (int stat) {
00288 mStatus = stat;
00289 return stat;
00290 }
00291
00292 };
00293
00300 class EXTRTCLASS OSRTCtxtPtr {
00301 protected:
00306 OSRTContext* mPointer;
00307
00308 public:
00315 OSRTCtxtPtr (OSRTContext* rf = 0) : mPointer(rf) {
00316 if (mPointer != 0) mPointer->_ref();
00317 }
00318
00325 OSRTCtxtPtr (const OSRTCtxtPtr& o) : mPointer(o.mPointer) {
00326 if (mPointer != 0) mPointer->_ref();
00327 }
00328
00334 virtual ~OSRTCtxtPtr() { if (mPointer != 0) mPointer->_unref(); }
00335
00344 OSRTCtxtPtr& operator= (const OSRTCtxtPtr& rf) {
00345 if (mPointer != 0) mPointer->_unref();
00346 mPointer = rf.mPointer;
00347 if (mPointer != 0) mPointer->_ref();
00348 return *this;
00349 }
00350
00355 OSRTCtxtPtr& operator= (OSRTContext* rf) {
00356 if (mPointer != 0) mPointer->_unref();
00357 mPointer = rf;
00358 if (mPointer != 0) mPointer->_ref();
00359 return *this;
00360 }
00361
00365 operator OSRTContext* () { return mPointer; }
00366 operator const OSRTContext* () const { return mPointer; }
00367
00371 OSRTContext* operator -> () { return mPointer; }
00372 const OSRTContext* operator -> () const { return mPointer; }
00373
00377 OSBOOL operator == (const OSRTContext* o) const {
00378 return (mPointer == o);
00379 }
00380
00384 inline OSBOOL isNull() const { return (mPointer == 0); }
00385
00390 inline OSCTXT* getCtxtPtr() { return isNull() ? 0 : mPointer->getPtr(); }
00391
00392 };
00393
00398 EXTERNRT void* operator new (size_t nbytes, OSCTXT* pctxt);
00399
00404 EXTERNRT void operator delete (void* pmem, OSCTXT* pctxt);
00405
00406 #endif // _OSRTCONTEXT_H_