[omniORB] Re: elementary questions on structs and exceptions

bjorn rohde jensen bjensen@fastmail.fm
Wed Nov 13 12:30:01 2002


Hi Stefano,

  The files generated by omniidl contain stub code
and various declarations relating to the static
CORBA interface, and you dont need to look in them
at all. You may want to give the -Wbexample option
to omniidl, which will cause it to generate example
implementations of servants to realise the interfaces
specified in your IDL.
  The CORBA::string_dup function returns a copy of
the provided string, this special function is required,
because the orb runtime may use its own memory management
subsystem. There are several interesting rules about
the ownership of data, and how it changes. Parameters
labeled as "in" in the IDL is on the server side controled
by the orb runtime, and servants may only read the data,
on the other hand servants dont have to worry about
deallocating the data either. Servants do have to allocate
any data to be returned by methods defined in the IDL, and
the orb runtime will asume ownership of the data, when your
servant method returns, which means, that the runtime will
deallocate the data, when it has been sent. You have to use
CORBA::string_dup to make a copy of the string, you want
to return to the remote caller in the echo example, or the
orb runtime will try to deallocate the input string twice.
  The question of how to design an IDL interface is pretty
equivalent to the question of how to design any other OO
interface, so it is a fairly personal choice. OMG IDL is
pretty flexible, so i would suggest designing IDL interfaces
like you design C++ interfaces with the added concerns, that
method invocations will take orders of magnitude longer and
may throw exceptions due to problems with the transport layer.
  Data types defined in the IDL may map to slightly different
types in a language mapping depending on, what IDL type it
is, especially if it is a complex data types such as structs,
unions etc. You should be able to return a struct struttura
simply by typing something like "return new struttura" in
your servant. I would highly recommend studying one of the
many books on CORBA to get a firm grip on the language
mapping. The book of choice for C++ is Advanced CORBA Programming
with C++ by Michi Henning and Steve Vinoski, it is pretty
good and full of examples.
  I hope, i have not confused you too much with all this:)
CORBA can be a bit tough to get used to, but once you do,
distibuted systems get so much simpler to work with;)

Yours sincerely,

Bjorn