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 new CIMExportIndicationResponseMessage(request->messageId,
177 cimException,
178 request->queueIds.copyAndPop());
|
179 tony 1.1
|
180 karl 1.17 response->dest = request->queueIds.top();
|
181 tony 1.1
|
182 karl 1.17 PEG_METHOD_EXIT();
|
183 tony 1.1
|
184 karl 1.17 return response;
|
185 tony 1.1 }
186
|
187 chuck 1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
|
188 karl 1.17 CIMInstance instance,
189 ContentLanguageList contentLangs)
|
190 tony 1.1 {
|
191 karl 1.17 // go thru all consumers and broadcast the result;
192 // should be run in seperate thread
|
193 venkat.puvvada 1.15 AutoPtr<Iterator> it( _consumers->iterator() );
194
|
195 karl 1.17 while(it->hasNext()==true)
196 {
197 CIMIndicationConsumer* consumer =
198 static_cast<CIMIndicationConsumer*>(it->next());
199 CIMListenerIndicationDispatchEvent* event =
200 new CIMListenerIndicationDispatchEvent(consumer,
201 url,
202 instance,
203 contentLangs);
204 ThreadStatus rtn = _thread_pool->allocate_and_awaken(
205 event,deliver_routine);
206
207 if (rtn != PEGASUS_THREAD_OK)
208 {
209 Logger::put(Logger::STANDARD_LOG, System::CIMLISTENER,
210 Logger::TRACE,
211 "Not enough threads to allocate a worker to deliver"
212 " the event. ");
213
214 PEG_TRACE_CSTRING(TRC_SERVER, Tracer::LEVEL2,
215 "Could not allocate thread to deliver event."
216 karl 1.17 " Instead using current thread.");
217 delete event;
218 throw Exception(MessageLoaderParms(
219 "Listener.CIMListenerIndicationDispatcher."
220 "CANNOT_ALLOCATE_THREAD",
221 "Not enough threads to allocate a worker to deliver the"
222 " event."));
223 }
224 }
225 }
226 ThreadReturnType PEGASUS_THREAD_CDECL
227 CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
228 {
229 CIMListenerIndicationDispatchEvent* event =
230 static_cast<CIMListenerIndicationDispatchEvent*>(param);
|
231 tony 1.1
|
232 karl 1.17 if(event!=NULL)
233 {
234 CIMIndicationConsumer* consumer = event->getConsumer();
235 OperationContext context;
236 context.insert(ContentLanguageListContainer(
237 event->getContentLanguages()));
238 if(consumer)
239 {
240 consumer->consumeIndication(context,
241 event->getURL(),event->getIndicationInstance());
242 }
|
243 venkat.puvvada 1.15
|
244 karl 1.17 delete event;
245 }
246
247 return (0);
|
248 tony 1.1 }
249
250 ///////////////////////////////////////////////////////////////////////////////
251 // CIMListenerIndicationDispatcher
252 ///////////////////////////////////////////////////////////////////////////////
253 CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
254 :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
255 ,_rep(new CIMListenerIndicationDispatcherRep())
256 {
257 }
258 CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
259 {
|
260 karl 1.17 if(_rep!=NULL)
261 delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
|
262 tony 1.1
|
263 karl 1.17 _rep=NULL;
|
264 tony 1.1 }
265
266 void CIMListenerIndicationDispatcher::handleEnqueue()
267 {
|
268 karl 1.17 PEG_METHOD_ENTER(TRC_SERVER,
269 "CIMListenerIndicationDispatcher::handleEnqueue");
|
270 venkat.puvvada 1.15
|
271 karl 1.17 Message *message = dequeue();
272 if(message)
273 handleEnqueue(message);
|
274 venkat.puvvada 1.15
|
275 karl 1.17 PEG_METHOD_EXIT();
|
276 tony 1.1 }
277
278 void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
279 {
|
280 karl 1.17 PEG_METHOD_ENTER(TRC_SERVER,
281 "CIMListenerIndicationDispatcher::handleEnqueue");
|
282 venkat.puvvada 1.15
|
283 karl 1.17 if(message!=NULL)
|
284 tony 1.1 {
|
285 karl 1.17 switch (message->getType())
286 {
287 case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
288 {
289 CIMExportIndicationRequestMessage* request =
290 (CIMExportIndicationRequestMessage*)message;
291
292 CIMExportIndicationResponseMessage* response =
293 static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->
294 handleIndicationRequest(request);
295
296 _enqueueResponse(request, response);
297 }
298 break;
299 default:
300 break;
301 }
302 delete message;
|
303 venkat.puvvada 1.15 }
304
|
305 karl 1.17 PEG_METHOD_EXIT();
|
306 tony 1.1 }
|
307 karl 1.17 Boolean CIMListenerIndicationDispatcher::addConsumer(
308 CIMIndicationConsumer* consumer)
|
309 tony 1.1 {
|
310 karl 1.17 return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(
311 consumer);
|
312 tony 1.1 }
|
313 karl 1.17 Boolean CIMListenerIndicationDispatcher::removeConsumer(
314 CIMIndicationConsumer* consumer)
|
315 tony 1.1 {
|
316 karl 1.17 return static_cast<CIMListenerIndicationDispatcherRep*>
317 (_rep)->removeConsumer(consumer);
|
318 tony 1.1 }
319
320 PEGASUS_NAMESPACE_END
|