XmlBlaster Logo

REQUIREMENT

client.cpp

XmlBlaster Logo


Type NEW
Priority HIGH
Status CLOSED
Topic XmlBlaster provides a complete client library written in c++.
Des
cription

For c++ client applications you can use the class XmlBlasterAccess which provides access to xmlBlaster in an easy way. All invocations to xmlBlaster are done by passing objects to the dispatcher.

For the invocation on the qos and key objects please refere to the APIs for
  • org::xmlBlaster::util::qos (for ConnectQos)
  • org::xmlBlaster::client::qos
  • org::xmlBlaster::client::key

Below you find an example for a typical C++ client connecting to xmlBlaster. In the configuration section there is a list of operating systems and CORBA libraries which are tested with xmlBlaster. Other combinations should work out of the box or with minor changes. Optionally you can use our native SOCKET protocol instead of CORBA to access the server.

Example
CPP
      
   
/*------------------------------------------------------------------------------
Name:      xmlBlaster/demo/c++/HelloWorld2.cpp
Project:   xmlBlaster.org
Comment:   C++ client example
Author:    Michele Laghi
------------------------------------------------------------------------------*/
#include <client/XmlBlasterAccess.h>
#include <util/XmlBlasterException.h>
#include <util/Global.h>
#include <util/Log.h>
#include <util/PlatformUtils.hpp>
#include <util/Timestamp.h>

using namespace std;
using namespace org::xmlBlaster::util;
using namespace org::xmlBlaster::client;
using namespace org::xmlBlaster::client::qos;
using namespace org::xmlBlaster::client::key;
using namespace org::xmlBlaster;

/**
 * This client connects to xmlBlaster and subscribes to a message.
 * <p>
 * We then publish the message and receive it asynchronous in the update() method.
 * </p>
 * <p>
 * Note that the CORBA layer is transparently hidden,
 * and all code conforms to STD C++ (with STL).
 * </p>
 * <pre>
 * Invoke: HelloWorld2
 * </pre>
 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.html"
 *              target="others">xmlBlaster interface</a>
 */
class HelloWorld2 : public I_Callback,          // for the asynchroneous updates
                    public I_ConnectionProblems // notification of connection problems when failsafe
{
private:
   string  ME;                        // the string identifying this class when logging
   Global& global_;
   Log&    log_;                      // the reference to the log object for this instance

public:
   HelloWorld2(Global& glob)
   : ME("HelloWorld2"),
     global_(glob),
     log_(glob.getLog("demo"))        // all logs written in this class are written to the
   {                                  // log channel called 'demo'. To see the traces of this
   }                                  // channel invoke -trace[demo] true on the command line,
                                      // then it will only switch on the traces for the demo channel

   virtual ~HelloWorld2()             // the constructor does nothing for the moment
   {
   }


   bool reachedAlive(StatesEnum /*oldState*/, I_ConnectionsHandler* /*connectionsHandler*/)
   {
      log_.info(ME, "reconnected");
      return true;
   }

   void reachedDead(StatesEnum /*oldState*/, I_ConnectionsHandler* /*connectionsHandler*/)
   {
      log_.info(ME, "lost connection");
   }

   void reachedPolling(StatesEnum /*oldState*/, I_ConnectionsHandler* /*connectionsHandler*/)
   {
      log_.info(ME, "going to poll modus");
   }

   void execute()
   {
      try {
         XmlBlasterAccess con(global_);
         con.initFailsafe(this);

         // Creates a connect qos with the user 'joe' and the password 'secret'
         ConnectQos qos(global_, "joe", "secret");
         log_.info(ME, string("connecting to xmlBlaster. Connect qos: ") + qos.toXml());

         // connects to xmlBlaster and gives a pointer to this class to tell
         // which update method to invoke when callbacks come from the server.
         ConnectReturnQos retQos = con.connect(qos, this);  // Login and register for updates
         log_.info(ME, "successfully connected to xmlBlaster. Return qos: " + retQos.toXml());

         // subscribe key. By invoking setOid you implicitly choose the 'EXACT' mode.
         // If you want to subscribe with XPATH use setQueryString instead.
         SubscribeKey subKey(global_);
         subKey.setOid("HelloWorld2");
         SubscribeQos subQos(global_);
         log_.info(ME, string("subscribing to xmlBlaster with key: ") + subKey.toXml() +
                       " and qos: " + subQos.toXml());

         SubscribeReturnQos subRetQos = con.subscribe(subKey, subQos);
         log_.info(ME, string("successfully subscribed to xmlBlaster. Return qos: ") +
                       subRetQos.toXml());

         // publish a message with the oid 'HelloWorld2'
         PublishQos publishQos(global_);
         PublishKey publishKey(global_);
         publishKey.setOid("HelloWorld2");
         MessageUnit msgUnit(publishKey, string("Hi"), publishQos);
         log_.info(ME, string("publishing to xmlBlaster with message: ") + msgUnit.toXml());
         PublishReturnQos pubRetQos = con.publish(msgUnit);
         log_.info(ME, "successfully published to xmlBlaster. Return qos: " + pubRetQos.toXml());
         try {
            Thread::sleepSecs(1);
         }
         catch(XmlBlasterException e) {
            cout << e.toXml() << endl;
         }

         // now an update should have come. Its time to erase the message,
         // otherwise you would get directly an update the next time you connect
         // to the same xmlBlaster server.
         // Specify which messages you want to erase. Note that you will get an
         // update with the status of the UpdateQos set to 'ERASED'.
         EraseKey eraseKey(global_);
         eraseKey.setOid("HelloWorld2");
         EraseQos eraseQos(global_);
         log_.info(ME, string("erasing the published message. Key: ") + eraseKey.toXml() +
                       " qos: " + eraseQos.toXml());
         vector<EraseReturnQos> eraseRetQos = con.erase(eraseKey, eraseQos);
         for (size_t i=0; i < eraseRetQos.size(); i++ ) {
            log_.info(ME, string("successfully erased the message. return qos: ") +
                          eraseRetQos[i].toXml());
         }

         log_.info(ME, "going to sleep for 2 sec and disconnect");
         org::xmlBlaster::util::thread::Thread::sleep(2000);

         DisconnectQos disconnectQos(global_);
         con.disconnect(disconnectQos);
      }
      catch (XmlBlasterException e) {
         cout << e.toXml() << endl;
      }
   }

   /**
    * Callbacks from xmlBlaster arrive here.
    */
   string update(const string& /*sessionId*/, UpdateKey& updateKey, void* /*content*/,
                 long /*contentSize*/, UpdateQos& updateQos)
   {
      log_.info(ME, "update: key: " + updateKey.toXml());
      log_.info(ME, "update: qos: " + updateQos.toXml());
      return "";
   }

};

