(file) Return to CIMListenerIndicationDispatcher.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Listener

  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           // Modified By:
 30           //
 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 chuck 1.2         ContentLanguages contentLangs = request->contentLanguages;
165 tony  1.1 
166 chuck 1.2 	deliverIndication(url,instance,contentLangs);
167 tony  1.1 
168           	// compose a response message  
169           	CIMException cimException;
170           
171           	CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage(
172           		request->messageId,
173           		cimException,
174           		request->queueIds.copyAndPop());
175           
176           	response->dest = request->queueIds.top();
177           
178           	PEG_METHOD_EXIT();
179           
180           	return response;
181           }
182           
183 chuck 1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
184                                                                      CIMInstance instance,
185                                                                      ContentLanguages contentLangs)
186 tony  1.1 {
187           	// go thru all consumers and broadcast the result; should be run in seperate thread
188           	Iterator* it = _consumers->iterator();
189           	while(it->hasNext()==true)
190           	{
191           		CIMIndicationConsumer* consumer = static_cast<CIMIndicationConsumer*>(it->next());
192 chuck 1.2 		CIMListenerIndicationDispatchEvent* event = new CIMListenerIndicationDispatchEvent(
193                                                                                                consumer,
194                                                                                                url,
195                                                                                                instance,
196                                                                                                contentLangs);
197 tony  1.1 		_thread_pool->allocate_and_awaken(event,deliver_routine);
198           	}
199           }
200           PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
201           {
202           	CIMListenerIndicationDispatchEvent* event = static_cast<CIMListenerIndicationDispatchEvent*>(param);
203           
204           	if(event!=NULL)
205           	{
206           		CIMIndicationConsumer* consumer = event->getConsumer();
207           		OperationContext context;
208 chuck 1.2 	        context.insert(ContentLanguageListContainer(event->getContentLanguages()));
209 tony  1.1 		if(consumer)
210           		{
211           			consumer->consumeIndication(context,event->getURL(),event->getIndicationInstance());
212           		}
213           
214           		delete event;
215           	}
216           		
217           	return (0);
218           }
219           
220           ///////////////////////////////////////////////////////////////////////////////
221           // CIMListenerIndicationDispatcher
222           ///////////////////////////////////////////////////////////////////////////////
223           CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
224           :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
225           ,_rep(new CIMListenerIndicationDispatcherRep())
226           {
227           }
228           CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
229           {
230 tony  1.1 	if(_rep!=NULL)
231 tony  1.3 		delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
232 tony  1.1 
233           	_rep=NULL;
234           }
235           
236           void CIMListenerIndicationDispatcher::handleEnqueue()
237           {
238           	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
239           	
240           	Message *message = dequeue();
241           	if(message)
242           		handleEnqueue(message);
243           	
244           	PEG_METHOD_EXIT();
245           }
246           
247           void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
248           {
249           	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
250           	
251           	if(message!=NULL)
252           	{
253 tony  1.1 		switch (message->getType())
254               {
255           			case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
256           				{
257           					CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message;
258           
259           					CIMExportIndicationResponseMessage* response = 
260           						static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->handleIndicationRequest(request);
261           
262           					_enqueueResponse(request, response);
263           				}
264           				break;
265           		default:
266           			break;
267               }	
268               delete message;
269           	}	
270              
271           	PEG_METHOD_EXIT();
272           }
273           Boolean CIMListenerIndicationDispatcher::addConsumer(CIMIndicationConsumer* consumer)
274 tony  1.1 {
275           	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(consumer);
276           }
277           Boolean CIMListenerIndicationDispatcher::removeConsumer(CIMIndicationConsumer* consumer)
278           {
279           	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->removeConsumer(consumer);
280           }
281           
282           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2