[omniORB] Name Service
Boris Khanales
boris@imagine-sw.com
ed, 22 Apr 1998 17:11:03 -0400
Sorry for this mail.
I have to take C++ lesson!
> From owner-omniorb-list@orl.co.uk Wed Apr 22 17:08 EDT 1998
> Date: Wed, 22 Apr 1998 15:11:36 -0400
> From: boris@mailhost.imagine-sw.com (Boris Khanales)
> To: omniorb-list@cam-orl.co.uk
> Subject: [omniORB] Name Service
> Mime-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Md5: 4mXKnSSTRd54MLtrxnXQ9g==
>
> I'm rtying to use Name Service and looks like I can bind
> the object to NS OK, but when I'm trying to _narrow it
> after resolve on the client side I'm geting
> COMMUNICATION_FAILE exception. If i write use object_to_string
> & string_to_object the client works. Any idea?
>
> Thanx.
>
>
>
> This is server side.
>
> START_HERE()
> {
> clService_ = new ImrDiServiceImpl( this );
> clService_->_obj_is_ready( ItsOrbWrapper::getItsORB()->getBOA() );
>
> ImrDiService_var obj = clService_->_this();
> // Register in Name Service
> ItsOrbWrapper::getItsORB()->registerInImagineNS(
>
> const_cast<char*>(ImrProfile::getGlobalProfile()->getImrServerName().data()),
> obj );
> }
>
>
>
> void ItsOrbWrapper::registerInImagineNS( char *path, CORBA::Object_ptr obj )
> {
> CosNaming::Name name;
> CosNaming::NamingContext_var context = buildNSName( name, path );
> try {
> context->bind( name, obj );
> }
> catch( CosNaming::NamingContext::AlreadyBound& ex ) {
> cout << "bind fail" << endl << "Trying to rebind" << endl;
> context->rebind( name, obj );
> cout << "rebind OK" << endl;
> }
> }
>
>
>
> CosNaming::NamingContext_var ItsOrbWrapper::buildNSName( CosNaming::Name
&name,
> char *path )
> {
> CORBA::Object_var initServ =
> orb_->resolve_initial_references("NameService");
> CosNaming::NamingContext_var context =
> CosNaming::NamingContext::_narrow(initServ);
> if (CORBA::is_nil(context))
> throw ItsExceptionBase( "Failed to narrow naming context." );
>
> name.length(1);
> name[0].kind = (const char*) "ImagineDir";
>
> name[0].id = (char *) "ImagineSw";
> RWCTokenizer next( path );
> RWCString nextToken;
> ItsBool found = ItsFalse;
>
> while( !(nextToken = next("/")).isNull() )
> {
> try {
> cout << "resolve : " << name[0].id << endl;
> CORBA::Object_var obj = context->resolve( name );
> CosNaming::NamingContext_var context =
> CosNaming::NamingContext::_narrow( obj );
> if( !CORBA::is_nil(context) )
> {
> cout << "resolve->_narrow : " << name[0].id << " OK" << endl;
> found = ItsTrue;
> }
> else
> {
> cout << "resolve->_narrow : " << name[0].id << " Fail. Trying
> resolve" << endl;
> found = ItsFalse;
> }
> }
> catch( ... ) {
> cout << "resolve : " << name[0].id << " Fail. Trying resolve" <<
> endl;
> found = ItsFalse;
> }
>
> if( !found )
> {
> try {
> context = context->bind_new_context( name );
> cout << "bind_new_context : " << name[0].id << " OK" << endl;
> }
> catch( ... ) {
> cout << "bind_new_context : " << name[0].id << " Exception" <<
> endl;
> throw;
> }
> }
>
> name[0].id = CORBA::string_dup( nextToken );
> }
>
>
> return context;
> }
>