Discussion:
[omniORB] CORBA.TypeCode() on enum fails in omniorbpy
Andrew Edem
2007-06-05 21:42:29 UTC
Permalink
Hello,

It does not seem possible to use CORBA.TypeCode() on enum definitions
from stubs. I think this is because the python type of the enum
definition is an instance while omniORB expects it to be a class.

I'm not entirely sure if this is a bug or by design, and I have no idea
where the "right" place to fix it would be.

Thanks,
-Andrew


test.idl:

module Test {
enum TestEnum {
TEST_VALUE1,
TEST_VALUE2
};
};


test.py:

import Test
from omniORB import CORBA
import logging

print "Type of enum: ", `type(Test.TestEnum)`

try:
print "Enum type code by object: ", `CORBA.TypeCode(Test.TestEnum)`
except:
logging.exception("Getting type code by class failed")

try:
print "Enum type code by string: ", \
`CORBA.TypeCode("IDL:Test/TestEnum:1.0")`
except:
logging.exception("Getting type code by string failed")


output:

Type of enum: <type 'instance'>
ERROR:root:Getting type code by class failed
Traceback (most recent call last):
File "test.py", line 8, in ?
print "Enum type code by object: ", `CORBA.TypeCode(Test.TestEnum)`
File "/usr/lib/python2.4/site-packages/omniORB/CORBA.py", line 405, in
__init__
self._t = tcInternal.typeCodeFromClassOrRepoId(cr)
File "/usr/lib/python2.4/site-packages/omniORB/tcInternal.py", line
192, in typeCodeFromClassOrRepoId
raise TypeError("Argument must be CORBA class or repository id.")
TypeError: Argument must be CORBA class or repository id.
Enum type code by string: CORBA.TypeCode("IDL:Test/TestEnum:1.0")
Duncan Grisby
2007-06-06 23:54:45 UTC
Permalink
Post by Andrew Edem
It does not seem possible to use CORBA.TypeCode() on enum definitions
from stubs. I think this is because the python type of the enum
definition is an instance while omniORB expects it to be a class.
I'm not entirely sure if this is a bug or by design, and I have no idea
where the "right" place to fix it would be.
It's kind-of by design. The Python language mapping says:

For user-defined types, a function CORBA.TypeCode can be used to
create the type codes. This function expects the repository ID. If
creation of the type code fails, CORBA.TypeCode raises a system
exception. The repository ID of a type can be obtained with the
function CORBA.id, passing the object representing the type. Such an
object shall be available for every IDL type with a <scoped_name>,
including names that are not otherwise mapped to a Python construct
(such as type aliases). If an invalid object is passed to CORBA.id, a
BAD_PARAM system exception is raised.

so you can get the TypeCode for your enum with:

tc = CORBA.TypeCode(CORBA.id(Test.TestEnum))

It's an omniORB extension that you can use CORBA.TypeCode() directly
with other generated classes like those for structs and interfaces. I'll
make it work for enums too.

Another omniORB extension is that the IDL compiler helpfully makes a
TypeCode for you, so you can get the TypeCode you want just like this:

tc = Test._tc_TestEnum

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...