[omniORB] omniORBpy newbie questions

Harri Pasanen harri.pasanen@trema.com
Thu, 10 Feb 2000 17:23:39 +0100


I'm playing with omniORBpy.  While the ReleaseNote says that "The CORBA
to Python mapping is extremely easy to use", I'm still struggling.  I
presume my troubles can be attributed to my relative CORBA newbie
status...

Anyway, I set about to translate the eg3_clt.cc to eg3_clt.py.  Below is
how far I got.

The program runs as far as trying to call echoString()

Traceback (innermost last):
  File "eg3_clt.py", line 67, in ?
    result  = object.echoString(message)
AttributeError: echoString

I've put some questions in comments, identified by '???'

I wonder what am I missing?

-Harri

-------------8<-------------8<-------------8<-------------
#!/usr/bin/env python

import sys, string

# set naming service location explicitly here
sys.argv = [sys.argv[0]] + \
	   string.split("-ORBInitialHost localhost -ORBInitialPort 3033")

# Import the CORBA module
from omniORB import CORBA
import CosNaming

# Import the stubs for the Example module -- not used directly,
side-effect magic ???
import _GlobalIDL

# Initialise the ORB
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)


def getObjectReference(orb):
    try:
	# Obtain a reference to the root context of the Name service:
	# Note that for Python we don't need to narrow ???
	rootContext = orb.resolve_initial_references("NameService")

	if CORBA.is_nil(rootContext):
	    print "Failed to narrow naming context." 
	    return CORBA.Object._nil()
	
    except: # CORBA.ORB.InvalidName:  -- InvalidName not found ???
	print "Service required is invalid [does not exist]."
	return CORBA.Object._nil()


    # Create a name object, containing the name test/context:
    nc = CosNaming.NameComponent
    name = [nc("test", "my_context"), nc("Echo", "Object")]

    try: 
	# Resolve the name to an object reference, and assign the reference 
	# returned to a CORBA.Object:
	obj = rootContext.resolve(name)
    except CosNaming.NamingContext.NotFound:
	# This exception is thrown if any of the components of the
	# path [contexts or the object] aren't found:
	print  "Context not found." 
	return CORBA.Object._nil()
    except CORBA.COMM_FAILURE:
	print "Caught system exception COMM_FAILURE, unable to contact the "
	print "naming service."
	return CORBA.Object._nil()
    except omniORB.fatalException:
	print "fatalException"
	sys.exit(-1)
    except:
	print "Caught a system exception while using the naming service."
	return CORBA.Object._nil()
    return obj
# end getObjectReference(orb)

# Contact the naming service
object = getObjectReference(orb)  # this returns omniORB.CORBA.Object
instance

# Invoke the echoString operation
message = "Hello from Python"
result  = object.echoString(message) # Attribute error ???
print "I said '" + result + "'. The object said '" + result + "'"