1 tony 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 tony 1.1 //==============================================================================
23 //
24 //
25 // Author: Dong Xiang, EMC Corporation (xiang_dong@emc.com)
26 //
27 // Modified By:
28 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
31 #include "CIMListenerIndicationDispatcher.h"
32
33 #include <Pegasus/Common/Config.h>
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/OperationContext.h>
36 #include <Pegasus/Common/CIMMessage.h>
37 #include <Pegasus/Common/Thread.h>
38 #include <Pegasus/Common/Tracer.h>
39
40 #include <Pegasus/Listener/List.h>
41 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
|
42 chuck 1.2 #include <Pegasus/Common/ContentLanguages.h>
|
43 tony 1.1
44 PEGASUS_NAMESPACE_BEGIN
45
46 ///////////////////////////////////////////////////////////////////////////////
47 // CIMListenerIndicationDispatchEvent
48 ///////////////////////////////////////////////////////////////////////////////
49 class CIMListenerIndicationDispatchEvent
50 {
51 public:
|
52 chuck 1.2 CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
53 String url,
54 CIMInstance instance,
55 ContentLanguages contentLangs);
|
56 tony 1.1 ~CIMListenerIndicationDispatchEvent();
57
58 CIMIndicationConsumer* getConsumer() const;
59
60 String getURL() const;
61 CIMInstance getIndicationInstance() const;
|
62 chuck 1.2 ContentLanguages getContentLanguages() const;
|
63 tony 1.1
64 private:
65 CIMIndicationConsumer* _consumer;
66 String _url;
67 CIMInstance _instance;
|
68 chuck 1.2 ContentLanguages _contentLangs;
|
69 tony 1.1 };
70
|
71 chuck 1.2 CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
72 String url,
73 CIMInstance instance,
74 ContentLanguages contentLangs)
75 :_consumer(consumer),_url(url),_instance(instance), _contentLangs(contentLangs)
|
76 tony 1.1 {
77 }
78 CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent()
79 {
80 }
81 CIMIndicationConsumer* CIMListenerIndicationDispatchEvent::getConsumer() const
82 {
83 return _consumer;
84 }
85 String CIMListenerIndicationDispatchEvent::getURL() const
86 {
87 return _url;
88 }
89 CIMInstance CIMListenerIndicationDispatchEvent::getIndicationInstance() const
90 {
91 return _instance;
92 }
|
93 chuck 1.2 ContentLanguages CIMListenerIndicationDispatchEvent::getContentLanguages() const
94 {
95 return _contentLangs;
96 }
|
97 tony 1.1
98 ///////////////////////////////////////////////////////////////////////////////
99 // CIMListenerIndicationDispatcherRep
100 ///////////////////////////////////////////////////////////////////////////////
101 class CIMListenerIndicationDispatcherRep
102 {
103 public:
104 CIMListenerIndicationDispatcherRep();
105 virtual ~CIMListenerIndicationDispatcherRep();
106
107 Boolean addConsumer(CIMIndicationConsumer* consumer);
108 Boolean removeConsumer(CIMIndicationConsumer* consumer);
109
110 CIMExportIndicationResponseMessage* handleIndicationRequest(CIMExportIndicationRequestMessage* request);
111
112
113 static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL deliver_routine(void *param);
114
115 private:
|
116 chuck 1.2 void deliverIndication(String url, CIMInstance instance, ContentLanguages contentLangs);
|
117 tony 1.1
118 ThreadPool* _thread_pool;
119 PtrList* _consumers;
120 };
121
122 static struct timeval create_time = {0, 1};
123 static struct timeval destroy_time = {15, 0};
124 static struct timeval deadlock_time = {0, 0};
125
126
127 CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep()
128 :_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0,
129 create_time, destroy_time, deadlock_time))
130 ,_consumers(new PtrList())
131 {
132
133 }
134 CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep()
135 {
136 if(_thread_pool!=NULL)
137 {
138 tony 1.1 _thread_pool->kill_dead_threads();
139 delete _thread_pool;
140 }
141 if(_consumers!=NULL)
142 delete _consumers;
143 }
144
145 Boolean CIMListenerIndicationDispatcherRep::addConsumer(CIMIndicationConsumer* consumer)
146 {
147 _consumers->add(consumer);
148 return true;
149 }
150 Boolean CIMListenerIndicationDispatcherRep::removeConsumer(CIMIndicationConsumer* consumer)
151 {
152 _consumers->remove(consumer);
153 return true;
154 }
155 CIMExportIndicationResponseMessage* CIMListenerIndicationDispatcherRep::handleIndicationRequest(CIMExportIndicationRequestMessage* request)
156 {
157 PEG_METHOD_ENTER(TRC_SERVER,
158 "CIMListenerIndicationDispatcherRep::handleIndicationRequest");
159 tony 1.1
160 CIMInstance instance = request->indicationInstance;
161 String url = request->destinationPath;
|
162 chuck 1.2 ContentLanguages contentLangs = request->contentLanguages;
|
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
|