Here is an abstract of the CORBA::Object interface:
module CORBA { interface Object { InterfaceDef get_interface (); boolean is_nil (); Object duplicate (); void release (); boolean is_a (in string logical_type_id); boolean non_existant (); boolean is_equivalent (in Object other_object); unsigned long hash (in unsigned long maximum); }; }; |
This interface is very important, because it is implicitly inherited by all the interfaces defined either by the CORBA standard or by you. This means that all the operations defined in this interface are available on all other CORBA objects.
Among these standard operations are those which deal with the object identity: copy, test, destruction...
The is_nil method allows you to test whether an object exists or not. If true, the object does not exist but if false, the object is not guaranteed to exist (see exception handling). This method is guaranteed to return true when tested against the CORBA_OBJECT_NIL macro.
The is_equivalent method will test whether two object references point to the same Object instance. To do so it will use the hash method.
Last, we have the duplicate and release methods which are used to do copies of objects references and destroy these copies. Please, note that these last 2 methods work on object references, not on the object itself: it would make no sense to copy the object itself.
When dealing with objects in CORBA, you always use a CORBA_Object opaque type variable which holds the object information and which is passed as first argument to every method. The duplicate method allows you to make a copy of this object reference and the release method to destroy this copy. These operations are necessary because the CORBA_Object type is opaque: you don't know its structure and it is thus impossible to copy its internal representation by yourself. (just because its internal structure is dependent on the implementation of the ORB).
Here is some sample code to allow you see these things work:
CORBA_Object obj; CORBA_Environment ev; CORBA_Object obj_copy = CORBA_OBJECT_NIL; /* here lies some code to link to the target object */ /* now, obj references a real object */ if (CORBA_Object_is_nil (obj, &ev)) printf (stderr, "Error: could not get object reference !!\n"); obj_copy = CORBA_Object_duplicate (obj, ev); if (CORBA_Object_is_equivalent(obj, obj_copy, &ev)) printf (stderr, "Cool: the copy succeeded\n"); CORBA_Object_release (obj_copy, &ev); |
I think that this code does not need any comments.
There is one last method we did not go into: get_interface. This method will be discussed in a later chapter on the interface repository. However, ORBit does not implement yet, so it is of little use :)