File: a00194.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 (207 lines) | stat: -rw-r--r-- 13,374 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
<!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>Servant.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>Servant.cc</h1><a href="a00134.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// Servant.cc                 Created   : 2003/12/04</font>
00003 <font class="comment">//                            Author    : Alex Tingle</font>
00004 <font class="comment">//</font>
00005 <font class="comment">//    Copyright (C) 2003 Alex Tingle.</font>
00006 <font class="comment">//</font>
00007 <font class="comment">//    This file is part of the omniEvents application.</font>
00008 <font class="comment">//</font>
00009 <font class="comment">//    omniEvents is free software; you can redistribute it and/or</font>
00010 <font class="comment">//    modify it under the terms of the GNU Lesser General Public</font>
00011 <font class="comment">//    License as published by the Free Software Foundation; either</font>
00012 <font class="comment">//    version 2.1 of the License, or (at your option) any later version.</font>
00013 <font class="comment">//</font>
00014 <font class="comment">//    omniEvents is distributed in the hope that it will be useful,</font>
00015 <font class="comment">//    but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment">//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00017 <font class="comment">//    Lesser General Public License for more details.</font>
00018 <font class="comment">//</font>
00019 <font class="comment">//    You should have received a copy of the GNU Lesser General Public</font>
00020 <font class="comment">//    License along with this library; if not, write to the Free Software</font>
00021 <font class="comment">//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00022 <font class="comment">//</font>
00023 
00024 <font class="preprocessor">#include "<a class="code" href="a00135.html">Servant.h</a>"</font>
00025 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00026 
00027 <font class="preprocessor">#ifdef HAVE_SYS_TYPES_H</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;sys/types.h&gt;</font> <font class="comment">// getpid</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 <font class="preprocessor">#ifdef HAVE_UNISTD_H</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font>    <font class="comment">// getpid</font>
00033 <font class="preprocessor">#elif defined(HAVE_PROCESS_H)</font>
00034 <font class="preprocessor"></font><font class="preprocessor"># include &lt;process.h&gt;</font>
00035 <font class="preprocessor">#endif</font>
00036 <font class="preprocessor"></font>
00037 <font class="preprocessor">#include &lt;stdio.h&gt;</font>     <font class="comment">// sprintf</font>
00038 <font class="preprocessor">#include &lt;assert.h&gt;</font>
00039 
00040 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00041 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream&gt;</font>
00042 <font class="preprocessor">#else</font>
00043 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream.h&gt;</font>
00044 <font class="preprocessor">#endif</font>
00045 <font class="preprocessor"></font>
00046 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00047 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00048 <font class="preprocessor">#endif</font>
00049 <font class="preprocessor"></font>
00050 <font class="keyword">namespace </font>OmniEvents {
00051 
<a name="l00052"></a><a class="code" href="a00138.html#a9">00052</a> CORBA::Object_ptr <a class="code" href="a00138.html#a9">createReference</a>(
00053   PortableServer::POA_ptr poa,          <font class="comment">// POA to own new object</font>
00054   <font class="keyword">const</font> <font class="keywordtype">char</font>*             repositoryId  <font class="comment">// e.g. _tc_ProxyPushSupplier-&gt;id()</font>
00055 )
00056 {
00057   CORBA::String_var oidStr =<a class="code" href="a00138.html#a10">newUniqueId</a>();
00058 
00059   PortableServer::ObjectId_var oid =
00060     PortableServer::string_to_ObjectId(oidStr.in());
00061 
00062   CORBA::Object_var obj =
00063     poa-&gt;create_reference_with_id(oid.in(),repositoryId);
00064 
00065   assert(!CORBA::is_nil(obj));
00066   <font class="keywordflow">return</font> obj._retn();
00067 }
00068 
<a name="l00069"></a><a class="code" href="a00138.html#a10">00069</a> <font class="keywordtype">char</font>* <a class="code" href="a00138.html#a10">newUniqueId</a>()
00070 {
00071   <font class="keyword">static</font> <font class="keywordtype">long</font>  count=0;
00072   <font class="keyword">static</font> omni_mutex  mutex;
00073   <font class="keywordtype">int</font>  mypid =getpid(); <font class="comment">// MS VC++6 doesn't have type pid_t!</font>
00074   <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font>  sec,nsec;
00075   omni_thread::get_time(&amp;sec,&amp;nsec); <font class="comment">// More portable than just time().</font>
00076   <font class="keywordtype">char</font> buf[128];
00077   {
00078     omni_mutex_lock l(mutex);
00079     sprintf(buf,<font class="stringliteral">"%lx.%d.%lx"</font>,++count,mypid,sec);
00080   }
00081   <font class="keywordflow">return</font> CORBA::string_dup(buf);
00082 }
00083 
00084 
00085 <font class="comment">//</font>
00086 <font class="comment">//  Servant</font>
00087 <font class="comment">//</font>
00088 
<a name="l00089"></a><a class="code" href="a00073.html#b0">00089</a> Servant::Servant(PortableServer::POA_ptr poa)
00090 : _poa(PortableServer::POA::_duplicate(poa))
00091 {
00092   <font class="comment">// pass</font>
00093 }
00094 
00095 
<a name="l00096"></a><a class="code" href="a00073.html#a1">00096</a> Servant::~Servant()
00097 {
00098   <font class="comment">// pass</font>
00099 }
00100 
00101 
<a name="l00102"></a><a class="code" href="a00073.html#a0">00102</a> PortableServer::POA_ptr Servant::_default_POA()
00103 {
00104   <font class="keywordflow">return</font> PortableServer::POA::_duplicate(<a class="code" href="a00073.html#n0">_poa</a>.in());
00105 }
00106 
00107 
<a name="l00108"></a><a class="code" href="a00073.html#b1">00108</a> <font class="keywordtype">void</font> Servant::activateObjectWithId(<font class="keyword">const</font> <font class="keywordtype">char</font>* oidStr)
00109 {
00110   <font class="keyword">using</font> <font class="keyword">namespace </font>PortableServer;
00111   CORBA::String_var poaName =<a class="code" href="a00073.html#n0">_poa</a>-&gt;the_name();
00112   <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"Activating object "</font>&lt;&lt;poaName.in()&lt;&lt;<font class="stringliteral">"/"</font>&lt;&lt;oidStr);
00113   <font class="keywordflow">try</font>
00114   {
00115     ObjectId_var oid =string_to_ObjectId(oidStr);
00116     <a class="code" href="a00073.html#n0">_poa</a>-&gt;activate_object_with_id(oid.in(),<font class="keyword">this</font>);
00117   }
00118   <font class="keywordflow">catch</font>(CORBA::BAD_PARAM&amp; ex)
00119   {
00120     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't activate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": "</font>
00121       <font class="stringliteral">"BAD_PARAM"</font> <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">" ("</font>&lt;&lt;<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)&lt;&lt;<font class="stringliteral">")"</font>) )
00122     <font class="keywordflow">throw</font>;
00123   }
00124   <font class="keywordflow">catch</font>(POA::ServantAlreadyActive&amp; ex)
00125   {
00126     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't activate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": Servant is already active."</font>)
00127     <font class="keywordflow">throw</font>;
00128   }
00129   <font class="keywordflow">catch</font>(POA::ObjectAlreadyActive&amp; ex)
00130   {
00131     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't activate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": Object is already active."</font>)
00132     <font class="keywordflow">throw</font>;
00133   }
00134   <font class="keywordflow">catch</font>(POA::WrongPolicy&amp; ex)
00135   {
00136     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't activate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": POA '"</font>&lt;&lt;poaName.in()
00137         &lt;&lt;<font class="stringliteral">"' has wrong policy for activate_object_with_id()."</font>)
00138     exit(1); <font class="comment">// Programming error - so quit.</font>
00139   }
00140 }
00141 
00142 
<a name="l00143"></a><a class="code" href="a00073.html#b2">00143</a> <font class="keywordtype">void</font> Servant::deactivateObject()
00144 {
00145   <font class="keyword">using</font> <font class="keyword">namespace </font>PortableServer;
00146   CORBA::String_var poaName =<a class="code" href="a00073.html#n0">_poa</a>-&gt;the_name();
00147 
00148   ObjectId_var oid;
00149   <font class="keywordflow">try</font>
00150   {
00151     oid=<a class="code" href="a00073.html#n0">_poa</a>-&gt;servant_to_id(<font class="keyword">this</font>);
00152   }
00153   <font class="keywordflow">catch</font>(POA::ServantNotActive&amp; ex)
00154   {
00155     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't deactivate servant: POA '"</font>&lt;&lt;poaName.in()
00156         &lt;&lt;<font class="stringliteral">"' says it is not active."</font>)
00157   }
00158   <font class="keywordflow">catch</font>(POA::WrongPolicy&amp; ex)
00159   {
00160     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't deactivate servant: POA '"</font>&lt;&lt;poaName.in()
00161         &lt;&lt;<font class="stringliteral">"' has wrong policy for servant_to_id()."</font>)
00162     exit(1); <font class="comment">// Programming error - so quit.</font>
00163   }
00164 
00165   CORBA::String_var oidStr;
00166   <font class="keywordflow">try</font>
00167   {
00168     oidStr=ObjectId_to_string(oid.in());
00169   }
00170   <font class="keywordflow">catch</font>(CORBA::BAD_PARAM&amp; ex)
00171   {
00172     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't deactivate servant. ObjectId looks bad: "</font>
00173       <font class="stringliteral">"BAD_PARAM"</font> <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">" ("</font>&lt;&lt;<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)&lt;&lt;<font class="stringliteral">")"</font>) )
00174   }
00175 
00176   <font class="keywordflow">try</font>
00177   {
00178     <a class="code" href="a00115.html#a2">DB</a>(7,<font class="stringliteral">"Deactivating object "</font>&lt;&lt;poaName&lt;&lt;<font class="stringliteral">"/"</font>&lt;&lt;oidStr.in());
00179     <a class="code" href="a00073.html#n0">_poa</a>-&gt;deactivate_object(oid.in());
00180   }
00181   <font class="keywordflow">catch</font>(POA::ObjectNotActive&amp; ex)
00182   {
00183     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't deactivate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": Object is not active."</font>)
00184   }
00185   <font class="keywordflow">catch</font>(POA::WrongPolicy&amp; ex)
00186   {
00187     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Can't deactivate "</font>&lt;&lt;oidStr&lt;&lt;<font class="stringliteral">": POA '"</font>&lt;&lt;poaName.in()
00188         &lt;&lt;<font class="stringliteral">"' has wrong policy for deactivate_object()."</font>)
00189     exit(1); <font class="comment">// Programming error - so quit.</font>
00190   }
00191 }
00192 
00193 }; <font class="comment">// end namespace OmniEvents</font>
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:21 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>