Siena C++ API documentation (v. 0.4.3)

publisher.cc

This is an example of how to program a simple subscriber application. To compile this example on a GNU/Linux system or on other Unix-like systems, assuming Siena has been installed in $prefix, execute:

  c++ publisher.cc -o publisher -I$prefix/include -L$prefix/lib -lsiena
  

On some platforms (notably Solaris), you will have to link additional libraris (e.g., -lsocket -lnsl).

To compile this example on a win32 system, using Visual C++, assuming Siena has been installed in %prefix%, execute:

  cl -I%prefix%
-GX -c publisher.cc link -out:publisher publisher.obj %prefix%.lib wsock32.lib

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: publisher.cc,v 1.1 2003/07/09 20:15:55 carzanig Exp carzanig $
00028 //
00029 #include <sienaconf.h>
00030 
00031 #ifdef USING_WIN32
00032 #include <stdlib.h>
00033 #define sleep _sleep
00034 #else
00035 #include <unistd.h>
00036 #endif
00037 
00038 #include <iostream>
00039 #include <exception>
00040                                                 // include Siena headers
00041 #include <siena/Siena.h>
00042 #include <siena/ThinClient.h>
00043 
00044 int main (int argc, char *argv[])
00045 {
00046     try {                                       // handles cmd-line params
00047         if (argc != 2) {
00048             cerr << "usage: " << argv[0] << " <uri>" << endl;
00049             return 1;
00050         }
00051 
00052         ThinClient siena(argv[1]);              // creates interface to 
00053                                                 // given master server
00054         Notification n;
00055         n["stock"] = "XYZ";
00056  
00057         for (int i = 10; i < 200; i += 10) {
00058             n["price"] = i;
00059             siena.publish(n);
00060             sleep(1);
00061         }
00062         siena.shutdown();                       // closes Siena interface
00063     } catch (exception &ex) {
00064         cout << "error: " << ex.what() << endl;
00065     }
00066     return 0;
00067 }

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