(file) Return to ProviderFacade.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / Default

  1 karl  1.4 //%2003////////////////////////////////////////////////////////////////////////
  2 chip  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 chip  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 karl  1.4 // 
 15 chip  1.1 // 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           // Author: Chip Vincent (cvincent@us.ibm.com)
 27           //
 28           // Modified By: Markus Mueller (sedgewick_de@yahoo.de)
 29           //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 30           //              Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 31           //              Sushma Fernandes, Hewlett-Packard Company
 32           //                  (sushma_fernandes@hp.com)
 33           //              Mike Day, IBM (mdday@us.ibm.com)
 34 chip  1.3 //              Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 35 chip  1.1 //
 36           //%/////////////////////////////////////////////////////////////////////////////
 37           
 38           #include "ProviderFacade.h"
 39           
 40           #include <Pegasus/Common/InternalException.h>
 41           #include <Pegasus/Common/Destroyer.h>
 42 chip  1.3 #include <Pegasus/Common/MessageLoader.h>
 43 chip  1.1 
 44 schuur 1.7 #include <Pegasus/ProviderManager2/SimpleResponseHandler.h>
 45 chip   1.1 
 46            PEGASUS_NAMESPACE_BEGIN
 47            
 48            class op_counter
 49            {
 50            public:
 51                op_counter(AtomicInt *counter)
 52                : _counter(counter)
 53                {
 54                    (*_counter)++;
 55                }
 56                ~op_counter(void)
 57                {
 58                    (*_counter)--;
 59                }
 60            private:
 61                op_counter(void);
 62                AtomicInt *_counter;
 63            };
 64            
 65            
 66 chip   1.1 template<class T>
 67            inline T * getInterface(CIMProvider * provider)
 68            {
 69                T * p = dynamic_cast<T *>(provider);
 70            
 71                if(p == 0)
 72                {
 73                    //l10n
 74                    //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "Invalid provider interface.");
 75                    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms(
 76                        "ProviderManager.ProviderFacade.INVALID_PROVIDER_INTERFACE",
 77                        "Invalid provider interface."));
 78                }
 79            
 80                return(p);
 81            }
 82            
 83            ProviderFacade::ProviderFacade(CIMProvider * provider) : _provider(provider)
 84            {
 85 schuur 1.8    _indications_enabled=false;
 86 chip   1.1 }
 87            
 88            ProviderFacade::~ProviderFacade(void)
 89            {
 90            }
 91            
 92            void ProviderFacade::initialize(CIMOMHandle & cimom)
 93            {
 94                _provider->initialize(cimom);
 95            }
 96            
 97 kumpf  1.2 #ifdef PEGASUS_PRESERVE_TRYTERMINATE
 98 chip   1.1 Boolean ProviderFacade::tryTerminate(void)
 99            {
100                return(_provider->tryTerminate());
101            }
102 kumpf  1.2 #endif
103 chip   1.1 
104            void ProviderFacade::terminate(void)
105            {
106                _provider->terminate();
107            }
108            
109            void ProviderFacade::getInstance(
110                const OperationContext & context,
111                const CIMObjectPath & instanceReference,
112                const Boolean includeQualifiers,
113                const Boolean includeClassOrigin,
114                const CIMPropertyList & propertyList,
115                InstanceResponseHandler & handler)
116            {
117                op_counter ops(&_current_operations);
118            
119                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
120            
121                // forward request
122                provider->getInstance(
123                    context,
124 chip   1.1         instanceReference,
125                    includeQualifiers,
126                    includeClassOrigin,
127                    propertyList,
128                    handler);
129            
130            }
131            
132            void ProviderFacade::enumerateInstances(
133                const OperationContext & context,
134                const CIMObjectPath & classReference,
135                const Boolean includeQualifiers,
136                const Boolean includeClassOrigin,
137                const CIMPropertyList & propertyList,
138                InstanceResponseHandler & handler)
139            {
140                op_counter ops(&_current_operations);
141                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
142            
143                // forward request
144                provider->enumerateInstances(
145 chip   1.1         context,
146                    classReference,
147                    includeQualifiers,
148                    includeClassOrigin,
149                    propertyList,
150                    handler);
151            
152                // try enumerateInstanceNames and getInstance if not supported
153            }
154            
155            void ProviderFacade::enumerateInstanceNames(
156                const OperationContext & context,
157                const CIMObjectPath & classReference,
158                ObjectPathResponseHandler & handler)
159            {
160                op_counter ops(&_current_operations);
161                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
162            
163                // forward request
164                provider->enumerateInstanceNames(
165                    context,
166 chip   1.1         classReference,
167                    handler);
168            
169                // try enumerateInstances if not supported
170            }
171            
172            void ProviderFacade::modifyInstance(
173                const OperationContext & context,
174                const CIMObjectPath & instanceReference,
175                const CIMInstance & instanceObject,
176                const Boolean includeQualifiers,
177                const CIMPropertyList & propertyList,
178                ResponseHandler & handler)
179            {
180                op_counter ops(&_current_operations);
181                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
182            
183                // forward request
184                provider->modifyInstance(
185                    context,
186                    instanceReference,
187 chip   1.1         instanceObject,
188                    includeQualifiers,
189                    propertyList,
190                    handler);
191            }
192            
193            void ProviderFacade::createInstance(
194                const OperationContext & context,
195                const CIMObjectPath & instanceReference,
196                const CIMInstance & instanceObject,
197                ObjectPathResponseHandler & handler)
198            {
199                op_counter ops(&_current_operations);
200                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
201            
202                // forward request
203                provider->createInstance(
204                    context,
205                    instanceReference,
206                    instanceObject,
207                    handler);
208 chip   1.1 }
209            
210            void ProviderFacade::deleteInstance(
211                const OperationContext & context,
212                const CIMObjectPath & instanceReference,
213                ResponseHandler & handler)
214            {
215                op_counter ops(&_current_operations);
216                CIMInstanceProvider * provider = getInterface<CIMInstanceProvider>(_provider);
217            
218                // forward request
219                provider->deleteInstance(
220                    context,
221                    instanceReference,
222                    handler);
223            }
224            
225 schuur 1.5 void ProviderFacade::execQuery(
226                const OperationContext & context,
227                const CIMObjectPath & nameSpaceAndClass,
228                const QueryExpression & query,
229                InstanceResponseHandler & handler)
230            {
231                op_counter ops(&_current_operations);
232                CIMInstanceQueryProvider *provider =
233                           getInterface<CIMInstanceQueryProvider>(_provider);
234               // forward request
235                provider->execQuery(
236                    context,
237                    nameSpaceAndClass,
238                    query,
239                    handler);
240            }
241            
242            
243 chip   1.1 void ProviderFacade::associators(
244                const OperationContext & context,
245                const CIMObjectPath & objectName,
246                const CIMName & associationClass,
247                const CIMName & resultClass,
248                const String & role,
249                const String & resultRole,
250                const Boolean includeQualifiers,
251                const Boolean includeClassOrigin,
252                const CIMPropertyList & propertyList,
253                ObjectResponseHandler & handler)
254            {
255                op_counter ops(&_current_operations);
256                CIMAssociationProvider * provider = getInterface<CIMAssociationProvider>(_provider);
257            
258                // forward request
259                provider->associators(
260                    context,
261                    objectName,
262                    associationClass,
263                    resultClass,
264 chip   1.1         role,
265                    resultRole,
266                    includeQualifiers,
267                    includeClassOrigin,
268                    propertyList,
269                    handler);
270            }
271            
272            void ProviderFacade::associatorNames(
273                const OperationContext & context,
274                const CIMObjectPath & objectName,
275                const CIMName & associationClass,
276                const CIMName & resultClass,
277                const String & role,
278                const String & resultRole,
279                ObjectPathResponseHandler & handler)
280            {
281                op_counter ops(&_current_operations);
282                CIMAssociationProvider * provider = getInterface<CIMAssociationProvider>(_provider);
283            
284                // forward request
285 chip   1.1     provider->associatorNames(
286                    context,
287                    objectName,
288                    associationClass,
289                    resultClass,
290                    role,
291                    resultRole,
292                    handler);
293            }
294            
295            void ProviderFacade::references(
296                const OperationContext & context,
297                const CIMObjectPath & objectName,
298                const CIMName & resultClass,
299                const String & role,
300                const Boolean includeQualifiers,
301                const Boolean includeClassOrigin,
302                const CIMPropertyList & propertyList,
303                ObjectResponseHandler & handler)
304            {
305                op_counter ops(&_current_operations);
306 chip   1.1     CIMAssociationProvider * provider = getInterface<CIMAssociationProvider>(_provider);
307            
308                // forward request
309                provider->references(
310                    context,
311                    objectName,
312                    resultClass,
313                    role,
314                    includeQualifiers,
315                    includeClassOrigin,
316                    propertyList,
317                    handler);
318            }
319            
320            void ProviderFacade::referenceNames(
321                const OperationContext & context,
322                const CIMObjectPath & objectName,
323                const CIMName & resultClass,
324                const String & role,
325                ObjectPathResponseHandler & handler)
326            {
327 chip   1.1     op_counter ops(&_current_operations);
328                CIMAssociationProvider * provider = getInterface<CIMAssociationProvider>(_provider);
329            
330                // forward request
331                provider->referenceNames(
332                    context,
333                    objectName,
334                    resultClass,
335                    role,
336                    handler);
337            }
338            
339            void ProviderFacade::getProperty(
340                const OperationContext & context,
341                const CIMObjectPath & instanceReference,
342                const CIMName & propertyName,
343                ValueResponseHandler & handler)
344            {
345                op_counter ops(&_current_operations);
346            
347 kumpf  1.9     // NOTE: Use the CIMInstanceProvider interface
348 chip   1.1     handler.processing();
349            
350                Array<CIMName> propertyList;
351            
352                propertyList.append(propertyName);
353            
354                SimpleInstanceResponseHandler instanceHandler;
355            
356                getInstance(
357                    context,
358                    instanceReference,
359                    false,  // includeQualifiers
360                    false,  // includeClassOrigin
361                    propertyList,
362                    instanceHandler);
363            
364                if(instanceHandler.getObjects().size())
365                {
366                    CIMInstance instance = instanceHandler.getObjects()[0];
367            
368                    Uint32 pos = instance.findProperty(propertyName);
369 chip   1.1 
370                    if(pos != PEG_NOT_FOUND)
371                    {
372                        handler.deliver(instance.getProperty(pos).getValue());
373                    }
374                    // Property not found. Return CIM_ERR_NO_SUCH_PROPERTY.
375                    else
376                    {
377                        handler.complete();
378                        throw PEGASUS_CIM_EXCEPTION(
379                            CIM_ERR_NO_SUCH_PROPERTY,
380                            propertyName.getString());
381                    }
382                }
383            
384                handler.complete();
385            }
386            
387            void ProviderFacade::setProperty(
388                const OperationContext & context,
389                const CIMObjectPath & instanceReference,
390 chip   1.1     const CIMName & propertyName,
391                const CIMValue & newValue,
392                ResponseHandler & handler)
393            {
394                op_counter ops(&_current_operations);
395            
396 kumpf  1.9     // NOTE: Use the CIMInstanceProvider interface
397 chip   1.1     handler.processing();
398            
399                CIMInstance instance(instanceReference.getClassName());
400            
401                instance.addProperty(CIMProperty(propertyName, newValue));
402            
403                Array<CIMName> propertyList;
404            
405                propertyList.append(propertyName);
406            
407                SimpleInstanceResponseHandler instanceHandler;
408            
409                modifyInstance(
410                    context,
411                    instanceReference,
412                    instance,
413                    false,  // includeQualifiers
414                    propertyList,
415                    instanceHandler);
416            
417                handler.complete();
418 chip   1.1 }
419            
420            void ProviderFacade::invokeMethod(
421                const OperationContext & context,
422                const CIMObjectPath & objectReference,
423                const CIMName & methodName,
424                const Array<CIMParamValue> & inParameters,
425                MethodResultResponseHandler & handler)
426            {
427                op_counter ops(&_current_operations);
428                CIMMethodProvider * provider = getInterface<CIMMethodProvider>(_provider);
429            
430                // forward request
431                provider->invokeMethod(
432                    context,
433                    objectReference,
434                    methodName,
435                    inParameters,
436                    handler);
437            }
438            
439 chip   1.1 void ProviderFacade::enableIndications(IndicationResponseHandler & handler)
440            {
441 schuur 1.6     _indications_enabled = true;
442                // _current_operations++;
443                op_counter ind_ops(&_current_operations);
444 chip   1.1 
445                CIMIndicationProvider * provider = getInterface<CIMIndicationProvider>(_provider);
446            
447                // forward request
448                provider->enableIndications(handler);
449            }
450            
451            void ProviderFacade::disableIndications(void)
452            {
453                CIMIndicationProvider * provider = getInterface<CIMIndicationProvider>(_provider);
454            
455                // forward request
456                provider->disableIndications();
457 schuur 1.6     _indications_enabled = false;
458                // _current_operations--;
459 chip   1.1 }
460            
461            void ProviderFacade::createSubscription(
462                const OperationContext & context,
463                const CIMObjectPath & subscriptionName,
464                const Array<CIMObjectPath> & classNames,
465                const CIMPropertyList & propertyList,
466                const Uint16 repeatNotificationPolicy)
467            {
468                op_counter ops(&_current_operations);
469 schuur 1.6 //    op_counter ind_ops(&_current_ind_operations);
470 chip   1.1     CIMIndicationProvider * provider = getInterface<CIMIndicationProvider>(_provider);
471            
472                // forward request
473                provider->createSubscription(
474                    context,
475                    subscriptionName,
476                    classNames,
477                    propertyList,
478                    repeatNotificationPolicy);
479            }
480            
481            void ProviderFacade::modifySubscription(
482                const OperationContext & context,
483                const CIMObjectPath & subscriptionName,
484                const Array<CIMObjectPath> & classNames,
485                const CIMPropertyList & propertyList,
486                const Uint16 repeatNotificationPolicy)
487            {
488                op_counter ops(&_current_operations);
489 schuur 1.6 //    op_counter ind_ops(&_current_ind_operations);
490 chip   1.1     CIMIndicationProvider * provider = getInterface<CIMIndicationProvider>(_provider);
491            
492                // forward request
493                provider->modifySubscription(
494                    context,
495                    subscriptionName,
496                    classNames,
497                    propertyList,
498                    repeatNotificationPolicy);
499            }
500            
501            void ProviderFacade::deleteSubscription(
502                const OperationContext & context,
503                const CIMObjectPath & subscriptionName,
504                const Array<CIMObjectPath> & classNames)
505            {
506                op_counter ops(&_current_operations);
507 chip   1.3 
508 schuur 1.6   //  op_counter ind_ops(&_current_ind_operations);
509 chip   1.3 
510 chip   1.1     CIMIndicationProvider * provider = getInterface<CIMIndicationProvider>(_provider);
511            
512                // forward request
513                provider->deleteSubscription(
514                    context,
515                    subscriptionName,
516                    classNames);
517            }
518            
519 chip   1.3 // CIMIndicationConsumerProvider interface
520 chip   1.1 void ProviderFacade::consumeIndication(
521                const OperationContext & context,
522 chip   1.3     const String & destinationPath,
523                const CIMInstance & indication)
524 chip   1.1 {
525                op_counter ops(&_current_operations);
526            
527 chip   1.3     CIMIndicationConsumerProvider * provider = getInterface<CIMIndicationConsumerProvider>(_provider);
528 chip   1.1 
529 chip   1.3     provider->consumeIndication(
530                    context,
531                    destinationPath,
532                    indication);
533 chip   1.1 }
534            
535            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2