[omniORB] Casting C++- to CORBA-objects

Nadine Ehlers nadine@Informatik.Uni-Bremen.DE
Tue, 10 Oct 2000 09:59:41 +0200


Dear omniORBers,

I might have a simple, obvious problem but since I didn't found the
answer within a few days, I hope someone of the list could give me (a
novice to CORBA-programming) a hint, and open my eyes. By the way I
found nothing to this problem in "Advanced CORBA programming with
C++".

I need a solution for the following problem:

I have already existing "raw" C++-code without CORBA. I'm not allowed
to change the C++-code in any way, and my CORBA-methods must call the
C++-methods. Most of them return a pointer to a new C++-object, and
that is the problem, since all of the four possible down-cast
(dynamic_cast, static_cast, reinterpret_cast, and () typecasts) are
not allowed and not specified. And _narrow is only accepting
everything that is of type CORBA::Object_ptr or derived from it.

Does someone know a method for safe casting? Or maybe a WRAPPER-object
might be the solution, but since I never implemented one, I would be
very glad about a short "pseudocode"-notation with a constructor and
a method like CorbaFooA_ptr CorbaFooB_i::getCorbaFooA().

Here a short code-snippet of the problem:

CFoo.cpp:
---------

class CFooA {
    void foo();
}

class CFooB {
    CFooA* getCFooA();
}

/////////////////////////////

CFooA* CFooB::getCFooA() {
    FooA* fooA = ... // Do something with fooA
    ...
    return fooA;
}

CorbaFoo.cpp:
-------------

#include "CorbaFoo.hh"

CorbaFooA_ptr CorbaFooB_i::getCorbaFooA() {

    CFooA* cFooA = CFooB::getCFooA();
    CorbaFooA_var corbaFooA = ???

    /* Cast cFooA somehow to corbaFooA,
       without using (CorbaFooA_ptr) as typecast,
       nor dynamic_cast, static_cast and reinterpret_cast.
       And _narrow is only accepting real CORBA objects and
       no objects that are only implemented in C++ */

    ...
    return corbaFooA._retn();
}

Does anyone have a clue about what I can do to solve this
problem, wether casting or implementing a wrapper-object,
I would be glad about every answer. Maybe someone had the
same problem and found already a solution.

Yours sincerely,
    Nadine Ehlers.

PS: I must use omniORB 3.0, but that shouldn't be the
problem I think.