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