1 karl 1.12 //%2006////////////////////////////////////////////////////////////////////////
|
2 tony 1.1 //
|
3 karl 1.6 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.4 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.6 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.12 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 tony 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 venkat.puvvada 1.15 //
|
21 tony 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include "CIMListenerIndicationDispatcher.h"
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Constants.h>
38 #include <Pegasus/Common/OperationContext.h>
39 #include <Pegasus/Common/CIMMessage.h>
40 #include <Pegasus/Common/Thread.h>
41 #include <Pegasus/Common/Tracer.h>
42 tony 1.1
43 #include <Pegasus/Listener/List.h>
44 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
|
45 kumpf 1.11 #include <Pegasus/Common/ContentLanguageList.h>
|
46 tony 1.1
47 PEGASUS_NAMESPACE_BEGIN
48
49 ///////////////////////////////////////////////////////////////////////////////
50 // CIMListenerIndicationDispatchEvent
51 ///////////////////////////////////////////////////////////////////////////////
52 class CIMListenerIndicationDispatchEvent
53 {
54 public:
|
55 karl 1.17 CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
|
56 chuck 1.2 String url,
57 CIMInstance instance,
|
58 kumpf 1.11 ContentLanguageList contentLangs);
|
59 karl 1.17 ~CIMListenerIndicationDispatchEvent();
|
60 tony 1.1
|
61 karl 1.17 CIMIndicationConsumer* getConsumer() const;
|
62 tony 1.1
|
63 karl 1.17 String getURL() const;
64 CIMInstance getIndicationInstance() const;
|
65 venkat.puvvada 1.15 ContentLanguageList getContentLanguages() const;
|
66 tony 1.1
67 private:
|
68 karl 1.17 CIMIndicationConsumer* _consumer;
69 String _url;
70 CIMInstance _instance;
71 ContentLanguageList _contentLangs;
|
72 tony 1.1 };
73
|
74 karl 1.17 CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent(
75 CIMIndicationConsumer* consumer,
76 String url,
77 CIMInstance instance,
78 ContentLanguageList contentLangs)
|
79 chuck 1.2 :_consumer(consumer),_url(url),_instance(instance), _contentLangs(contentLangs)
|
80 tony 1.1 {
81 }
82 CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent()
83 {
84 }
85 CIMIndicationConsumer* CIMListenerIndicationDispatchEvent::getConsumer() const
86 {
|
87 karl 1.17 return _consumer;
|
88 tony 1.1 }
89 String CIMListenerIndicationDispatchEvent::getURL() const
90 {
|
91 karl 1.17 return _url;
|
92 tony 1.1 }
93 CIMInstance CIMListenerIndicationDispatchEvent::getIndicationInstance() const
94 {
|
95 karl 1.17 return _instance;
|
96 tony 1.1 }
|
97 karl 1.17 ContentLanguageList
98 CIMListenerIndicationDispatchEvent::getContentLanguages() const
|
99 chuck 1.2 {
|
100 karl 1.17 return _contentLangs;
|
101 chuck 1.2 }
|
102 tony 1.1
103 ///////////////////////////////////////////////////////////////////////////////
104 // CIMListenerIndicationDispatcherRep
105 ///////////////////////////////////////////////////////////////////////////////
106 class CIMListenerIndicationDispatcherRep
107 {
108 public:
|
109 karl 1.17 CIMListenerIndicationDispatcherRep();
110 virtual ~CIMListenerIndicationDispatcherRep();
|
111 venkat.puvvada 1.15
|
112 karl 1.17 Boolean addConsumer(CIMIndicationConsumer* consumer);
113 Boolean removeConsumer(CIMIndicationConsumer* consumer);
|
114 tony 1.1
|
115 karl 1.17 CIMExportIndicationResponseMessage* handleIndicationRequest(
116 CIMExportIndicationRequestMessage* request);
|
117 tony 1.1
|
118 venkat.puvvada 1.15
|
119 karl 1.17 static ThreadReturnType PEGASUS_THREAD_CDECL deliver_routine(void *param);
|
120 tony 1.1
121 private:
|
122 karl 1.17 void deliverIndication(String url,
123 CIMInstance instance,
124 ContentLanguageList contentLangs);
|
125 tony 1.1
|
126 karl 1.17 ThreadPool* _thread_pool;
127 PtrList* _consumers;
|
128 tony 1.1 };
129
|
130 kumpf 1.9 static struct timeval deallocateWait = {15, 0};
|
131 tony 1.1
132
133 CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep()
|
134 karl 1.17 : _thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0,
135 deallocateWait)), _consumers(new PtrList())
|
136 tony 1.1 {
|
137 venkat.puvvada 1.15
|
138 tony 1.1 }
139 CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep()
140 {
|
141 karl 1.17 delete _thread_pool;
142 delete _consumers;
|
143 tony 1.1 }
|
144 venkat.puvvada 1.15
|
145 karl 1.17 Boolean CIMListenerIndicationDispatcherRep::addConsumer(
146 CIMIndicationConsumer* consumer)
|
147 tony 1.1 {
|
148 karl 1.17 _consumers->add(consumer);
149 return true;
|
150 tony 1.1 }
|
151 karl 1.17 Boolean CIMListenerIndicationDispatcherRep::removeConsumer(
152 CIMIndicationConsumer* consumer)
|
153 tony 1.1 {
|
154 karl 1.17 _consumers->remove(consumer);
155 return true;
|
156 tony 1.1 }
|
157 karl 1.17 CIMExportIndicationResponseMessage*
158 CIMListenerIndicationDispatcherRep::handleIndicationRequest(
159 CIMExportIndicationRequestMessage* request)
|
160 tony 1.1 {
|
161 karl 1.17 PEG_METHOD_ENTER(TRC_SERVER,
162 "CIMListenerIndicationDispatcherRep::handleIndicationRequest");
|
163 tony 1.1
|
164 karl 1.17 CIMInstance instance = request->indicationInstance;
165 String url = request->destinationPath;
166 ContentLanguageList contentLangs =
167 ((ContentLanguageListContainer)request->operationContext.
168 get(ContentLanguageListContainer::NAME)).getLanguages();
|
169 tony 1.1
|
170 karl 1.17 deliverIndication(url,instance,contentLangs);
|
171 tony 1.1
|
172 karl 1.17 // compose a response message
173 CIMException cimException;
|
174 tony 1.1
|
175 karl 1.17 CIMExportIndicationResponseMessage* response =
|
176 kumpf 1.18 dynamic_cast<CIMExportIndicationResponseMessage*>(
177 request->buildResponse());
178 response->cimException = cimException;
|
179 karl 1.17 response->dest = request->queueIds.top();
|
180 tony 1.1
|
181 karl 1.17 PEG_METHOD_EXIT();
|
182 tony 1.1
|
183 karl 1.17 return response;
|
184 tony 1.1 }
185
|
186 chuck 1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
|
187 karl 1.17 CIMInstance instance,
188 ContentLanguageList contentLangs)
|
189 tony 1.1 {
|
190 karl 1.17 // go thru all consumers and broadcast the result;
191 // should be run in seperate thread
|
192 venkat.puvvada 1.15 AutoPtr<Iterator> it( _consumers->iterator() );
193
|
194 karl 1.17 while(it->hasNext()==true)
195 {
196 CIMIndicationConsumer* consumer =
197 static_cast<CIMIndicationConsumer*>(it->next());
198 CIMListenerIndicationDispatchEvent* event =
199 new CIMListenerIndicationDispatchEvent(consumer,
200 url,
201 instance,
202 contentLangs);
203 ThreadStatus rtn = _thread_pool->allocate_and_awaken(
204 event,deliver_routine);
205
206 if (rtn != PEGASUS_THREAD_OK)
207 {
|
208 marek 1.19 PEG_TRACE_CSTRING(
209 TRC_SERVER,
|
210 marek 1.20 Tracer::LEVEL1,
|
211 karl 1.17 "Could not allocate thread to deliver event."
212 " Instead using current thread.");
213 delete event;
214 throw Exception(MessageLoaderParms(
215 "Listener.CIMListenerIndicationDispatcher."
216 "CANNOT_ALLOCATE_THREAD",
217 "Not enough threads to allocate a worker to deliver the"
218 " event."));
219 }
220 }
221 }
222 ThreadReturnType PEGASUS_THREAD_CDECL
223 CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
224 {
225 CIMListenerIndicationDispatchEvent* event =
226 static_cast<CIMListenerIndicationDispatchEvent*>(param);
|
227 tony 1.1
|
228 karl 1.17 if(event!=NULL)
229 {
230 CIMIndicationConsumer* consumer = event->getConsumer();
231 OperationContext context;
232 context.insert(ContentLanguageListContainer(
233 event->getContentLanguages()));
234 if(consumer)
235 {
236 consumer->consumeIndication(context,
237 event->getURL(),event->getIndicationInstance());
238 }
|
239 venkat.puvvada 1.15
|
240 karl 1.17 delete event;
241 }
242
243 return (0);
|
244 tony 1.1 }
245
246 ///////////////////////////////////////////////////////////////////////////////
247 // CIMListenerIndicationDispatcher
248 ///////////////////////////////////////////////////////////////////////////////
249 CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
250 :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
251 ,_rep(new CIMListenerIndicationDispatcherRep())
252 {
253 }
254 CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
255 {
|
256 karl 1.17 if(_rep!=NULL)
257 delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
|
258 tony 1.1
|
259 karl 1.17 _rep=NULL;
|
260 tony 1.1 }
261
262 void CIMListenerIndicationDispatcher::handleEnqueue()
263 {
|
264 karl 1.17 PEG_METHOD_ENTER(TRC_SERVER,
265 "CIMListenerIndicationDispatcher::handleEnqueue");
|
266 venkat.puvvada 1.15
|
267 karl 1.17 Message *message = dequeue();
268 if(message)
269 handleEnqueue(message);
|
270 venkat.puvvada 1.15
|
271 karl 1.17 PEG_METHOD_EXIT();
|
272 tony 1.1 }
273
274 void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
275 {
|
276 karl 1.17 PEG_METHOD_ENTER(TRC_SERVER,
277 "CIMListenerIndicationDispatcher::handleEnqueue");
|
278 venkat.puvvada 1.15
|
279 karl 1.17 if(message!=NULL)
|
280 tony 1.1 {
|
281 karl 1.17 switch (message->getType())
282 {
283 case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
284 {
285 CIMExportIndicationRequestMessage* request =
286 (CIMExportIndicationRequestMessage*)message;
287
288 CIMExportIndicationResponseMessage* response =
289 static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->
290 handleIndicationRequest(request);
291
292 _enqueueResponse(request, response);
293 }
294 break;
295 default:
296 break;
297 }
298 delete message;
|
299 venkat.puvvada 1.15 }
300
|
301 karl 1.17 PEG_METHOD_EXIT();
|
302 tony 1.1 }
|
303 karl 1.17 Boolean CIMListenerIndicationDispatcher::addConsumer(
304 CIMIndicationConsumer* consumer)
|
305 tony 1.1 {
|
306 karl 1.17 return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(
307 consumer);
|
308 tony 1.1 }
|
309 karl 1.17 Boolean CIMListenerIndicationDispatcher::removeConsumer(
310 CIMIndicationConsumer* consumer)
|
311 tony 1.1 {
|
312 karl 1.17 return static_cast<CIMListenerIndicationDispatcherRep*>
313 (_rep)->removeConsumer(consumer);
|
314 tony 1.1 }
315
316 PEGASUS_NAMESPACE_END
|