resource_i.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00007 /*
00008   AUTHOR(S): Stephan Broennimann (vb)
00009 
00010   RCS information
00011    $Name: OSB_060808 $
00012    $Revision: 1.16 $
00013 
00014   License
00015    OSB rating and billing library for communication networks
00016    Copyright (C) 2004, 2005, 2006  OSB systems
00017 
00018    This file may be distributed and/or modify under the terms of the
00019    GNU General Public License (GPL) as published by the Free Software
00020    Foundation which is provided in the file LICENSE.GPL included in the
00021    packaging of this file.
00022 
00023    The file is distributed in the hope that it will be useful, but WITHOUT
00024    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00025    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00026    for more details.
00027 
00028    Holders of a OSB Commercial License may use this file under the terms
00029    and conditions of this commercial license.
00030  */
00031 #ifndef _RESOURCE_I_H_
00032 #define _RESOURCE_I_H_
00033 
00034 // ************************************************************************
00035 // included header files
00036 // + standard includes
00037 
00038 // + libraries
00039 #include <resourcelists.h>
00040 
00041 // + local headers
00042 #include "resourceS.h"
00043 #include "corba_utility.h"
00044 #include "networkmanager_i.h"
00045 
00046 // + class declarations
00047 
00048 // ************************************************************************
00049 // namespace extensions
00050 namespace OSB_CORBA {
00051 
00052 // ************************************************************************
00053 // type definitions
00054     using CORBA::Boolean;
00055     using corba::common::Date;
00056 
00057 // ************************************************************************
00058 // class definitions
00062     class Resource_i :
00063         public virtual POA_corba::res::Resource
00064     {
00065     public:
00067         static const std::string IFC;
00068 
00070         Resource_i(
00071                   NetworkManager_i&       nmgri,
00072             const OSB_LIB::Resource::Oid& oid
00073         );
00074 
00076         ~Resource_i();
00077 
00078     public:
00080 
00081 
00082         ResourceTypeId type()
00083             throw (CORBA::SystemException, OsbCorbaException);
00084 
00086         ResourceId id()
00087             throw (CORBA::SystemException, OsbCorbaException);
00088 
00095         corba::imgmt::PoolId poolId()
00096             throw (CORBA::SystemException, OsbCorbaException);
00097 
00099         Boolean isPrepaid()
00100             throw (CORBA::SystemException, OsbCorbaException);
00101 
00103         Utf8String* resNumber()
00104             throw (CORBA::SystemException, OsbCorbaException);
00105 
00107         ResourceStatus status()
00108             throw (CORBA::SystemException, OsbCorbaException);
00109 
00121         Boolean isAvailable()
00122             throw (CORBA::SystemException, OsbCorbaException);
00123 
00129         Date quarantineEnd()
00130             throw (CORBA::SystemException, OsbCorbaException);
00131 
00137         NetworkId networkId()
00138             throw (CORBA::SystemException, OsbCorbaException);
00139 
00145         NetworkElementId networkElementId()
00146             throw (CORBA::SystemException, OsbCorbaException);
00147 
00153         Date assigned()
00154             throw (CORBA::SystemException, OsbCorbaException);
00155 
00157         Boolean canUpd()
00158             throw (CORBA::SystemException, OsbCorbaException);
00159 
00161         Boolean canDel()
00162             throw (CORBA::SystemException, OsbCorbaException);
00164 
00165     protected:
00167         typedef OSB_LIB::ResourceList<OSB_LIB::Resource>::Rg ReadGuard;
00168 
00170         virtual ReadGuard lock() const = 0;
00171 
00172     protected:
00174         NetworkManager_i& nmgri_;
00175 
00177         const OSB_LIB::Resource::Oid resId_;
00178     };                                  // class Resource_i
00179 
00186     class ResourceWriter_i :
00187         public virtual POA_corba::res::ResourceWriter,
00188         public virtual Resource_i
00189     {
00190     public:
00192         static const std::string IFC;
00193 
00195         ResourceWriter_i(
00196                   NetworkManager_i&       nmgri,
00197             const OSB_LIB::Resource::Oid& resId
00198         );
00199 
00201         virtual ~ResourceWriter_i();
00202 
00203     private:
00205         ResourceWriter_i(const ResourceWriter_i&);
00207         ResourceWriter_i& operator=(const ResourceWriter_i&);
00208 
00209     public:
00211         void setLoctKey(const Locators::Key& key);
00212 
00222         void setPool(
00223           const corba::imgmt::PoolId& poolId
00224         ) throw (CORBA::SystemException, OsbCorbaException);
00235         void setStatus(
00236             ResourceStatus newStatus
00237         ) throw (OsbCorbaException);
00238 
00254         virtual ResourceId create(
00255             CORBA::Boolean noWait
00256         ) throw (CORBA::SystemException, OsbCorbaException);
00257 
00258         virtual void updData(
00259             CORBA::Boolean noWait
00260         ) throw (CORBA::SystemException, OsbCorbaException);
00261 
00262         virtual void updStatus(
00263             CORBA::Boolean noWait
00264         ) throw (CORBA::SystemException, OsbCorbaException);
00265 
00269         void destroy() throw (CORBA::SystemException);
00270 
00271     protected:
00273         virtual OSB_LIB::Resource& resource() = 0;
00274 
00293         virtual bool writeToList(bool isNew) const = 0;
00294 
00295     private:
00297         Locators::Key loctKey_;
00298     };
00299 
00300 // ************************************************************************
00301 // Free functions
00315     template<typename R>
00316     const R& getResource(
00317         const OSB_LIB::ReadGuard<R*>& rg,
00318               OSB_LIB::Resource::Oid  resId
00319     ) throw (OsbCorbaException);
00320 
00334     template<typename R>
00335     R& getResource(
00336         OSB_LIB::WriteGuard<R*>& wg,
00337         OSB_LIB::Resource::Oid   resId
00338     ) throw (OsbCorbaException);
00339 
00343     OSB_LIB::Resource::Status rsStatus(ResourceStatus s);
00344 
00348     ResourceStatus rsStatus(const OSB_LIB::Resource::Status s);
00349 }                                       // namespace OSB_CORBA
00350 
00351 // ************************************************************************
00352 // inline definitions
00353 namespace OSB_CORBA {
00354 
00355     template<typename R>
00356     const R& getResource(
00357         const OSB_LIB::ReadGuard<R*>& rg,
00358               OSB_LIB::Resource::Oid  resId
00359     ) throw (OsbCorbaException)
00360     {
00361         // trivial case: everything as is should be
00362         const R* rc = rg.get();
00363         if (0 != rc) return *rc;
00364 
00365         // handle the error
00366         typedef OSB_LIB::ResourceList<R> List;
00367         typedef typename List::GuardStatus Status;
00368 
00369         using OSB_LIB::OsbError;
00370 
00371         OsbError error;
00372         switch (Status(rg.status_)) {
00373           case List::objectNotFound:
00374             error = OsbError(721);
00375             error << resId;
00376             break;
00377 
00378           case List::lockFailed:
00379             error = OsbError(722);
00380             error << resId;
00381             break;
00382 
00383           case List::success:
00384             if (rg.locked()) error = OsbError(723);
00385             else             error = OsbError(724);
00386             break;
00387         }
00388 
00389         if (error.noError())  {
00390             error = OsbError(725);
00391             error << rg.status_;
00392         }
00393         throw osbCorbaException(error);
00394     }
00395 
00396     template<typename R>
00397     R& getResource(
00398         OSB_LIB::WriteGuard<R*>& wg,
00399         OSB_LIB::Resource::Oid   resId
00400     ) throw (OsbCorbaException)
00401     {
00402         // trivial case: everything as is should be
00403         R* rc = wg.get();
00404         if (0 != rc) return *rc;
00405 
00406         // handle the error
00407         typedef OSB_LIB::ResourceList<R> List;
00408         typedef typename List::GuardStatus Status;
00409 
00410         using OSB_LIB::OsbError;
00411 
00412         OsbError error;
00413         switch (Status(wg.status_)) {
00414           case List::objectNotFound:
00415             error = OsbError(721);
00416             error << resId;
00417             break;
00418 
00419           case List::lockFailed:
00420             error = OsbError(726);
00421             error << resId;
00422             break;
00423 
00424           case List::success:
00425             if (wg.locked()) error = OsbError(723);
00426             else             error = OsbError(727);
00427             break;
00428         }
00429 
00430         if (error.noError())  {
00431             error = OsbError(728);
00432             error << wg.status_;
00433         }
00434         throw osbCorbaException(error);
00435     }
00436 }                                       // namespace OSB_CORBA
00437 #endif                                  // #ifndef _RESOURCE_I_H_

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