Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Concurrency / CC_naming_service.cpp
blobf0b111d5ec71ea65e70bb92ff190e80ee7d95437
2 //=============================================================================
3 /**
4 * @file CC_naming_service.cpp
6 * This class implements the naming services necessary to test the
7 * concurrency service
9 * @author Torben Worm <tworm@cs.wustl.edu>
11 //=============================================================================
14 #include "CC_naming_service.h"
15 #include "ace/OS_NS_string.h"
16 #include "ace/Log_Msg.h"
20 CC_naming_service::CC_naming_service (CORBA::ORB_var orb)
21 : cc_factory_key_ (0),
22 orb_ (0),
23 factory_ (0)
25 this->Init(orb);
27 instance_ = this;
30 CC_naming_service::CC_naming_service(void)
31 : cc_factory_key_ (0),
32 orb_ (0),
33 factory_ (0)
37 void
38 CC_naming_service::Init(CORBA::ORB_var orb)
40 this->orb_ = orb;
42 int success = init_naming_service ();
43 if (success < 0)
44 throw CORBA::INTERNAL ();
47 CC_naming_service::~CC_naming_service (void)
49 // if(instance_!=0)
50 // delete instance_;
51 // @TAO somthing went wrong when these lines were uncommented
54 CC_naming_service *
55 CC_naming_service::Instance(void)
57 if(instance_ == 0)
59 instance_ = new CC_naming_service();
61 return instance_;
64 CORBA::Object_var
65 CC_naming_service::get_obj_from_name (const char *c_name,
66 const char *name)
68 ACE_DEBUG ((LM_DEBUG, "C: %s, N: %s\n", c_name, name));
69 CORBA::Object_var obj;
71 try
73 if (ACE_OS::strlen (c_name) == 0)
75 CosNaming::Name ns_name (1);
76 ns_name.length (1);
77 ns_name[0].id = CORBA::string_dup (name);
78 obj = my_name_client_->resolve (ns_name);
80 else
82 CosNaming::Name ns_name (2);
83 ns_name.length (2);
84 ns_name[0].id = CORBA::string_dup (c_name);
85 ns_name[1].id = CORBA::string_dup (name);
86 obj = my_name_client_->resolve (ns_name);
88 if (CORBA::is_nil (obj.in ()) )
89 ACE_DEBUG((LM_DEBUG,
90 "OBJ was nill (aieee)\n"));
92 catch (const CORBA::Exception& ex)
94 ex._tao_print_exception ("CC_Client::get_obj_from_name (...)");
95 return obj;
98 return obj;
101 void
102 CC_naming_service::bind_name (const char *n,
103 CORBA::Object_ptr obj)
105 ACE_DEBUG ((LM_DEBUG, "CC_Client::bind_name\n"));
109 CosNaming::Name ns_name (1);
110 ns_name.length (1);
111 ns_name[0].id = CORBA::string_dup (n);
112 my_name_client_->bind (ns_name,
113 obj);
115 catch (const CORBA::Exception& ex)
117 ex._tao_print_exception ("CC_Client::bind_name (...)");
121 CosConcurrencyControl::LockSetFactory_var
122 CC_naming_service::get_lock_set_factory (void)
124 return this->factory_;
128 CC_naming_service::init_naming_service (void)
132 // Initialize the naming services
133 if (my_name_client_.init (orb_.in ()) != 0)
134 ACE_ERROR_RETURN ((LM_ERROR,
135 " (%P|%t) Unable to initialize "
136 "the TAO_Naming_Client.\n"),
137 -1);
139 CORBA::Object_var factory_obj = get_obj_from_name ("CosConcurrency",
140 "LockSetFactory");
142 this->factory_ =
143 CosConcurrencyControl::LockSetFactory::_narrow
144 (factory_obj.in ());
146 if (CORBA::is_nil (this->factory_.in ()))
147 ACE_ERROR_RETURN ((LM_ERROR,
148 " could not resolve lock set factory in Naming service\n"),
149 -1);
151 catch (const CORBA::Exception& ex)
153 ex._tao_print_exception ("CC_Client::init_naming_service");
154 return -1;
157 return 0;
160 CC_naming_service* CC_naming_service::instance_ = 0;