[omniORB] Is this a bug in omniORB/omniORBpy

Ivan Ivanov ivan.ivanov@trema.com
Wed, 20 Jun 2001 01:36:08 -0700


The code below is from eg2_clt.cc.
I have modified it so now it invokes omniORBpy
to do some work. The bad news are that omniORB and
omniORBpy instances fail to co-exist together.
If I uncomment the orb.destroy() in python all
following C++ code will fail. If I uncomment at least
the orb->destroy() the program will hang apparently
waiting for something to complete...
Hope it's my fault and there's a simple way to
correct this. Any ideas?

Thanks,
Ivan





// eg2_clt.cc - This is the source code of example 2 used in Chapter 2
//              "The Basics" of the omniORB user guide.
//
//              This is the client. The object reference is given as a
//              stringified IOR on the command line.
//
// Usage: eg2_clt <object reference> [message]
//


#include <iostream.h>
#include <string>
#include <echo.hh>
#include "/export/home/iivanov/python_src/Python-1.5.2/Include/Python.h"

static void hello(Echo_ptr e, const char* src)
{
  CORBA::String_var dest = e->echoString(src);

  cerr << "I said, \"" << (char*)src << "\"." << endl
       << "The Echo object replied, \"" << (char*)dest <<"\"." << endl;
}

//////////////////////////////////////////////////////////////////////

int main(int argc, char** argv)
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");

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

    Py_Initialize();
    std::string s;
    s = "import sys;";
    s += "from omniORB import CORBA;";
    s += "import _GlobalIDL;";
    s += "argv2 = [ \"aaa\", \"bbb\" ];";
    s += "orb = CORBA.ORB_init(argv2, CORBA.ORB_ID);";
    s += std::string("ior = ") + "\"" + argv[1] + "\";";
    s += "obj = orb.string_to_object(ior);";


   s += "eo  = obj._narrow(_GlobalIDL.Echo);";
//   s += "if eo is None: ";
//   s+=  "print \"Object reference is not an Echo\";";
//   s+=  "sys.exit(1);";
	s+= "message = \"Hello from Python\";";
	s+= "result  = eo.echoString(message);";
	s+= "print \"I said '%s'. The object said '%s'.\" % (message,result) ;";
	//    s += "orb.destroy();";




    PyRun_SimpleString((char*)s.c_str());



    CORBA::Object_var obj = orb->string_to_object(argv[1]);
    Echo_var echoref = Echo::_narrow(obj);
    if( CORBA::is_nil(echoref) ) {
      cerr << "Can't narrow reference to type Echo (or it was nil)." <<
endl;
      return 1;
    }

    const char* message = (argc == 3) ? argv[2] : "Hello!";

    hello(echoref, message);


    //    orb->destroy();
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
         << "object." << endl;
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught a CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught unknown exception." << endl;
  }


//PyRun_SimpleString("orb.destroy();");
  return 0;
}