/**
 * Try
 * <pre>
 *   HelloWorld2 -help
 * </pre>
 * for usage help
 */
int main(int args, char ** argv)
{
   XMLPlatformUtils::Initialize();
   Global& glob = Global::getInstance();
   glob.initialize(args, argv);
// XmlBlasterAccess::usage();
// glob.getLog().info("HelloWorld2", "Example: HelloWorld2\n");

   HelloWorld2 hello(glob);
   hello.execute();
   return 0;
}
   
   
Configure

These configurations are tested:

No. OS Compiler xmlBlaster Thread library Protocol library XML library Date Author Comment
1 WindowsXP VC++ 7 (Jan.2003) and VC++ STL 0.842 omnithread, boost CORBA: ACE/TAO 1.2.2 or ACE 5.3/TAO 1.3 XERCES C++ 2.2 2003-02-14 Martin, Marcel Edit build.properties and use xmlBlaster/build.xml to compile
2 WindowsXP VC++ 7 (Jan.2003) and VC++ STL 0.842 omnithread, boost CORBA: mico 2.3.8 XERCES C++ 1.7 2003-02-14 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
3 Linux 2.4.18 g++ 3.2 0.842 omnithread, boost CORBA: ACE 5.3 and TAO 1.3 XERCES C++ 2.2 2003-02-14 Michele, Marcel Edit build.properties and use xmlBlaster/build.xml to compile
4 Linux 2.4.4 and 2.4.18 g++ 2.95.3 and 3.2 0.842 omnithread, boost CORBA: mico 2.3.7 XERCES C++ 2.2 2003-02-14 Michele, Marcel Edit build.properties and use xmlBlaster/build.xml to compile
5 SunOS 5.8 Sun WorkShop 6 update 2 C++ 5.3 compiler 0.842 omnithread CORBA: Orbix 2000 2.0 XERCES C++ 1.6 2003-02-19 Guy Donadio Edit build.properties and use xmlBlaster/build.xml to compile
build -Duse-CC=true cpp
6 SunOS 5.8 sparc CC: Forte Developer 7 C++ 5.4 2002/03/09 0.843 omnithread CORBA: Orbix ASP 5.1 XERCES C++ 1.6 2003-03-02 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
./build -Duse-gcc=true c cpp
7 Linux 2.4.4 gcc 2.95.3 compiler 0.842 omnithread CORBA: Orbix E2A v. 5.1 XERCES C++ 2.2.0 2003-02-23 Michele Edit build.properties and use xmlBlaster/build.xml to compile
8 Linux 2.4.4 gcc 2.95.3 compiler 0.844 omnithread CORBA: ORBACUS v. 4.1.0 XERCES C++ 2.2.0 2003-02-23 Michele Edit build.properties and use xmlBlaster/build.xml to compile
9 Linux 2.4.20 g++ 3.3 0.846 omnithread CORBA: ACE 5.3 and TAO 1.3 XERCES C++ 2.2 2003-04-14 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
10 Linux 2.4.20 g++ 3.3 0.846 omnithread CORBA: mico 2.3.8 XERCES C++ 2.2 2003-05-03 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
11 Linux 2.4.20 g++ 3.3 0.848+ omnithread CORBA: OmniORB 4.0.1 XERCES C++ 2.2 2003-05-03 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
12 Linux 2.4.20 Intel(R) C++ Compiler for 32-bit applications, Version 7.1 (icc) 0.848+ omnithread - XERCES C++ 2.2 2003-07-03 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
build -Duse-icc=true cpp
13 Linux 2.4.21 g++ 3.3.1 0.85e+ omnithread CORBA: mico 2.3.11 (is now multi threaded) XERCES C++ 2.2 2003-11-19 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
14 Linux 2.6.8 g++ 3.3.4 1.RC2 omnithread SOCKET XERCES C++ 2.6 2004-12-01 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
15 WindowsXP VC++ 7 (Jan.2003) 0.85e+ omnithread SOCKET XERCES C++ 2.2 2004-01-14 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
build -Duse-msvc=true cpp
16 Linux 2.4.21 Intel(R) C++ Compiler for 32-bit applications, Version 8.0 (icc) 0.85e+ omnithread SOCKET XERCES C++ 2.2 2004-01-15 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
build -Duse-icc=true cpp
17 Linux 2.6.8 Intel(R) C++ Compiler for 32-bit applications, Version 8.1 (icc) 1.RC2 omnithread SOCKET XERCES C++ 2.6 2004-12-01 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
build -Duse-icc=true cpp
18 IBM s390 with Linux 2.4.19 g++ 3.2.2 0.9 omnithread SOCKET XERCES C++ 2.5 2004-04-02 Michele Edit build.properties and use xmlBlaster/build.xml to compile
build cpp
19 SunOS 5.8 sparc CC: Forte Developer 7 Sun C++ 5.5 2003/03/12 1.RC2 omnithread SOCKET XERCES C++ 2.6 2004-12-01 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
./build -Duse-CC=true c cpp
20 Windows XP Home with SDK VC++ 8 express 2005 (beta 2) 1.03 omnithread SOCKET XERCES C++ 2.6 2005-05-16 Marcel Edit build.properties and use xmlBlaster/build.xml to compile
./build -Duse-msvc=true c cpp
21 Linux 2.6.13 g++ 4.0.2 1.0.6 omnithread SOCKET XERCES C++ 2.7 2005-10-24 Marcel Edit build.properties and use xmlBlaster/build.xml to compile.
22 Linux 2.6.13 x86 64 bit g++ 4.0.2 1.0.7 omnithread SOCKET XERCES C++ 2.6 64-bit 2005-11-12 Marcel Edit build.properties and use xmlBlaster/build.xml to compile The 64bit SQLite, Xerces 2.6 and zlib were installed from SUSE 10.0 CD.

