File: a00143.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 (172 lines) | stat: -rw-r--r-- 12,714 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
<!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>ConsumerAdmin.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>ConsumerAdmin.cc</h1><a href="a00083.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// ConsumerAdmin.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="a00084.html">ConsumerAdmin.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="a00127.html">ProxyPushSupplier.h</a>"</font>
00028 <font class="preprocessor">#include "<a class="code" href="a00123.html">ProxyPullSupplier.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 <font class="preprocessor">#include "<a class="code" href="a00101.html">Filter.h</a>"</font>
00032 
00033 <font class="keyword">namespace </font>OmniEvents {
00034 
00035 
00036 CosEventChannelAdmin::ProxyPushSupplier_ptr
<a name="l00037"></a><a class="code" href="a00043.html#a0">00037</a> ConsumerAdmin_i::obtain_push_supplier()
00038 {
00039   <font class="keywordflow">if</font>(!<a class="code" href="a00043.html#o2">_pushSupplier</a>)
00040   {
00041     <a class="code" href="a00043.html#o2">_pushSupplier</a>=<font class="keyword">new</font> <a class="code" href="a00070.html">ProxyPushSupplierManager</a>(<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00043.html#o1">_queue</a>);
00042     <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#a7">_add_ref</a>();
00043   }
00044   <font class="keywordflow">return</font> <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#a4">createObject</a>();
00045 }
00046 
00047 
00048 CosEventChannelAdmin::ProxyPullSupplier_ptr
<a name="l00049"></a><a class="code" href="a00043.html#a1">00049</a> ConsumerAdmin_i::obtain_pull_supplier()
00050 {
00051   <font class="keywordflow">if</font>(!<a class="code" href="a00043.html#o3">_pullSupplier</a>)
00052       <a class="code" href="a00043.html#o3">_pullSupplier</a>=<font class="keyword">new</font> <a class="code" href="a00066.html">ProxyPullSupplierManager</a>(<a class="code" href="a00043.html#o0">_channel</a>,<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00043.html#o1">_queue</a>);
00053   <font class="keywordflow">return</font> <a class="code" href="a00043.html#o3">_pullSupplier</a>-&gt;<a class="code" href="a00066.html#a3">createObject</a>();
00054 }
00055 
00056 
<a name="l00057"></a><a class="code" href="a00043.html#a2">00057</a> ConsumerAdmin_i::ConsumerAdmin_i(
00058   <font class="keyword">const</font> <a class="code" href="a00046.html">EventChannel_i</a>&amp;   channel,
00059   PortableServer::POA_ptr poa
00060 )
00061 : <a class="code" href="a00073.html">Servant</a>(poa),
00062   _channel(channel),
00063   _queue(channel.maxQueueLength()),
00064   _pushSupplier(NULL),
00065   _pullSupplier(NULL)
00066 {
00067   <font class="keywordflow">if</font>(<a class="code" href="a00043.html#o0">_channel</a>.<a class="code" href="a00046.html#a11">properties</a>().<a class="code" href="a00060.html#a10">hasAttr</a>(<font class="stringliteral">"FilterId"</font>))
00068   {
00069     string rid =<a class="code" href="a00043.html#o0">_channel</a>.<a class="code" href="a00046.html#a11">properties</a>().<a class="code" href="a00060.html#a11">attrString</a>(<font class="stringliteral">"FilterId"</font>);
00070     <a class="code" href="a00043.html#o1">_queue</a>.<a class="code" href="a00049.html#a2">setFilter</a>(<font class="keyword">new</font> <a class="code" href="a00052.html">FilterByRepositoryId</a>(rid.c_str()));
00071   }
00072   <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="a00043.html#o0">_channel</a>.<a class="code" href="a00046.html#a11">properties</a>().<a class="code" href="a00060.html#a10">hasAttr</a>(<font class="stringliteral">"FilterKind"</font>))
00073   {
00074     CORBA::TCKind kind =
00075       CORBA::TCKind(<a class="code" href="a00043.html#o0">_channel</a>.<a class="code" href="a00046.html#a11">properties</a>().<a class="code" href="a00060.html#a12">attrLong</a>(<font class="stringliteral">"FilterKind"</font>));
00076     <a class="code" href="a00043.html#o1">_queue</a>.<a class="code" href="a00049.html#a2">setFilter</a>(<font class="keyword">new</font> <a class="code" href="a00053.html">FilterByTCKind</a>(kind));
00077   }
00078 
00079   <a class="code" href="a00073.html#b1">activateObjectWithId</a>(<font class="stringliteral">"ConsumerAdmin"</font>);
00080   _remove_ref();
00081 }
00082 
00083 
<a name="l00084"></a><a class="code" href="a00043.html#a3">00084</a> ConsumerAdmin_i::~ConsumerAdmin_i()
00085 {
00086   <font class="keywordflow">if</font>(_pushSupplier)
00087   {
00088     <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#a8">_remove_ref</a>(); <font class="comment">// terminates thread.</font>
00089     <a class="code" href="a00043.html#o2">_pushSupplier</a>=NULL;
00090   }
00091   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ConsumerAdmin_i()"</font>)
00092 }
00093 
00094 
<a name="l00095"></a><a class="code" href="a00043.html#a4">00095</a> <font class="keywordtype">void</font> ConsumerAdmin_i::send(CORBA::Any* event)
00096 {
00097   <a class="code" href="a00071.html">ProxyPushSupplierManager::PauseThenWake</a> p(<a class="code" href="a00043.html#o2">_pushSupplier</a>);
00098   <a class="code" href="a00043.html#o1">_queue</a>.<a class="code" href="a00049.html#a3">append</a>(event);
00099 }
00100 
00101 
<a name="l00102"></a><a class="code" href="a00043.html#a5">00102</a> <font class="keywordtype">void</font> ConsumerAdmin_i::send(list&lt;CORBA::Any*&gt;&amp; events)
00103 {
00104   <font class="keywordflow">if</font>(!events.empty())
00105   {
00106     <a class="code" href="a00071.html">ProxyPushSupplierManager::PauseThenWake</a> p(<a class="code" href="a00043.html#o2">_pushSupplier</a>);
00107     <font class="keywordflow">for</font>(list&lt;CORBA::Any*&gt;::iterator i=events.begin(); i!=events.end(); ++i)
00108         <a class="code" href="a00043.html#o1">_queue</a>.<a class="code" href="a00049.html#a3">append</a>( *i );
00109     events.clear();
00110   }
00111 }
00112 
00113 
<a name="l00114"></a><a class="code" href="a00043.html#a6">00114</a> <font class="keywordtype">void</font> ConsumerAdmin_i::disconnect()
00115 {
00116   <font class="keywordflow">if</font>(_pushSupplier)
00117      <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#a5">disconnect</a>();
00118   <font class="keywordflow">if</font>(_pullSupplier)
00119      <a class="code" href="a00043.html#o3">_pullSupplier</a>-&gt;<a class="code" href="a00066.html#a4">disconnect</a>();
00120 }
00121 
00122 
<a name="l00123"></a><a class="code" href="a00043.html#a7">00123</a> <font class="keywordtype">void</font> ConsumerAdmin_i::reincarnate(<font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>&amp; node)
00124 {
00125   <font class="comment">// Build Push Supplier proxies</font>
00126   <a class="code" href="a00060.html">PersistNode</a>* pushsNode =node.<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ProxyPushSupplier"</font>);
00127   <font class="keywordflow">if</font>(pushsNode &amp;&amp; !pushsNode-&gt;<a class="code" href="a00060.html#m0">_child</a>.empty())
00128   {
00129     <a class="code" href="a00043.html#o2">_pushSupplier</a>=<font class="keyword">new</font> <a class="code" href="a00070.html">ProxyPushSupplierManager</a>(<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00043.html#o1">_queue</a>);
00130     <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#a7">_add_ref</a>();
00131     <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00062.html#a1">reincarnate</a>(*pushsNode);
00132   }
00133 
00134   <font class="comment">// Build Pull Supplier proxies</font>
00135   <a class="code" href="a00060.html">PersistNode</a>* pullsNode =node.<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ProxyPullSupplier"</font>);
00136   <font class="keywordflow">if</font>(pullsNode &amp;&amp; !pullsNode-&gt;<a class="code" href="a00060.html#m0">_child</a>.empty())
00137   {
00138     <a class="code" href="a00043.html#o3">_pullSupplier</a>=<font class="keyword">new</font> <a class="code" href="a00066.html">ProxyPullSupplierManager</a>(<a class="code" href="a00043.html#o0">_channel</a>,<a class="code" href="a00073.html#n0">_poa</a>,<a class="code" href="a00043.html#o1">_queue</a>);
00139     <a class="code" href="a00043.html#o3">_pullSupplier</a>-&gt;<a class="code" href="a00062.html#a1">reincarnate</a>(*pullsNode);
00140   }
00141 }
00142 
00143 
<a name="l00144"></a><a class="code" href="a00043.html#a8">00144</a> <font class="keywordtype">void</font> ConsumerAdmin_i::output(ostream&amp; os)
00145 {
00146   <font class="keywordflow">if</font>(_pushSupplier)
00147   {
00148     omni_mutex_lock l(<a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00070.html#m0">_lock</a>);
00149     <a class="code" href="a00043.html#o2">_pushSupplier</a>-&gt;<a class="code" href="a00062.html#a2">output</a>(os);
00150   }
00151   <font class="keywordflow">if</font>(_pullSupplier)
00152   {
00153     <a class="code" href="a00043.html#o3">_pullSupplier</a>-&gt;<a class="code" href="a00062.html#a2">output</a>(os);
00154   }
00155 }
00156 
00157 
00158 }; <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>