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
00209 inline void* memAllocZ (size_t numocts) {
00210 return rtxMemAllocZ (&mCtxt, numocts);
00211 }
00212
00219 inline void memFreeAll () {
00220 rtxMemFree (&mCtxt);
00221 }
00222
00231 inline void memFreePtr (void* ptr) {
00232 rtxMemFreePtr (&mCtxt, ptr);
00233 }
00234
00244 inline void* memRealloc (void* ptr, size_t numocts) {
00245 return rtxMemRealloc (&mCtxt, ptr, numocts);
00246 }
00247
00252 inline void memReset () {
00253 rtxMemReset (&mCtxt);
00254 }
00255
00260 inline void printErrorInfo () {
00261 rtxErrPrint (&mCtxt);
00262 }
00263
00268 inline void resetErrorInfo () {
00269 rtxErrReset (&mCtxt);
00270 }
00271
00278 inline OSBOOL setDiag (OSBOOL value=TRUE) {
00279 return rtxSetDiag (&mCtxt, value);
00280 }
00281
00292 virtual EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, size_t keylen);
00293
00300 inline int setStatus (int stat) {
00301 mStatus = stat;
00302 return stat;
00303 }
00304
00305 };
00306
00313 class EXTRTCLASS OSRTCtxtPtr {
00314 protected:
00319 OSRTContext* mPointer;
00320
00321 public:
00328 OSRTCtxtPtr (OSRTContext* rf = 0) : mPointer(rf) {
00329 if (mPointer != 0) mPointer->_ref();
00330 }
00331
00338 OSRTCtxtPtr (const OSRTCtxtPtr& o) : mPointer(o.mPointer) {
00339 if (mPointer != 0) mPointer->_ref();
00340 }
00341
00347 virtual ~OSRTCtxtPtr() { if (mPointer != 0) mPointer->_unref(); }
00348
00357 OSRTCtxtPtr& operator= (const OSRTCtxtPtr& rf) {
00358 if (mPointer != 0) mPointer->_unref();
00359 mPointer = rf.mPointer;
00360 if (mPointer != 0) mPointer->_ref();
00361 return *this;
00362 }
00363
00368 OSRTCtxtPtr& operator= (OSRTContext* rf) {
00369 if (mPointer != 0) mPointer->_unref();
00370 mPointer = rf;
00371 if (mPointer != 0) mPointer->_ref();
00372 return *this;
00373 }
00374
00378 operator OSRTContext* () { return mPointer; }
00379 operator const OSRTContext* () const { return mPointer; }
00380
00384 OSRTContext* operator -> () { return mPointer; }
00385 const OSRTContext* operator -> () const { return mPointer; }
00386
00390 OSBOOL operator == (const OSRTContext* o) const {
00391 return (mPointer == o);
00392 }
00393
00397 inline OSBOOL isNull() const { return (mPointer == 0); }
00398
00403 inline OSCTXT* getCtxtPtr() { return isNull() ? 0 : mPointer->getPtr(); }
00404
00405 };
00406
00411 EXTERNRT void* operator new (size_t nbytes, OSCTXT* pctxt);
00412
00417 EXTERNRT void operator delete (void* pmem, OSCTXT* pctxt);
00418
00419 #endif // _OSRTCONTEXT_H_