File: a00168.html

package info (click to toggle)
omnievents 2.6.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,228 kB
  • ctags: 2,538
  • sloc: cpp: 7,346; sh: 2,568; python: 2,171; xml: 2,057; java: 1,407; makefile: 304; ansic: 9
file content (233 lines) | stat: -rw-r--r-- 14,132 bytes parent folder | download
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>naming.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>naming.cc</h1><a href="a00108.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// -*- Mode: C++; -*-</font>
00002 <font class="comment">//                            Package   : omniEvents</font>
00003 <font class="comment">// naming.cc                  Created   : 1/10/99</font>
00004 <font class="comment">//                            Author    : Paul Nader (pwn)</font>
00005 <font class="comment">//</font>
00006 <font class="comment">//    Copyright (C) 1998 Paul Nader.</font>
00007 <font class="comment">//</font>
00008 <font class="comment">//    This file is part of the omniEvents application.</font>
00009 <font class="comment">//</font>
00010 <font class="comment">//    omniEvents is free software; you can redistribute it and/or</font>
00011 <font class="comment">//    modify it under the terms of the GNU Lesser General Public</font>
00012 <font class="comment">//    License as published by the Free Software Foundation; either</font>
00013 <font class="comment">//    version 2.1 of the License, or (at your option) any later version.</font>
00014 <font class="comment">//</font>
00015 <font class="comment">//    omniEvents is distributed in the hope that it will be useful,</font>
00016 <font class="comment">//    but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment">//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00018 <font class="comment">//    Lesser General Public License for more details.</font>
00019 <font class="comment">//</font>
00020 <font class="comment">//    You should have received a copy of the GNU Lesser General Public</font>
00021 <font class="comment">//    License along with this library; if not, write to the Free Software</font>
00022 <font class="comment">//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00023 <font class="comment">//</font>
00024 <font class="comment">// Description:</font>
00025 <font class="comment">//</font>
00026 <font class="comment">//    naming Service Utility functions.</font>
00027 <font class="comment">//</font>
00028 
00029 <font class="comment">/*</font>
00030 <font class="comment">  $Log: naming.cc,v $</font>
00031 <font class="comment">  Revision 1.8  2004/10/08 14:27:59  alextingle</font>
00032 <font class="comment">  Changed local variable initialisation style back to using '=' in order to please MS VC++.</font>
00033 <font class="comment"></font>
00034 <font class="comment">  Revision 1.7  2004/09/25 23:12:28  alextingle</font>
00035 <font class="comment">  New method: Orb::reportObjectFailure() - flags unexpected failures at a higher</font>
00036 <font class="comment">  priority than normal non-fatal exceptions.</font>
00037 <font class="comment"></font>
00038 <font class="comment">  New macro: NP_MINORSTRING() - a safe interface to</font>
00039 <font class="comment">  CORBA::SystemException::NP_minorString() that returns "??" when there is no</font>
00040 <font class="comment">  mapping for the exception's minor code.</font>
00041 <font class="comment"></font>
00042 <font class="comment">  Revision 1.6  2004/08/04 08:13:44  alextingle</font>
00043 <font class="comment">  Unix daemon &amp; Windows service now both working. Accessed through interface class Daemon (in daemon.h).</font>
00044 <font class="comment"></font>
00045 <font class="comment">  Revision 1.5  2004/07/26 21:17:49  alextingle</font>
00046 <font class="comment">  Added missing #include &lt;string&gt;</font>
00047 <font class="comment"></font>
00048 <font class="comment">  Revision 1.4  2004/07/26 16:22:25  alextingle</font>
00049 <font class="comment">  New method: str2name() parses a stringified naming service name info a CosNaming::Name.</font>
00050 <font class="comment"></font>
00051 <font class="comment">  Revision 1.3  2004/07/02 15:20:39  alextingle</font>
00052 <font class="comment">  Added daemonization, syslog &amp; pidfile support on Unix.</font>
00053 <font class="comment">  Corrected trace levels for consistency with omniORB.</font>
00054 <font class="comment"></font>
00055 <font class="comment">  Revision 1.2  2004/04/21 10:01:42  alextingle</font>
00056 <font class="comment">  Removed unused code. Now silently fails if the Orb has no naming service ref.</font>
00057 <font class="comment"></font>
00058 <font class="comment">  Revision 1.1  2003/12/21 16:19:49  alextingle</font>
00059 <font class="comment">  Moved into 'src' directory as part of the change to POA implementation.</font>
00060 <font class="comment"></font>
00061 <font class="comment">  Revision 1.3  2003/12/01 09:03:13  alextingle</font>
00062 <font class="comment">  Now reports more specific exceptions (only with omniORB4).</font>
00063 <font class="comment"></font>
00064 <font class="comment">  Revision 1.2  2003/11/03 22:45:31  alextingle</font>
00065 <font class="comment">  Removed all platform specific switches. Now uses autoconf, config.h.</font>
00066 <font class="comment"></font>
00067 <font class="comment">  Revision 1.1.1.1  2002/09/25 19:00:35  shamus13</font>
00068 <font class="comment">  Import of OmniEvents source tree from release 2.1.1</font>
00069 <font class="comment"></font>
00070 <font class="comment">  Revision 1.3  2000/09/26 08:44:58  naderp</font>
00071 <font class="comment">  Added stdlib.h include for exit function.</font>
00072 <font class="comment"></font>
00073 <font class="comment">  Revision 1.2  2000/09/04 03:45:52  naderp</font>
00074 <font class="comment">  Changed headers.</font>
00075 <font class="comment"></font>
00076 <font class="comment">  Revision 1.1  1999/11/01 17:00:16  naderp</font>
00077 <font class="comment">  Initial revision</font>
00078 <font class="comment"></font>
00079 <font class="comment">*/</font>
00080 
00081 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00082 
00083 <font class="preprocessor">#include &lt;string&gt;</font>
00084 
00085 <font class="preprocessor">#ifdef HAVE_IOMANIP</font>
00086 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iomanip&gt;</font>
00087 <font class="preprocessor">#else</font>
00088 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iomanip.h&gt;</font>
00089 <font class="preprocessor">#endif</font>
00090 <font class="preprocessor"></font>
00091 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00092 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;stdlib.h&gt;</font> <font class="comment">// for exit</font>
00093 <font class="preprocessor">#endif</font>
00094 <font class="preprocessor"></font>
<a name="l00095"></a><a class="code" href="a00108.html#a0">00095</a> ostream&amp; <a class="code" href="a00108.html#a0">operator&lt;&lt;</a>(ostream&amp; os, <font class="keyword">const</font> CosNaming::Name &amp;n)
00096 {
00097   <font class="keywordflow">for</font>(CORBA::ULong i=0; i&lt;n.length(); i++)
00098   {
00099     os&lt;&lt;<font class="stringliteral">"/"</font>&lt;&lt;n[i].id.in();
00100     <font class="keyword">const</font> <font class="keywordtype">char</font>* kind =n[i].kind.in();
00101     <font class="keywordflow">if</font>(kind &amp;&amp; kind[0])
00102         os&lt;&lt;<font class="stringliteral">"."</font>&lt;&lt;kind;
00103   }
00104   <font class="keywordflow">return</font> os;
00105 }
00106 
00107 
<a name="l00108"></a><a class="code" href="a00108.html#a1">00108</a> CosNaming::Name <a class="code" href="a00108.html#a1">str2name</a>(<font class="keyword">const</font> <font class="keywordtype">char</font>* namestr)
00109 {
00110   CosNaming::Name name;
00111   CORBA::ULong nameLen=0;
00112   name.length(nameLen);
00113 
00114   string n =namestr;
00115   string::size_type pos=0;
00116   <font class="keywordtype">char</font> last=<font class="charliteral">'/'</font>;
00117   <font class="keywordflow">while</font>(true)
00118   {
00119     pos=n.find_first_not_of(<font class="stringliteral">"/."</font>,pos);
00120     <font class="keywordflow">if</font>(pos==string::npos) <font class="keywordflow">break</font>;
00121     string::size_type sep=n.find_first_of(<font class="stringliteral">"/."</font>,pos);
00122     string piece =n.substr(pos,sep-pos);
00123     <font class="keywordflow">if</font>(last==<font class="charliteral">'/'</font>)
00124     {
00125       name.length(++nameLen);
00126       name[nameLen-1].id=CORBA::string_dup(piece.c_str());
00127     }
00128     <font class="keywordflow">else</font>
00129     {
00130       name[nameLen-1].kind=CORBA::string_dup(piece.c_str());
00131     }
00132     pos=sep;
00133     last=n[sep];
00134   }
00135   <font class="keywordflow">return</font> name;
00136 }
00137 
00138 
<a name="l00139"></a><a class="code" href="a00108.html#a2">00139</a> <font class="keywordtype">int</font> <a class="code" href="a00108.html#a2">bindName2Object</a>(
00140   CosNaming::NamingContext_ptr namingContext,
00141   <font class="keyword">const</font> CosNaming::Name&amp; name,
00142   CORBA::Object_ptr obj
00143 )
00144 {
00145   <font class="comment">// If there is no naming service, then ignore this call.</font>
00146   <font class="keywordflow">if</font>(CORBA::is_nil(namingContext))
00147       <font class="keywordflow">return</font> 1;
00148 
00149   <font class="keywordflow">try</font>
00150   {
00151 
00152       CosNaming::Name n;
00153       n.length(1);
00154       <font class="comment">// Drill down through contexts.</font>
00155       <font class="keywordflow">for</font>(CORBA::ULong i=0; i&lt;(name.length()-1); ++i)
00156       {
00157         n[0]=name[i];
00158         <font class="keywordflow">try</font>
00159         {
00160           namingContext=namingContext-&gt;bind_new_context(n);
00161         }
00162         <font class="keywordflow">catch</font>(CosNaming::NamingContext::AlreadyBound&amp;)
00163         {
00164           CORBA::Object_var obj2 =namingContext-&gt;resolve(n);
00165           namingContext=CosNaming::NamingContext::_narrow(obj2);
00166         }
00167         <font class="comment">// One of the context names is already bound to an object. Bail out!</font>
00168         <font class="keywordflow">if</font>(CORBA::is_nil(namingContext))
00169             <font class="keywordflow">return</font> 2;
00170       }
00171       <font class="comment">// Bind the object</font>
00172       n[0]=name[name.length()-1];
00173       <font class="keywordflow">try</font>
00174       {
00175         namingContext-&gt;bind(n,obj);
00176       }
00177       <font class="keywordflow">catch</font>(CosNaming::NamingContext::AlreadyBound&amp; ex)
00178       {
00179         <font class="comment">// overwrite previously bound object</font>
00180         namingContext-&gt;rebind(n,obj);
00181       }
00182       <font class="keywordflow">return</font> 0;
00183 
00184   }
00185   <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE&amp; ex)
00186   {
00187      cerr &lt;&lt; <font class="stringliteral">"Caught system exception COMM_FAILURE, unable to contact the "</font>
00188           &lt;&lt; <font class="stringliteral">"naming service."</font> &lt;&lt; endl;
00189   }
00190   <font class="keywordflow">catch</font> (omniORB::fatalException&amp; ex)
00191   {
00192      cerr &lt;&lt; <font class="stringliteral">"Caught omniORB fatal exception binding "</font> &lt;&lt; name &lt;&lt; endl;
00193      <font class="keywordflow">throw</font>;
00194   }
00195   <font class="keywordflow">catch</font> (CORBA::SystemException&amp; ex)
00196   {
00197      <font class="keyword">const</font> <font class="keywordtype">char</font>* exName  =NULL;
00198      <font class="keyword">const</font> <font class="keywordtype">char</font>* exMinor =NULL;
00199 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00200 <font class="preprocessor"></font>     exName =ex.NP_minorString();
00201      exMinor=ex.NP_minorString();
00202 <font class="preprocessor">#endif</font>
00203 <font class="preprocessor"></font>     cerr&lt;&lt;<font class="stringliteral">"System exception binding "</font>&lt;&lt;name;
00204      <font class="keywordflow">if</font>(exName)
00205        cerr&lt;&lt;<font class="stringliteral">": "</font>&lt;&lt;exName;
00206      <font class="keywordflow">if</font>(exMinor)
00207        cerr&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;exMinor&lt;&lt;<font class="stringliteral">")"</font>;
00208      cerr&lt;&lt;endl;
00209   }
00210   <font class="keywordflow">catch</font> (CORBA::Exception&amp; ex)
00211   {
00212      cerr&lt;&lt;<font class="stringliteral">"CORBA exception binding "</font>&lt;&lt;name
00213 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00214 <font class="preprocessor"></font>         &lt;&lt;<font class="stringliteral">": "</font>&lt;&lt;ex._name()
00215 <font class="preprocessor">#endif</font>
00216 <font class="preprocessor"></font>         &lt;&lt; endl;
00217   }
00218   ::exit(1);
00219 }
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:20 2004 for OmniEvents by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>