Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

SQLDBC_IRuntime.h

Go to the documentation of this file.
00001 #line 1 "C:\\SAPDevelop\\DEV\\develop\\sys\\src\\SAPDB\\Interfaces\\SQLDBC\\SQLDBC_IRuntime.h"
00002 
00024 #ifndef SQLDBC_IRUNTIME_H
00025 #define SQLDBC_IRUNTIME_H
00026 
00027 #include <string.h>
00028 
00029 #ifdef SQLDBC_FOR_KERNEL
00030 #  define IFR_NAMESPACE SQLDBC_Kernel
00031 #  define SQLDBC SQLDBC_Kernel
00032 #  define SQLDBC_RUNTIME_IN_NAMESPACE
00033 #elif defined(SQLDBC_FOR_LOADER)
00034 #  define IFR_NAMESPACE SQLDBC_Loader
00035 #endif
00036 
00037 // For encoding
00038 #include "Interfaces/SQLDBC/SQLDBC_Types.h"
00039 #include "SAPDBCommon/SAPDB_Types.h"
00040 #include "SAPDB/SAPDBCommon/MemoryManagement/SAPDBMem_IRawAllocator.hpp"
00041 #include "SAPDB/Interfaces/SQLDBC/SQLDBC_Internals.h"
00042 
00043 #ifdef IFR_NAMESPACE
00044 namespace IFR_NAMESPACE {
00045 class IFR_Environment;
00046 class IFR_ParseInfoCacheImpl;
00047 class IFR_ParseInfoCache;
00048 };
00049 using namespace IFR_NAMESPACE;
00050 #else
00051 class IFR_Environment;
00052 class IFR_ParseInfoCacheImpl;
00053 class IFR_ParseInfoCache;
00054 #endif
00055 
00056 namespace SQLDBC {
00057     class SQLDBC_Connection;
00058 }
00059 using namespace SQLDBC;
00060 
00061 #ifdef SQLDBC_RUNTIME_IN_NAMESPACE
00062 namespace SQLDBC {
00063 #endif
00064 
00108 class SQLDBC_IRuntime
00109 {
00110 public:
00111 
00116     struct Error
00117     {
00118         inline Error()
00119         :errorcode(0)
00120         {
00121             errortext[0]='\0';
00122         }
00123 
00124         inline operator SAPDB_Bool () const { return errorcode != 0; }
00125 
00126         SAPDB_Int4 errorcode;     
00127         char       errortext[80]; 
00128     };
00129     
00133     typedef void *MutexHandle;
00134 
00138     typedef void *SemaphoreHandle;
00139 
00143     typedef void *CounterHandle;
00144 
00148     struct TaskTraceContext
00149     {
00150         void           *currentEntry;   
00151         // -- further settings, used by the trace stream abstraction.
00152         SAPDB_Bool  hex;               
00153         SAPDB_UInt4 inputlength;       
00154         SQLDBC_StringEncoding encoding;
00155         SAPDB_UInt4 indent;            
00156         SAPDB_UInt4 flags;             
00157         SAPDB_UInt4 traceableLimit;    
00158         SAPDB_UInt4 pos;               
00159     };
00160         
00164     typedef SAPDB_UInt4 TaskID;
00165 
00169     virtual ~SQLDBC_IRuntime() {}
00170 
00176     virtual const char *getIdentifier() const { return ""; }
00177 
00204     virtual SAPDB_Bool checkKeyOption(const char *keyoption,
00205                                       char *servernode,
00206                                       SAPDB_Int4& servernodelength,
00207                                       char *serverdb,
00208                                       SAPDB_Int4& serverdblength,
00209                                       SAPDB_Int4& isolationlevel,
00210                                       SAPDB_Int4& cachelimit,
00211                                       SAPDB_Int4& sqlmode,
00212                                       SAPDB_Int4& timeout,
00213                                       char *username,
00214                                       SAPDB_Int4& usernamelength,
00215                                       SQLDBC_StringEncoding& usernameEncoding,
00216                                       SQLDBC_IRuntime::Error& error)
00217     {
00218         return false;
00219     }
00220                                   
00221 
00222     
00233     virtual SAPDBMem_IRawAllocator& getGlobalAllocator() = 0;
00234 
00235     // Packet and Session Handling
00236 
00274     virtual SAPDB_Bool getSession(const char *connectUrl,
00275                                   const char *connectCommand,
00276                                   const char *password,
00277                                   SAPDB_Int4  passwordLength,
00278                                   const SQLDBC_StringEncoding commandEncoding,
00279                                   SAPDB_Int8&  sessionID,
00280                                   SAPDB_UInt4& packetSize,
00281                                   SAPDB_Int4& packetListSize,
00282                                   void **packetList,  
00283                                   void **sessionInfoReply,
00284                                   SQLDBC_IRuntime::Error& error,
00285                                   SAPDBMem_IRawAllocator* allocator = 0) = 0;
00286 
00287 
00288     virtual SAPDB_Bool getSession(const char *connectUrl,
00289                                   const char *connectCommand,
00290                                   const char *username,
00291                                   SAPDB_Int4  usernamelength,
00292                                   const char *password,
00293                                   SAPDB_Int4  passwordLength,
00294                                   const SQLDBC_StringEncoding commandEncoding,
00295                                   SAPDB_Int8&  sessionID,
00296                                   SAPDB_UInt4& packetSize,
00297                                   SAPDB_Int4& packetListSize,
00298                                   void **packetList,  
00299                                   void **sessionInfoReply,
00300                                   SQLDBC_IRuntime::Error& error,
00301                                   SAPDBMem_IRawAllocator* allocator = 0) = 0;
00302 
00311     virtual SAPDB_Bool releaseSession(SAPDB_Int8 sessionID,
00312                                       SQLDBC_IRuntime::Error& error) = 0;
00313     
00324     virtual SAPDB_Bool request(SAPDB_Int8  sessionID,
00325                                void       *requestData,
00326                                SAPDB_UInt4 requestDataLength,
00327                                SQLDBC_IRuntime::Error& error) = 0; 
00328 
00338     virtual SAPDB_Bool receive(SAPDB_Int8 sessionID,
00339                                void **replyData,
00340                                SAPDB_Int4& replyDataLength,
00341                                SQLDBC_IRuntime::Error& error) = 0;
00342 
00347     virtual SAPDB_Bool isReplyAvailable(SAPDB_Int8 sessionID)
00348     {
00349         return true;
00350     }
00351     
00359     virtual SAPDB_Bool cancelCurrentCommand(SAPDB_Int8 sessionID,
00360                                             SQLDBC_IRuntime::Error& error) = 0;
00361 
00362     // -- synchronization primitives
00369     virtual SQLDBC_Spinlock* createSpinlock(SAPDBMem_IRawAllocator& allocator)  = 0;
00370 
00378     virtual SAPDB_Bool releaseSpinlock(SAPDBMem_IRawAllocator& allocator, SQLDBC_Spinlock* lock) = 0;
00379 
00389     virtual SAPDB_Bool createMutex(MutexHandle& mutexHandle, 
00390                                    SAPDBMem_IRawAllocator& allocator,
00391                                    SQLDBC_IRuntime::Error& error)  = 0;
00392 
00399     virtual SAPDB_Bool lockMutex(MutexHandle mutexHandle) = 0;
00400     
00407     virtual SAPDB_Bool releaseMutex(MutexHandle mutexHandle) = 0;
00408     
00417     virtual SAPDB_Bool destroyMutex(MutexHandle& mutexHandle, 
00418                                     SAPDBMem_IRawAllocator& allocator,
00419                                     SQLDBC_IRuntime::Error& error) = 0;
00420     
00429     virtual SAPDB_Bool  createCounter(CounterHandle& counterHandle,
00430                                       SAPDBMem_IRawAllocator& allocator,
00431                                       SQLDBC_IRuntime::Error& error)  = 0;
00432 
00433     
00439     virtual SAPDB_UInt4 nextCounter(CounterHandle counterHandle) = 0;
00440     
00450     virtual SAPDB_Bool  destroyCounter(CounterHandle counterHandle,
00451                                       SAPDBMem_IRawAllocator& allocator,
00452                                       SQLDBC_IRuntime::Error& error)  = 0;
00453            
00460     virtual TaskID getCurrentTaskID() = 0;                                      
00461                                       
00471     virtual SAPDB_Bool createSemaphore(SemaphoreHandle& semaphoreHandle,
00472                                        SAPDB_Int4 initialValue,
00473                                        SAPDBMem_IRawAllocator& allocator,
00474                                        SQLDBC_IRuntime::Error& error) = 0;
00475 
00483     virtual SAPDB_Bool waitSemaphore(SemaphoreHandle semaphoreHandle) =0;
00484 
00491     virtual SAPDB_Bool signalSemaphore(SemaphoreHandle semaphoreHandle) =0;
00492     
00502     virtual SAPDB_Bool destroySemaphore(SemaphoreHandle& semaphoreHandle,
00503                                         SAPDBMem_IRawAllocator& allocator,
00504                                         SQLDBC_IRuntime::Error& error)  = 0;
00505     
00506     // -- Tracing    
00514     virtual TaskTraceContext* getTaskTraceContext() = 0;
00515     
00522     virtual void write(const char *s, SAPDB_Int4 size) = 0;
00523     
00530     virtual void writeln(const char *s, SAPDB_Int4 size) = 0;
00531     
00541     virtual void updateTraceFlags(SAPDB_Bool& traceEnabled) {
00542         TaskTraceContext *ctx = getTaskTraceContext();
00543         if(ctx) {
00544             if(ctx->flags) {
00545                 traceEnabled = true;
00546                 return;
00547             }
00548         } 
00549         traceEnabled = false;
00550         return;
00551     }
00552 
00559     virtual SAPDB_Bool traceError(SAPDB_Int4 errorcode) { return false; }
00560 
00561     //-- internally for client runtime used, no use in Kernel/OMS/...
00562     
00563     virtual void setTraceOptions(const char *optionstring) 
00564     { 
00565         return; 
00566     }
00567     
00568     virtual SAPDB_Int4 getTraceOptions(char *options, SAPDB_Int4 optionslength) 
00569     { 
00570         if(options && optionslength>0) {
00571             *options = '\0';
00572         }
00573         return 0; 
00574     }
00575 
00580     virtual void addTraceFlags(unsigned int flags) = 0;
00581 
00586     virtual void removeTraceFlags(unsigned int flags) = 0;
00587 
00591     virtual unsigned int getTraceFlags()
00592     {
00593         return 0;
00594     }
00595 
00596 
00600     virtual SAPDB_Bool getSessionInformation(SQLDBC_Connection *connection,
00601                                              SAPDB_Int8& sessionID,
00602                                              SAPDB_UInt4& packetSize,
00603                                              SAPDB_UInt4& pagesSize,
00604                                              SAPDB_Int4&  packetListSize,
00605                                              void **packetList,
00606                                              char *usergroup,
00607                                              char *sysdba,
00608                                              SQLDBC_StringEncoding& userencoding)
00609     {
00610         return false;
00611     }
00612     
00613 
00614 protected:
00615     struct EnvironmentList
00616     {
00617         EnvironmentList   *next;
00618         EnvironmentList   *prev;
00619         SQLDBC_Spinlock *spinlock;
00620     };
00621     
00622     struct Profile
00623     {
00624         SQLDBC_UInt8      counter[SQLDBC_PROFILE_MAX];
00625         void             *environmentlist;  // SUN cannot use pointer to EnvironmentList list here 
00626                                             // (compiler bug)
00627     };
00628 
00629     SQLDBC_IRuntime (SQLDBC_Spinlock* lock)
00630     {
00631         m_environmentlist.next = &m_environmentlist;
00632         m_environmentlist.prev = &m_environmentlist;
00633         m_environmentlist.spinlock = lock;
00634         
00635         memset(m_profile.counter, 0, sizeof(m_profile.counter));
00636         m_profile.environmentlist = &m_environmentlist;
00637     }
00638     
00639     EnvironmentList m_environmentlist;
00640     Profile         m_profile;
00641     
00642 private:
00643 #if defined(IFR_NAMESPACE)
00644     friend class ::IFR_NAMESPACE::IFR_Environment;
00645     friend class ::IFR_NAMESPACE::IFR_ParseInfoCacheImpl;
00646     friend class ::IFR_NAMESPACE::IFR_ParseInfoCache;
00647 #else
00648     friend class IFR_Environment;
00649     friend class IFR_ParseInfoCacheImpl;
00650     friend class IFR_ParseInfoCache;
00651 #endif
00652 };
00653 
00654 #ifdef SQLDBC_RUNTIME_IN_NAMESPACE
00655 };
00656 #endif
00657 
00658 #endif
00659