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