resource.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.92.2.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 _RESOURCE_H_
00031 #define _RESOURCE_H_
00032 
00033 // *********************************************************************
00034 // included header files
00035 // + standard includes
00036 
00037 // + local headers
00038 #include "chrono.h"
00039 #include "osbid.h"
00040 #include "osbconst.h"
00041 #include "resourcefwd.h"
00042 
00043 // *********************************************************************
00044 // class declarations
00045 namespace OSB_DB {
00046     class Session;
00047     class ResourceGw;
00048 }
00049 
00050 namespace OSB_LIB {
00051     class Device;
00052     class InventoryPool;
00053     class OsbError;
00054     class PersResource;
00055     class Status;
00056 }
00057 
00058 // *********************************************************************
00059 // namespace extensions
00060 namespace OSB_LIB {
00061 
00062 // *********************************************************************
00063 // type definitions
00064 
00065 // *********************************************************************
00066 // class definitions
00067 
00068     // *****************************************************************
00069     // class Resource
00087     class Resource {
00092         friend class OSB_DB::ResourceGw;
00093 
00098         friend class PersResource;
00100         friend class Device;
00101     public:                             // type definitions
00103         typedef Id<Resource> Oid;
00105         typedef ResourceType Type;
00107         typedef ResourceNumber Number;
00108 
00121         enum Status {
00123             rsUnknown = '\0',
00128             rsCreated    = 'c',
00130             rsAvailable  = 'v',
00132             rsAssigned   = 'a',
00138             rsQuarantine  = 'q',
00142             rsDeactivated = 'd',
00147             rsLinked = 'l'
00148         };
00149 
00150     public:                             // construction, destruction
00156 
00157         explicit Resource(const Oid& oid = Oid());
00166         explicit Resource(
00167             const Number&      rn,
00168             const Id<Network>& nw = Id<Network>()
00169         );
00177         Resource(
00178             const Number&              rn,
00179             const Id2<NetworkElement>& ne
00180         );
00181 
00183         virtual ~Resource();
00185 
00186     protected:
00188         Resource(const Resource& rhs);
00190         Resource& operator=(const Resource& rhs);
00191 
00192     public:
00194 
00195 
00201         virtual Type typeId() const = 0;
00202 
00204         const Oid& oid() const;
00205 
00207         long objVs() const;
00208 
00215         bool isPrepaid() const;
00216 
00227         const Number& resourceNumber() const;
00228 
00230         const Status status() const;
00231 
00238         const Date& quarantineEnd() const;
00239 
00241         const Date& assigned() const;
00242 
00251         const Id<Network> nwId() const;
00252 
00261         const Id2<NetworkElement>& neId() const;
00262 
00268         const Id<Device> deviceId() const;
00269 
00275         const Id<InventoryPool> poolId() const;
00276 
00286         bool canDel() const;
00287 
00298         virtual bool isAvailable() const;
00299 
00310         virtual bool canUpd() const;
00312 
00325         virtual void setStatus(
00326             const Status newStatus
00327         );
00328 
00334         void setPool(
00335             const Id<InventoryPool>& poolId
00336         );
00337 
00346         void setDevice(
00347             const Id<Device>& deviceId
00348         );
00349 
00350     protected:
00366         virtual void setAssigned();
00367 
00376         virtual void setDeassigned();
00377 
00384         virtual void setAvailable();
00386 
00387     protected:
00402         bool assignResource(const OSB_DB::Session& session);
00403 
00412         bool deassignResource(const OSB_DB::Session& session);
00413 
00422         bool unassignResource(const OSB_DB::Session& session);
00423 
00424     public:
00435         void updStatus(
00436             const OSB_DB::Session& session,
00437                   bool             isLocked
00438         );
00439 
00459         virtual bool read(const OSB_DB::Session& session) = 0;
00466         virtual bool insert(const OSB_DB::Session& session) = 0;
00476         virtual void updData(const OSB_DB::Session& session) = 0;
00483         virtual bool remove(const OSB_DB::Session& session) = 0;
00485 
00486     protected:
00488 
00489 
00512         bool readBase(const OSB_DB::Session& session);
00513 
00520         bool insBase(const OSB_DB::Session& session);
00521 
00531         void updDataBase(const OSB_DB::Session& session);
00532 
00541         void updAssigned(
00542             const OSB_DB::Session& session,
00543             const DateTime&        firstAss
00544         );
00545 
00576         bool removeBase(
00577             const OSB_DB::Session& session,
00578                   bool             isLocked
00579         );
00581 
00590         void lock(
00591             const OSB_DB::Session& session,
00592                   bool             noWait
00593         ) const;
00594 
00606         static void handleObjectStatus(
00607                   ObjectStatus os,
00608             const Oid&         id
00609         );
00610 
00622         void incObjVs(
00623             const OSB_DB::Session& session
00624         );
00625 
00639         OSB_LIB::Status getPersResourceStatus(
00640             const OSB_DB::Session& session,
00641             const DateTime&        ts = DateTime::now()
00642         ) const;
00643 
00644     private:
00646         Oid oid_;
00648         long objVs_;
00650         Status status_;
00657         Date quarantineEnd_;
00659         Date assigned_;
00660 
00662         Id<Device> deviceId_;
00664         Id<InventoryPool> poolId_;
00665 
00666     protected:
00673         Number resourceNumber_;
00685         Id2<NetworkElement> neId_;
00687         bool prepaid_;
00688     };                                  // class Resource
00689 }                                       // namespace OSB_LIB
00690 #endif                                  // #ifndef _RESOURCE_H_

Generated on Sat Sep 2 14:06:34 2006 for OSB Library by  doxygen 1.4.7