File: a00196.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 (183 lines) | stat: -rw-r--r-- 13,626 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
<!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>SupplierAdmin.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>SupplierAdmin.cc</h1><a href="a00136.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// SupplierAdmin.h            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="a00137.html">SupplierAdmin.h</a>"</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="a00093.html">EventChannel.h</a>"</font>
00027 <font class="preprocessor">#include "<a class="code" href="a00125.html">ProxyPushConsumer.h</a>"</font>
00028 <font class="preprocessor">#include "<a class="code" href="a00121.html">ProxyPullConsumer.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="a00117.html">PersistNode.h</a>"</font>
00031 
<a name="l00032"></a><a class="code" href="a00136.html#a0">00032</a> <font class="preprocessor">#define MILLION 1000000</font>
<a name="l00033"></a><a class="code" href="a00136.html#a1">00033</a> <font class="preprocessor"></font><font class="preprocessor">#define BILLION 1000000000</font>
00034 <font class="preprocessor"></font>
00035 <font class="keyword">namespace </font>OmniEvents {
00036 
00037 CosEventChannelAdmin::ProxyPushConsumer_ptr
<a name="l00038"></a><a class="code" href="a00076.html#a0">00038</a> SupplierAdmin_i::obtain_push_consumer()
00039 {
00040   <font class="keywordflow">return</font> <a class="code" href="a00076.html#o1">_pushConsumer</a>-&gt;<a class="code" href="a00067.html#a6">createObject</a>();
00041 }
00042 
00043 
00044 CosEventChannelAdmin::ProxyPullConsumer_ptr
<a name="l00045"></a><a class="code" href="a00076.html#a1">00045</a> SupplierAdmin_i::obtain_pull_consumer()
00046 {
00047   <font class="keywordflow">if</font>(!<a class="code" href="a00076.html#o2">_pullConsumer</a>)
00048       <a class="code" href="a00076.html#o2">_pullConsumer</a>=<font class="keyword">new</font> <a class="code" href="a00064.html">ProxyPullConsumerManager</a>(<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00076.html#o3">_queue</a>);
00049   <font class="keywordflow">return</font> <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00064.html#a3">createObject</a>();
00050 }
00051 
00052 
<a name="l00053"></a><a class="code" href="a00076.html#a2">00053</a> SupplierAdmin_i::SupplierAdmin_i(
00054   <font class="keyword">const</font> <a class="code" href="a00046.html">EventChannel_i</a>&amp;   channel,
00055   PortableServer::POA_ptr poa
00056 )
00057 : <a class="code" href="a00073.html">Servant</a>(poa),
00058   _channel(channel),
00059   _pushConsumer(NULL),
00060   _pullConsumer(NULL),
00061   _queue(),
00062   _nextPull(0,0)
00063 {
00064   <font class="comment">// Initialise _nextPull. Only set it if the cycle period is LESS than the</font>
00065   <font class="comment">// pull retry period - otherwise just pull every cycle.</font>
00066   <font class="keywordflow">if</font>(<a class="code" href="a00076.html#o0">_channel</a>.<a class="code" href="a00046.html#a12">pullRetryPeriod_ms</a>() &gt; (<a class="code" href="a00076.html#o0">_channel</a>.<a class="code" href="a00046.html#a15">cyclePeriod_ns</a>()/<a class="code" href="a00136.html#a0">MILLION</a>))
00067   {
00068     omni_thread::get_time(&amp;(<a class="code" href="a00076.html#o4">_nextPull</a>.first),&amp;(<a class="code" href="a00076.html#o4">_nextPull</a>.second));
00069   }
00070 
00071   <font class="comment">// Always create the ProxyPushConsumer_i default servant. This allows</font>
00072   <font class="comment">// lazy clients to connect suppliers without having to go through the</font>
00073   <font class="comment">// proper procedure - they can make up an appropriate ObjectId, call push()</font>
00074   <font class="comment">// and it will just work (TM).</font>
00075   <font class="comment">// Note: A SupplierAdmin_i is always created by the EventChannel to allow this</font>
00076   <font class="comment">// behaviour.</font>
00077   <a class="code" href="a00076.html#o1">_pushConsumer</a>=<font class="keyword">new</font> <a class="code" href="a00067.html">ProxyPushConsumer_i</a>(<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00076.html#o3">_queue</a>,<a class="code" href="a00076.html#o0">_channel</a>.<a class="code" href="a00046.html#a10">consumerAdmin</a>());
00078   
00079   <a class="code" href="a00073.html#b1">activateObjectWithId</a>(<font class="stringliteral">"SupplierAdmin"</font>);
00080   _remove_ref();
00081 }
00082 
00083 
<a name="l00084"></a><a class="code" href="a00076.html#a3">00084</a> SupplierAdmin_i::~SupplierAdmin_i()
00085 {
00086   <font class="keywordflow">if</font>(_pushConsumer)
00087   {
00088     <font class="keyword">delete</font> <a class="code" href="a00076.html#o1">_pushConsumer</a>;
00089     <a class="code" href="a00076.html#o1">_pushConsumer</a>=NULL;
00090   }
00091   <font class="keywordflow">for</font>(list&lt;CORBA::Any*&gt;::iterator i=<a class="code" href="a00076.html#o3">_queue</a>.begin(); i!=<a class="code" href="a00076.html#o3">_queue</a>.end(); ++i)
00092       <font class="keyword">delete</font> *i;
00093   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~SupplierAdmin_i()"</font>)
00094 }
00095 
00096 
<a name="l00097"></a><a class="code" href="a00076.html#a4">00097</a> <font class="keywordtype">void</font> SupplierAdmin_i::collect(list&lt;CORBA::Any*&gt;&amp; events)
00098 {
00099   <font class="keywordflow">if</font>(_pullConsumer)
00100   {
00101     <font class="keywordflow">if</font>(<a class="code" href="a00076.html#o4">_nextPull</a>.first)
00102     {
00103       <font class="comment">// Only trigger the ProxyPullConsumer if `pullRetry' ms have passed.</font>
00104       pair&lt;unsigned long,unsigned long&gt; now;
00105       omni_thread::get_time(&amp;(now.first),&amp;(now.second));
00106       <font class="keywordflow">if</font>(now&gt;=<a class="code" href="a00076.html#o4">_nextPull</a>)
00107       {
00108         <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00064.html#a4">trigger</a>();
00109         CORBA::ULong p =<a class="code" href="a00076.html#o0">_channel</a>.<a class="code" href="a00046.html#a12">pullRetryPeriod_ms</a>();
00110         <font class="keywordflow">do</font>{
00111           <a class="code" href="a00076.html#o4">_nextPull</a>.second += (p%1000)*<a class="code" href="a00136.html#a0">MILLION</a>;                    <font class="comment">// nsec</font>
00112           <a class="code" href="a00076.html#o4">_nextPull</a>.first  +=  p/1000 + <a class="code" href="a00076.html#o4">_nextPull</a>.second/<a class="code" href="a00136.html#a1">BILLION</a>;  <font class="comment">// sec</font>
00113           <a class="code" href="a00076.html#o4">_nextPull</a>.second %= <a class="code" href="a00136.html#a1">BILLION</a>;                             <font class="comment">// nsec</font>
00114         } <font class="keywordflow">while</font>(now&gt;=<a class="code" href="a00076.html#o4">_nextPull</a>);
00115       }
00116     }
00117     <font class="keywordflow">else</font>
00118     {
00119       <font class="comment">// Always trigger the ProxyPullConsumer.</font>
00120       <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00064.html#a4">trigger</a>();
00121     }
00122   }
00123   <a class="code" href="a00076.html#o1">_pushConsumer</a>-&gt;<a class="code" href="a00067.html#a5">trigger</a>();
00124   <font class="comment">// Pick up events from both pull &amp; push consumers.</font>
00125   events=<a class="code" href="a00076.html#o3">_queue</a>;
00126   <a class="code" href="a00076.html#o3">_queue</a>.clear();
00127 }
00128 
00129 
<a name="l00130"></a><a class="code" href="a00076.html#a5">00130</a> <font class="keywordtype">void</font> SupplierAdmin_i::disconnect()
00131 {
00132   <font class="keywordflow">if</font>(_pushConsumer)
00133      <a class="code" href="a00076.html#o1">_pushConsumer</a>-&gt;<a class="code" href="a00067.html#a7">disconnect</a>();
00134   <font class="keywordflow">if</font>(_pullConsumer)
00135      <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00064.html#a5">disconnect</a>();
00136 }
00137 
00138 
<a name="l00139"></a><a class="code" href="a00076.html#a6">00139</a> <font class="keywordtype">void</font> SupplierAdmin_i::reincarnate(<font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>&amp; node)
00140 {
00141   <font class="comment">// Build Push Consumer proxies</font>
00142   <a class="code" href="a00060.html">PersistNode</a>* pushcNode =node.<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ProxyPushConsumer"</font>);
00143   <font class="keywordflow">if</font>(pushcNode &amp;&amp; !pushcNode-&gt;<a class="code" href="a00060.html#m0">_child</a>.empty())
00144   {
00145     assert(<a class="code" href="a00076.html#o1">_pushConsumer</a>!=NULL);
00146     <a class="code" href="a00076.html#o1">_pushConsumer</a>-&gt;<a class="code" href="a00067.html#a8">reincarnate</a>(*pushcNode);
00147   }
00148 
00149   <font class="comment">// Build Pull Consumer proxies</font>
00150   <a class="code" href="a00060.html">PersistNode</a>* pullcNode =node.<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ProxyPullConsumer"</font>);
00151   <font class="keywordflow">if</font>(pullcNode &amp;&amp; !pullcNode-&gt;<a class="code" href="a00060.html#m0">_child</a>.empty())
00152   {
00153     <font class="keywordflow">if</font>(!<a class="code" href="a00076.html#o2">_pullConsumer</a>)
00154         <a class="code" href="a00076.html#o2">_pullConsumer</a>=<font class="keyword">new</font> <a class="code" href="a00064.html">ProxyPullConsumerManager</a>(<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00076.html#o3">_queue</a>);
00155     <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00062.html#a1">reincarnate</a>(*pullcNode);
00156   }
00157 }
00158 
00159 
<a name="l00160"></a><a class="code" href="a00076.html#a7">00160</a> <font class="keywordtype">void</font> SupplierAdmin_i::output(ostream&amp; os)
00161 {
00162   <font class="keywordflow">if</font>(_pushConsumer)
00163      <a class="code" href="a00076.html#o1">_pushConsumer</a>-&gt;<a class="code" href="a00067.html#a9">output</a>(os);
00164   <font class="keywordflow">if</font>(_pullConsumer)
00165      <a class="code" href="a00076.html#o2">_pullConsumer</a>-&gt;<a class="code" href="a00062.html#a2">output</a>(os);
00166 }
00167 
00168 
00169 }; <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>