00001 // OSB library ************************************************ -*- C++ -*- 00006 /* 00007 AUTHOR(S): Stephan Broennimann (vb) 00008 00009 RCS information 00010 $Name: OSB_060808 $ 00011 $Revision: 1.8 $ 00012 00013 License 00014 OSB rating and billing library for communication networks 00015 Copyright (C) 2004, 2005, 2006 OSB systems 00016 00017 This file may be distributed and/or modify under the terms of the 00018 GNU General Public License (GPL) as published by the Free Software 00019 Foundation which is provided in the file LICENSE.GPL included in the 00020 packaging of this file. 00021 00022 The file is distributed in the hope that it will be useful, but WITHOUT 00023 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00024 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00025 for more details. 00026 00027 Holders of a OSB Commercial License may use this file under the terms 00028 and conditions of this commercial license. 00029 */ 00030 #ifndef _RQSGLOBAL_H_ 00031 #define _RQSGLOBAL_H_ 00032 00033 // ************************************************************************ 00034 // included header files 00035 // + standard includes 00036 #include <memory> 00037 00038 // + libraries 00039 00040 // + local headers 00041 00042 // + class declarations 00043 namespace OSB_DB { 00044 class Session; 00045 } 00046 00047 namespace OSB_LIB { 00048 class Mutex; 00049 class RequestHandler; 00050 } 00051 00052 namespace corba { 00053 namespace common { 00054 class ServerInfo; 00055 } 00056 } 00057 00058 // ************************************************************************ 00059 // forward declarations 00060 class RqsGlobal; 00066 extern RqsGlobal& rqsGlobal; 00067 00068 // ************************************************************************ 00069 // class definitions 00070 00074 class RhGuard { 00076 static OSB_LIB::Mutex mutex_; 00077 public: 00084 RhGuard(); 00086 ~RhGuard(); 00087 00093 OSB_LIB::RequestHandler& get(); 00094 private: 00096 RhGuard(const RhGuard&); 00098 RhGuard& operator=(const RhGuard&); 00099 }; // class RhGuard 00100 00104 class RqsGlobal { 00106 friend class RhGuard; 00107 public: 00109 typedef std::auto_ptr<corba::common::ServerInfo> ServerInfoPtr; 00110 00111 public: 00113 RqsGlobal(); 00115 virtual ~RqsGlobal(); 00116 public: 00118 virtual ServerInfoPtr srvInfo() = 0; 00119 private: 00121 virtual OSB_LIB::RequestHandler& srqHandler() = 0; 00122 private: 00124 RqsGlobal(const RqsGlobal&); 00126 RqsGlobal& operator=(const RqsGlobal&); 00127 }; // class RqsGlobal 00128 00129 // ******************************************************************** 00130 // Database session guards. 00134 class SessionGuardBase { 00136 static OSB_LIB::Mutex mutex_; 00138 static OSB_DB::Session* pSession_; 00139 00141 friend int main(int, char**); 00142 00143 protected: 00149 SessionGuardBase(); 00157 SessionGuardBase(bool noWait); 00159 virtual ~SessionGuardBase() = 0; 00160 00161 protected: 00163 bool locked() const; 00172 void lock(bool noWait); 00178 OSB_DB::Session& get(); 00179 00180 private: 00182 bool locked_; 00183 private: 00185 SessionGuardBase(const SessionGuardBase&); 00187 SessionGuardBase& operator=(const SessionGuardBase&); 00188 }; 00189 00191 struct ReadSession : private SessionGuardBase { 00197 ReadSession(); 00203 ReadSession(bool noWait); 00204 public: 00206 bool locked() const; 00214 void lock(bool noWait); 00216 const OSB_DB::Session& get(); 00217 }; 00218 00220 struct WriteSession : private SessionGuardBase { 00227 WriteSession(); 00233 WriteSession(bool noWait); 00239 ~WriteSession(); 00240 public: 00242 bool locked() const; 00250 void lock(bool noWait); 00252 const OSB_DB::Session& getConst(); 00254 OSB_DB::Session& get(); 00256 void commit(); 00258 void rollback(); 00259 private: 00261 bool dirty_; 00262 }; 00263 00264 // ************************************************************************ 00265 // inline definitions 00266 #endif // #ifndef _RQSGLOBAL_H_