00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _FILTER_H_
00031 #define _FILTER_H_
00032
00033
00034
00035
00036 #include <string>
00037 #include <list>
00038 #include <vector>
00039
00040
00041 #include "osbid.h"
00042 #include "osbconst.h"
00043 #include "chrono.h"
00044 #include "osberror.h"
00045
00046
00047
00048 namespace OSB_DB {
00049 class Session;
00050 struct FilterGw;
00051 struct FilterVersionGw;
00052 struct FilterExprGw;
00053 struct FilterCondGw;
00054 struct ScFilterGw;
00055 struct TcFilterGw;
00056 }
00057
00058 namespace OSB_LIB {
00059 class Cdr;
00060 class UsedService;
00061 }
00062
00063
00064
00065 namespace OSB_LIB {
00066
00067 class FilterManager;
00068
00069
00070
00077 enum FilterType
00078 {
00079 ftUnknown = 0,
00080 ftServiceClass = 1,
00081 ftTariffClass = 2
00082 };
00083
00090 enum OperatorType
00091 {
00092 otUnknown = 0,
00093 otEqualTo = 1,
00094 otNotEqualTo = 2,
00095 otAnd = 3,
00096 otOr = 4,
00097 otXor = 5,
00098 otNot = 6
00099 };
00100
00109 enum FilterAction
00110 {
00111 faUnknown = 0,
00112 faDiscard = 1,
00113 faFilter = 2,
00114 faNoAction = 3
00115 };
00116
00117
00118
00119
00129 class Filter
00130 {
00135 friend struct OSB_DB::FilterGw;
00139 friend class FilterManager;
00140
00141 public:
00143 typedef Id<Filter> Oid;
00144
00152 Filter(
00153 const std::string& name,
00154 const std::string& des
00155 );
00156
00169 Filter(
00170 const Oid& oid = Oid(),
00171 const long& objVs = 0,
00172 const std::string& name = "",
00173 const std::string& des = ""
00174 );
00175
00177
00178
00187 bool setName(const std::string& name);
00188
00197 bool setDes(const std::string& des);
00199
00201
00202
00203 const Oid& oid() const;
00204
00206 long objVs() const;
00207
00209 const std::string& name() const;
00210
00212 const std::string& des() const;
00214
00216 void print();
00217
00219
00220
00232 bool read(const OSB_DB::Session& session);
00233
00234 private:
00253 bool insert(const OSB_DB::Session& session);
00254
00273 bool update(const OSB_DB::Session& session);
00274
00289 bool remove(const OSB_DB::Session& session);
00291
00293 Oid oid_;
00294
00299 long objVs_;
00300
00302 std::string name_;
00303
00305 std::string des_;
00306 };
00307
00309 typedef std::vector<Filter> Filters;
00310
00311
00312
00326 class FilterCond
00327 {
00332 friend struct OSB_DB::FilterCondGw;
00333
00337 friend class FilterManager;
00338
00339 public:
00341 typedef Id<FilterCond> Oid;
00342
00344 typedef std::auto_ptr<FilterCond> AutoPtr;
00345
00351 FilterCond(const Oid& oid = Oid());
00352
00360 FilterCond(
00361 const Oid& oid,
00362 const FilterType ft
00363 );
00364
00366 virtual ~FilterCond();
00367
00410 AutoPtr clone() const;
00411
00429 virtual bool eval(
00430 const Cdr& cdr,
00431 const UsedService& us
00432 ) = 0;
00433
00435
00436
00438 const FilterCond::Oid& oid() const;
00439
00441 long objVs() const;
00442
00444 FilterType fType() const;
00445
00447 CfgStatus status() const;
00448
00450 const Date& releaseDate() const;
00451
00453
00455
00456
00457 bool setReleaseDate(const Date& date);
00459
00469 bool isReleased(const OSB_DB::Session& session);
00470
00472 virtual void print() = 0;
00473
00475
00476
00490 bool read(const OSB_DB::Session& session);
00491
00492 private:
00504 bool insert(const OSB_DB::Session& session);
00505
00518 bool update(const OSB_DB::Session& session);
00519
00534 bool remove(const OSB_DB::Session& session);
00535
00537
00555 virtual bool readSpecific(
00556 const OSB_DB::Session& session
00557 ) = 0;
00558
00568 virtual bool insSpecific(
00569 const OSB_DB::Session& session
00570 ) = 0;
00571
00581 virtual bool updSpecific(
00582 const OSB_DB::Session& session
00583 ) = 0;
00584
00593 virtual bool removeSpecific(
00594 const OSB_DB::Session& session
00595 ) = 0;
00596
00598
00618 virtual FilterCond* clone_() const = 0;
00619
00621
00622
00634 bool freeze(
00635 const OSB_DB::Session& session,
00636 std::vector<OsbError>& errors
00637 );
00638
00652 bool release(
00653 const OSB_DB::Session& session,
00654 std::vector<OsbError>& errors
00655 );
00656
00669 bool revoke(
00670 const OSB_DB::Session& session,
00671 std::vector<OsbError>& errors
00672 );
00673
00686 bool unfreeze(
00687 const OSB_DB::Session& session,
00688 std::vector<OsbError>& errors
00689 );
00691
00708 virtual bool freezeSpecific(
00709 const OSB_DB::Session& session,
00710 std::vector<OsbError>& errors
00711 ) = 0;
00712
00721 virtual bool releaseSpecific(
00722 const OSB_DB::Session& session,
00723 std::vector<OsbError>& errors
00724 ) = 0;
00725
00734 virtual bool revokeSpecific(
00735 const OSB_DB::Session& session,
00736 std::vector<OsbError>& errors
00737 ) = 0;
00738
00747 virtual bool unfreezeSpecific(
00748 const OSB_DB::Session& session,
00749 std::vector<OsbError>& errors
00750 ) = 0;
00752
00753 Oid oid_;
00754
00756 FilterType ft_;
00757
00762 long objVs_;
00763
00765 CfgStatus status_;
00766
00768 Date releaseDate_;
00769 };
00770
00772 struct FilterConds
00773 {
00775
00776
00777 typedef std::list<FilterCond*> List;
00778
00780 typedef List::iterator Iterator;
00781
00783 typedef List::const_iterator ConstIterator;
00784
00786 typedef List::size_type SizeType;
00788
00790 List items;
00791
00793 FilterConds() {};
00794
00800 FilterConds(const FilterConds& rhs);
00801
00803 FilterConds& operator=(const FilterConds& rhs);
00804
00806 ~FilterConds();
00807
00814
00815 Iterator begin();
00817 Iterator end();
00819 ConstIterator begin() const;
00821 ConstIterator end() const;
00823 SizeType size() const;
00825 void swap(FilterConds& rhs);
00827
00837 void push_back(const FilterCond& fc);
00838
00848 void push_back(FilterCond::AutoPtr fc);
00849
00859 Iterator erase(Iterator pos);
00860
00867 void clear();
00868 };
00869
00870
00871
00898 class FilterExpr
00899 {
00904 friend struct OSB_DB::FilterExprGw;
00905
00910 friend class FilterManager;
00911 public:
00912
00914 typedef Id<FilterExpr> Oid;
00915
00925 FilterExpr(const FilterExpr::Oid& oid = Oid());
00926
00937 FilterExpr(
00938 const Oid& oid,
00939 const FilterCond::Oid& fcId,
00940 const FilterExpr::Oid& lhsfeId,
00941 const FilterExpr::Oid& rhsfeId,
00942 OperatorType op = otUnknown
00943 );
00944
00951 ~FilterExpr();
00952
00962 FilterExpr(FilterExpr& rhs);
00971 FilterExpr(const FilterExpr& rhs);
00972
00987 bool eval(
00988 const Cdr& cdr,
00989 const UsedService& us
00990 );
00991
00999 void build();
01000
01002
01003
01005 const Oid& oid() const;
01006
01008 long objVs() const;
01009
01011 const FilterCond::Oid& fcId() const;
01012
01017 const Oid& lhsfeId() const;
01018
01023 const Oid& rhsfeId() const;
01024
01026 OperatorType optype() const;
01027
01029 CfgStatus status() const;
01030
01032 const Date& releaseDate() const;
01033
01035
01037
01038
01040 bool setLhsFeId(const Oid& lhsId);
01041
01043 bool setRhsFeId(const Oid& rhsId);
01044
01046 bool setFcId(const FilterCond::Oid& fcId);
01047
01049 bool setOperator(OperatorType op);
01050
01052 bool setReleaseDate(const Date& date);
01054
01063 bool isReleased(const OSB_DB::Session& session);
01064
01066 void print();
01067
01069
01070
01083 bool read(const OSB_DB::Session& session);
01084
01085 private:
01098 bool insert(const OSB_DB::Session& session);
01099
01112 bool update(const OSB_DB::Session& session);
01113
01128 bool remove(const OSB_DB::Session& session);
01129
01131
01133
01134
01146 bool freeze(
01147 const OSB_DB::Session& session,
01148 std::vector<OsbError>& errors
01149 );
01150
01169 bool release(
01170 const OSB_DB::Session& session,
01171 std::vector<OsbError>& errors
01172 );
01173
01186 bool revoke(
01187 const OSB_DB::Session& session,
01188 std::vector<OsbError>& errors
01189 );
01190
01203 bool unfreeze(
01204 const OSB_DB::Session& session,
01205 std::vector<OsbError>& errors
01206 );
01208
01210 Oid oid_;
01211
01217 FilterCond::Oid fcId_;
01218
01220 FilterCond* fc_;
01221
01223 FilterExpr::Oid lhsfeId_;
01224
01226 FilterExpr* lhsfe_;
01227
01229 FilterExpr::Oid rhsfeId_;
01230
01232 FilterExpr* rhsfe_;
01233
01235 OperatorType op_;
01236
01241 long objVs_;
01242
01244 CfgStatus status_;
01245
01247 Date releaseDate_;
01248 };
01249
01251 typedef std::vector<FilterExpr> FilterExprs;
01252
01253
01254
01261 class FilterVersion
01262 {
01267 friend struct OSB_DB::FilterVersionGw;
01268
01273 friend class FilterManager;
01274 public:
01276 typedef Id2<FilterVersion> Oid;
01277
01282 typedef std::pair<FilterExpr,FilterAction> FeFaPair;
01283
01285 typedef std::vector<FeFaPair> FExprs;
01286
01296 FilterVersion(
01297 const Oid& oid = Oid(),
01298 const std::string& name = ""
01299 );
01300
01313 FilterAction eval(
01314 Cdr& cdr,
01315 UsedService& us
01316 );
01317
01319
01320
01321 const Oid& oid() const;
01322
01324 long objVs() const;
01325
01327 const std::string& name() const;
01328
01330 CfgStatus status() const;
01331
01333 const Date& releaseDate() const;
01334
01338 const FExprs& filterExprs() const;
01339
01341
01343
01344
01355 bool setName(const std::string& name );
01356
01365 bool setReleaseDate(const Date& date);
01366
01368
01370 void print();
01371
01382 void addFExpr(
01383 const FilterExpr::Oid& oid,
01384 FilterAction fa
01385 );
01386
01397 void removeFExpr(const FilterExpr::Oid& oid);
01398
01400
01401
01413 bool read(const OSB_DB::Session& session);
01414
01415 private:
01431 bool insert(const OSB_DB::Session& session);
01432
01450 bool update(const OSB_DB::Session& session);
01451
01466 bool remove(const OSB_DB::Session& session);
01467
01469
01471
01472
01484 bool freeze(
01485 const OSB_DB::Session& session,
01486 std::vector<OsbError>& errors
01487 );
01488
01506 bool release(
01507 const OSB_DB::Session& session,
01508 std::vector<OsbError>& errors
01509 );
01510
01523 bool revoke(
01524 const OSB_DB::Session& session,
01525 std::vector<OsbError>& errors
01526 );
01527
01540 bool unfreeze(
01541 const OSB_DB::Session& session,
01542 std::vector<OsbError>& errors
01543 );
01545
01553 void build();
01554
01556 Oid oid_;
01557
01562 long objVs_;
01563
01565 std::string name_;
01566
01568 CfgStatus status_;
01569
01571 Date releaseDate_;
01572
01577 FExprs fexprs_;
01578 };
01579
01581 typedef std::vector<FilterVersion> FilterVersions;
01582
01583
01584
01591 class ScFilter : public FilterCond
01592 {
01597 friend struct OSB_DB::ScFilterGw;
01598
01603 friend class FilterCondFactory;
01604
01608 friend class FilterManager;
01609
01610 public:
01611
01613 typedef std::auto_ptr<ScFilter> AutoPtr;
01614
01620 ScFilter(const Oid& oid);
01621
01629 ScFilter(
01630 const Oid& oid,
01631 long tId,
01632 OperatorType op
01633 );
01634
01636
01637
01639 long targetId() const;
01640
01642 OperatorType oType() const;
01643
01645
01647
01648
01650 bool setTargetId(long tId);
01651
01653 bool setOperator(OperatorType op);
01654
01656
01658 virtual void print();
01659
01670 bool eval(
01671 const Cdr& cdr,
01672 const UsedService& us
01673 );
01674
01679 AutoPtr clone() const;
01680 private:
01682
01683
01694 bool readSpecific(const OSB_DB::Session& session);
01695
01705 bool insSpecific(const OSB_DB::Session& session);
01706
01716 bool updSpecific(const OSB_DB::Session& session);
01717
01727 bool removeSpecific(const OSB_DB::Session& session);
01728
01730
01732
01733
01741 virtual bool freezeSpecific(
01742 const OSB_DB::Session& session,
01743 std::vector<OsbError>& errors
01744 );
01745
01754 virtual bool releaseSpecific(
01755 const OSB_DB::Session& session,
01756 std::vector<OsbError>& errors
01757 );
01758
01767 virtual bool revokeSpecific(
01768 const OSB_DB::Session& session,
01769 std::vector<OsbError>& errors
01770 );
01771
01780 virtual bool unfreezeSpecific(
01781 const OSB_DB::Session& session,
01782 std::vector<OsbError>& errors
01783 );
01785
01796 virtual FilterCond* clone_() const;
01797
01799 OperatorType op_;
01800
01802 long tId_;
01803 };
01804
01805
01806
01814 class TcFilter : public FilterCond
01815 {
01820 friend struct OSB_DB::TcFilterGw;
01821
01826 friend class FilterCondFactory;
01827
01831 friend class FilterManager;
01832
01833 public:
01834
01836 typedef std::auto_ptr<TcFilter> AutoPtr;
01837
01843 TcFilter(const Oid& oid);
01844
01852 TcFilter(
01853 const Oid& oid,
01854 long tId,
01855 OperatorType op
01856 );
01857
01859
01860
01861 long targetId() const;
01862
01864 OperatorType oType() const;
01865
01867
01869
01870
01872 bool setTargetId(long tId);
01873
01875 bool setOperator(OperatorType op);
01876
01878
01879 virtual void print();
01880
01891 bool eval(
01892 const Cdr& cdr,
01893 const UsedService& us
01894 );
01895
01900 AutoPtr clone() const;
01901 private:
01903
01904
01915 bool readSpecific(const OSB_DB::Session& session);
01916
01926 bool insSpecific(const OSB_DB::Session& session);
01927
01937 bool updSpecific(const OSB_DB::Session& session);
01938
01948 bool removeSpecific(const OSB_DB::Session& session);
01949
01951
01953
01954
01962 virtual bool freezeSpecific(
01963 const OSB_DB::Session& session,
01964 std::vector<OsbError>& errors
01965 );
01966
01975 virtual bool releaseSpecific(
01976 const OSB_DB::Session& session,
01977 std::vector<OsbError>& errors
01978 );
01979
01988 virtual bool revokeSpecific(
01989 const OSB_DB::Session& session,
01990 std::vector<OsbError>& errors
01991 );
01992
02001 virtual bool unfreezeSpecific(
02002 const OSB_DB::Session& session,
02003 std::vector<OsbError>& errors
02004 );
02006
02017 virtual FilterCond* clone_() const;
02018
02020 OperatorType op_;
02021
02023 long tId_;
02024 };
02025
02026
02027
02031 class FilterCondFactory
02032 {
02037 friend struct FilterCondGw;
02038 public:
02039
02049 static FilterCond::AutoPtr create(
02050 FilterType ft,
02051 const FilterCond::Oid& oid,
02052 long targetId = 0,
02053 OperatorType op = otUnknown
02054 );
02055 };
02056
02057
02058
02065 class FilterManager
02066 {
02067 public:
02068
02074 static FilterManager* getFilterManager();
02075
02083 void read(const OSB_DB::Session& session);
02084
02092 const Filter* findFilter(const Filter::Oid& oid);
02093
02102 const Filter& getFilter(const Filter::Oid& oid);
02103
02115 Filter::Oid creFilter(
02116 OSB_DB::Session& session,
02117 std::string& name,
02118 std::string& des
02119 );
02120
02133 OsbError updFilter(
02134 OSB_DB::Session& session,
02135 Filter& filt
02136 );
02137
02145 void delFilter(
02146 OSB_DB::Session& session,
02147 const Filter::Oid& oid
02148 );
02149
02158 const FilterVersion* findFilterVersion(
02159 const FilterVersion::Oid& oid
02160 );
02161
02171 const FilterVersion& getFilterVersion(
02172 const FilterVersion::Oid& oid
02173 );
02174
02187 FilterVersion::Oid creFilterVersion(
02188 OSB_DB::Session& session,
02189 const Filter::Oid& filtId,
02190 const std::string& name
02191 );
02192
02203 OsbError updFilterVersion(
02204 OSB_DB::Session& session,
02205 FilterVersion& fv
02206 );
02207
02216 void delFilterVersion(
02217 OSB_DB::Session& session,
02218 const FilterVersion::Oid& oid
02219 );
02220
02229 size_t freezeFilterVersion(
02230 OSB_DB::Session& session,
02231 const FilterVersion::Oid& oid,
02232 std::vector<OsbError>& errors
02233 );
02234
02243 size_t unfreezeFilterVersion(
02244 OSB_DB::Session& session,
02245 const FilterVersion::Oid& oid,
02246 std::vector<OsbError>& errors
02247 );
02248
02257 size_t releaseFilterVersion(
02258 OSB_DB::Session& session,
02259 const FilterVersion::Oid& oid,
02260 std::vector<OsbError>& errors
02261 );
02262
02271 size_t revokeFilterVersion(
02272 OSB_DB::Session& session,
02273 const FilterVersion::Oid& oid,
02274 std::vector<OsbError>& errors
02275 );
02285 const FilterExpr* findFilterExpr(const FilterExpr::Oid& oid);
02286
02296 const FilterExpr& getFilterExpr(const FilterExpr::Oid& oid);
02297
02310 FilterExpr::Oid creFilterExpr(
02311 OSB_DB::Session& session,
02312 const FilterCond::Oid& fcId = FilterCond::Oid(),
02313 const FilterExpr::Oid& lhsfeId = FilterExpr::Oid(),
02314 const FilterExpr::Oid& rhsfeId = FilterExpr::Oid(),
02315 OperatorType op = otUnknown
02316 );
02317
02328 OsbError updFilterExpr(
02329 OSB_DB::Session& session,
02330 FilterExpr& fe
02331 );
02332
02341 void delFilterExpr(
02342 OSB_DB::Session& session,
02343 const FilterExpr::Oid& oid
02344 );
02345
02354 size_t freezeFilterExpr(
02355 OSB_DB::Session& session,
02356 const FilterExpr::Oid& oid,
02357 std::vector<OsbError>& errors
02358 );
02359
02368 size_t unfreezeFilterExpr(
02369 OSB_DB::Session& session,
02370 const FilterExpr::Oid& oid,
02371 std::vector<OsbError>& errors
02372 );
02373
02382 size_t releaseFilterExpr(
02383 OSB_DB::Session& session,
02384 const FilterExpr::Oid& oid,
02385 std::vector<OsbError>& errors
02386 );
02387
02396 size_t revokeFilterExpr(
02397 OSB_DB::Session& session,
02398 const FilterExpr::Oid& oid,
02399 std::vector<OsbError>& errors
02400 );
02401
02411 const FilterCond* findFilterCond(const FilterCond::Oid& oid);
02412
02422 const FilterCond& getFilterCond(const FilterCond::Oid& oid);
02423
02435 FilterCond::Oid creFilterCond(
02436 OSB_DB::Session& session,
02437 FilterType ft,
02438 long targetId,
02439 OperatorType op
02440 );
02441
02452 OsbError updFilterCond(
02453 OSB_DB::Session& session,
02454 FilterCond& fc
02455 );
02456
02465 void delFilterCond(
02466 OSB_DB::Session& session,
02467 const FilterCond::Oid& oid
02468 );
02469
02478 size_t freezeFilterCond(
02479 OSB_DB::Session& session,
02480 const FilterCond::Oid& oid,
02481 std::vector<OsbError>& errors
02482 );
02483
02492 size_t unfreezeFilterCond(
02493 OSB_DB::Session& session,
02494 const FilterCond::Oid& oid,
02495 std::vector<OsbError>& errors
02496 );
02497
02506 size_t releaseFilterCond(
02507 OSB_DB::Session& session,
02508 const FilterCond::Oid& oid,
02509 std::vector<OsbError>& errors
02510 );
02511
02520 size_t revokeFilterCond(
02521 OSB_DB::Session& session,
02522 const FilterCond::Oid& oid,
02523 std::vector<OsbError>& errors
02524 );
02525
02527 void print();
02528 private:
02532 FilterManager();
02533
02541 void readFilter(const OSB_DB::Session& session);
02542
02550 void readFilterVersion(const OSB_DB::Session& session);
02551
02559 void readFilterExpr(const OSB_DB::Session& session);
02560
02568 void readFilterCond(const OSB_DB::Session& session);
02569
02576 void buildFilterVersions();
02577
02579 Filters filters_;
02580
02582 FilterVersions filterVs_;
02583
02585 FilterExprs filterexprs_;
02586
02588 FilterConds filterconds_;
02589
02591 static FilterManager* filtermgr_;
02592 };
02593
02594
02595
02596
02597 }
02598 # endif // #ifndef _FILTER_H_
02599