Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

CorbaHelpers.cpp

Go to the documentation of this file.
00001 /***************** <Tweek heading BEGIN do not edit this line> ****************
00002  * Tweek
00003  *
00004  * -----------------------------------------------------------------
00005  * File:          $RCSfile: CorbaHelpers.cpp,v $
00006  * Date modified: $Date: 2003/02/26 16:01:00 $
00007  * Version:       $Revision: 1.5 $
00008  * -----------------------------------------------------------------
00009  ***************** <Tweek heading END do not edit this line> *****************/
00010 
00011 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00012  *
00013  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00014  *
00015  * Original Authors:
00016  *   Allen Bierbaum, Christopher Just,
00017  *   Patrick Hartling, Kevin Meinert,
00018  *   Carolina Cruz-Neira, Albert Baker
00019  *
00020  * This library is free software; you can redistribute it and/or
00021  * modify it under the terms of the GNU Library General Public
00022  * License as published by the Free Software Foundation; either
00023  * version 2 of the License, or (at your option) any later version.
00024  *
00025  * This library is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00028  * Library General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU Library General Public
00031  * License along with this library; if not, write to the
00032  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00033  * Boston, MA 02111-1307, USA.
00034  *
00035  *************** <auto-copyright.pl END do not edit this line> ***************/
00036 
00037 #include <tweek/tweekConfig.h>
00038 
00039 #include <string>
00040 #include <vpr/vpr.h>
00041 #include <vpr/System.h>
00042 #include <vpr/Util/Assert.h>
00043 #include <vpr/Util/Debug.h>
00044 
00045 #include <tweek/Util/Debug.h>
00046 #include <tweek/CORBA/CorbaHelpers.h>
00047 
00048 namespace tweek
00049 {
00050 
00051 CosNaming::NamingContext_var getRootNamingContextByInitRef(CORBA::ORB_ptr orb)
00052 {
00053 #ifdef OMNIORB_VER
00054    // If the user does not have the OMNIORB_CONFIG environment variable set,
00055    // there will most likely be problems finding and/or contacting the
00056    // Naming Service.  To that end, print a warning saying as much when the
00057    // variable is not set.
00058    std::string temp;
00059    if ( vpr::System::getenv("OMNIORB_CONFIG", temp).failure() )
00060    {
00061       vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00062          << clrOutBOLD(clrYELLOW, "WARNING: OMNIORB_CONFIG not set!")
00063          << "  Expect problems contacting the Naming Service\n"
00064          << vprDEBUG_FLUSH;
00065    }
00066 #endif
00067 
00068    CORBA::Object_var name_obj;
00069    CosNaming::NamingContext_var root_context;
00070 
00071    vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Requesting Name Service\n"
00072                                               << vprDEBUG_FLUSH;
00073    name_obj     = orb->resolve_initial_references("NameService");
00074    root_context = CosNaming::NamingContext::_narrow(name_obj);
00075 
00076    if ( CORBA::is_nil(root_context) )
00077    {
00078       vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00079          << "Failed to narrow Naming Service root context\n"
00080          << vprDEBUG_FLUSH;
00081    }
00082 
00083    return root_context;
00084 }
00085 
00086 CosNaming::NamingContext_var getRootNamingContextByURI(CORBA::ORB_ptr orb,
00087                                                        const std::string& nameServiceURI)
00088 {
00089    CORBA::Object_var name_obj;
00090    CosNaming::NamingContext_var root_context;
00091 
00092    vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Requesting Name Service\n"
00093                                               << vprDEBUG_FLUSH;
00094    name_obj     = orb->string_to_object(nameServiceURI.c_str());
00095    root_context = CosNaming::NamingContext::_narrow(name_obj);
00096 
00097    if ( CORBA::is_nil(root_context) )
00098    {
00099       vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00100          << "Failed to narrow Naming Service root context\n"
00101          << vprDEBUG_FLUSH;
00102    }
00103 
00104    return root_context;
00105 }
00106 
00107 CosNaming::NamingContext_var bindLocalNamingContext(CosNaming::NamingContext_ptr parentContext,
00108                                                     const std::string& localId)
00109 {
00110    vprASSERT(! CORBA::is_nil(parentContext) && "Root context is invalid");
00111 
00112    std::string kind("context");
00113    CosNaming::Name tweek_context_name;
00114 
00115    tweek_context_name.length(1);
00116    tweek_context_name[0].id   = CORBA::string_dup(localId.c_str());
00117    tweek_context_name[0].kind = CORBA::string_dup(kind.c_str());
00118 
00119    CosNaming::NamingContext_var local_context;
00120 
00121    try
00122    {
00123       local_context = parentContext->bind_new_context(tweek_context_name);
00124    }
00125    catch (CosNaming::NamingContext::AlreadyBound& ex)
00126    {
00127       CORBA::Object_var temp_obj;
00128 
00129       temp_obj      = parentContext->resolve(tweek_context_name);
00130       local_context = CosNaming::NamingContext::_narrow(temp_obj);
00131 
00132       if ( CORBA::is_nil(local_context) )
00133       {
00134          vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00135             << "Failed to narrow Naming Service to local Tweek context\n"
00136             << vprDEBUG_FLUSH;
00137       }
00138    }
00139 
00140    return local_context;
00141 }
00142 
00143 } // End of tweek namespace

Generated on Sun May 2 14:41:03 2004 for Tweek by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002