1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#include "Name_Utilities.h"
#include "ace/Auto_Ptr.h"
#include "ace/SString.h"
#include "ace/Tokenizer_T.h"
#include "ciao/Logger/Log_Macros.h"
namespace CIAO
{
namespace Name_Utilities {
bool
write_ior (const ACE_TCHAR *file, const char *ior)
{
FILE* ior_output_file_ = ACE_OS::fopen (file, "w");
if (ior_output_file_)
{
ACE_OS::fprintf (ior_output_file_,
"%s",
ior);
ACE_OS::fclose (ior_output_file_);
return true;
}
return false;
}
bool
bind_object (const char *name,
CORBA::Object_ptr obj,
CosNaming::NamingContext_ptr ctx)
{
CIAO_TRACE ("Name_Utilities::bind_object");
if (CORBA::is_nil (ctx))
{
CIAO_ERROR (1, (LM_WARNING, CLINFO "Name_Utilities::bind_object - "
"Provided naming context is nil, component <%C> will not be registered.",
name));
return false;
}
try
{
CosNaming::Name nm;
Name_Utilities::build_name (name, nm);
if (nm.length () == 0)
{
CIAO_ERROR (1, (LM_WARNING, CLINFO
"Name_Utilities::bind_object - "
"build_name resulted in an invalid name for string <%C>\n",
name));
return false;
}
Name_Utilities::bind_context (nm, ctx);
try
{
ctx->bind (nm, obj);
}
catch (const CosNaming::NamingContext::AlreadyBound &)
{
CIAO_ERROR (1, (LM_WARNING, CLINFO "Name_Utilities::bind_object - "
"Name <%C> already bound, rebinding....\n",
name));
ctx->rebind (nm, obj);
}
}
catch (const CORBA::Exception &ex)
{
CIAO_ERROR (1, (LM_ERROR, CLINFO "Name_Utilities::bind_object - "
"Caught CORBA exception while attempting to bind name <%C>: <%C>\n",
name, ex._info ().c_str ()));
return false;
}
catch (...)
{
CIAO_ERROR (1, (LM_ERROR, CLINFO "Name_Utilities::bind_object - "
"Caught unknown C++ exception while attemptint to bind name <%C>\n",
name));
return false;
}
return true;
}
void
bind_context (CosNaming::Name &nm,
CosNaming::NamingContext_ptr ctx)
{
CIAO_TRACE ("Name_Utilities::bind_context");
if (CORBA::is_nil (ctx))
{
CIAO_ERROR (1, (LM_WARNING, CLINFO
"Name_Utilities::bind_context - "
"Provided naming context is nil, the naming context will not be bound."));
return;
}
CosNaming::Name newname (nm.length ());
for (CORBA::ULong i = 0;
i < (nm.length () - 1); ++i)
{
newname.length (i + 1);
newname[i] = nm[i];
try
{
ctx->bind_new_context (newname);
CIAO_DEBUG (9, (LM_TRACE, CLINFO
"Name_Utilities::bind_context - "
"Bound new context <%C>\n",
newname[i].id.in ()));
}
catch (CosNaming::NamingContext::AlreadyBound &)
{
CIAO_DEBUG (9, (LM_TRACE, CLINFO
"Name_Utilities::bind_context - "
"Context <%C> already bound.\n",
newname[i].id.in ()));
}
}
}
bool
unbind_object (const char *name,
CosNaming::NamingContext_ptr ctx)
{
CIAO_TRACE ("Name_Utilities::unbind_object");
if (CORBA::is_nil (ctx))
{
CIAO_ERROR (1, (LM_WARNING, CLINFO
"Name_Utilities::unbind_object - "
"Provided naming context is nil, instance <%C> will not be unbound\n",
name));
return false;
}
CosNaming::Name nm;
Name_Utilities::build_name (name, nm);
try
{
ctx->unbind (nm);
}
catch (const CORBA::Exception &e)
{
CIAO_ERROR (1, (LM_ERROR, CLINFO
"Name_Utilities::unbind_object - "
"Caught CORBA exception whilst unbinding name <%C>: <%C>\n",
name, e._info ().c_str ()));
return false;
}
return true;
}
void
build_name (const char *name, CosNaming::Name &nm)
{
CIAO_TRACE ("Name_Utilities::build_name");
char* buf = ACE_OS::strdup (name);
ACE_Tokenizer_T<char> parser (buf);
parser.delimiter ('/');
for (char *next = parser.next (); next; next = parser.next ())
{
CORBA::ULong const i = nm.length ();
nm.length (i + 1);
CIAO_DEBUG (9, (LM_TRACE, CLINFO
"Name_Utilities::build_name - "
"Found name component <%C>\n",
next));
nm[i].id = CORBA::string_dup (next);
}
ACE_OS::free (buf);
}
}
}
|