[omniORB] Return Struct o None
Michael
omniorb at bindone.de
Thu Mar 26 18:41:35 GMT 2009
Hi Antonio,
there is no conecpt of None/Nil/Null whatever when return a
struct/string/int or any datatype. That is because you're dealing with
pods and not pointers/references. This becomes more apparent when you're
imagening the following construct in C++:
int x = myinft->get_whatever();
So when your servant returned None, what should this do in this code?
You can only return None when returning an object reference (because it
is.. a reference :) - that will map to a nil reference in other
languages). So for what you want to accomplish it might be best to
return a sequence and make that empty in case there is no return value,
so in your IDL:
typedef sequence<SInfo> SInfoSeq;
SInfoSeq get_personal_info(in wstring name);
in python:
def get_personal_info(self, name):
if name in self.personal_dict:
return [SInfo(self.personal_dict[name]['id'],
self.personal_dict[name]['address'],
self.personal_dict[name]['tlf'])]
else:
return []
As an alternative, if that interface should usually return something (so
a miss is an exceptional event) you could throw a user exception instead
(never throw CORBA::OBJECT_NOT_EXIST in such a case, because it tells
the orb that the object reference you called get_personal_info on does
not exist - in case of location forwards and other scenarios that will
lead to disaster). Bottomline, in this case alter your idl:
exception PersonalInfoNotFoundException {
string message;
};
SInfo get_personal_info(in wstring name) raises
(PersonalInfoNotFoundException);
And in python:
...
else:
raise PersonalInfoNotFoundExceptino("Nothing there")
br
michael
Antonio Beamud Montero wrote:
> Hi all:
> I've defined a struct, and a method that returns this struct type. The
> problem is when I try to return a null value instead this struct. For
> example:
>
> idl:
> ...
> struct SInfo {
> wstring id;
> wstring address;
> wstring tlf;
> }
>
> SInfo get_personal_info(in wstring name);
>
> in python:
> ..
> def get_personal_info(self, name):
> if name in self.personal_dict:
> return SInfo(self.personal_dict[name]['id'],
> self.personal_dict[name]['address'],
> self.personal_dict[name]['tlf'])
> else:
> return None
>
> If the name exists, all works well, but if not exists, the next error
> appears:
> omniORB.CORBA.BAD_PARAM:
> ORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_MAYBE)
>
> I've tried with None, Corba.types.NoneType and CORBA.Object._nil
> , but the same error.
>
> Thanks.
>
>
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
More information about the omniORB-list
mailing list