00001
00032 #ifndef SQLDBC_IRUNTIME_H
00033 #define SQLDBC_IRUNTIME_H
00034
00035 #ifdef SQLDBC_FOR_KERNEL
00036 # define IFR_NAMESPACE SQLDBC_Kernel
00037 # define SQLDBC SQLDBC_Kernel
00038 # define SQLDBC_RUNTIME_IN_NAMESPACE
00039 #endif
00040
00041
00042 #include "Interfaces/SQLDBC/SQLDBC_Types.h"
00043 #include "SAPDBCommon/SAPDB_Types.h"
00044 #include "SAPDBCommon/SAPDB_ReuseLib.h"
00045 #include "SAPDB/SAPDBCommon/MemoryManagement/SAPDBMem_IRawAllocator.hpp"
00046 #include "SAPDB/Interfaces/SQLDBC/SQLDBC_Internals.h"
00047
00048 #ifdef IFR_NAMESPACE
00049 namespace IFR_NAMESPACE {
00050 class IFR_Environment;
00051 };
00052 using namespace IFR_NAMESPACE;
00053 #else
00054 class IFR_Environment;
00055 #endif
00056
00057 namespace SQLDBC {
00058 class SQLDBC_Connection;
00059 }
00060 using namespace SQLDBC;
00061
00062 #ifdef SQLDBC_RUNTIME_IN_NAMESPACE
00063 namespace SQLDBC {
00064 #endif
00065
00109 class SQLDBC_IRuntime
00110 {
00111 public:
00112
00117 struct Error
00118 {
00119 inline Error()
00120 :errorcode(0)
00121 {
00122 errortext[0]='\0';
00123 }
00124
00125 inline operator SAPDB_Bool () const { return errorcode != 0; }
00126
00127 SAPDB_Int4 errorcode;
00128 char errortext[80];
00129 };
00130
00134 typedef void *MutexHandle;
00135
00139 typedef void *SemaphoreHandle;
00140
00144 typedef void *CounterHandle;
00145
00149 struct TaskTraceContext
00150 {
00151 void *currentEntry;
00152
00153 SAPDB_Bool hex;
00154 SAPDB_UInt4 inputlength;
00155 SQLDBC_StringEncoding encoding;
00156 SAPDB_UInt4 indent;
00157 SAPDB_UInt4 flags;
00158 SAPDB_UInt4 traceableLimit;
00159 SAPDB_UInt4 pos;
00160 };
00161
00165 typedef SAPDB_UInt4 TaskID;
00166
00170 virtual ~SQLDBC_IRuntime() {}
00171
00177 virtual const char *getIdentifier() const { return ""; }
00178
00205 virtual SAPDB_Bool checkKeyOption(const char *keyoption,
00206 char *servernode,
00207 SAPDB_Int4& servernodelength,
00208 char *serverdb,
00209 SAPDB_Int4& serverdblength,
00210 SAPDB_Int4& isolationlevel,
00211 SAPDB_Int4& cachelimit,
00212 SAPDB_Int4& sqlmode,
00213 SAPDB_Int4& timeout,
00214 char *username,
00215 SAPDB_Int4& usernamelength,
00216 SQLDBC_StringEncoding& usernameEncoding,
00217 SQLDBC_IRuntime::Error& error)
00218 {
00219 return false;
00220 }
00221
00222
00223
00234 virtual SAPDBMem_IRawAllocator& getGlobalAllocator() = 0;
00235
00236
00237
00275 virtual SAPDB_Bool getSession(const char *connectUrl,
00276 const char *connectCommand,
00277 const char *password,
00278 SAPDB_Int4 passwordLength,
00279 const SQLDBC_StringEncoding commandEncoding,
00280 SAPDB_Int8& sessionID,
00281 SAPDB_UInt4& packetSize,
00282 SAPDB_Int4& packetListSize,
00283 void **packetList,
00284 void **sessionInfoReply,
00285 SQLDBC_IRuntime::Error& error,
00286 SAPDBMem_IRawAllocator* allocator = 0) = 0;
00287
00288
00289 virtual SAPDB_Bool getSession(const char *connectUrl,
00290 const char *connectCommand,
00291 const char *username,
00292 SAPDB_Int4 usernamelength,
00293 const char *password,
00294 SAPDB_Int4 passwordLength,
00295 const SQLDBC_StringEncoding commandEncoding,
00296 SAPDB_Int8& sessionID,
00297 SAPDB_UInt4& packetSize,
00298 SAPDB_Int4& packetListSize,
00299 void **packetList,
00300 void **sessionInfoReply,
00301 SQLDBC_IRuntime::Error& error,
00302 SAPDBMem_IRawAllocator* allocator = 0) = 0;
00303
00312 virtual SAPDB_Bool releaseSession(SAPDB_Int8 sessionID,
00313 SQLDBC_IRuntime::Error& error) = 0;
00314
00325 virtual SAPDB_Bool request(SAPDB_Int8 sessionID,
00326 void *requestData,
00327 SAPDB_UInt4 requestDataLength,
00328 SQLDBC_IRuntime::Error& error) = 0;
00329
00339 virtual SAPDB_Bool receive(SAPDB_Int8 sessionID,
00340 void **replyData,
00341 SAPDB_Int4& replyDataLength,
00342 SQLDBC_IRuntime::Error& error) = 0;
00343
00348 virtual SAPDB_Bool isReplyAvailable(SAPDB_Int8 sessionID)
00349 {
00350 return true;
00351 }
00352
00360 virtual SAPDB_Bool cancelCurrentCommand(SAPDB_Int8 sessionID,
00361 SQLDBC_IRuntime::Error& error) = 0;
00362
00363
00370 virtual SQLDBC_Spinlock* createSpinlock(SAPDBMem_IRawAllocator& allocator) = 0;
00371
00379 virtual SAPDB_Bool releaseSpinlock(SAPDBMem_IRawAllocator& allocator, SQLDBC_Spinlock* lock) = 0;
00380
00390 virtual SAPDB_Bool createMutex(MutexHandle& mutexHandle,
00391 SAPDBMem_IRawAllocator& allocator,
00392 SQLDBC_IRuntime::Error& error) = 0;
00393
00400 virtual SAPDB_Bool lockMutex(MutexHandle mutexHandle) = 0;
00401
00408 virtual SAPDB_Bool releaseMutex(MutexHandle mutexHandle) = 0;
00409
00418 virtual SAPDB_Bool destroyMutex(MutexHandle& mutexHandle,
00419 SAPDBMem_IRawAllocator& allocator,
00420 SQLDBC_IRuntime::Error& error) = 0;
00421
00430 virtual SAPDB_Bool createCounter(CounterHandle& counterHandle,
00431 SAPDBMem_IRawAllocator& allocator,
00432 SQLDBC_IRuntime::Error& error) = 0;
00433
00434
00440 virtual SAPDB_UInt4 nextCounter(CounterHandle counterHandle) = 0;
00441
00451 virtual SAPDB_Bool destroyCounter(CounterHandle counterHandle,
00452 SAPDBMem_IRawAllocator& allocator,
00453 SQLDBC_IRuntime::Error& error) = 0;
00454
00461 virtual TaskID getCurrentTaskID() = 0;
00462
00472 virtual SAPDB_Bool createSemaphore(SemaphoreHandle& semaphoreHandle,
00473 SAPDB_Int4 initialValue,
00474 SAPDBMem_IRawAllocator& allocator,
00475 SQLDBC_IRuntime::Error& error) = 0;
00476
00484 virtual SAPDB_Bool waitSemaphore(SemaphoreHandle semaphoreHandle) =0;
00485
00492 virtual SAPDB_Bool signalSemaphore(SemaphoreHandle semaphoreHandle) =0;
00493
00503 virtual SAPDB_Bool destroySemaphore(SemaphoreHandle& semaphoreHandle,
00504 SAPDBMem_IRawAllocator& allocator,
00505 SQLDBC_IRuntime::Error& error) = 0;
00506
00507
00515 virtual TaskTraceContext* getTaskTraceContext() = 0;
00516
00523 virtual void write(const char *s, SAPDB_Int4 size) = 0;
00524
00531 virtual void writeln(const char *s, SAPDB_Int4 size) = 0;
00532
00542 virtual void updateTraceFlags(SAPDB_Bool& traceEnabled) {
00543 TaskTraceContext *ctx = getTaskTraceContext();
00544 if(ctx) {
00545 if(ctx->flags) {
00546 traceEnabled = true;
00547 return;
00548 }
00549 }
00550 traceEnabled = false;
00551 return;
00552 }
00553
00560 virtual SAPDB_Bool traceError(SAPDB_Int4 errorcode) { return false; }
00561
00562
00563
00564 virtual void setTraceOptions(const char *optionstring)
00565 {
00566 return;
00567 }
00568
00569 virtual SAPDB_Int4 getTraceOptions(char *options, SAPDB_Int4 optionslength)
00570 {
00571 if(options && optionslength>0) {
00572 *options = '\0';
00573 }
00574 return 0;
00575 }
00576
00581 virtual void addTraceFlags(unsigned int flags) = 0;
00582
00587 virtual void removeTraceFlags(unsigned int flags) = 0;
00588
00589
00593 virtual SAPDB_Bool getSessionInformation(SQLDBC_Connection *connection,
00594 SAPDB_Int8& sessionID,
00595 SAPDB_UInt4& packetSize,
00596 SAPDB_UInt4& pagesSize,
00597 SAPDB_Int4& packetListSize,
00598 void **packetList,
00599 char *usergroup,
00600 char *sysdba,
00601 SQLDBC_StringEncoding& userencoding)
00602 {
00603 return false;
00604 }
00605
00606
00607 protected:
00608 struct EnvironmentList
00609 {
00610 EnvironmentList *next;
00611 EnvironmentList *prev;
00612 SQLDBC_Spinlock *spinlock;
00613 };
00614
00615 struct Profile
00616 {
00617 SQLDBC_UInt8 counter[SQLDBC_PROFILE_MAX];
00618 void *environmentlist;
00619
00620 };
00621
00622 SQLDBC_IRuntime (SQLDBC_Spinlock* lock)
00623 {
00624 m_environmentlist.next = &m_environmentlist;
00625 m_environmentlist.prev = &m_environmentlist;
00626 m_environmentlist.spinlock = lock;
00627
00628 memset(m_profile.counter, 0, sizeof(m_profile.counter));
00629 m_profile.environmentlist = &m_environmentlist;
00630 }
00631
00632 EnvironmentList m_environmentlist;
00633 Profile m_profile;
00634
00635 private:
00636 friend class IFR_Environment;
00637 friend class IFR_ParseInfoCacheImpl;
00638 friend class IFR_ParseInfoCache;
00639 };
00640
00641 #ifdef SQLDBC_RUNTIME_IN_NAMESPACE
00642 };
00643 #endif
00644
00645 #endif
00646