[omniORB] eg3_clt.cc eg3_impl.cc design questions

Andre Konopka andre.konopka at presse-data.de
Mon Apr 7 14:26:56 BST 2008


Hi,

I'm new on corba and played around with the enclosed examples 
(especially eg3_clt.cc eg3_impl.cc).
I use Suse SLES9 and omniORB-4.1.2

I would like to 'hide' the complete corba stuff in an additional class 
so that I can call the 'echoString' method as you see if you have a look 
at the following code


#include "sendecho.hh"

int main (int argc, char **argv)  {

   sendecho x;
   x.echoit("hello world!");

}


I wrote a new class 'sendecho' to hide the corba details.

I defined the 'CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr)' 
method from the example eg3_clt.cc as a member of my new class 
'sendecho'. All the corba initialising is hidden in my 'echoit' method

more sendecho.hh

#ifndef _SENDECHO_H
#define _SENDECHO_H

#include "echo.hh"

class sendecho {

  private:
   CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr);

  public:
   sendecho();
   ~sendecho();
   void echoit(const char *);

};

#endif


Here comes the sendecho.cc file

#include "sendecho.hh"

#ifdef HAVE_STD
#  include <iostream>
    using namespace std;
#else
#  include <iostream.h>
#endif


sendecho::sendecho() {}
sendecho::~sendecho() {}

void sendecho::echoit(const char *msg) {

   int argc=0;
   char** argv=0;
   cout << "initializing corba " << endl;
   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
   cout << "calling getObjectReference" << endl;
   CORBA::Object_var obj = getObjectReference(orb);
   Echo_var echoref = Echo::_narrow(obj);
   cout << "calling echoString with parameter "<< msg << endl;
   CORBA::String_var dest = echoref->echoString(msg);
   cout << "server replied: " << dest << endl;

}

CORBA::Object_ptr sendecho::getObjectReference(CORBA::ORB_ptr orb) {

original code from eg3_clt.cc

}



It works fine as long as my 'server' eg3_impl.cc is up and running

If I stop the server and restart my 'client' I get just

Aborted

./main
initializing corba
calling getObjectReference
try return rootContext->resolve(name)
calling echoString with parameter hello world!
Aborted




If I run the original code

./eg3_clt
Caught system exception TRANSIENT -- unable to contact the server.

the 'client' aborted as expected.


The 'critical' code seems to be the following (from CORBA::Object_ptr 
getObjectReference(CORBA::ORB_ptr orb)


name[0].id   = (const char*) "test";       // string copied
   name[0].kind = (const char*) "my_context"; // string copied
   name[1].id   = (const char*) "Echo";
   name[1].kind = (const char*) "Object";
   // Note on kind: The kind field is used to indicate the type
   // of the object. This is to avoid conventions such as that used
   // by files (name.type -- e.g. test.ps = postscript etc.)

   try {
     // Resolve the name to an object reference.
     return rootContext->resolve(name);
   }


Why the code doesn't throw an exception?
Is there a better (clean) way to hide corba implementation details?



Best regards


Andre















More information about the omniORB-list mailing list