[omniORB] Re: I'll try again...[Fwd: Proxy Object Factories]

Sai-Lai Lo S.Lo@orl.co.uk
Wed, 18 Mar 1998 20:38:14 GMT


>>>>> Ole Storm writes:

> Section 8.2 of the manual for omniORB 2.4 describes how to define a new
> proxy class and a new proxy object factory for the simple Echo example.

> I have tried to follow the steps outlined in section 8.2.2 in order to
> modify the proxy object and factory for the eg2_clt.cc example. I am
> pretty sure that I have covered the three necessary steps described in
> the manual. I have left the caching-part out, so echoString() is not
> overloaded in my proxy class - I am more interested in the construction
> and destruction of the proxy objects. However, things seem to go wrong:


This is a good lesson not to put up an example that hasn't been compiled
and *run* verbatim!

Attached is a modified eg2_clt.cc that actually works using a application
installed  proxy object factory.

The missing bit is the explicit call to the ctor of the public virtual
omniObject:

  _new_proxy_Echo (Rope *r,
                  CORBA::Octet *key,
                  size_t keysize,IOP::TaggedProfileList *profiles,
                  CORBA::Boolean release) 
         : _proxy_Echo(r,key,keysize,profiles,release),
           omniObject(Echo_IntfRepoID,r,key,keysize,profiles,release) {}

instead of

  _new_proxy_Echo (Rope *r,
                  CORBA::Octet *key,
                  size_t keysize,IOP::TaggedProfileList *profiles,
                  CORBA::Boolean release) 
         : _proxy_Echo(r,key,keysize,profiles,release) {}


I thought I understand the initialisation order/rule of virtual public base
class.... Shame!


Sai-Lai



-------------------------------------------------------------------------
// eg2_clt.cc - This is the source code of example 2 used in Chapter 2
//              "The Basics" of the omniORB2 user guide.
//
//              This is the client. The object reference is given as a
//              stringified IOR on the command line.
//
// Usage: eg2_clt <object reference>
//
#include <iostream.h>
#include "echo.hh"

#include "greeting.cc"

extern void hello(CORBA::Object_ptr obj);

class _new_proxy_Echo : public virtual _proxy_Echo {
public:
  _new_proxy_Echo (Rope *r,
                  CORBA::Octet *key,
                  size_t keysize,IOP::TaggedProfileList *profiles,
                  CORBA::Boolean release) 
         : _proxy_Echo(r,key,keysize,profiles,release),
           omniObject(Echo_IntfRepoID,r,key,keysize,profiles,release) 
  {
    cerr << "_new_proxy_Echo ctor" << endl;
  }

   virtual ~_new_proxy_Echo() {
     cerr << "_new_proxy_Echo dtor" << endl;
   }
};

class _new_Echo_proxyObjectFactory : public virtual Echo_proxyObjectFactory
{
public:
   _new_Echo_proxyObjectFactory () {}
   virtual ~_new_Echo_proxyObjectFactory() {}

   // Only have to override newProxyObject
   virtual CORBA::Object_ptr newProxyObject(Rope *r,
                                            CORBA::Octet *key,
                                            size_t keysize,
                                            IOP::TaggedProfileList *profiles,
                                            CORBA::Boolean release) {
      _new_proxy_Echo *p = new _new_proxy_Echo(r,key,keysize,profiles,release);
      return p;
   }
};

int
main (int argc, char **argv) 
{
  CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB2");
  CORBA::BOA_ptr boa = orb->BOA_init(argc,argv,"omniORB2_BOA");

  if (argc < 2) {
    cerr << "usage: eg2_clt <object reference>" << endl;
    return 1;
  }

   _new_Echo_proxyObjectFactory* f =  new _new_Echo_proxyObjectFactory;

  try {
    CORBA::Object_var obj = orb->string_to_object(argv[1]);
    hello(obj);
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE, unable to contact the "
         << "object." << endl;
  }
  catch(omniORB::fatalException& ex) {
    cerr << "Caught omniORB2 fatalException. This indicates a bug is caught "
         << "within omniORB2.\nPlease send a bug report.\n"
         << "The exception was thrown in file: " << ex.file() << "\n"
         << "                            line: " << ex.line() << "\n"
         << "The error message is: " << ex.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught a system exception." << endl;
  }

  return 0;
}