[omniORB] Re: DynAny & CORBA 2.3 spec.
David Riddoch
djr@uk.research.att.com
Thu, 25 May 2000 08:58:49 +0100 (BST)
On Wed, 24 May 2000, Olivier Thiboutot wrote:
> We want to use OmniORB as or broker but we are not able to build
> dynamic complexe structure with DynAny and pass them as Any... like
>
> struct ToPass
> {
> short Mine;
> long MyLongArray[25];
> }
Why not? Try this...
/////////////////////////////////////////////////////////////
#include <omniORB3/CORBA.h>
CORBA::TypeCode_ptr create_tc(CORBA::ORB_ptr orb)
{
CORBA::TypeCode_var a = orb->create_array_tc(25, CORBA::_tc_long);
CORBA::StructMemberSeq m;
m.length(2);
m[0].name = (const char*) "Mine";
m[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_short);
m[1].name = (const char*) "MyLongArray";
m[1].type = CORBA::TypeCode::_duplicate(a);
return orb->create_struct_tc("IDL:ToPass:1.0", "ToPass", m);
}
CORBA::DynAny_ptr create_DynAny(CORBA::ORB_ptr orb, CORBA::TypeCode_ptr
tc)
{
CORBA::DynStruct_var ds = orb->create_dyn_struct(tc);
ds->insert_short(5);
CORBA::DynAny_var d = ds->current_component();
CORBA::DynArray_var da = CORBA::DynArray::_narrow(d);
for( int i = 0; i < 25; i++ )
da->insert_long(i);
return ds._retn();
}
int main(int argc, char** argv)
{
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
CORBA::TypeCode_var tc = create_tc(orb);
CORBA::DynAny_var d = create_DynAny(orb, tc);
CORBA::Any_var a = d->to_any();
return 0;
}
/////////////////////////////////////////////////////////////
> trying to build this with DynAny and having MyLongArray to be in
> fact a Seqence looks impossible... to transfert to a Any.
It is certainly not impossible. Perhaps the above example will give you
enough of a hint...
Cheers,
David
PS. Its probably best if you send such queries to
<omniorb-list@uk.research.att.com> in future please.