productcat.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00010 /*
00011   AUTHOR(S): Stephan Broennimann (vb)
00012 
00013   RCS information
00014    $Name: OSB_060808 $
00015    $Revision: 1.38 $
00016 
00017   License
00018    OSB rating and billing library for communication networks
00019    Copyright (C) 2004, 2005, 2006  OSB systems
00020 
00021    This file may be distributed and/or modify under the terms of the
00022    GNU General Public License (GPL) as published by the Free Software
00023    Foundation which is provided in the file LICENSE.GPL included in the
00024    packaging of this file.
00025 
00026    The file is distributed in the hope that it will be useful, but WITHOUT
00027    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00028    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00029    for more details.
00030 
00031    Holders of a OSB Commercial License may use this file under the terms
00032    and conditions of this commercial license.
00033  */
00034 #ifndef _PRODUCTCAT_H_
00035 #define _PRODUCTCAT_H_
00036 
00037 // *********************************************************************
00038 // included header files
00039 // + standard includes
00040 #include <iosfwd>
00041 #include <string>
00042 
00043 // + local headers
00044 #include "mutex.h"
00045 #include "pricelist.h"
00046 #include "product.h"
00047 #include "productitem.h"
00048 
00049 // *********************************************************************
00050 // namespace extensions
00051 namespace OSB_LIB {
00052 
00053 // *********************************************************************
00054 // class declarations
00055     class PcatLockMgr;
00056     class PcatMgr;
00057 
00058 // *********************************************************************
00059 // class definitions
00060 
00061     // *****************************************************************
00062     // class ProductCatalogue
00063 
00065     class ProductCatalogue {
00071         friend class PcatLockMgr;
00073         friend class PcatMgr;
00074 
00075     private:
00077         ProductCatalogue();
00079         ~ProductCatalogue();
00080 
00081     public:
00082         // *************************************************************
00083         // Init methods
00084 
00086         void read(const OSB_DB::Session&);
00087 
00096         PcatLockMgr& lockMgr();
00097 
00099         std::ostream& prInfo(std::ostream&);
00100 
00101         // *************************************************************
00102         // Product maintenance
00103 
00104     private:
00106 
00107 
00117         void addProduct(
00118             OSB_DB::Session& session,
00119             Product&         pd
00120         );
00121 
00132         void updProduct(
00133             OSB_DB::Session& session,
00134             Product&         pd
00135         );
00137 
00138     public:
00140 
00141 
00155         void saveProduct(
00156             OSB_DB::Session& session,
00157             Product&         pd
00158         );
00159 
00168         void delProduct(
00169                   OSB_DB::Session& session,
00170             const Product::Oid&    pdId
00171         );
00172 
00174         const Product* findProduct(const Product::Oid& pdId) const;
00175 
00177         const Products& products() const { return products_; }
00178 
00185         void sortProdByName(bool desc = false);
00187 
00188         // *************************************************************
00189         // Pricelist maintenance
00190 
00192 
00193 
00194         const Pricelist* findPricelist(const Pricelist::Oid&) const;
00195 
00197         const Pricelist& getPricelist(const Pricelist::Oid&) const;
00198 
00200         Pricelist* pricelist(const Pricelist::Oid&);
00201 
00203         const Pricelists&
00204             pricelists() const { return pricelists_; }
00205 
00214         bool addPricelist(
00215             OSB_DB::Session& session,
00216             Pricelist&       pl);
00217 
00226         bool updPricelist(
00227             OSB_DB::Session& session,
00228             Pricelist&       pl);
00229 
00238         bool delPricelist(
00239             OSB_DB::Session& session,
00240             Pricelist::Oid&  pl);
00241 
00248         void sortPricelistByName(bool desc = false);
00249 
00258         const PricelistCfg* findPricelistCfg(
00259             const Pricelist::Oid& oid,
00260             const DateTime&       refDate
00261         ) const;
00262 
00264         const PricelistCfg* findPricelistCfg(
00265             const PricelistCfg::Oid&
00266         ) const;
00267 
00269         const PricelistCfg& getPricelistCfg(
00270             const PricelistCfg::Oid&
00271         ) const;
00272 
00274         PricelistCfg* pricelistCfg(const PricelistCfg::Oid&);
00275 
00277         const PricelistCfgs&
00278             pricelistCfgs() const { return pricelistCfgs_; }
00279 
00290         bool addPricelistCfg(
00291             OSB_DB::Session& session,
00292             PricelistCfg&    plCfg);
00293 
00304         bool updPricelistCfg(
00305             OSB_DB::Session& session,
00306             PricelistCfg&    plCfg);
00307 
00319         bool delPricelistCfg(
00320             OSB_DB::Session&   session,
00321             PricelistCfg::Oid& plCfg);
00322 
00334         bool checkPricelistCfg(
00335             OSB_DB::Session&   session,
00336             PricelistCfg::Oid& plCfg);
00337 
00349         bool releasePricelistCfg(
00350             OSB_DB::Session&   session,
00351             PricelistCfg::Oid& plCfg);
00352 
00364         bool revokePricelistCfg(
00365             OSB_DB::Session&   session,
00366             PricelistCfg::Oid& plCfg);
00367 
00379         bool unfreezePricelistCfg(
00380             OSB_DB::Session&   session,
00381             PricelistCfg::Oid& plCfg);
00383 
00384         // *************************************************************
00385         // Subscription functions maintenance
00386 
00388 
00389 
00390         const SubsFuncCfgs&
00391             subsFuncCfgs() const { return subsFuncCfgs_; }
00392 
00394         const SubsFuncCfg* findSubsFuncCfg(
00395             const SubsFuncCfg::Oid&) const;
00397 
00398         // *************************************************************
00399         // Read access to product item types
00400     private:
00402         typedef TypeId<ProductItemBase> PiType;
00403 
00404     public:
00406 
00407 
00409         const ProductItemTypes& piTypes() const { return piTypes_; }
00410 
00412         const ProductItemTypes::Info& piType(
00413             const PiType& type
00414         ) const;
00416 
00417     private:
00419         ProductCatalogue(const ProductCatalogue& rhs);
00421         ProductCatalogue& operator=(const ProductCatalogue& rhs);
00422 
00424 
00425 
00426         Product* product(const Product::Oid& productId);
00428 
00430         void buildNodeTree(const OSB_DB::Session& session);
00432         int setPlSubsFunc();
00433 
00434     private:
00436         Products products_;
00438         Pricelists pricelists_;
00440         PricelistCfgs pricelistCfgs_;
00442         SubsFuncCfgs subsFuncCfgs_;
00443 
00445         ProductItemTypes piTypes_;
00446 
00448         PcatLockMgr*   pcatLm_;
00449     };                                  // class ProductCatalogue
00450 
00451     // *****************************************************************
00452     // PcatMgr
00467     class PcatMgr {
00468     public:
00475         static ProductCatalogue& pcat();
00476 
00477     private:
00479         PcatMgr();
00481         PcatMgr(const PcatMgr&);
00482 
00484         static ProductCatalogue* pcat_;
00485     };
00486 
00487     // *****************************************************************
00488     // class PcatLockMgr
00523     class PcatLockMgr {
00525         friend class ProductCatalogue;
00526 
00527     public:
00536 
00537         typedef ReadGuard<Product*> ProductRg;
00539         typedef ReadGuard<Products*> ProductsRg;
00541         typedef ReadGuard<Pricelist*> PricelistRg;
00543         typedef ReadGuard<Pricelists*> PricelistsRg;
00544 
00546         typedef ReadGuard<ProductNode*> ProductNodeRg;
00547 
00549         typedef WriteGuard<Pricelists*> PricelistsWg;
00550 
00558         typedef RwGuard ProductsWg;
00560 
00562         enum Status {
00564             success        = 0,
00565             lockFailed     = 1,         
00566             objectNotFound = 2,         
00567             wrongPiType    = 3          
00568         };
00569 
00570     public:
00576         PcatLockMgr(ProductCatalogue& pcat);
00577 
00578     public:
00580         ProductRg readLock(const Product::Oid& id);
00582         ProductsRg readLockPds();
00593         ProductNodeRg readLock(
00594             const Product::Oid&     pdId,
00595             const ProductNode::Oid& pnId
00596         );
00597 
00599         PricelistRg readLock(const Pricelist::Oid& id);
00601         PricelistsRg readLockPls();
00602 
00603     private:
00605         ProductsWg writeLockPds();
00606 
00608         PricelistsWg writeLockPls();
00609     private:
00611         ProductCatalogue& pcat_;
00613         RwMutex pdMutex_;
00615         RwMutex plMutex_;
00616     };
00617 }                                       // namespace OSB_LIB
00618 #endif                                  // #ifndef _PRODUCTCAT_H_

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