statusrequest.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.22 $
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 _STATUSREQUEST_H_
00031 #define _STATUSREQUEST_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <set>
00037 
00038 // + libraries
00039 
00040 // + local headers
00041 #include "chrono.h"
00042 #include "osbid.h"
00043 #include "period.h"
00044 #include "status.h"
00045 
00046 // + class declarations
00047 namespace OSB_DB {
00048     class StatusRequestGw;
00049     class Session;
00050 }
00051 
00052 namespace {
00053     struct StatusRequestRow;            // used in statusrequest-gw.h
00054 }
00055 
00056 namespace OSB_LIB {
00057     class RequestHandler;
00058 }
00059 
00060 // ************************************************************************
00061 // namespace extensions
00062 namespace OSB_LIB {
00063 
00064 // ************************************************************************
00065 // forward declarations
00066 
00067 // ************************************************************************
00068 // type definitions
00069 
00070 // ************************************************************************
00071 // class definitions
00078     class StatusRequest {
00080         friend class OSB_DB::StatusRequestGw;
00082         friend class RequestHandler;
00084         friend struct ::StatusRequestRow;
00085 
00086     public:
00088         typedef Id<StatusRequest> Oid;
00089 
00090         // defined below
00091         class GeValidFrom;
00092 
00098         enum Cascade {
00100             cscdNone = 0,
00102             cscdOwner = 1,
00104             cscdByParent = 2
00105         };
00106     public:
00110         explicit StatusRequest(const Oid& oid = Oid());
00114         StatusRequest(
00115             const StatusValue        s,
00116             const StatusReason::Oid& r
00117         );
00118 
00119     public:
00121 
00122 
00123         const Oid oid() const;
00125         const Status& status() const;
00127         const StatusValue reqStatus() const;
00129         const StatusReason::Oid reason() const;
00136         Cascade cascade() const;
00138         const DateTime& validFrom() const;
00140         const DateTime& applied() const;
00142         const DateTime& entered() const;
00149         const std::string& errCode() const;
00151 
00153         GeValidFrom geValidFrom() const;
00154 
00156 
00157 
00158         void setReqStatus(const Status& status);
00165         void setCascade(Cascade cascade);
00167         void setValidFrom(const DateTime& validFrom);
00169 
00178         void read(
00179             const OSB_DB::Session& session
00180         );
00181 
00194         void updApplied(
00195             const OSB_DB::Session& session,
00196                   bool             noWait
00197         );
00198 
00199     private:
00211         void read(
00212             const OSB_DB::Session& session,
00213                   bool             lockFirst
00214         );
00215 
00225         bool remove(
00226             const OSB_DB::Session& session
00227         );
00228 
00239         static void lock(
00240             const OSB_DB::Session& session,
00241             const Oid&             id,
00242                   bool             noWait
00243         );
00244 
00253         void lock(
00254             const OSB_DB::Session& session,
00255                   bool             noWait
00256         ) const;
00257 
00269         static void handleObjectStatus(
00270                   ObjectStatus os,
00271             const Oid&         id
00272         );
00273 
00285         void incObjVs(const OSB_DB::Session& session);
00286 
00287     private:
00289         Oid oid_;
00291         long objVs_;
00293         Status reqStatus_;
00295         Cascade cascade_;
00297         DateTime validFrom_;
00299         DateTime applied_;
00301         DateTime entered_;
00303         std::string errCode_;
00304     };                                  // class StatusRequest
00305 
00314     class StatusRequest::GeValidFrom {
00315     public:
00317         GeValidFrom(const DateTime& rhs);
00319         bool operator()(const StatusRequest& lhs);
00320     private:
00322         const DateTime rhs_;
00323     };                              // class StatusRequest::GeValidFrom
00324 
00335     class StatusRequests {
00337         friend class OSB_DB::StatusRequestGw;
00338     public:
00340         struct Cmp {
00348             bool operator()(
00349                 const StatusRequest& lhs,
00350                 const StatusRequest& rhs
00351             ) const;
00352         };
00353     public:
00359         typedef std::set<StatusRequest, Cmp> Cont;
00361         typedef Cont::const_iterator ConstIter;
00363         typedef Cont::const_reverse_iterator ConstRiter;
00364 
00365     public:
00371         StatusRequests();
00372 
00374         StatusRequests(
00375             const Period& period
00376         );
00377 
00378     public:
00380         const Period& period() const;
00381 
00383         bool empty() const;
00385         size_t size() const;
00386 
00388         ConstIter begin() const;
00390         ConstIter end() const;
00392         ConstRiter rbegin() const;
00394         ConstRiter rend() const;
00395 
00401         const StatusRequest& last() const;
00407         const StatusRequest& first() const;
00408 
00410         const Cont& requests() const;
00411 
00419         void setPeriod(
00420             const Period& period
00421         );
00422 
00435         const StatusRequest* getReqStatus(
00436             const OSB_LIB::DateTime& ts
00437         ) const;
00438 
00440         template<typename Pred>
00441         size_t countIf(Pred pred) const;
00442 
00444         void swap(StatusRequests& rhs) throw();
00445 
00446     private:
00448         Period period_;
00458         Cont requests_;
00459     };                                  // class StatusRequests
00460 }                                       // namespace OSB_LIB
00461 
00462 // ************************************************************************
00463 // inline definitions
00464 namespace OSB_LIB {
00465 
00466     // ********************************************************************
00467     // class StatusRequest
00468     inline const StatusRequest::Oid StatusRequest::oid() const
00469     {
00470         return oid_;
00471     }
00472 
00473     inline const Status& StatusRequest::status() const
00474     {
00475         return reqStatus_;
00476     }
00477 
00478     inline StatusRequest::Cascade StatusRequest::cascade() const
00479     {
00480         return cascade_;
00481     }
00482 
00483     inline const DateTime& StatusRequest::validFrom() const
00484     {
00485         return validFrom_;
00486     }
00487 
00488     inline bool StatusRequest::GeValidFrom::operator()(
00489         const StatusRequest& lhs
00490     )
00491     {
00492         return lhs.validFrom() >= rhs_;
00493     }
00494 
00495     // ********************************************************************
00496     // class StatusRequests
00497     inline bool StatusRequests::empty() const
00498     {
00499         return requests_.empty();
00500     }
00501 
00502     inline size_t StatusRequests::size() const
00503     {
00504         return requests_.size();
00505     }
00506 
00507     inline StatusRequests::ConstIter StatusRequests::begin() const
00508     {
00509         return requests_.begin();
00510     }
00511 
00512     inline StatusRequests::ConstIter StatusRequests::end() const
00513     {
00514         return requests_.end();
00515     }
00516 
00517     inline StatusRequests::ConstRiter StatusRequests::rbegin() const
00518     {
00519         return requests_.rbegin();
00520     }
00521 
00522     inline StatusRequests::ConstRiter StatusRequests::rend() const
00523     {
00524         return requests_.rend();
00525     }
00526 
00527     inline bool StatusRequests::Cmp::operator()(
00528         const StatusRequest& lhs,
00529         const StatusRequest& rhs
00530     ) const
00531     {
00532         if (lhs.validFrom() < rhs.validFrom()) return true;
00533         if (lhs.validFrom() > rhs.validFrom()) return false;
00534         return lhs.oid() < rhs.oid();
00535     }
00536 
00537     template<typename Pred>
00538     inline size_t StatusRequests::countIf(Pred pred) const
00539     {
00540         return std::count_if(begin(), end(), pred);
00541     }
00542 }                                       // namespace OSB_LIB
00543 #endif                                  // #ifndef _STATUSREQUEST_H_

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