network.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00009 /*
00010   AUTHOR(S): Stephan Broennimann (vb)
00011 
00012   RCS information
00013    $Name: OSB_060808 $
00014    $Revision: 1.48 $
00015 
00016   License
00017    OSB rating and billing library for communication networks
00018    Copyright (C) 2004, 2005, 2006  OSB systems
00019 
00020    This file may be distributed and/or modify under the terms of the
00021    GNU General Public License (GPL) as published by the Free Software
00022    Foundation which is provided in the file LICENSE.GPL included in the
00023    packaging of this file.
00024 
00025    The file is distributed in the hope that it will be useful, but WITHOUT
00026    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00028    for more details.
00029 
00030    Holders of a OSB Commercial License may use this file under the terms
00031    and conditions of this commercial license.
00032  */
00033 #ifndef _NETWORK_H_
00034 #define _NETWORK_H_
00035 
00036 // *********************************************************************
00037 // included header files
00038 // + standard includes
00039 #include <string>
00040 #include <list>
00041 #include <vector>
00042 
00043 // + local headers
00044 #include "osberror.h"
00045 #include "osbid.h"
00046 #include "mutex.h"
00047 #include "timezone.h"
00048 
00049 // *********************************************************************
00050 // class declarations
00051 namespace OSB_LIB {
00052     class ConnectionPt;                 // connectionpt.h
00053     class Resource;                     // resource.h
00054 }
00055 
00056 namespace OSB_DB {
00057     class Session;
00058     class NetworkGw;
00059     class NetworkElementGw;
00060     class TrunkGroupGw;
00061 }
00062 
00063 // *********************************************************************
00064 // namespace extensions
00065 namespace OSB_LIB {
00066 
00067 // *********************************************************************
00068 // class forward declarations
00069     class Network;
00070     class NetworkElement;
00071     class NetworkManager;
00072     class NumberAnalyzer;
00073 
00074 // *********************************************************************
00075 // type definitions
00077     typedef std::list<NetworkElement> NetworkElements;
00078 
00079 // *********************************************************************
00080 // class definitions
00081 
00082     // *****************************************************************
00083     // struct NetworkAddressInfo
00092     struct NetworkAddressInfo {
00094         struct Code {
00096             std::string code_;
00098             bool isDefault_;
00100             Code() : isDefault_(false) {}
00102             explicit Code(
00103                 const std::string& c,
00104                       bool         d = false
00105             ) : code_(c), isDefault_(d) {}
00106         };
00107 
00109         typedef std::vector<Code> List;
00110 
00117         Id2<NetworkElement> neId_;
00119         List ccs_;
00121         List ndcs_;
00123         List iacs_;
00125         List nacs_;
00126 
00128         bool empty() const;
00129 
00131         NetworkAddressInfo();
00132 
00134         explicit NetworkAddressInfo(
00135             const Id<Network>& nw
00136         );
00137 
00139         explicit NetworkAddressInfo(
00140             const Id2<NetworkElement>& ne
00141         );
00142     };                                  // struct NetworkAddressInfo
00143 
00144     // *****************************************************************
00145     // class TrunkGroup
00149     class TrunkGroup {
00151         friend class OSB_DB::TrunkGroupGw;
00153         friend class NetworkElement;
00154     public:
00162         typedef Id<TrunkGroup> Oid;
00163 
00165 
00166 
00171         enum Direction {
00172            dirUnknown = '\0',           
00173            dirIn      = 'i',            
00174            dirOut     = 'o'             
00175         };
00183         static char toChar(Direction dir);
00191         static Direction direction(char c);
00193 
00195 
00196 
00202         enum LinkType {
00204             lkUnknown  = '\0',
00206             lkExternal = 'e',
00208             lkInternal = 'i',
00210             lkTerminal = 't'
00211         };
00219         static char toChar(LinkType lt);
00227         static LinkType linkType(char c);
00229 
00230     public:
00232         TrunkGroup();
00234         TrunkGroup(
00235             const Oid&                 oid,
00236             const Id2<NetworkElement>& elementId
00237         );
00239         TrunkGroup(const TrunkGroup& rhs);
00241         TrunkGroup& operator=(const TrunkGroup& rhs);
00242 
00244         ~TrunkGroup();
00245 
00247 
00248 
00249         const Oid& oid() const;
00251         const Id2<NetworkElement>& networkElementId() const;
00253         Id<Network> networkId() const;
00260         const std::string& name() const;
00262         Direction direction() const;
00264         LinkType linkType() const;
00275         const Id2<NetworkElement>& extNetworkElementId() const;
00277         long objVs() const;
00279         const NumberAnalyzer* numberAnalyzer() const;
00281 
00283 
00284 
00285         void setName(const std::string& name);
00287         void setDirection(Direction dir);
00289         void setLinkType(LinkType lType);
00291         void setExtNetworkElementId(
00292             const Id2<NetworkElement>& eNetElementId
00293         );
00299         void setNumAnalyzer(NumberAnalyzer* numAnalyzer);
00300 
00302         void delNumAnalyzer();
00304 
00315         bool read(const OSB_DB::Session& session);
00316 
00317     private:
00319 
00320 
00334         bool insert(const OSB_DB::Session& session);
00335 
00348         bool update(const OSB_DB::Session& session);
00349 
00361         bool remove(const OSB_DB::Session& session);
00363 
00373         void checkExternal();
00374 
00375     private:
00377         Oid oid_;
00379         Id2<NetworkElement> networkElementId_;
00381         long objVs_;
00383         std::string name_;
00385         Direction direction_;
00387         LinkType linkType_;
00389         Id2<NetworkElement> extNetworkElementId_;
00391         NumberAnalyzer* numAnalyzer_;
00392     };                                  // class TrunkGroup
00393 
00395     typedef std::list<TrunkGroup> TrunkGroups;
00396 
00397     // ****************************************************************`
00398     // class NetworkElement
00402     class NetworkElement {
00404         friend class OSB_DB::NetworkElementGw;
00406         friend class Network;
00407     public:
00416 
00417         typedef Id2<NetworkElement> Oid;
00418 
00420         enum DialledNumType {
00421             incomingDialledNum = 'i',  
00422             outgoingDialledNum = 'o'   
00423         };
00424 
00426         static char dialledNumType(const DialledNumType& type);
00427 
00429         static DialledNumType dialledNumType(const char type);
00430 
00431     public:
00433         NetworkElement();
00435         NetworkElement(const NetworkElement& rhs);
00437         NetworkElement(const Oid& oid);
00439         NetworkElement(
00440             const Oid&         oid,
00441                   long         objVs,
00442             const std::string& name,
00443             const std::string& des = ""
00444         );
00445 
00447         ~NetworkElement();
00448 
00450         NetworkElement& operator=(const NetworkElement& rhs);
00451 
00453 
00454 
00455         const Oid& oid() const;
00457         Id<Network> networkId() const;
00459         const std::string& name() const;
00461         const std::string& des() const;
00463         long objVs() const;
00465         const Id<ConnectionPt>& connectionPt() const;
00467         bool hasNdc() const;
00473         const std::string& ndc() const;
00475         const TrunkGroups& trunkGroups() const;
00482         const TimeZone::Oid tzId() const;
00484         const DialledNumType& dialledNumType() const;
00486         const NumberAnalyzer* numberAnalyzer() const;
00488 
00490 
00491 
00492         void setName(const std::string& name) { name_ = name; }
00494         void setDes(const std::string& des) { des_ = des; }
00496         void setConnectionPt(const Id<ConnectionPt>& cpId);
00504         void setNdc(const std::string ndc);
00510         void unsetNdc();
00512         void setTimeZone(const TimeZone::Oid& tzId);
00514         void setDialledNumType(const DialledNumType& type);
00516         void setNumAnalyzer(NumberAnalyzer* numAnalyzer);
00518         void delNumAnalyzer();
00520 
00532         bool read(const OSB_DB::Session& session);
00533 
00535 
00536 
00553         bool addTrkGroup(
00554             OSB_DB::Session& session,
00555             TrunkGroup&      trkGroup
00556         );
00557 
00575         bool updTrkGroup(
00576             OSB_DB::Session& session,
00577             TrunkGroup&      trunkGroup
00578         );
00579 
00594         bool delTrkGroup(
00595                   OSB_DB::Session& session,
00596             const TrunkGroup::Oid& oid
00597         );
00598 
00606         const TrunkGroup* findTrkGroup(
00607             const TrunkGroup::Oid& oid
00608         ) const;
00609 
00617         TrunkGroup* trkGroup(const TrunkGroup::Oid& oid);
00618 
00626         const TrunkGroup& getTrkGroup(
00627             const TrunkGroup::Oid& oid
00628         ) const;
00629 
00638         const TrunkGroup* findTrkGroup(
00639             const std::string&          name,
00640                   TrunkGroup::Direction direction
00641         ) const;
00642 
00651         TrunkGroup* trkGroup(
00652             const std::string&          name,
00653                   TrunkGroup::Direction direction
00654         );
00655 
00664         const TrunkGroup& getTrkGroup(
00665             const std::string&          name,
00666                   TrunkGroup::Direction direction
00667         ) const;
00668 
00675         void sortTrkGroupByName(bool desc = false);
00677 
00678     private:
00680 
00681 
00693         bool insert(const OSB_DB::Session& session);
00694 
00705         bool update(const OSB_DB::Session& session);
00706 
00718         bool remove(const OSB_DB::Session& session);
00720 
00728 
00729         void putAddressInfo(
00730             NetworkAddressInfo& dest
00731         ) const;
00733         void getAddressInfo(
00734             const NetworkAddressInfo& src
00735         );
00737 
00738     private:
00740         Oid oid_;
00742         long objVs_;
00744         std::string name_;
00746         std::string des_;
00748         Id<ConnectionPt> connectionPt_;
00750         bool hasNdc_;
00759         std::string ndc_;
00761         TrunkGroups trunkGroups_;
00763         TimeZone::Oid tzId_;
00768         DialledNumType dialledNumType_;
00770         NumberAnalyzer* numAnalyzer_;
00771     };                                  // class NetworkElement
00772 
00773     // *****************************************************************
00774     // class Network
00778     class Network {
00780         friend class OSB_DB::NetworkGw;
00782         friend class NetworkManager;
00783 
00784     public:
00786         typedef Id<Network> Oid;
00787 
00794         struct NwAddrInfo {
00796             typedef std::vector<std::string> List;
00797 
00799             std::string cc_;
00812             std::string ndc_;
00819             List ndcs_;
00826             List iacs_;
00828             std::string nac_;
00829         };                              // struct NwAddrInfo
00830 
00831     public:
00833         Network(const Oid& oid = Oid());
00835         Network(
00836             const Oid&         oid,
00837                   long         objVs,
00838             const std::string& name,
00839             const std::string& des = ""
00840         );
00841 
00843 
00844 
00845         const Oid& oid() const;
00847         const std::string& name() const;
00849         const std::string& des() const;
00851         long objVs() const;
00853         const Id<ConnectionPt>& connectionPt() const;
00855         const NwAddrInfo& nwAddrInfo() const;
00857         const NetworkElements& elements() const;
00864         const TimeZone::Oid tzId() const;
00866 
00868 
00869 
00870         void setName(const std::string& name) { name_ = name; }
00872         void setDes(const std::string& des) { des_ = des; }
00874         void setConnectionPt(const Id<ConnectionPt>& cpId);
00876         void setNwAddrInfo(const NwAddrInfo& info);
00878         void setTimeZone(const TimeZone::Oid& tzId);
00880 
00892         bool read(const OSB_DB::Session& session);
00893 
00895 
00896 
00910         bool addElement(
00911             OSB_DB::Session& session,
00912             NetworkElement&  element
00913         );
00914 
00930         bool updElement(
00931             OSB_DB::Session& session,
00932             NetworkElement&  netElement
00933         );
00934 
00949         bool delElement(
00950                   OSB_DB::Session&     session,
00951             const Id2<NetworkElement>& neId
00952         );
00953 
00961         const NetworkElement* findElement(
00962             const Id2<NetworkElement>& neId
00963         ) const;
00971         NetworkElement* element(const Id2<NetworkElement>& neId);
00979         const NetworkElement& getElement(
00980             const Id2<NetworkElement>& neId
00981         ) const;
00982 
00989         void sortElementByName(bool desc = false);
00991 
00999         const TrunkGroup& getTrkGroup(
01000             const Id<TrunkGroup>& tgId
01001         ) const;
01002 
01003     private:
01005 
01006 
01018         bool insert(const OSB_DB::Session& session);
01019 
01030         bool update(const OSB_DB::Session& session);
01031 
01043         bool remove(const OSB_DB::Session& session);
01045 
01054 
01055         void putAddressInfo(
01056             NetworkAddressInfo& dest
01057         ) const;
01059         void getAddressInfo(
01060             const NetworkAddressInfo& src
01061         );
01063 
01064     private:
01066         Oid oid_;
01068         long objVs_;
01070         std::string name_;
01072         std::string des_;
01074         Id<ConnectionPt> connectionPt_;
01076         NwAddrInfo nwAddrInfo_;
01078         NetworkElements elements_;
01080         TimeZone::Oid tzId_;
01081     };                                  // class Network
01082 
01084     typedef std::list<Network> Networks;
01085 
01086     // *****************************************************************
01087     // class NetworkManager
01091     class NetworkManager {
01092     public:
01094 
01095 
01096         typedef ReadGuard<Network*> NetworkRg;
01098         typedef ReadGuard<Networks*> NetworksRg;
01100         typedef WriteGuard<Network*> NetworkWg;
01101 
01109         typedef RwGuard NetworksWg;
01111 
01113         NetworkManager();
01114 
01116 
01117         const Networks& networks() const { return networks_; }
01119 
01121 
01122 
01132         long readNetworks(const OSB_DB::Session& session);
01133 
01150         bool addNetwork(
01151             OSB_DB::Session& session,
01152             Network&         net
01153         );
01154 
01171         bool updNetwork(
01172             OSB_DB::Session& session,
01173             Network&         net
01174         );
01175 
01192         bool delNetwork(
01193                   OSB_DB::Session& session,
01194             const Network::Oid&    oid
01195         );
01196 
01204         const Network* findNetwork(const Network::Oid& oid) const;
01205 
01213         Network* network(const Network::Oid& oid);
01214 
01222         const Network& getNetwork(
01223             const Network::Oid& oid
01224         ) const;
01225 
01232         void sortNetworkByName(bool desc = false);
01234 
01236 
01237 
01246         NetworkRg readLock(const Network::Oid& oid);
01247 
01255         NetworksRg readLockList();
01256 
01266         NetworkWg writeLock(const Network::Oid& oid);
01268 
01276         const TrunkGroup& getTrkGroup(
01277             const Id<TrunkGroup>& tgId
01278         ) const;
01279 
01281 
01282 
01289         long readTimeZones(
01290             const OSB_DB::Session& session
01291         );
01292 
01305         const TimeZone& getTimeZone(
01306             const TimeZone::Oid& oid
01307         )const;
01308 
01314         const TimeZones& getTimeZones() const;
01316 
01317     private:
01319         NetworksWg writeLockList();
01320 
01321     private:
01323         Networks  networks_;
01325         RwMutex   mutex_;
01327         TimeZones timezones_;
01328     };                                  // class NetworkManager
01329 
01330     // *****************************************************************
01331     // TheNetworkManager
01346     class TheNetworkManager {
01347     public:
01354         static NetworkManager& instance();
01355 
01356     private:
01358         TheNetworkManager();
01360         TheNetworkManager(const TheNetworkManager& rhs);
01361 
01363         static NetworkManager* instance_;
01364     };
01365 
01366 }                                       // namespace OSB_LIB
01367 #endif                                  // #ifndef _NETWORK_H_

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