00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _Siena_h
00030 #define _Siena_h
00031
00032 #include <sienaconf.h>
00033
00034 #include <sys/types.h>
00035
00036 #ifdef HAVE_STDINT_H
00037 #include <stdint.h>
00038 #else
00039 #ifdef HAVE_INTTYPES_H
00040 #include <inttypes.h>
00041 #endif
00042 #endif
00043
00044 #include <vector>
00045 #include <map>
00046 #include <exception>
00047 #include <string>
00048
00049 using namespace std;
00050
00051 #ifdef WITH_DATE
00052 #include <siena/Date.h>
00053 #endif
00054 #include <siena/SienaId.h>
00055
00056 #ifdef HAVE_CXX_NAMESPACE
00057
00059 namespace Siena {
00060 #endif
00061
00127 class SienaBase;
00128 class SienaPush;
00129 class SienaPull;
00130 class Notifiable;
00131 class AttributeValue;
00132 class Notification;
00133 class AttributeConstraint;
00134 class Filter;
00135 class Pattern;
00136 class NotificationSequence;
00137
00138 class BadType;
00139
00146 class SienaBase {
00147 public:
00150 virtual void publish(const Notification &e) = 0;
00151
00154 virtual void advertise(const Filter &f, const SienaId &);
00155
00158 virtual void unadvertise(const Filter &, const SienaId &);
00161 virtual void unadvertise(const SienaId &);
00162
00165 virtual void shutdown();
00166 };
00167
00178 class SienaPush: public SienaBase {
00179 public:
00180 virtual void subscribe(const Filter &f, Notifiable *n) = 0;
00181 virtual void subscribe(const Pattern &p, Notifiable *n);
00182
00183 virtual void unsubscribe(const Filter &f, Notifiable *n) = 0;
00184 virtual void unsubscribe(const Pattern &p, Notifiable *n);
00185 virtual void unsubscribe(Notifiable *) = 0;
00186
00187 virtual void suspend(Notifiable *n) = 0;
00188 virtual void resume(Notifiable *) = 0;
00189 };
00190
00201 class SienaPull: public SienaBase {
00202 public:
00205 virtual void subscribe(const Filter &f) = 0;
00208 virtual void subscribe(const Pattern &p);
00209
00212 virtual void unsubscribe(const Filter &f) = 0;
00215 virtual void unsubscribe(const Pattern &p);
00218 virtual void unsubscribe() = 0;
00219
00220 virtual void suspend() = 0;
00221 virtual void resume() = 0;
00222
00228 virtual Notification * get_notification() = 0;
00229 virtual NotificationSequence * get_notification_sequence() = 0;
00230 };
00231
00255 class Notifiable {
00256 public:
00265 virtual void notify(Notification &e) = 0;
00266
00275 virtual void notify(NotificationSequence &s) = 0;
00276 };
00277
00297 enum SXType {
00300 SX_null = 0,
00303 SX_string = 1,
00306 SX_integer = 2,
00309 SX_bool = 3,
00314 SX_date = 4,
00317 SX_double = 5,
00318 };
00319
00331 extern const string SXTypeDescription[];
00332
00366 class AttributeValue {
00367 public:
00368
00371 AttributeValue();
00374 AttributeValue(const AttributeValue &v);
00377 AttributeValue(const string &);
00380 AttributeValue(const char *);
00383 AttributeValue(int);
00386 AttributeValue(short);
00389 AttributeValue(long);
00392 AttributeValue(bool);
00395 AttributeValue(double);
00398 #ifdef WITH_DATE
00399 AttributeValue(const Date &);
00400 #endif
00401 ~AttributeValue();
00402
00405 SXType type() const;
00406
00423 int32_t & int_value();
00424
00430 bool & bool_value();
00431
00445 string & string_value();
00446
00452 double & double_value();
00453 #ifdef WITH_DATE
00454
00459 Date & date_value();
00460 #endif
00461
00466 const int32_t & int_value() const;
00472 const bool & bool_value() const;
00478 const string & string_value() const;
00484 const double & double_value() const;
00485 #ifdef WITH_DATE
00486
00491 const Date & date_value() const;
00492 #endif
00493
00509 operator long () const;
00510
00526 operator int () const;
00527
00543 operator short () const;
00544
00562 operator string () const;
00570 operator bool () const;
00578 operator double () const;
00579 #ifdef WITH_DATE
00580
00587 operator Date () const;
00588 #endif
00589
00591 AttributeValue & operator = (const AttributeValue &);
00594 AttributeValue & operator = (const string &);
00597 AttributeValue & operator = (const char *);
00600 AttributeValue & operator = (int);
00603 AttributeValue & operator = (short);
00606 AttributeValue & operator = (long);
00609 AttributeValue & operator = (bool);
00612 AttributeValue & operator = (double);
00613 #ifdef WITH_DATE
00614
00616 AttributeValue & operator = (const Date &);
00617 #endif
00618
00620 bool operator == (const AttributeValue &) const;
00623 bool operator < (const AttributeValue &) const;
00624
00625 protected:
00626 SXType sxtype;
00627 union {
00628 string * str;
00629 int32_t num;
00630 bool bln;
00631 double dbl;
00632 #ifdef WITH_DATE
00633 Date * date;
00634 #endif
00635 };
00636 };
00637
00685 class Notification : public map<string, AttributeValue> {
00686 public:
00689 Notification();
00692 Notification(const Notification &);
00693
00704 Notification & operator = (const string &);
00705 };
00706
00713 enum SXOperator {
00716 SX_eq = 1,
00723 SX_lt = 2,
00726 SX_gt = 3,
00729 SX_ge = 4,
00732 SX_le = 5,
00741 SX_sf = 7,
00750 SX_pf = 6,
00755 SX_any = 8,
00758 SX_ne = 9,
00767 SX_ss = 10
00768 };
00769
00770 extern const string SXOperatorDescription[];
00771
00793 extern bool apply_operator(SXOperator op,
00794 const AttributeValue & x,
00795 const AttributeValue & y);
00796
00806 class AttributeConstraint {
00807 public:
00810 SXOperator op;
00813 AttributeValue value;
00814
00820 AttributeConstraint();
00829 AttributeConstraint(const AttributeValue & v);
00830
00836 AttributeConstraint(SXOperator o,
00837 const AttributeValue & v);
00840 AttributeConstraint(const AttributeConstraint & c);
00841
00844 AttributeConstraint & operator = (const AttributeConstraint & c);
00845
00853 AttributeConstraint & operator = (const AttributeValue & v);
00854
00857 bool operator == (const AttributeConstraint & c) const;
00858
00863 bool apply_to(const AttributeValue & v);
00864 };
00865
00882 class Filter : public multimap<string, AttributeConstraint> {
00883 public:
00888 Filter();
00891 Filter(const Filter &);
00892
00903 Filter & operator = (const string &);
00904
00907 bool operator == (const Filter &) const;
00908
00911 iterator add_constraint(const string &,
00912 SXOperator, const AttributeValue &);
00913
00916 iterator add_constraint(const string &,
00917 const AttributeConstraint &);
00918
00919 Filter & reduce();
00920 };
00921
00926 class Pattern: public vector<Filter> {
00927
00928
00929
00930
00931 public:
00934 Pattern();
00937 Pattern(const Pattern &);
00938 };
00939
00940 class NotificationSequence: public vector<Notification> {
00941
00942
00943
00944
00945 public:
00946 NotificationSequence();
00947 NotificationSequence(const NotificationSequence &);
00948 };
00949
00952 class SienaException: public exception {
00955 virtual const char * what() const throw ();
00956 };
00957
00960 class ServiceUnavailable: public exception {
00963 virtual const char * what() const throw ();
00964 };
00965
00968 class NotificationModelException: public SienaException {
00971 virtual const char * what() const throw ();
00972 };
00973
00976 class BadType: public NotificationModelException {
00977 public:
00980 SXType type;
00981
00984 BadType(SXType);
00985
00988 virtual const char * what() const throw ();
00989 };
00990
00993 class BadOperator: virtual public NotificationModelException {
00994 public:
00997 SXOperator op;
01000 BadOperator(SXOperator);
01001
01004 virtual const char * what() const throw ();
01005 };
01006
01009 class NullFilter: virtual public NotificationModelException {
01010 public:
01013 string name;
01016 AttributeConstraint af1;
01019 AttributeConstraint af2;
01020
01023 NullFilter(const AttributeConstraint &,
01024 const AttributeConstraint &);
01027 NullFilter(const string &,
01028 const AttributeConstraint &,
01029 const AttributeConstraint &);
01030
01031 virtual ~NullFilter() throw() {};
01032
01035 virtual const char * what() const throw ();
01036 };
01037
01038 #ifndef NO_INLINE
01039 #include <siena/Siena.icc>
01040 #endif
01041
01042 #ifdef HAVE_CXX_NAMESPACE
01043 };
01044 #endif
01045
01046 #endif