(file) Return to CIMOMSampleProvider.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / test / TestProviders / CIMOMSample

  1 karl  1.3 //%2006////////////////////////////////////////////////////////////////////////
  2 s.soni 1.1 //
  3 karl   1.2 // 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 s.soni 1.1 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl   1.2 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9            // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl   1.3 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 s.soni 1.1 //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            // 
 21            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            // Author: <Subodh Soni> (<ssubodh@in.ibm.com>)
 33            //
 34 s.soni 1.1 // Modified By:
 35            //
 36            //%/////////////////////////////////////////////////////////////////////////////
 37            
 38            #include <stdio.h>
 39            #include <iostream>
 40            #include "CIMOMSampleProvider.h"
 41            #include <Pegasus/Common/Config.h>
 42            #include <Pegasus/Common/String.h>
 43            #include <Pegasus/Common/Constants.h>
 44            #include <Pegasus/Common/CIMDateTime.h>
 45            #include <Pegasus/Common/OperationContextInternal.h>
 46            #include <Pegasus/Common/InternalException.h>
 47            
 48            PEGASUS_NAMESPACE_BEGIN
 49            PEGASUS_USING_STD;
 50            
 51            CIMOMSampleProvider::CIMOMSampleProvider(void)
 52            {
 53            }
 54            
 55 s.soni 1.1 CIMOMSampleProvider::~CIMOMSampleProvider(void)
 56            {
 57            }
 58            
 59            void CIMOMSampleProvider::initialize(CIMOMHandle & cimom)
 60            {
 61                cout <<" CIMOMSampleProvider::initialize" << endl;
 62            	
 63                // create some instances
 64            	
 65                CIMInstance instance1("CIMOMSample");
 66                CIMObjectPath reference1("CIMOMSample.Id=187");
 67            
 68                instance1.addProperty(CIMProperty("Id", Uint16(100)));
 69            
 70                _instances.append(instance1);
 71                _instanceNames.append(reference1);
 72            
 73            }
 74            
 75            void CIMOMSampleProvider::terminate(void)
 76 s.soni 1.1 {
 77            }
 78            
 79            void CIMOMSampleProvider::getInstance(
 80            	const OperationContext & context,
 81            	const CIMObjectPath & instanceReference,
 82            	const Boolean includeQualifiers,
 83            	const Boolean includeClassOrigin,
 84            	const CIMPropertyList & propertyList,
 85            	InstanceResponseHandler & handler)
 86            {
 87            	// convert a potential fully qualified reference into a local reference
 88            	// (class name and keys only).
 89            	CIMObjectPath localReference = CIMObjectPath(
 90            		String(),
 91            		String(),
 92            		instanceReference.getClassName(),
 93            		instanceReference.getKeyBindings());
 94            
 95            	CIMName className = instanceReference.getClassName();
 96            	//cout << "className(Method: getInstance)" <<className;
 97 s.soni 1.1 	
 98            	    // instance index corresponds to reference index
 99            	    for(Uint32 i = 0, n = _instances.size(); i < n; i++)
100            	    {
101            	        if(localReference == _instanceNames[i])
102            	        {
103            		    // deliver requested instance
104            		    handler.deliver(_instances[i]);
105            		    break;
106            	        }
107            	    }
108            	// complete processing the request
109            	handler.complete();
110            }
111            
112            void CIMOMSampleProvider::enumerateInstances(
113            	const OperationContext & context,
114            	const CIMObjectPath & classReference,
115            	const Boolean includeQualifiers,
116            	const Boolean includeClassOrigin,
117            	const CIMPropertyList & propertyList,
118 s.soni 1.1 	InstanceResponseHandler & handler)
119            {
120            	OperationContext localContext;
121            	cout << "CIMOMSampleProvider::enumerateInstances" << endl;	
122            	// announce operation processing.
123            	handler.processing();
124            
125            	// OperationContext Identity related statements. What will happen
126            	// if we change the User identity at this point ?
127            	//
128            	// Update from TechCall: This seems to be a problem which is a major
129            	// security issue at this point of time in Pegasus and also a bugzilla
130            	// record exists for this problem. Not changing as of now.
131            
132            	String user("subodh");
133            	cout << " User (Initialized here statically) = " << user;
134            	
135            	IdentityContainer container = context.get(IdentityContainer::NAME);
136            	cout << " User in context passed to the method (container.getUserName) = "<< container.getUserName()<< endl;
137            	
138            	// Changing the UserIdentity in OperationContext
139 s.soni 1.1 	localContext.insert(IdentityContainer(user));
140            	container = localContext.get(IdentityContainer::NAME);
141            
142            	cout << " User in localContext (container.getUserName) = "<< container.getUserName()<< endl;
143            
144            	// begin processing the request
145            	handler.processing();
146            	
147            	if (String::equal(user, container.getUserName()))
148            	{
149            	    for(Uint32 i = 0, n = _instances.size(); i < n; i++)
150            	    // deliver instance
151                        handler.deliver(_instances[i]);
152                }	    
153                else
154            	{
155            	    cout << "User should be " << user << "but its " << container.getUserName() << endl;
156            	    throw(CIM_ERR_INVALID_PARAMETER);
157                    }
158            	// complete processing the request
159            	handler.complete();
160 s.soni 1.1 }
161            
162            void CIMOMSampleProvider::enumerateInstanceNames(
163            	const OperationContext & context,
164            	const CIMObjectPath & classReference,
165            	ObjectPathResponseHandler & handler)
166            {
167            	cout << "CIMOMSampleProvider::enumerateInstanceNames" << endl;	
168            	// begin processing the request
169            
170            	CIMName clName = classReference.getClassName();
171            	handler.processing();
172            
173            	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
174            		// deliver reference
175            		handler.deliver(_instanceNames[i]);
176            
177            	// complete processing the request
178            	handler.complete();
179            }
180            
181 s.soni 1.1 void CIMOMSampleProvider::modifyInstance(
182            	const OperationContext & context,
183            	const CIMObjectPath & instanceReference,
184            	const CIMInstance & instanceObject,
185            	const Boolean includeQualifiers,
186            	const CIMPropertyList & propertyList,
187            	ResponseHandler & handler)
188            {
189            	cout << "CIMOMSampleProvider::modifyInstance" << endl;	
190            	// convert a potential fully qualified reference into a local reference
191            	// (class name and keys only).
192            	CIMObjectPath localReference = CIMObjectPath(
193            		String(),
194            		String(),
195            		instanceReference.getClassName(),
196            		instanceReference.getKeyBindings());
197            
198            	// begin processing the request
199            	handler.processing();
200            
201            	// instance index corresponds to reference index
202 s.soni 1.1 	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
203            	{
204            		if(localReference == _instanceNames[i])
205            		{
206            			// overwrite existing instance
207            			_instances[i] = instanceObject;
208            
209            			break;
210            		}
211            	}
212            	// complete processing the request
213            	handler.complete();
214            }
215            
216            void CIMOMSampleProvider::createInstance(
217            	const OperationContext & context,
218            	const CIMObjectPath & instanceReference,
219            	const CIMInstance & instanceObject,
220            	ObjectPathResponseHandler & handler)
221            {
222            	cout << "CIMOMSampleProvider::createInstance" << endl;	
223 s.soni 1.1 	// convert a potential fully qualified reference into a local reference
224            	// (class name and keys only).
225            	CIMObjectPath localReference = CIMObjectPath(
226            		String(),
227            		String(),
228            		instanceReference.getClassName(),
229            		instanceReference.getKeyBindings());
230            
231            	// instance index corresponds to reference index
232            	for(Uint32 i = 0, n = _instanceNames.size(); i < n; i++)
233            	{
234            		if(localReference == _instanceNames[i])
235            		{
236            			throw CIMObjectAlreadyExistsException(
237                                              localReference.toString());
238            		}
239            	}
240            
241            	// begin processing the request
242            	handler.processing();
243            
244 s.soni 1.1 	// add the new instance to the array
245            	_instances.append(instanceObject);
246            	_instanceNames.append(instanceReference);
247            
248            	// deliver the new instance
249            	handler.deliver(_instanceNames[_instanceNames.size() - 1]);
250            
251            	// complete processing the request
252            	handler.complete();
253            }
254            
255            void CIMOMSampleProvider::deleteInstance(
256            	const OperationContext & context,
257            	const CIMObjectPath & instanceReference,
258            	ResponseHandler & handler)
259            {
260            	cout << "CIMOMSampleProvider::deleteInstance" << endl;	
261            	// convert a potential fully qualified reference into a local reference
262            	// (class name and keys only).
263            	CIMObjectPath localReference = CIMObjectPath(
264            		String(),
265 s.soni 1.1 		String(),
266            		instanceReference.getClassName(),
267            		instanceReference.getKeyBindings());
268            
269            	// begin processing the request
270            	handler.processing();
271            
272            	// instance index corresponds to reference index
273            	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
274            	{
275            		if(localReference == _instanceNames[i])
276            		{
277            			// save the instance locally
278            			CIMInstance cimInstance(_instances[i]);
279            
280            			// remove instance from the array
281            			_instances.remove(i);
282            			_instanceNames.remove(i);
283            
284            			// exit loop
285            			break;
286 s.soni 1.1 		}
287            	}
288            
289            	// complete processing the request
290            	handler.complete();
291            }
292            
293            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2