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

  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              static struct timeval create_time = {0, 1};
129              static struct timeval destroy_time = {15, 0};
130              static struct timeval deadlock_time = {0, 0};
131              
132              
133              CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep()
134              :_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0,
135              	create_time, destroy_time, deadlock_time))
136              ,_consumers(new PtrList())
137              {
138              	      
139              }
140              CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep()
141              {
142              	if(_thread_pool!=NULL)
143              	{
144 tony     1.1 		 _thread_pool->kill_dead_threads();
145              		 delete _thread_pool;
146                }
147              	if(_consumers!=NULL)
148              		delete _consumers;
149              }
150              	
151              Boolean CIMListenerIndicationDispatcherRep::addConsumer(CIMIndicationConsumer* consumer)
152              {
153              	_consumers->add(consumer);
154              	return true;
155              }
156              Boolean CIMListenerIndicationDispatcherRep::removeConsumer(CIMIndicationConsumer* consumer)
157              {
158              	_consumers->remove(consumer);
159              	return true;
160              }
161              CIMExportIndicationResponseMessage* CIMListenerIndicationDispatcherRep::handleIndicationRequest(CIMExportIndicationRequestMessage* request)
162              {
163              	PEG_METHOD_ENTER(TRC_SERVER,
164              		"CIMListenerIndicationDispatcherRep::handleIndicationRequest");
165 tony     1.1 
166              	CIMInstance instance = request->indicationInstance;
167              	String			url = request->destinationPath;
168 se.gupta 1.5     ContentLanguages contentLangs =((ContentLanguageListContainer)request->operationContext.
169              			                                    get(ContentLanguageListContainer::NAME)).getLanguages();
170 tony     1.1 
171 chuck    1.2 	deliverIndication(url,instance,contentLangs);
172 tony     1.1 
173              	// compose a response message  
174              	CIMException cimException;
175              
176              	CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage(
177              		request->messageId,
178              		cimException,
179              		request->queueIds.copyAndPop());
180              
181              	response->dest = request->queueIds.top();
182              
183              	PEG_METHOD_EXIT();
184              
185              	return response;
186              }
187              
188 chuck    1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
189                                                                         CIMInstance instance,
190                                                                         ContentLanguages contentLangs)
191 tony     1.1 {
192              	// go thru all consumers and broadcast the result; should be run in seperate thread
193              	Iterator* it = _consumers->iterator();
194              	while(it->hasNext()==true)
195              	{
196              		CIMIndicationConsumer* consumer = static_cast<CIMIndicationConsumer*>(it->next());
197 chuck    1.2 		CIMListenerIndicationDispatchEvent* event = new CIMListenerIndicationDispatchEvent(
198                                                                                                   consumer,
199                                                                                                   url,
200                                                                                                   instance,
201                                                                                                   contentLangs);
202 tony     1.1 		_thread_pool->allocate_and_awaken(event,deliver_routine);
203              	}
204              }
205              PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
206              {
207              	CIMListenerIndicationDispatchEvent* event = static_cast<CIMListenerIndicationDispatchEvent*>(param);
208              
209              	if(event!=NULL)
210              	{
211              		CIMIndicationConsumer* consumer = event->getConsumer();
212              		OperationContext context;
213 chuck    1.2 	        context.insert(ContentLanguageListContainer(event->getContentLanguages()));
214 tony     1.1 		if(consumer)
215              		{
216              			consumer->consumeIndication(context,event->getURL(),event->getIndicationInstance());
217              		}
218              
219              		delete event;
220              	}
221              		
222              	return (0);
223              }
224              
225              ///////////////////////////////////////////////////////////////////////////////
226              // CIMListenerIndicationDispatcher
227              ///////////////////////////////////////////////////////////////////////////////
228              CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
229              :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
230              ,_rep(new CIMListenerIndicationDispatcherRep())
231              {
232              }
233              CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
234              {
235 tony     1.1 	if(_rep!=NULL)
236 tony     1.3 		delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
237 tony     1.1 
238              	_rep=NULL;
239              }
240              
241              void CIMListenerIndicationDispatcher::handleEnqueue()
242              {
243              	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
244              	
245              	Message *message = dequeue();
246              	if(message)
247              		handleEnqueue(message);
248              	
249              	PEG_METHOD_EXIT();
250              }
251              
252              void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
253              {
254              	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
255              	
256              	if(message!=NULL)
257              	{
258 tony     1.1 		switch (message->getType())
259                  {
260              			case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
261              				{
262              					CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message;
263              
264              					CIMExportIndicationResponseMessage* response = 
265              						static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->handleIndicationRequest(request);
266              
267              					_enqueueResponse(request, response);
268              				}
269              				break;
270              		default:
271              			break;
272                  }	
273                  delete message;
274              	}	
275                 
276              	PEG_METHOD_EXIT();
277              }
278              Boolean CIMListenerIndicationDispatcher::addConsumer(CIMIndicationConsumer* consumer)
279 tony     1.1 {
280              	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(consumer);
281              }
282              Boolean CIMListenerIndicationDispatcher::removeConsumer(CIMIndicationConsumer* consumer)
283              {
284              	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->removeConsumer(consumer);
285              }
286              
287              PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2