[omniORB] Any type

Lionel Gilet lgilet@san-jose.tt.slb.com
Wed Jun 26 15:45:41 2002


Make sure that you use the appropriate IDL compilation option. The option
-Wba is required to generate the appropriate stubs for a user defined
structure to be passed as any.
The server must return an any, but this any can be nil (the default
constructor will create a nil one).
The client should not assume that the any contains a sequence<data_s>, it
must check that this is the case. One approach is to do:
data* theData;
CORBA::Any theAny;
theAny = server->load(id);
if ( !theAny >= theData ) {
  // Error did not find the record corresponding to id.
}
else {
  // Do something with theData. Note that it is valid only within the scope
in which theAny is defined.
  // If you need to keep it longer you must copy it.
  data copyData = *data;
}

Alternatively you can use an exception mechanism but I would not recommend
it at least until you have a good understanding of what is going on.

Hope this helps,

Lionel

Alexander Deruwe wrote:

> Hewwo everybody,
>
> I've converted my IDL to use the any type a few days ago, and am in the
> process of modifying my existing code now (which becomes alot simpler
> :).
>
> I have a question though:
>
> ### SAMPLE IDL
>
> struct data_s
>     {
>     long id;
>     string name;
>     };
> typedef sequence<data_s> data;
> any load (in long id); // supposed to return a data type
>
> ### END SAMPLE
>
> Suppose this function 'load' does not find a record; I would somehow
> have to show this to the client. If I do this by returning None, my
> client crashes.
> What is the value that omniORB expects to be returned in case no valid
> data is found? Do I create a special "error struct" (which I could then
> load with diagnostic messages), or do I load a 'data' structure with
> bogus values? Or something else?
>
> Thanks for the help,
>
> --
> Alexander Deruwe
> AQS-CarControl
> _______________________________________________
> omniORB-list mailing list
> omniORB-list@realvnc.com
> http://www.realvnc.com/mailman/listinfo/omniorb-list