Siena C++ API documentation (v. 0.4.3)

Siena.h

00001 // -*- C++ -*-
00002 //
00003 //  This file is part of Siena, a wide-area event notification system.
00004 //  See http://www.cs.colorado.edu/serl/siena/
00005 //
00006 //  Author: Antonio Carzaniga <[email protected]>
00007 //  See the file AUTHORS for full details. 
00008 //
00009 //  Copyright (C) 1998-2001 University of Colorado
00010 //
00011 //  This program is free software; you can redistribute it and/or
00012 //  modify it under the terms of the GNU General Public License
00013 //  as published by the Free Software Foundation; either version 2
00014 //  of the License, or (at your option) any later version.
00015 //
00016 //  This program is distributed in the hope that it will be useful,
00017 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License
00022 //  along with this program; if not, write to the Free Software
00023 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00024 //  USA, or send email to [email protected].
00025 //
00026 //
00027 // $Id: Siena.h,v 1.1 2003/07/09 20:17:31 carzanig Exp $
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 // a Pattern is simply a list of (event) filters. This might be
00929 // changed in the future, requiring a more complex data structure
00930 //
00931  public:
00934                         Pattern();
00937                         Pattern(const Pattern &);
00938 };
00939 
00940 class NotificationSequence: public vector<Notification> {
00941 //
00942 // a Pattern is simply a list of (event) filters. This might be
00943 // changed in the future, requiring a more complex data structure
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

Copyright © 2001 University of Colorado.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". This documentation is authored and maintained by Antonio Carzaniga