Discussion:
[omniORB] understanding out parameters and returned values and how to use them
Nutty Loaf
2011-07-22 20:06:16 UTC
Permalink
Hi all

I'm new to CORBA and I'm finding it very difficult to understand.

Can anyone please explain with a short example how to use returned values
and out parameters.

For example, I have a Python class to use in the servant code like this:


## servant starts ##

class servicehelper_i (services.servicehelper):

def __init__ (self):
self.clientid = None

def create_client (self, dictClient, template):

try:
clientid = createClientProcess (dictClient, template)
self.clientid = clientid
success = 1
except:
success = 0

return success

## servant ends ##


This is the IDL, which I think must have something wrong:

module services
{
struct dictClientDetails
{
string company;
string contactname;
string login;
string password;
};

interface servicehelper
{
boolean create_client (in dictClientDetails client_details, in string
template_name, out long clientid);
}

}


The client code I've written is:


### client starts ###

from omniORB import CORBA
import services

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)


ior = sys.argv[1]
obj = orb.string_to_object(ior)


objService = obj._narrow (services.servicehelper)

dictClient = services.servicehelper.dictClientDetails ("test_company11",
"testname11", "test11", "mypasswordis11")
result = objService.create_client (dictClient, "Standard")

### client ends ###


How do I access the clientid attribute?

I've tried putting a third argument in the call to create_client but this
doesn't work.

I don't seem to get anything in the "result" variable.

Looks like my code must have lots of mistakes, which I can't identify.

Any help is appreciated.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20110722/e5dfeb34/attachment.htm
Bailey, Kendall
2011-07-22 20:26:03 UTC
Permalink
The Python mapping is documented here: http://www.omg.org/spec/PYTH/1.2/PDF

The relevant portion is:

Operations of an interface map to methods available on the object references.
Parameters with a parameter attribute of in or inout are passed from left to right to
the method, skipping out parameters. The return value of a method depends on the
number of out parameters and the return type. If the operation returns a value, this
value forms the first result value. All inout or out parameters form consecutive result
values. The method result depends then on the number of result values:
* If there is no result value, the method returns None.
* If there is exactly one result value, it is returned as a single value.
* If there is more than one result value, all of them are packed into a tuple, and this
tuple is returned.


So for your example, you should return a tuple consisting of the return value first, followed by the one out parameter value. On the client side expect to receive a 2 element tuple as well.

HTH,
Kendall

Loading...