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
|
<!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>ProxyPullSupplier.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> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center>
<hr><h1>ProxyPullSupplier.cc</h1><a href="a00122.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// Package : omniEvents</font>
00002 <font class="comment">// ProxyPullSupplier.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="a00123.html">ProxyPullSupplier.h</a>"</font>
00025 <font class="preprocessor">#include "<a class="code" href="a00093.html">EventChannel.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 <font class="preprocessor">#include "<a class="code" href="a00117.html">PersistNode.h</a>"</font>
00029 <font class="preprocessor">#include <assert.h></font>
00030
00031 <font class="keyword">namespace </font>OmniEvents {
00032
00033 <font class="comment">//</font>
00034 <font class="comment">// ProxyPullSupplierManager</font>
00035 <font class="comment">//</font>
00036
<a name="l00037"></a><a class="code" href="a00066.html#a0">00037</a> PortableServer::Servant ProxyPullSupplierManager::incarnate(
00038 <font class="keyword">const</font> PortableServer::ObjectId& oid,
00039 PortableServer::POA_ptr poa
00040 )
00041 {
00042 <font class="comment">// Evict the oldest proxy servant, if we have reached the maximum number.</font>
00043 <font class="keywordflow">if</font>(<a class="code" href="a00062.html#n0">_servants</a>.size()>=<a class="code" href="a00066.html#o0">_channel</a>.<a class="code" href="a00046.html#a14">maxNumProxies</a>())
00044 {
00045 <a class="code" href="a00065.html">ProxyPullSupplier_i</a>* oldest =NULL;
00046 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> age =0;
00047 <font class="keywordflow">for</font>(set<Proxy*>::iterator i=<a class="code" href="a00062.html#n0">_servants</a>.begin(); i!=<a class="code" href="a00062.html#n0">_servants</a>.end(); ++i)
00048 <font class="keywordflow">if</font>(!oldest || dynamic_cast<ProxyPullSupplier_i*>(*i)-><a class="code" href="a00065.html#a8">timestamp</a>()<age)
00049 {
00050 oldest=dynamic_cast<ProxyPullSupplier_i*>(*i);
00051 age=oldest-><a class="code" href="a00065.html#a8">timestamp</a>();
00052 }
00053 <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"Evicting oldest ProxyPullSupplier to make space for a new one"</font>)
00054 <font class="keywordflow">try</font>{ oldest-><a class="code" href="a00065.html#a1">disconnect_pull_supplier</a>(); }<font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST&){}
00055 }
00056 <font class="comment">// Make a new servant.</font>
00057 <a class="code" href="a00065.html">ProxyPullSupplier_i</a>* result =<font class="keyword">new</font> <a class="code" href="a00065.html">ProxyPullSupplier_i</a>(<a class="code" href="a00062.html#n1">_managedPoa</a>,<a class="code" href="a00066.html#o1">_queue</a>);
00058 <a class="code" href="a00062.html#n0">_servants</a>.insert(result);
00059 <font class="keywordflow">return</font> result;
00060 }
00061
<a name="l00062"></a><a class="code" href="a00066.html#a1">00062</a> ProxyPullSupplierManager::ProxyPullSupplierManager(
00063 <font class="keyword">const</font> <a class="code" href="a00046.html">EventChannel_i</a>& channel,
00064 PortableServer::POA_ptr parentPoa,
00065 <a class="code" href="a00049.html">EventQueue</a>& q
00066 )
00067 : <a class="code" href="a00062.html">ProxyManager</a>(parentPoa,"ProxyPullSupplier"),
00068 _queue(q),
00069 _channel(channel)
00070 {
00071 <font class="comment">// pass</font>
00072 }
00073
<a name="l00074"></a><a class="code" href="a00066.html#a2">00074</a> ProxyPullSupplierManager::~ProxyPullSupplierManager()
00075 {
00076 <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPullSupplierManager()"</font>)
00077 }
00078
00079 CosEventChannelAdmin::ProxyPullSupplier_ptr
<a name="l00080"></a><a class="code" href="a00066.html#a3">00080</a> ProxyPullSupplierManager::createObject()
00081 {
00082 <font class="keywordflow">return</font> createNarrowedReference<CosEventChannelAdmin::ProxyPullSupplier>(
00083 <a class="code" href="a00062.html#n1">_managedPoa</a>.in(),
00084 CosEventChannelAdmin::_tc_ProxyPullSupplier->id()
00085 );
00086 }
00087
<a name="l00088"></a><a class="code" href="a00066.html#a4">00088</a> <font class="keywordtype">void</font> ProxyPullSupplierManager::disconnect()
00089 {
00090 <font class="keywordflow">for</font>(set<Proxy*>::iterator i =<a class="code" href="a00062.html#n0">_servants</a>.begin(); i!=<a class="code" href="a00062.html#n0">_servants</a>.end(); ++i)
00091 {
00092 <a class="code" href="a00065.html">ProxyPullSupplier_i</a>* narrowed =dynamic_cast<ProxyPullSupplier_i*>(*i);
00093 narrowed-><a class="code" href="a00065.html#a1">disconnect_pull_supplier</a>();
00094 }
00095 }
00096
00097
00098 <font class="comment">//</font>
00099 <font class="comment">// ProxyPullSupplier_i</font>
00100 <font class="comment">//</font>
00101
00102 <font class="comment">// CORBA interface methods</font>
00103
<a name="l00104"></a><a class="code" href="a00065.html#a0">00104</a> <font class="keywordtype">void</font> ProxyPullSupplier_i::connect_pull_consumer(
00105 CosEventComm::PullConsumer_ptr pullConsumer
00106 )
00107 {
00108 <font class="keywordflow">if</font>(<a class="code" href="a00065.html#o1">_connected</a> || !CORBA::is_nil(<a class="code" href="a00065.html#o0">_target</a>) || !CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>))
00109 <font class="keywordflow">throw</font> CosEventChannelAdmin::AlreadyConnected();
00110 <a class="code" href="a00065.html#c0">touch</a>();
00111 <a class="code" href="a00065.html#o1">_connected</a>=<font class="keyword">true</font>;
00112 <font class="keywordflow">if</font>(!CORBA::is_nil(pullConsumer))
00113 <a class="code" href="a00065.html#o0">_target</a>=CosEventComm::PullConsumer::_duplicate(pullConsumer);
00114
00115 <a class="code" href="a00065.html#a7">output</a>(<a class="code" href="a00080.html">WriteLock</a>().os);
00116 }
00117
<a name="l00118"></a><a class="code" href="a00065.html#a1">00118</a> <font class="keywordtype">void</font> ProxyPullSupplier_i::disconnect_pull_supplier()
00119 {
00120 <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"ProxyPullSupplier_i::disconnect_pull_supplier()"</font>);
00121 <a class="code" href="a00065.html#c0">touch</a>();
00122 <a class="code" href="a00061.html#b2">eraseKey</a>(<font class="stringliteral">"ConsumerAdmin/ProxyPullSupplier"</font>);
00123 <a class="code" href="a00073.html#b2">deactivateObject</a>();
00124 <font class="keywordflow">if</font>(!<a class="code" href="a00065.html#o1">_connected</a>)
00125 {
00126 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST(
00127 <a class="code" href="a00115.html#a0">IFELSE_OMNIORB4</a>(omni::OBJECT_NOT_EXIST_NoMatch,0),
00128 CORBA::COMPLETED_NO
00129 );
00130 }
00131 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00065.html#o0">_target</a>))
00132 {
00133 CORBA::Request_var req=<a class="code" href="a00065.html#o0">_target</a>->_request(<font class="stringliteral">"disconnect_pull_consumer"</font>);
00134 req->send_deferred();
00135 Orb::inst().deferredRequest(req._retn());
00136 }
00137 <a class="code" href="a00065.html#o0">_target</a>=CosEventComm::PullConsumer::_nil();
00138 }
00139
<a name="l00140"></a><a class="code" href="a00065.html#a2">00140</a> CORBA::Any* ProxyPullSupplier_i::pull()
00141 {
00142 <font class="keywordflow">if</font>(!<a class="code" href="a00065.html#o1">_connected</a>)
00143 <font class="keywordflow">throw</font> CosEventComm::Disconnected();
00144 <a class="code" href="a00065.html#c0">touch</a>();
00145 <font class="keywordflow">if</font>(<a class="code" href="a00050.html#a1">moreEvents</a>())
00146 <font class="keywordflow">return</font> <font class="keyword">new</font> CORBA::Any(*<a class="code" href="a00050.html#a2">nextEvent</a>());
00147 <font class="keywordflow">else</font>
00148 <font class="keywordflow">throw</font> CORBA::TRANSIENT(
00149 <a class="code" href="a00115.html#a0">IFELSE_OMNIORB4</a>(omni::TRANSIENT_CallTimedout,0),
00150 CORBA::COMPLETED_NO
00151 );
00152 }
00153
<a name="l00154"></a><a class="code" href="a00065.html#a3">00154</a> CORBA::Any* ProxyPullSupplier_i::try_pull(CORBA::Boolean& has_event)
00155 {
00156 <font class="keywordflow">if</font>(!<a class="code" href="a00065.html#o1">_connected</a>)
00157 <font class="keywordflow">throw</font> CosEventComm::Disconnected();
00158 <a class="code" href="a00065.html#c0">touch</a>();
00159 <font class="keywordflow">if</font>(<a class="code" href="a00050.html#a1">moreEvents</a>())
00160 {
00161 has_event=1;
00162 <font class="keywordflow">return</font> <font class="keyword">new</font> CORBA::Any(*<a class="code" href="a00050.html#a2">nextEvent</a>());
00163 }
00164 <font class="keywordflow">else</font>
00165 {
00166 has_event=0;
00167 <font class="keywordflow">return</font> <font class="keyword">new</font> CORBA::Any();
00168 }
00169 }
00170
00171 <font class="comment">//</font>
00172
<a name="l00173"></a><a class="code" href="a00065.html#a4">00173</a> ProxyPullSupplier_i::ProxyPullSupplier_i(
00174 PortableServer::POA_ptr poa,
00175 <a class="code" href="a00049.html">EventQueue</a>& q
00176 )
00177 : <a class="code" href="a00061.html">Proxy</a>(poa),
00178 <a class="code" href="a00049.html">EventQueue</a>::Reader(q),
00179 _target(CosEventComm::PullConsumer::_nil()),
00180 _connected(false),
00181 _timestamp(0)
00182 {
00183 <a class="code" href="a00065.html#c0">touch</a>();
00184 }
00185
<a name="l00186"></a><a class="code" href="a00065.html#a5">00186</a> ProxyPullSupplier_i::~ProxyPullSupplier_i()
00187 {
00188 <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPullSupplier_i()"</font>)
00189 }
00190
<a name="l00191"></a><a class="code" href="a00065.html#a6">00191</a> <font class="keywordtype">void</font> ProxyPullSupplier_i::reincarnate(
00192 <font class="keyword">const</font> string& oid,
00193 <font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>& node
00194 )
00195 {
00196 CosEventComm::PullConsumer_var pullConsumer =
00197 string_to_<CosEventComm::PullConsumer>(node.<a class="code" href="a00060.html#a11">attrString</a>(<font class="stringliteral">"IOR"</font>).c_str());
00198 <font class="comment">// Do not activate until we know that we have read a valid target.</font>
00199 <a class="code" href="a00073.html#b1">activateObjectWithId</a>(oid.c_str());
00200 <a class="code" href="a00065.html#a0">connect_pull_consumer</a>(pullConsumer.in());
00201 }
00202
<a name="l00203"></a><a class="code" href="a00065.html#a7">00203</a> <font class="keywordtype">void</font> ProxyPullSupplier_i::output(ostream& os)
00204 {
00205 <a class="code" href="a00061.html#b3">basicOutput</a>(os,<font class="stringliteral">"ConsumerAdmin/ProxyPullSupplier"</font>,<a class="code" href="a00065.html#o0">_target</a>.in());
00206 }
00207
<a name="l00208"></a><a class="code" href="a00065.html#c0">00208</a> <font class="keyword">inline</font> <font class="keywordtype">void</font> ProxyPullSupplier_i::touch()
00209 {
00210 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> nsec; <font class="comment">// dummy</font>
00211 omni_thread::get_time(&<a class="code" href="a00065.html#o2">_timestamp</a>,&nsec);
00212 }
00213
00214 }; <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>
|