[omniORB] Interface Inheritance

Clarke Brunt clarke.brunt at trafficmaster.co.uk
Fri Jan 9 10:11:27 GMT 2009


Someone else will have to confirm whether or not there are actually any
automatic conversions between the CORBA interface pointers and their base
classes - I can't remember without much studying.

Though actually, I see in the CORBA spec:

=====
OMG IDL interface inheritance does not require that the corresponding C++
classes
are related, though that is certainly one possible implementation. However,
if interface
B inherits from interface A, the following implicit widening operations for
B must be
supported by a compliant implementation:
. B_ptr to A_ptr
. B_ptr to Object_ptr
. B_var to A_ptr
. B_var to Object_ptr
=====

In general, it's not considered 'correct' to make the arguments to methods
be _var types. So your function test:

// --- some random class does:
Void test (BaseInterface_var baseInterface)
{
	cout << "yay";
}

would be better as test (BaseInterface_ptr baseInterface) i.e. the same
signature it would have had if this was implementing a CORBA IDL method.

It's not 'wrong' to use _var - you can use whatever you like - but if you
use _var, there's a danger that someone will call the function with a _ptr,
which will likely go wrong - the _var will 'consume' the pointer, and
automatically release/delete it after the function call. And even if you
call it passing a _var, there's still a _var to _var copy operation going on
to pass the argument.

Whereas with the argument declared as _ptr, you can call it with either _ptr
or _var with no problems.

And from the extract from the spec above, your code will probably then work
- there's a conversion to _ptr but not to _var.

> If I use ChildInterface_ptr, do I have to explicitly destroy it once I'm
finished using it? If so, how?

Best to leave your variable as _var, but just make the argument to the
method be _ptr.
But if you _really_ wanted to make things more difficult and use _ptr, the
you want CORBA::release(X_ptr) on it (which does the 'opposite' of
X::_duplicate(X_ptr)). You'd probably have to understand _duplicate to
implement your GetChildInterface function correctly.




More information about the omniORB-list mailing list