00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00055
00056
00057
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 }