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