For compilation options please use

   build cpp     compiles client lib and testsuite on UNIX or Windows

   build usage   show other compile options

Compilation with VC 6 will fail (broken namespace support leads to internal compiler error).

Besides the orbs mentioned in the table the source code is already prepared for other corba vendors such as

  1. ORBACUS

but the current status of the library has not been tested against these orbs. See CompatibleCorba.h for a current list.

Please let us know if you successfully compiled and ran the testsuite with other combinations. Particularly interesting it would be the INTEL compiler on Linux and Windows and Solaris with the GCC Compiler.

How to check to the version of the library

To check which version your shared library is (UNIX only) try one of the following:

cd xmlBlaster/lib

# Searching manually the lib:
strings libxmlBlasterClient.so  | grep Global.cpp

# Or using the what command:
what libxmlBlasterClient.so

# Or (ident is part of the RCS package):
ident libxmlBlasterClient.so

# The result is something like:
Global.cpp,v 1.29 2003/03/02 19:53:42 ruff Exp

# You can now lookup Global.cpp 1.29 with
cd xmlBlaster/src/c++/util
svn log Global.cpp

How to create the Doxygen documentation

The C++ code is commented to suit the Doxygen tool from http://www.doxygen.org and the generated C++ API documentation is available online.

If you want to generate the documentation yourself you need to install Doxygen and GraphViz as described in their manuals. Than create the documentation like that:

cd $XMLBLASTER_HOME/src/c++/doc

doxygen Doxyfile
        

Now you can point your browser on $XMLBLASTER_HOME/doc/doxygen/cpp/html/index.html to view the documentation.

After setting export MANPATH=:$XMLBLASTER_HOME/doc/doxygen/c/man:$XMLBLASTER_HOME/doc/doxygen/cpp/man you are ready to read the manual pages with for example 'man XmlBlasterAccess' or 'man 3 Global'.

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See API HelloWorld2
See API XmlBlasterAccess
See http://www.xmlBlaster.org/xmlBlaster/doc/doxygen/cpp/html/namespaces.html
See REQ C++ compilation hints
See REQ client.c.socket
See REQ protocol.socket
See REQ client.cpp.mico
See REQ client.cpp.tao
See REQ client.cpp.orbix
See REQ client.cpp.failsafe
See REQ client.cpp.protocol

This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.cpp.xml

Back to overview