Discussion:
[omniORB] how to pass python list through CORBA IDL?
Deepan N Seeralan
2009-01-07 02:48:22 UTC
Permalink
Hi All,

I am trying to communicate between a client and server located in different
address spaces using the CORBA Naming service. Since I am a newbie to
omniORB and CORBA, I tried the example given in the page
http://omniorb.sourceforge.net/omnipy2/omniORBpy/omniORBpy002.html . The IDL
definition of this example goes like this:

module Example {
interface Echo {
string echoString(in string mesg);
};
};

The definition of echoString is given by,

class Echo_i (Example__POA.Echo):
def echoString(self, mesg):
print "echoString() called with message:", mesg
return mesg

This example works just fine without any modifications. However, if i try to
change the parameters of the method 'echoString' from string to a sequence,
I get CORBA_BAD_PARAM error.
Here is the new IDL and piece of client code where i invoke the method
echoString.
module Example {
typedef sequence<string> sample;
interface Echo {
void echoString(inout sample mesg);
};
};
.. client code:
message = ["hello"] #python list
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)

I referred to the CORBA-Python mapping document which says that list and
tuples are the equivalent objects of CORBA sequence. However, when I run the
server and client, it throws the error omniORB.CORBA.BAD_PARAM:
CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_MAYBE).

Could anyone please help me in getting rid of this error? I would like to
know how to pass python list objects between CORBA client and server through
omniORB.

Thank you,
Deepan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20090106/91d75fe3/attachment.htm
Martin Trappel
2009-01-07 12:49:40 UTC
Permalink
Post by Deepan N Seeralan
Hi All,
I am trying to communicate between a client and server located in
different address spaces using the CORBA Naming service. Since I am a
newbie to omniORB and CORBA, I tried the example given in the page
http://omniorb.sourceforge.net/omnipy2/omniORBpy/omniORBpy002.html . The
module Example {
interface Echo {
string echoString(in string mesg);
};
};
....
This example works just fine without any modifications. However, if i
try to change the parameters of the method 'echoString' from string to a
sequence, I get CORBA_BAD_PARAM error.
Here is the new IDL and piece of client code where i invoke the method
echoString.
module Example {
typedef sequence<string> sample;
interface Echo {
void echoString(inout sample mesg);
};
};
message = ["hello"] #python list
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)
You should also have posted your new server code.
Post by Deepan N Seeralan
I referred to the CORBA-Python mapping document which says that list and
tuples are the equivalent objects of CORBA sequence. However, when I run
CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_MAYBE).
CORBA.COMPLETED_MAYBE suggests that the *in* part of the call worked, as
otherwise you would have seen COMPLETED_NO.
What does the server do?

br,
Martin
Duncan Grisby
2009-01-07 18:37:49 UTC
Permalink
Post by Deepan N Seeralan
This example works just fine without any modifications. However, if i try to
change the parameters of the method 'echoString' from string to a sequence, I
get CORBA_BAD_PARAM error.
That means the Python type of either the arguments or the return value
do not match the IDL.
Post by Deepan N Seeralan
Here is the new IDL and piece of client code where i invoke the method
echoString.
module Example {
typedef sequence<string> sample;
interface Echo {
void echoString(inout sample mesg);
};
};
Did you really mean to use inout there? That means the sequence is
returned from the server back to the client.
Post by Deepan N Seeralan
message = ["hello"] #python list
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)
I referred to the CORBA-Python mapping document which says that list and
tuples are the equivalent objects of CORBA sequence. However, when I run the
CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_MAYBE).
You probably aren't returning the list from your servant method. What
does your servant class look like?

You can get more information about where the exception came from by
running your code with command line arguments -ORBtraceExceptions 1

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Deepan N Seeralan
2009-01-07 23:00:02 UTC
Permalink
Hello Duncan and Martin,

Thanks for your answers.
Here is my server class.
It just takes a list and append a new item to the list.
----------------------------------------------------------------------------------
class Echo_i (Example__POA.Echo):
def echoString(self, mesg):
print "echoString() called with message:", mesg
mesg.append("new")
return mesg

My objective is to pass a sequence (i.e list) to the server method and
modify the list from there. I suppose python lists are passed by reference
by default. The changes that I am doing to the list within the server method
should be reflected on the client without actually returning the list. But
when I tried it did not happen that way. I had to return the list to the
client to update the list on its side. I am not sure whether this is the
expected behavior or am i doing something wrong here. Could anyone please
help me here?

After few trials, I was able to get rid of the CORBA_BAD_PARAM error. Here
is my new IDL and client code. Server code is same as what I pasted above.
---IDL--------
module Example {
typedef sequence<string> sample;
interface Echo {
void echoString(inout sample mesg);
};
};

----Client code--------------
message = ["hello"]
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)

-------- output from client execution ---
I said '['hello']'. The object said '['hello', 'new']'.

Thanks a lot once again for your help.

Regards,
Deepan
Post by Deepan N Seeralan
Post by Deepan N Seeralan
This example works just fine without any modifications. However, if i try
to
Post by Deepan N Seeralan
change the parameters of the method 'echoString' from string to a
sequence, I
Post by Deepan N Seeralan
get CORBA_BAD_PARAM error.
That means the Python type of either the arguments or the return value
do not match the IDL.
Post by Deepan N Seeralan
Here is the new IDL and piece of client code where i invoke the method
echoString.
module Example {
typedef sequence<string> sample;
interface Echo {
void echoString(inout sample mesg);
};
};
Did you really mean to use inout there? That means the sequence is
returned from the server back to the client.
Post by Deepan N Seeralan
message = ["hello"] #python list
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)
I referred to the CORBA-Python mapping document which says that list and
tuples are the equivalent objects of CORBA sequence. However, when I run
the
Post by Deepan N Seeralan
CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
CORBA.COMPLETED_MAYBE).
You probably aren't returning the list from your servant method. What
does your servant class look like?
You can get more information about where the exception came from by
running your code with command line arguments -ORBtraceExceptions 1
Cheers,
Duncan.
--
-- Duncan Grisby --
-- http://www.grisby.org --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20090107/9a72b9fe/attachment.htm
Duncan Grisby
2009-01-08 16:48:43 UTC
Permalink
On Wednesday 7 January, "Deepan N Seeralan" wrote:

[...]
My objective is to pass a sequence (i.e list) to the server method and modify
the list from there. I suppose python lists are passed by reference by
default. The changes that I am doing to the list within the server method
should be reflected on the client without actually returning the list. But
when I tried it did not happen that way. I had to return the list to the
client to update the list on its side. I am not sure whether this is the
expected behavior or am i doing something wrong here. Could anyone please help
me here?
It is expected. The Python language mapping says that out and inout
arguments have their values returned as extra return values. The fact
that in your case the inout argument happens to be a mutable Python type
doesn't change that. Plenty of other things you can declare as inout are
not mutable when mapped to Python.

The Python language mapping is here:

http://www.omg.org/technology/documents/formal/python.htm

Cheers,

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