ORBit mail 2 - MI Upcasting



Implementing dynamic upcasting of binary corba objects in C
-----------------------------------------------------------

Upcasting a multiply-inherited object into a base class requires the
pointer to be changed so that it points to an object with a vtable
corresponding to the base object. (see the MI-problems.txt file)


Unfortunately you can't actually change the vtable pointer in the
object itself, because there may be other clients pointing to it
expecting the original vtable. e.g.:

    intf3* f3 = <create an intf3 implementation (with intf3 vtable)>

    intf2* f2 = CORBA_CAST(f3);  /* changes the vtable member to point
                                         to an f2 vtable */

    intf2_op4(f2,&env); /* works because using f2 vtable */

    intf3_op4(f3,&env); /* breaks because f3 vtable actually points to
f2 */



A good strategy for overcoming this obstacle is to add another layer
of indirection by making CORBA_Object a smart-pointer structure. This
holds a pointer to the current vtable, and a pointer to the raw object
structure:


struct CORBA_Object_Ptr
{
    gpointer vtable;
    raw_CORBA_Object obj;
};

typedef CORBA_Object_Ptr CORBA_Object;


The casting function then simply returns a CORBA_Object_Ptr struct
with the appropriate vtable pointer in it. N.B. the obj pointer will
always point to the same object, since we are only supporting
interface inheritence in CORBA, not implementation inheritence.


This means that the corba macros in the ORBit C mapping must look
like this:

#define intf3_op6(_o, evptr) \
(_o.vtable[3])->op6((_o.obj, evptr)



In addition, the IDL compiler will generate client C casting macros:

#define CORBA_INTF1(o) /* ... */
#define CORBA_INTF2(o) /* ... */
#define CORBA_INTF3(o) /* ... */

which return the appropriate CORBA_Object_Ptr structure.


-- 
_______________________________________________________________________
 Phil Dawes                               |   My opinions are my own
 WWW:    err.. temporarily non-existant   |   and nothing to do with
 Email:  philipd@parallax.co.uk           |      my employer.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]