Discussion:
[omniORB] eg3_clt.cc eg3_impl.cc design questions
Andre Konopka
2008-04-07 17:26:49 UTC
Permalink
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
Martin Trappel
2008-04-09 14:45:03 UTC
Permalink
Post by Andre Konopka
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
(...)
I wrote a new class 'sendecho' to hide the corba details.
(...)
Here comes the sendecho.cc file
(...)
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;
}
I guess it's just test code so it should be all right. But if you want
to hide the CORBA stuff, it will be better to call ORB_init (and maybe
also getObjReferences) in the dtor (or another initializer fn) of your
helper class.
Post by Andre Konopka
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
(...)
If I run the original code
./eg3_clt
Caught system exception TRANSIENT -- unable to contact the server.
the 'client' aborted as expected.
Why the code doesn't throw an exception?
Is there a better (clean) way to hide corba implementation details?
When you read the error messages given in eg3_clt you will see that the
try-catch block in getObjRef() is for the Naming Service and _not_ for
the Object. The TRANSIENT error message you are getting in the original
code comes from main() as there is also a try-catch block.

br,
Martin
Andre Konopka
2008-04-10 17:47:30 UTC
Permalink
Hi Martin,

thank you for your help.

Yes, you are right!!! The exception is catched by main!
I overlooked it

best regards

Andre
Post by Martin Trappel
Post by Andre Konopka
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
(...)
I wrote a new class 'sendecho' to hide the corba details.
(...)
Here comes the sendecho.cc file
(...)
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;
}
I guess it's just test code so it should be all right. But if you want
to hide the CORBA stuff, it will be better to call ORB_init (and maybe
also getObjReferences) in the dtor (or another initializer fn) of your
helper class.
Post by Andre Konopka
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
(...)
If I run the original code
./eg3_clt
Caught system exception TRANSIENT -- unable to contact the server.
the 'client' aborted as expected.
Why the code doesn't throw an exception?
Is there a better (clean) way to hide corba implementation details?
When you read the error messages given in eg3_clt you will see that the
try-catch block in getObjRef() is for the Naming Service and _not_ for
the Object. The TRANSIENT error message you are getting in the original
code comes from main() as there is also a try-catch block.
br,
Martin
Loading...