Heu ...
I've found this email
http://www.mico.org/pipermail/mico-commit/2004-May/000192.html
That says:
This patch fixes ORB_init to delete created ORBInitInfo object which
caused memory leak when multiple ORB_init calls were issued.
So ... if this is true, I understand why my previous code is segfault.
But, now, my question is:
I'm on the ORB Initializer function:
> post_init( PortableInterceptor::ORBInitInfo_ptr info )
I want to save into the CosTransactions::Current object a reference to an ORB or
ORBInitInfo to be able to call 'resolve_initial_reference("PICurrent")' in the
'Current::begin()' method (and all others).
How may I do that ? Because if I save the 'info', this one is deleted when
'ORB_init' is called, and I do not have any CORBA::ORB_var variable !
Thanks you very much.
Quoting Laurent Marzullo <[EMAIL PROTECTED]>:
> Hello,
>
> I'm trying to do a CosTransactions service based on 'Stefano Marocco' source
> (http://www.mico.org/pipermail/mico-devel/2003-April/006872.html)
>
> But I've a segmentation fault ...
>
>
> Here my client Code:
> --------------------------------------------------------------------------
> #include <ots.h>
> #include <util.h>
> #include <sys-excp.h>
> #include <CosTransactions.h>
> #include <orb-initializer.h>
>
> using namespace ONED;
> using namespace ONED::OTS;
>
> CORBA::ORB_var orb;
>
> int
> main( int argc , char** argv )
> try
> {
> OrbInitializer::init();
> orb = CORBA::ORB_init( argc , argv , "mico-local-orb" );
>
> CosTransactions::Current_var c =
> resolve_initial<CosTransactions::Current>( orb , "TransactionCurrent" );
> // See below for the code of 'resolve_initial'
> c->begin();
> }
> catch ( ONED::Exception& p_excp )
> {
> std::cerr << p_excp << '\n';
> }
> catch ( std::exception& p_excp )
> {
> std::cerr << "Main catch std::exception : " << p_excp.what() << '\n';
> }
> catch ( ... )
> {
> std::cerr << "Unknown exception !\n";
> }
>
>
> -------------------------------------------------------------------------
>
>
>
> --- OrbInitializer ------------------------------------------------------
> void
> ONED::OTS::OrbInitializer::pre_init( PortableInterceptor::ORBInitInfo_ptr
> info )
> {
> _transaction_slot = info->allocate_slot_id();
>
> // Allocate the codec
> IOP::CodecFactory_var codec_factory = info->codec_factory();
> IOP::Encoding encoding;
> encoding.format = IOP::ENCODING_CDR_ENCAPS;
> encoding.minor_version = 1;
> encoding.major_version = 2;
> IOP::Codec_var codec_var = codec_factory->create_codec( encoding );
>
> //
> // Allocate the client and server interceptor and pass the allocating
> slot
> // and codec to it for future use in 'send_request' and
> // 'receive_request_service_context'
> //
> info->add_server_request_interceptor( new ONED::OTS::ServerInterceptor(
> _transaction_slot , codec_var ) );
> info->add_client_request_interceptor( new ONED::OTS::ClientInterceptor(
> _transaction_slot , codec_var ) );
> }
>
>
>
> void
> ONED::OTS::OrbInitializer::post_init( PortableInterceptor::ORBInitInfo_ptr
> info
> )
> {
> //
> // Resolve initial reference of 'TransactionService'
> // The Transaction service should then create a persistent
> TransactionFactory
> // object with an objectId of 'TransactionService'.
> //
> CosTransactions::TransactionFactory_ptr ptr =
> resolve_initial<CosTransactions::TransactionFactory>( info ,
> "TransactionService" );
> // see below for the code of 'resolve_initial'
>
> //
> // Register initial reference for 'CosTransactions::Current'
> //
> CurrentImpl *_current = new CurrentImpl( info , ptr , _transaction_slot
> );
> info->register_initial_reference( "TransactionCurrent" , _current );
> }
>
>
>
> void
> OrbInitializer::init( void )
> {
> OrbInitializer *init = new OrbInitializer;
> PortableInterceptor::register_orb_initializer( init );
> }
>
>
>
>
>
> Right now, Server interceptor and client interceptor are empty.
> Here the code of 'resolve_initial'
>
>
> template <typename _narrowType, typename T_resolve_intf>
> typename _narrowType::_ptr_type
> resolve_initial( T_resolve_intf p_orb , const char* p_object_id )
> try
> {
> CORBA::Object_var obj;
> obj = p_orb->resolve_initial_references( p_object_id );
> if ( CORBA::is_nil( obj ) )
> THROW_EXCP_WITH_ARG( ResolveException,
> << ONED::Msg( "Unable to resolve initial
> reference
> for name $1 !\n")
> << ONED::Param( 1 , p_object_id ));
>
> typename _narrowType::_var_type ref;
> ref = _narrowType::_narrow(obj);
>
> if ( CORBA::is_nil( ref ) )
> THROW_EXCP_WITH_ARG( ResolveException,
> << ONED::Msg( "Unable to narrow object reference
> `$2' to type `$1'\n" )
> << ONED::Param( 2 , ONED::ABI::demangle(
> typeid(ref).name() ) )
> << ONED::Param( 1 , p_object_id ));
>
> return ref._retn();
> } // try Server::resolve_initial
> catch ( CORBA::ORB::InvalidName& p_excp )
> {
> THROW_EXCP_WITH_ARG( ResolveException,
> << ONED::Msg( "Could not resolve initial reference
> $1\n"
> "$1 is an invalid name !" )
> << ONED::Param( 1 , p_object_id ) );
> } // catch ( InvalidName )
> catch ( CORBA::Exception& p_excp )
> {
> CORBA::Any tmp;
>
> tmp <<= p_excp;
> CORBA::TypeCode_var tc = tmp.type();
> const char* p = tc->name();
>
> THROW_EXCP_WITH_ARG( ResolveException,
> << ONED::Msg( "Could not resolve initial reference
> `$1'\n"
> "[$2]: $3 !" )
> << ONED::Param( 1 , p_object_id )
> << ONED::Param( 2 , tc->id() )
> << ONED::Param( 3 , p ? p : "(null)" ) );
> } // catch ( CORBA::Exception )
>
>
> ------ CURRENT-IMPL.CPP -------------------
> CurrentImpl::CurrentImpl(
> PortableInterceptor::ORBInitInfo_ptr p_info_ptr
> , CosTransactions::TransactionFactory_ptr p_factory_ptr
> , PortableInterceptor::SlotId p_slot )
> : _info_ptr( p_info_ptr )
> , _factory_ptr( p_factory_ptr )
> , _slot( p_slot )
> {
> }
>
>
> void
> CurrentImpl::begin( void )
> {
> std::cerr << __PRETTY_FUNCTION__ << '\n';
>
> // ---- SEGFAULT HERE ---
> PortableInterceptor::Current_var picurrent =
> resolve_initial<PortableInterceptor::Current>(
> _info_ptr , "PICurrent" );
> std::cerr << "COUCOU -1-\n";
> CORBA::Any* anyptr = picurrent->get_slot( _slot );
> std::cerr << "COUCOU -2-\n";
> CORBA::TypeCode_var tc = anyptr->type();
> std::cerr << "COUCOU -3-\n";
> if ( tc->kind() != CORBA::tk_void && tc->kind() != CORBA::tk_null )
> mico_throw( CosTransactions::SubtransactionsUnavailable() );
> std::cerr << "COUCOU -4-\n";
> }
>
>
> I'm on RH ES 3, mico 2.3.12, gcc 3.2.3
> here the bt from gdb
>
> #0 0x00000018 in ?? ()
> #1 0x0015ad49 in ONED::OTS::resolve_initial<PortableInterceptor::Current,
> PortableInterceptor::ORBInitInfo*> (p_orb=0x8465de8,
> p_object_id=0x161c42 "PICurrent") at
> /users/home/lmarzullo/work/devel/CosTransactions/head/include/util.h:47
> #2 0x0015a98a in ONED::OTS::CurrentImpl::begin (this=0x8467d08) at
> ../../../devel/CosTransactions/head/src/current-impl.cpp:96
> #3 0x0804c24f in main (argc=1, argv=0xbfff8464) at
> ../../../../../devel/CosTransactions/head/test/current/client.cpp:44
>
>
> line 47 of 'util.h' is 'obj = p_orb->resolve_initial_references( p_object_id
> );'
>
> What am I doing wrong ?
>
> Thanks a lot
> +--------------------+
> + Laurent Marzullo
> +
> _______________________________________________
> Mico-devel mailing list
> [email protected]
> http://www.mico.org/mailman/listinfo/mico-devel
>
+--------------------+
+ Laurent Marzullo
+
_______________________________________________
Mico-devel mailing list
[email protected]
http://www.mico.org/mailman/listinfo/mico-devel