File: a00178.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 (220 lines) | stat: -rw-r--r-- 13,738 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
<!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>ProxyManager.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>ProxyManager.cc</h1><a href="a00118.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// ProxyManager.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="a00119.html">ProxyManager.h</a>"</font>
00025 <font class="preprocessor">#include "<a class="code" href="a00117.html">PersistNode.h</a>"</font>
00026 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00027 <font class="preprocessor">#include "<a class="code" href="a00113.html">omniEventsLog.h</a>"</font>
00028 
00029 <font class="preprocessor">#include &lt;string&gt;</font>
00030 <font class="preprocessor">#include &lt;map&gt;</font>
00031 <font class="preprocessor">#include &lt;assert.h&gt;</font>
00032 <font class="preprocessor">#include &lt;memory&gt;</font>
00033 
00034 <font class="keyword">namespace </font>OmniEvents {
00035 
00036 <font class="comment">//</font>
00037 <font class="comment">//  ProxyManager</font>
00038 <font class="comment">//</font>
00039 
00040 <font class="keywordtype">void</font>
<a name="l00041"></a><a class="code" href="a00062.html#a0">00041</a> ProxyManager::etherealize(
00042   <font class="keyword">const</font> PortableServer::ObjectId&amp; oid,
00043   PortableServer::POA_ptr         adapter,
00044   PortableServer::Servant         serv,
00045   CORBA::Boolean                  cleanup_in_progress,
00046   CORBA::Boolean                  remaining_activations
00047 )
00048 {
00049   auto_ptr&lt;Proxy&gt; narrowed( dynamic_cast&lt;Proxy*&gt;(serv) );
00050   assert(narrowed.get()!=NULL);
00051   set&lt;Proxy*&gt;::iterator pos =<a class="code" href="a00062.html#n0">_servants</a>.find(narrowed.get());
00052   <font class="keywordflow">if</font>(pos!=<a class="code" href="a00062.html#n0">_servants</a>.end())
00053       <a class="code" href="a00062.html#n0">_servants</a>.erase(pos);
00054   <font class="keywordflow">else</font>
00055       <a class="code" href="a00115.html#a2">DB</a>(1,<font class="stringliteral">"\t\teh? - POA attempted to etherealize unknown servant."</font>);
00056   <font class="comment">// memory freed when narrowed goes out of scope.</font>
00057 }
00058 
00059 
<a name="l00060"></a><a class="code" href="a00062.html#a1">00060</a> <font class="keywordtype">void</font> ProxyManager::reincarnate(<font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>&amp; node)
00061 {
00062   <font class="comment">// Reincarnate all connections from node's children.</font>
00063   <font class="keywordflow">for</font>(map&lt;string,PersistNode*&gt;::const_iterator i=node.<a class="code" href="a00060.html#m0">_child</a>.begin();
00064       i!=node.<a class="code" href="a00060.html#m0">_child</a>.end();
00065       ++i)
00066   {
00067     assert(i-&gt;second!=NULL);
00068     PortableServer::Servant serv =
00069       this-&gt;incarnate(PortableServer::ObjectId(),<a class="code" href="a00062.html#n1">_managedPoa</a>);
00070     <a class="code" href="a00061.html">Proxy</a>* proxy =dynamic_cast&lt;Proxy*&gt;(serv);
00071     assert(proxy!=NULL);
00072     <font class="keywordflow">try</font>
00073     {
00074       proxy-&gt;<a class="code" href="a00061.html#a1">reincarnate</a>(i-&gt;first,*(i-&gt;second));
00075     }
00076     <font class="keywordflow">catch</font>(CORBA::BAD_PARAM&amp; ex)
00077     {
00078       <font class="comment">// This will happen when IOR fails to narrow.</font>
00079       <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"Failed to reincarnate proxy: "</font>&lt;&lt;i-&gt;first.c_str());
00080       <a class="code" href="a00062.html#n0">_servants</a>.erase(proxy);
00081       <font class="keyword">delete</font> proxy;
00082     }
00083   }
00084 }
00085 
00086 
<a name="l00087"></a><a class="code" href="a00062.html#a2">00087</a> <font class="keywordtype">void</font> ProxyManager::output(ostream&amp; os)
00088 {
00089   <font class="keywordflow">for</font>(set&lt;Proxy*&gt;::iterator i =<a class="code" href="a00062.html#n0">_servants</a>.begin(); i!=<a class="code" href="a00062.html#n0">_servants</a>.end(); ++i)
00090   {
00091     (*i)-&gt;<a class="code" href="a00061.html#a2">output</a>(os);
00092   }
00093 }
00094 
00095 
<a name="l00096"></a><a class="code" href="a00062.html#b0">00096</a> ProxyManager::ProxyManager(PortableServer::POA_ptr p, <font class="keyword">const</font> <font class="keywordtype">char</font>* name)
00097 : <a class="code" href="a00073.html">Servant</a>(p),
00098   _servants(),
00099   _managedPoa(PortableServer::POA::_nil())
00100 {
00101   <font class="keyword">using</font> <font class="keyword">namespace </font>PortableServer;
00102   <font class="keywordflow">try</font>
00103   {  
00104     <font class="comment">// POLICIES:</font>
00105     <font class="comment">//  Lifespan          =PERSISTENT             // we can persist</font>
00106     <font class="comment">//  Assignment        =USER_ID                // write our own oid</font>
00107     <font class="comment">//  Uniqueness        =[default] UNIQUE_ID    // one servant per object</font>
00108     <font class="comment">//  ImplicitActivation=NO_IMPLICIT_ACTIVATION // disable auto activation</font>
00109     <font class="comment">//  RequestProcessing =USE_SERVANT_MANAGER</font>
00110     <font class="comment">//  ServantRetention  =[default] RETAIN</font>
00111     <font class="comment">//  Thread            =SINGLE_THREAD_MODEL    // keep it simple</font>
00112 
00113     CORBA::PolicyList policies;
00114     policies.length(5);
00115     policies[0]=p-&gt;create_lifespan_policy(PERSISTENT);
00116     policies[1]=p-&gt;create_id_assignment_policy(USER_ID);
00117     policies[2]=p-&gt;create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION);
00118     policies[3]=p-&gt;create_request_processing_policy(USE_SERVANT_MANAGER);
00119     policies[4]=p-&gt;create_thread_policy(SINGLE_THREAD_MODEL);
00120 
00121     <font class="comment">// Create a POA for this proxy type in this channel.</font>
00122     CORBA::String_var parentName    =p-&gt;the_name();
00123     string            poaName       =string(parentName.in())+<font class="stringliteral">"."</font>+name;
00124     POAManager_var    parentManager =p-&gt;the_POAManager();
00125     <a class="code" href="a00062.html#n1">_managedPoa</a>=p-&gt;create_POA(poaName.c_str(),parentManager.in(),policies);
00126   }
00127   <font class="keywordflow">catch</font>(POA::AdapterAlreadyExists&amp; ex) <font class="comment">// create_POA</font>
00128   {
00129     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"ProxyManager::ProxyManager() - POA::AdapterAlreadyExists"</font>)
00130   }
00131   <font class="keywordflow">catch</font>(POA::InvalidPolicy&amp; ex) <font class="comment">// create_POA</font>
00132   {
00133     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"ProxyManager::ProxyManager() - POA::InvalidPolicy: "</font>&lt;&lt;ex.index)
00134   }
00135   string oidStr =string(name)+<font class="stringliteral">"Manager"</font>;
00136   <a class="code" href="a00073.html#b1">activateObjectWithId</a>(oidStr.c_str());
00137   <a class="code" href="a00062.html#n1">_managedPoa</a>-&gt;set_servant_manager(_this());
00138 }
00139 
00140 
<a name="l00141"></a><a class="code" href="a00062.html#b1">00141</a> ProxyManager::~ProxyManager()
00142 {
00143   <font class="comment">// pass</font>
00144 }
00145 
00146 
00147 <font class="comment">//</font>
00148 <font class="comment">// Proxy</font>
00149 <font class="comment">//</font>
00150 
00151 
<a name="l00152"></a><a class="code" href="a00061.html#a0">00152</a> Proxy::~Proxy()
00153 {
00154   <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>))
00155   {
00156     Orb::inst().deferredRequest(<a class="code" href="a00061.html#n0">_req</a>._retn());
00157     <a class="code" href="a00061.html#n0">_req</a>=CORBA::Request::_nil();
00158   }
00159 }
00160 
<a name="l00161"></a><a class="code" href="a00061.html#b0">00161</a> Proxy::Proxy(PortableServer::POA_ptr poa)
00162 : <a class="code" href="a00073.html">Servant</a>(poa),
00163   _req(CORBA::Request::_nil())
00164 {
00165   <font class="comment">// pass</font>
00166 }
00167 
<a name="l00168"></a><a class="code" href="a00061.html#b1">00168</a> <font class="keywordtype">void</font> Proxy::keyOutput(ostream&amp; os, <font class="keyword">const</font> <font class="keywordtype">char</font>* name)
00169 {
00170   PortableServer::POA_var parentPoa=<a class="code" href="a00073.html#n0">_poa</a>-&gt;the_parent();
00171   CORBA::String_var channelName=parentPoa-&gt;the_name();
00172 
00173   PortableServer::ObjectId_var oid=<a class="code" href="a00073.html#n0">_poa</a>-&gt;servant_to_id(<font class="keyword">this</font>);
00174   CORBA::String_var oidStr =PortableServer::ObjectId_to_string(oid.in());
00175   os&lt;&lt;<font class="stringliteral">"ecf/"</font>&lt;&lt;channelName.in()&lt;&lt;<font class="stringliteral">"/"</font>&lt;&lt;name&lt;&lt;<font class="stringliteral">"/"</font>&lt;&lt;oidStr.in();
00176 }
00177 
<a name="l00178"></a><a class="code" href="a00061.html#b2">00178</a> <font class="keywordtype">void</font> Proxy::eraseKey(<font class="keyword">const</font> <font class="keywordtype">char</font>* name)
00179 {
00180   <font class="comment">// Remove this key from the persistency logfile.</font>
00181   <a class="code" href="a00080.html">WriteLock</a> log;
00182   log.<a class="code" href="a00080.html#m0">os</a>&lt;&lt;<font class="stringliteral">"-"</font>;
00183   <a class="code" href="a00061.html#b1">keyOutput</a>(log.<a class="code" href="a00080.html#m0">os</a>,name);
00184   log.<a class="code" href="a00080.html#m0">os</a>&lt;&lt;<font class="charliteral">'\n'</font>;
00185 }
00186 
<a name="l00187"></a><a class="code" href="a00061.html#b3">00187</a> <font class="keywordtype">void</font> Proxy::basicOutput(
00188   ostream&amp;          os,
00189   <font class="keyword">const</font> <font class="keywordtype">char</font>*       name,
00190   CORBA::Object_ptr target,
00191   <font class="keyword">const</font> <font class="keywordtype">char</font>*       extraAttributes
00192 )
00193 {
00194   <a class="code" href="a00061.html#b1">keyOutput</a>(os,name);
00195   <font class="keywordflow">if</font>(!CORBA::is_nil(target))
00196   {
00197     CORBA::String_var iorstr =Orb::inst()._orb-&gt;object_to_string(target);
00198     os&lt;&lt;<font class="stringliteral">" IOR="</font>&lt;&lt;iorstr.in();
00199     <font class="keywordflow">if</font>(extraAttributes)
00200         os&lt;&lt;extraAttributes;
00201   }
00202   os&lt;&lt;<font class="stringliteral">" ;;\n"</font>;
00203 }
00204 
00205 
00206 }; <font class="comment">// end namespace OmniEvents</font>
</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>