Siena C++ API documentation (v. 0.4.1)

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Examples  

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 <carzanig@cs.colorado.edu>
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 serl@cs.colorado.edu.
00025 //
00026 //
00027 // $Id: Siena.h,v 1.18 2001/07/15 16:15:33 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_INTTYPES_H
00037 #include <inttypes.h>
00038 #else
00039 #ifdef HAVE_STDINT_H
00040 #include <stdint.h>
00041 #endif
00042 #endif
00043 
00044 #include <string>
00045 #ifdef USING_WIN32
00046 using namespace std;
00047 #endif
00048 
00049 #include <vector>
00050 #include <map>
00051 #include <exception>
00052 
00053 #ifdef WITH_DATE
00054 #include <siena/Date.h>
00055 #endif
00056 
00057 #include <siena/SienaId.h>
00058 
00059 #ifdef HAVE_CXX_NAMESPACE
00060 
00062 namespace Siena {
00063 #endif
00064 
00130 class SienaBase;
00131 class SienaPush;
00132 class SienaPull;
00133 class Notifiable;
00134 class AttributeValue;
00135 class Notification;
00136 class AttributeConstraint;
00137 class Filter;
00138 class Pattern;
00139 class NotificationSequence;
00140 
00141 class BadType;
00142 
00149 class SienaBase {
00150 public:
00153     virtual void        publish(const Notification &e)                  = 0;
00154 
00157     virtual void        advertise(const Filter &f, const SienaId &);
00158 
00161     virtual void        unadvertise(const Filter &, const SienaId &);
00164     virtual void        unadvertise(const SienaId &);
00165 
00168     virtual void        shutdown();
00169 };
00170 
00181 class SienaPush: public SienaBase {
00182 public:
00183     virtual void        subscribe(const Filter &f, Notifiable *n)       = 0;
00184     virtual void        subscribe(const Pattern &p, Notifiable *n);
00185 
00186     virtual void        unsubscribe(const Filter &f, Notifiable *n)     = 0;
00187     virtual void        unsubscribe(const Pattern &p, Notifiable *n);
00188     virtual void        unsubscribe(Notifiable *)                       = 0;
00189 
00190     virtual void        suspend(Notifiable *n)                          = 0;
00191     virtual void        resume(Notifiable *)                            = 0;
00192 };
00193 
00204 class SienaPull: public SienaBase {
00205 public:
00208     virtual void        subscribe(const Filter &f)                      = 0;
00211     virtual void        subscribe(const Pattern &p);
00212 
00215     virtual void        unsubscribe(const Filter &f)                    = 0;
00218     virtual void        unsubscribe(const Pattern &p);
00221     virtual void        unsubscribe()                                   = 0;
00222 
00223     virtual void        suspend()                                       = 0;
00224     virtual void        resume()                                        = 0;
00225 
00231     virtual Notification *              get_notification()              = 0;
00232     virtual NotificationSequence *      get_notification_sequence()     = 0;
00233 };
00234 
00258 class Notifiable {
00259  public:
00268     virtual void        notify(Notification &e)                         = 0;
00269 
00278     virtual void        notify(NotificationSequence &s)                 = 0;
00279 };
00280 
00300 enum SXType {
00303     SX_null                     = 0,
00306     SX_string                   = 1,
00309     SX_integer                  = 2,
00312     SX_bool                     = 3,
00317     SX_date                     = 4,
00320     SX_double                   = 5,
00321 };
00322 
00334 extern const string     SXTypeDescription[];
00335 
00369 class AttributeValue {
00370  public:
00371     
00374                         AttributeValue();
00377                         AttributeValue(const AttributeValue &v);
00380                         AttributeValue(const string &);
00383                         AttributeValue(const char *);
00386                         AttributeValue(int);
00389                         AttributeValue(short);
00392                         AttributeValue(long);
00395                         AttributeValue(bool);
00398                         AttributeValue(double);
00401 #ifdef WITH_DATE
00402                         AttributeValue(const Date &);
00403 #endif
00404                         ~AttributeValue();
00405 
00408     SXType              type()                                  const;
00409 
00426     int32_t &           int_value();
00427 
00433     bool &              bool_value();
00434 
00448     string &            string_value();
00449 
00455     double &            double_value();
00456 #ifdef WITH_DATE
00457 
00462     Date &              date_value();
00463 #endif
00464 
00469     const int32_t &     int_value()                             const;
00475     const bool &        bool_value()                            const;
00481     const string &      string_value()                          const;
00487     const double &      double_value()                          const;
00488 #ifdef WITH_DATE
00489 
00494     const Date &        date_value()                            const;
00495 #endif
00496 
00512                         operator long ()                        const;
00513 
00529                         operator int ()                 const;
00530 
00546                         operator short ()                       const;
00547 
00565                         operator string ()                      const;
00573                         operator bool ()                        const;
00581                         operator double ()                      const;
00582 #ifdef WITH_DATE
00583 
00590                         operator Date ()                        const;
00591 #endif
00592 
00594     AttributeValue &    operator = (const AttributeValue &);
00597     AttributeValue &    operator = (const string &);
00600     AttributeValue &    operator = (const char *);
00603     AttributeValue &    operator = (int);
00606     AttributeValue &    operator = (short);
00609     AttributeValue &    operator = (long);
00612     AttributeValue &    operator = (bool);
00615     AttributeValue &    operator = (double);
00616 #ifdef WITH_DATE
00617 
00619     AttributeValue &    operator = (const Date &);
00620 #endif
00621 
00623     bool                operator == (const AttributeValue &)    const;
00626     bool                operator < (const AttributeValue &)     const;
00627 
00628  protected:
00629     SXType              sxtype;
00630     union {
00631         string *        str;
00632         int32_t         num;
00633         bool            bln;
00634         double          dbl;
00635 #ifdef WITH_DATE
00636         Date *          date;
00637 #endif
00638     };
00639 };
00640 
00688 class Notification : public map<string, AttributeValue> {
00689  public:
00692                         Notification();
00695                         Notification(const Notification &);
00696 };
00697 
00704 enum SXOperator {
00707     SX_eq               = 1, 
00714     SX_lt               = 2, 
00717     SX_gt               = 3, 
00720     SX_ge               = 4, 
00723     SX_le               = 5, 
00732     SX_sf               = 7,
00741     SX_pf               = 6,
00746     SX_any              = 8, 
00749     SX_ne               = 9, 
00758     SX_ss               = 10 
00759 };
00760 
00761 extern const string     SXOperatorDescription[];
00762 
00784 extern bool             apply_operator(SXOperator op, 
00785                                        const AttributeValue & x, 
00786                                        const AttributeValue & y);
00787 
00797 class AttributeConstraint {
00798  public:
00801     SXOperator  op;
00804     AttributeValue      value;
00805 
00811                         AttributeConstraint();
00820                         AttributeConstraint(const AttributeValue & v);
00821 
00827                         AttributeConstraint(SXOperator o,
00828                                             const AttributeValue & v);
00831                         AttributeConstraint(const AttributeConstraint & c);
00832 
00835     AttributeConstraint &       operator = (const AttributeConstraint & c);
00836 
00844     AttributeConstraint &       operator = (const AttributeValue & v);
00845 
00848     bool                operator == (const AttributeConstraint & c) const;
00849 
00854     bool                apply_to(const AttributeValue & v);
00855 };
00856 
00873 class Filter : public multimap<string, AttributeConstraint> {
00874  public:
00879                         Filter();
00882                         Filter(const Filter &);
00883 
00886     bool                operator == (const Filter &)            const;
00887 
00890     iterator            add_constraint(const string &, 
00891                                        SXOperator, const AttributeValue &);
00892 
00895     iterator            add_constraint(const string &, 
00896                                        const AttributeConstraint &);
00897 
00898     Filter &            reduce();
00899 };
00900 
00905 class Pattern: public vector<Filter> {
00906 //
00907 // a Pattern is simply a list of (event) filters. This might be
00908 // changed in the future, requiring a more complex data structure
00909 //
00910  public:
00913                         Pattern();
00916                         Pattern(const Pattern &);
00917 };
00918 
00919 class NotificationSequence: public vector<Notification> {
00920 //
00921 // a Pattern is simply a list of (event) filters. This might be
00922 // changed in the future, requiring a more complex data structure
00923 //
00924  public:
00925                         NotificationSequence();
00926                         NotificationSequence(const NotificationSequence &);
00927 };
00928 
00931 class SienaException: public exception {
00934     virtual const char *        what()                          const;
00935 };
00936 
00939 class ServiceUnavailable: public exception {
00942     virtual const char *        what()                          const;
00943 };
00944 
00947 class NotificationModelException: public SienaException {
00950     virtual const char *        what()                          const;
00951 };
00952 
00955 class BadType: public NotificationModelException {
00956  public:
00959     SXType                      type;
00960 
00963                                 BadType(SXType);
00964 
00967     virtual const char *        what()                          const;
00968 };
00969 
00972 class BadOperator: virtual public NotificationModelException {
00973 public:
00976     SXOperator          op;
00979                                 BadOperator(SXOperator); 
00980 
00983     virtual const char *        what()                          const;
00984 };
00985 
00988 class NullFilter: virtual public NotificationModelException {
00989 public:
00992     string                      name;
00995     AttributeConstraint         af1;
00998     AttributeConstraint         af2;
00999 
01002                                 NullFilter(const AttributeConstraint &,
01003                                            const AttributeConstraint &);
01006                                 NullFilter(const string &,
01007                                            const AttributeConstraint &,
01008                                            const AttributeConstraint &);
01009 
01012     virtual const char *        what()                          const;
01013 };
01014 
01015 #ifndef NO_INLINE
01016 #include <siena/Siena.icc>
01017 #endif
01018 
01019 #ifdef HAVE_CXX_NAMESPACE
01020 };
01021 #endif
01022 
01023 #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