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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2