dvcbase_i.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.1 $
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 _DVCBASE_I_H_
00031 #define _DVCBASE_I_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 
00037 // + libraries
00038 #include <device.h>
00039 
00040 // + local headers
00041 #include "corba_utility.h"
00042 #include "deviceS.h"
00043 #include "servantlocators.h"
00044 
00045 // + class declarations
00046 
00047 // ************************************************************************
00048 // namespace extensions
00049 namespace OSB_CORBA {
00050 
00051     using corba::common::OsbCorbaException;
00052     using corba::dvc::DeviceId;
00053     using corba::dvc::DeviceStatus;
00054     using corba::dvc::DeviceType;
00055 
00056 // ************************************************************************
00057 // forward declarations
00058 
00059 // ************************************************************************
00060 // type definitions
00061 
00062 // ************************************************************************
00063 // class definitions
00067     class Device_i : public virtual POA_corba::dvc::Device {
00068     public:
00070         static const std::string IFC;
00071     public:                             // construction
00078         Device_i(
00079             OSB_LIB::Device::Oid dvcId,
00080             Locators&            srvtLoc
00081         );
00083         virtual ~Device_i();
00084     private:
00086         Device_i(const Device_i&);
00088         void operator=(const Device_i&);
00089 
00090     public:                             // CORBA interface
00092         DeviceType type()
00093           throw (OsbCorbaException);
00095         DeviceId id()
00096           throw (OsbCorbaException);
00098         DeviceStatus status()
00099           throw (OsbCorbaException);
00106         corba::imgmt::PoolId poolId()
00107           throw (OsbCorbaException);
00108 
00115         void destroy() throw();
00116 
00117     public:                             // utilities
00119         static OSB_LIB::Device::Status dvcStatus(DeviceStatus);
00121         static DeviceStatus dvcStatus(OSB_LIB::Device::Status);
00122 
00124         Locators::Key loctKey() const;
00125 
00127         enum GuardStatus {
00129             success    = 0,
00131             lockFailed = 1,
00133             notFound   = 2
00134         };
00135 
00149         template<typename D>
00150         static const D& get(
00151             const OSB_LIB::ReadGuard<D*>& rg,
00152                   OSB_LIB::Device::Oid    dvcId
00153         ) throw (OsbCorbaException);
00154 
00155     protected:
00157         typedef OSB_LIB::ReadGuard<OSB_LIB::Device*> ReadGuard;
00158 
00160         virtual ReadGuard lock() const = 0;
00161 
00162     protected:
00164         OSB_LIB::Device::Oid dvcId_;
00166         Locators& srvtLoc_;
00167     private:
00169         Locators::Key loctKey_;
00170     };                                  // class Device_i
00171 }                                       // namespace OSB_CORBA
00172 
00173 // ************************************************************************
00174 // inline definitions
00175 namespace OSB_CORBA {
00176     // ********************************************************************
00177     // class Device_i
00178     template<typename D>
00179     const D& Device_i::get(
00180         const OSB_LIB::ReadGuard<D*>& rg,
00181               OSB_LIB::Device::Oid    dvcId
00182     ) throw (OsbCorbaException)
00183     {
00184         // trivial case: everything as is should be
00185         const D* rc = rg.get();
00186         if (0 != rc) return *rc;
00187 
00188         // handle the error
00189         using OSB_LIB::OsbError;
00190         OsbError error;
00191         switch (rg.status_) {
00192           case notFound:
00193             error = OsbError(991);
00194             error << dvcId;
00195             break;
00196 
00197           case lockFailed:
00198             error = OsbError(992);
00199             error << dvcId;
00200             break;
00201 
00202           case success:
00203             if (rg.locked()) error = OsbError(993);
00204             else             error = OsbError(994);
00205             break;
00206         }
00207 
00208         if (error.noError())  {
00209             error = OsbError(995);
00210             error << rg.status_;
00211         }
00212         throw osbCorbaException(error);
00213     }
00214 }                                       // namespace OSB_CORBA
00215 #endif                                  // #ifndef _DVCBASE_I_H_

Generated on Sat Sep 2 14:25:51 2006 for OSB Library by  doxygen 1.4.7