(file) Return to OperationResponseHandler.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2

  1 karl  1.8 //%2004////////////////////////////////////////////////////////////////////////
  2 schuur 1.1 //
  3 karl   1.8 // 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 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl   1.8 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 schuur 1.1 //
 10            // Permission is hereby granted, free of charge, to any person obtaining a copy
 11            // of this software and associated documentation files (the "Software"), to
 12            // deal in the Software without restriction, including without limitation the
 13            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14            // sell copies of the Software, and to permit persons to whom the Software is
 15            // furnished to do so, subject to the following conditions:
 16            // 
 17            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25            //
 26            //==============================================================================
 27            //
 28            // Author: Chip Vincent (cvincent@us.ibm.com)
 29            //
 30 schuur 1.1 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 31            //                  (carolann_graves@hp.com)
 32            //              Dave Rosckes (rosckes@us.ibm.com)
 33            //		Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 34            //		Adrian Schuur (schuur@de.ibm.com)
 35 se.gupta 1.3 //		Seema Gupta (gseema@in.ibm.com) for PEP135
 36 brian.campbell 1.9 //    Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase2
 37 schuur         1.1 //
 38                    //%/////////////////////////////////////////////////////////////////////////////
 39                    
 40                    #ifndef Pegasus_OperationResponseHandler_h
 41                    #define Pegasus_OperationResponseHandler_h
 42                    
 43                    #include <Pegasus/Common/Config.h>
 44                    #include <Pegasus/Server/Linkage.h>
 45                    #include <Pegasus/Common/CIMMessage.h>
 46                    #include <Pegasus/Common/MessageQueueService.h>
 47                    #include <Pegasus/Common/Constants.h>
 48                    #include <Pegasus/Common/ContentLanguages.h>  // l10n
 49                    
 50                    #include <Pegasus/Common/CIMClass.h>
 51                    #include <Pegasus/Common/CIMInstance.h>
 52                    #include <Pegasus/Common/CIMIndication.h>
 53                    #include <Pegasus/Common/CIMValue.h>
 54                    
 55                    #include <Pegasus/Common/ResponseHandler.h>
 56                    #include <Pegasus/Common/Logger.h>
 57 kumpf          1.6 #include <Pegasus/Common/XmlWriter.h>
 58 schuur         1.1 
 59                    #include <Pegasus/ProviderManager2/SimpleResponseHandler.h>
 60                    #include <Pegasus/ProviderManager2/Linkage.h>
 61                    
 62                    PEGASUS_NAMESPACE_BEGIN
 63                    
 64                    class PEGASUS_PPM_LINKAGE OperationResponseHandler
 65                    {
 66 brian.campbell 1.9 	friend class SimpleResponseHandler;
 67                    
 68 schuur         1.1 public:
 69 brian.campbell 1.9     OperationResponseHandler(CIMRequestMessage * request, 
 70                    														 CIMResponseMessage * response);
 71 schuur         1.1 
 72 brian.campbell 1.9     virtual ~OperationResponseHandler(void);
 73                        
 74 schuur         1.1     CIMRequestMessage * getRequest(void) const
 75                        {
 76                            return(_request);
 77                        }
 78                    
 79                        CIMResponseMessage * getResponse(void) const
 80                        {
 81                            return(_response);
 82                        }
 83                    
 84                        virtual void setStatus(const Uint32 code, const String & message = String::EMPTY)
 85                        {
 86                            _response->cimException = PEGASUS_CIM_EXCEPTION(CIMStatusCode(code), message);
 87                        }
 88                    
 89                        virtual void setStatus(const Uint32 code,
 90                        						const ContentLanguages & langs,
 91                        						const String & message = String::EMPTY)
 92                        {
 93                            _response->cimException = PEGASUS_CIM_EXCEPTION_LANG(
 94                            						langs,
 95 schuur         1.1         						CIMStatusCode(code),
 96                            						 message);
 97                        }
 98                    
 99                    protected:
100 brian.campbell 1.9 
101                    		// the default for all derived handlers. Some handlers may not apply
102                    		// async behavior because their callers cannot handle partial responses.
103                    		virtual Boolean isAsync() const { return true; }
104                    
105                    		// send (deliver) asynchronously
106                    		virtual void send(Boolean isComplete);
107                    
108                    		// transfer any objects from handler to response. this does not clear()
109                    		virtual void transfer() {}
110                    
111                    		// validate whatever is necessary before the transfer
112                    		virtual void validate() {}
113                    
114                    	  virtual const String& getClass() const
115                    	  { 
116                    			static const String n("OperationResponseHandler");
117                    			return n;
118                    		}
119                    
120                       	Uint32 getResponseObjectTotal() const { return _responseObjectTotal; }
121 brian.campbell 1.9 
122                    		// there can be many objects per message (or none at all - i.e complete())
123                    		Uint32 getResponseMessageTotal() const { return _responseMessageTotal; }
124                    
125                    		Uint32 getResponseObjectThreshold() const { return _responseObjectThreshold; }
126                    
127 schuur         1.1     CIMRequestMessage * _request;
128                        CIMResponseMessage * _response;
129                    
130 brian.campbell 1.9 private:
131                    		Uint32 _responseObjectTotal;
132                    		Uint32 _responseMessageTotal;
133                    		Uint32 _responseObjectThreshold;
134 schuur         1.1 };
135                    
136                    
137                    /* ------------------------------------------------------------------------- */
138                    /* operation specific response handlers                                      */
139                    /* ------------------------------------------------------------------------- */
140                    
141 brian.campbell 1.9 #define PEGASUS_RESPONSE_HANDLER_DERIVED_CONSTRUCT(c, b)                      \
142                    c ## ResponseHandler(CIM ## c ## RequestMessage *request,                     \
143                    		                 CIM ## c ## ResponseMessage *response)                   \
144                    : OperationResponseHandler(request, response) {}   
145                    
146                    #define PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(c, b)                           \
147                    PEGASUS_RESPONSE_HANDLER_DERIVED_CONSTRUCT(c, b)                              \
148                    virtual const String& getClass() const                                        \
149                    { static const String n(#c "ResponseHandler"); return n; }
150                    
151 schuur         1.1 class GetInstanceResponseHandler:  public OperationResponseHandler, public SimpleInstanceResponseHandler
152                    {
153                    public:
154 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(GetInstance, SimpleInstance);
155 schuur         1.1 
156 brian.campbell 1.9 	virtual void transfer()
157                    	{
158                    		if (size() > 0)
159                    		{
160                    			CIMGetInstanceResponseMessage &msg = 
161                    				*static_cast<CIMGetInstanceResponseMessage *>(getResponse());
162                    			msg.cimInstance = getObjects()[0];
163                    		}
164                    	}
165 schuur         1.1 
166 brian.campbell 1.9 	virtual void validate()
167                    	{
168                    		if (getResponseObjectTotal() == 0)
169                    		{
170                    			// error? provider claims success,
171                    			// but did not deliver an instance.
172                    			setStatus(CIM_ERR_NOT_FOUND);
173                    		}
174                    	}
175 schuur         1.1 };
176                    
177                    class EnumerateInstancesResponseHandler : public OperationResponseHandler, public SimpleInstanceResponseHandler
178                    {
179                    public:
180 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(EnumerateInstances, SimpleInstance);
181 schuur         1.1 
182 brian.campbell 1.9 	virtual void transfer()
183                    	{
184                    		CIMEnumerateInstancesResponseMessage &msg =
185                    			*static_cast<CIMEnumerateInstancesResponseMessage *>(getResponse());
186                    		msg.cimNamedInstances = getObjects();
187                    	}
188 schuur         1.1 };
189                    
190                    class EnumerateInstanceNamesResponseHandler : public OperationResponseHandler, public SimpleObjectPathResponseHandler
191                    {
192                    public:
193 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(EnumerateInstanceNames, SimpleObjectPath);
194                    	
195                    	virtual void transfer()
196                    	{
197                    		CIMEnumerateInstanceNamesResponseMessage &msg =
198                    			*static_cast<CIMEnumerateInstanceNamesResponseMessage *>(getResponse());
199                    		msg.instanceNames = getObjects();
200                    	}
201 schuur         1.1 };
202                    
203                    class CreateInstanceResponseHandler : public OperationResponseHandler, public SimpleObjectPathResponseHandler
204                    {
205                    public:
206 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(CreateInstance, SimpleObjectPath);
207                    	// ATTN: is it an error to not return instance name?
208                    #if 0
209                    	virtual void validate()
210                    	{
211                    		if (getResponseObjectTotal() == 0)
212                    			setStatus(CIM_ERR_NOT_FOUND);
213                    	}
214                    #endif
215 schuur         1.1 
216 brian.campbell 1.9 	virtual void transfer()
217                    	{
218                    		if (size() > 0)
219                    		{
220                    			CIMCreateInstanceResponseMessage &msg =
221                    				*static_cast<CIMCreateInstanceResponseMessage *>(getResponse());
222                    			msg.instanceName = getObjects()[0];
223                    		}
224                    	}
225 schuur         1.1 };
226                    
227                    class ModifyInstanceResponseHandler : public OperationResponseHandler, public SimpleResponseHandler
228                    {
229                    public:
230 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(ModifyInstance, Simple);
231 schuur         1.1 };
232                    
233                    class DeleteInstanceResponseHandler : public OperationResponseHandler, public SimpleResponseHandler
234                    {
235                    public:
236 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(DeleteInstance, Simple);
237 schuur         1.1 };
238                    
239                    class GetPropertyResponseHandler : public OperationResponseHandler, public SimpleValueResponseHandler
240                    {
241                    public:
242 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(GetProperty, SimpleValue);
243 schuur         1.1 
244 brian.campbell 1.9 	virtual void transfer()
245                    	{
246                    		if (size() > 0)
247                    		{
248                    			CIMGetPropertyResponseMessage &msg =
249                    				*static_cast<CIMGetPropertyResponseMessage *>(getResponse());
250                    			msg.value = getObjects()[0];
251                    		}
252                    	}
253 schuur         1.1 
254 brian.campbell 1.9 	virtual void validate()
255                    	{
256                    		// error? provider claims success,
257                    		// but did not deliver an instance.
258                    		if (getResponseObjectTotal() == 0)
259                    			setStatus(CIM_ERR_NOT_FOUND);
260                    	}
261 schuur         1.1 };
262                    
263                    class SetPropertyResponseHandler : public OperationResponseHandler, public SimpleResponseHandler
264                    {
265                    public:
266 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(SetProperty, Simple);
267 schuur         1.1 };
268                    
269                    class ExecQueryResponseHandler : public OperationResponseHandler, public SimpleInstance2ObjectResponseHandler
270                    {
271                    public:
272 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(ExecQuery, SimpleInstance2Object);
273 schuur         1.1 
274 brian.campbell 1.9 	virtual void transfer()
275                    	{
276                    		CIMExecQueryResponseMessage &msg = *
277                    			static_cast<CIMExecQueryResponseMessage *>(getResponse());
278                    		msg.cimObjects = getObjects();
279                    	}
280 schuur         1.1 
281 brian.campbell 1.9 	// this handler will not send async but sync
282                    	virtual Boolean isAsync() const { return false; }
283 schuur         1.1 };
284                    
285                    class AssociatorsResponseHandler : public OperationResponseHandler, public SimpleObjectResponseHandler
286                    {
287                    public:
288 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(Associators, SimpleObject);
289 schuur         1.1 
290 brian.campbell 1.9 	virtual void transfer()
291                    	{
292                    		CIMAssociatorsResponseMessage &msg =
293                    			*static_cast<CIMAssociatorsResponseMessage *>(getResponse());
294                    		msg.cimObjects = getObjects();
295                    	}
296 schuur         1.1 };
297                    
298                    class AssociatorNamesResponseHandler : public OperationResponseHandler, public SimpleObjectPathResponseHandler
299                    {
300                    public:
301 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(AssociatorNames, SimpleObjectPath);
302                    	virtual void transfer()
303                    	{
304                    		CIMAssociatorNamesResponseMessage &msg =
305                    			*static_cast<CIMAssociatorNamesResponseMessage *>(getResponse());
306                    		msg.objectNames = getObjects();
307                    	}
308 schuur         1.1 };
309                    
310                    class ReferencesResponseHandler : public OperationResponseHandler, public SimpleObjectResponseHandler
311                    {
312                    public:
313 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(References, SimpleObject);
314                    	virtual void transfer()
315                    	{
316                    		CIMReferencesResponseMessage &msg =
317                    			*static_cast<CIMReferencesResponseMessage *>(getResponse());
318                    		msg.cimObjects = getObjects();
319                    	}
320 schuur         1.1 };
321                    
322                    class ReferenceNamesResponseHandler : public OperationResponseHandler, public SimpleObjectPathResponseHandler
323                    {
324                    public:
325 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(ReferenceNames, SimpleObjectPath);
326                    	virtual void transfer()
327                    	{
328                    		CIMReferenceNamesResponseMessage &msg =
329                    			*static_cast<CIMReferenceNamesResponseMessage *>(getResponse());
330                    		msg.objectNames = getObjects();
331                    	}
332 schuur         1.1 };
333                    
334                    class InvokeMethodResponseHandler : public OperationResponseHandler, public SimpleMethodResultResponseHandler
335                    {
336                    public:
337 brian.campbell 1.9 	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(InvokeMethod, SimpleMethodResult);
338 schuur         1.1 
339 brian.campbell 1.9 	virtual void transfer()
340                    	{
341                    		CIMInvokeMethodResponseMessage &msg = 
342                    			*static_cast<CIMInvokeMethodResponseMessage *>(getResponse());
343                    		msg.outParameters = getParamValues();
344                    		
345                    		// ATTN-RK-20020903: Is it legal for the return value to be null?
346                    		// if not, then the check must be done here since deliver() works off the
347                    		// virtual size, which refers to out parameters!
348                    		
349                    		msg.retValue = getReturnValue();
350                    	}
351 schuur         1.1 };
352                    
353 brian.campbell 1.9 typedef void (*PEGASUS_INDICATION_CALLBACK)(CIMProcessIndicationRequestMessage*);
354 kumpf          1.2 
355 schuur         1.1 class EnableIndicationsResponseHandler : public OperationResponseHandler, public SimpleIndicationResponseHandler
356                    {
357                    public:
358 brian.campbell 1.9 
359                    	// our own contructor is used, not the default one in the macro
360                    #undef PEGASUS_RESPONSE_HANDLER_DERIVED_CONSTRUCT
361                    #define PEGASUS_RESPONSE_HANDLER_DERIVED_CONSTRUCT(c,b)
362                    
363                    	PEGASUS_RESPONSE_HANDLER_DERIVED_INIT(EnableIndications, SimpleIndication);
364                    
365                    	EnableIndicationsResponseHandler
366                    	(CIMEnableIndicationsRequestMessage * request,
367                    	 CIMEnableIndicationsResponseMessage * response,
368                    	 CIMInstance & provider,
369                    	 PEGASUS_INDICATION_CALLBACK indicationCallback)
370 schuur         1.1     : OperationResponseHandler(request, response),
371 brian.campbell 1.9 			_request_copy(*request),
372                    			_response_copy(*response),
373                    			_indicationCallback(indicationCallback)
374                    	{
375                    		_provider = provider;
376                    	}
377                    
378                    	// this handler will not send async but sync
379                    	virtual Boolean isAsync() const { return false; }
380                    
381                    	virtual void deliver(const CIMIndication & cimIndication)
382                    	{
383                    		OperationContext context;
384                    		Array<CIMObjectPath> subscriptionInstanceNames;
385                    		context.insert(SubscriptionInstanceNamesContainer(subscriptionInstanceNames));
386                    		deliver(context, cimIndication);
387                    	}
388                    
389                    	virtual void deliver(const OperationContext & context, const CIMIndication & cimIndication)
390                    	{
391                    		// ATTN: temporarily convert indication to instance
392 brian.campbell 1.9 		CIMInstance cimInstance(cimIndication);
393                    		
394                    		//
395                    		//  Get list of subscription instance names from context
396                    		//
397                    		Array<CIMObjectPath> subscriptionInstanceNames;
398                    		try
399                    		{
400                    			SubscriptionInstanceNamesContainer container = context.get
401                    				(SubscriptionInstanceNamesContainer::NAME);
402                    			subscriptionInstanceNames =	container.getInstanceNames();
403                    		}
404                    		catch (Exception&)
405                    		{
406                    			subscriptionInstanceNames.clear();
407                    		}
408                    		
409                    		// l10n
410                    		ContentLanguages contentLangs;
411                    		try
412                    		{
413 brian.campbell 1.9 			// Get the Content-Language for this indication.  The provider
414                    			// does not have to add specify a language for the indication.
415                    			ContentLanguageListContainer langContainer = context.get
416                    				(ContentLanguageListContainer::NAME);
417                    			
418                    			contentLangs = langContainer.getLanguages();
419                    		}
420                    		catch (Exception&)
421                    		{
422                    			// The provider did not explicitly set a Content-Language for
423                    			// the indication.  Fall back to the lang set in this object.
424                    			contentLangs = getLanguages();
425                    		}
426                    		// l10n -end
427                    		
428                    		// create message
429                    		// l10n
430                    		CIMProcessIndicationRequestMessage * request =
431                    			new CIMProcessIndicationRequestMessage(
432                    																						 XmlWriter::getNextMessageId(),
433                    																						 cimInstance.getPath().getNameSpace(),
434 brian.campbell 1.9 																						 cimInstance,
435                    																						 subscriptionInstanceNames,
436                    																						 _provider,
437                    																						 QueueIdStack());  // Must be filled in by the callback function
438                    																						 
439                    		request->operationContext = context;
440 se.gupta       1.4 		try
441                    		{
442                    			request->operationContext.set(ContentLanguageListContainer(contentLangs));
443 brian.campbell 1.9 		}
444                    		catch(const Exception &)
445 se.gupta       1.4 		{
446                    			request->operationContext.insert(ContentLanguageListContainer(contentLangs));
447                    		}
448 brian.campbell 1.9 		
449                    		_indicationCallback(request);
450                    	}
451                    	
452                    	virtual void deliver(const Array<CIMIndication> & cimIndications)
453                    	{
454                    		OperationContext context;
455                    		
456                    		deliver(context, cimIndications);
457                    	}
458                    	
459                    	virtual void deliver(const OperationContext & context, const Array<CIMIndication> & cimIndications)
460                    	{
461                    		for(Uint32 i = 0, n = cimIndications.size(); i < n; i++)
462                    		{
463                    			deliver(context, cimIndications[i]);
464                    		}
465                    	}
466                    	
467                    private:
468                    	CIMEnableIndicationsRequestMessage _request_copy;
469 brian.campbell 1.9 	CIMEnableIndicationsResponseMessage _response_copy;
470                    	PEGASUS_INDICATION_CALLBACK _indicationCallback;
471 schuur         1.1 
472 brian.campbell 1.9 };
473 schuur         1.1 
474 brian.campbell 1.9 #undef PEGASUS_RESPONSE_HANDLER_DERIVED_INIT
475 schuur         1.1 
476                    PEGASUS_NAMESPACE_END
477                    
478                    #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2