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

  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            // IBM Corp.; EMC Corporation, The Open Group.
  7            // 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 karl   1.2 // 
 21 s.soni 1.1 // 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 karl   1.2 //==============================================================================
 31 s.soni 1.1 //
 32            // Author: Subodh Soni IBM Corporation, (ssubodh@in.ibm.com)
 33            //
 34            // Modified By:
 35            //             
 36            //             
 37            //
 38            //%////////////////////////////////////////////////////////////////////////////
 39            
 40            #include <stdio.h>
 41            #include <unistd.h>
 42            #include <iostream>
 43            #include <Pegasus/Common/String.h>
 44            #include <Pegasus/Common/InternalException.h>
 45            #include "TimingProvider.h"
 46            
 47            PEGASUS_NAMESPACE_BEGIN
 48            PEGASUS_USING_STD;
 49            
 50            #define PEGASUS_USE_DEPRECATED_INTERFACES
 51            TimingProvider::TimingProvider(void)
 52 s.soni 1.1 {
 53            }
 54            
 55            TimingProvider::~TimingProvider(void)
 56            {
 57            }
 58            
 59            void TimingProvider::initialize(CIMOMHandle & cimom)
 60            {
 61            	cout <<" TimingProvider::initialize" << endl;
 62            
 63            	// Create Instances for TimeOne Class
 64                CIMInstance instance1("TimeOne");
 65                CIMObjectPath reference1("TimeOne.Id=1");
 66            
 67                instance1.addProperty(CIMProperty("Id", Uint8(1)));   // key
 68                instance1.addProperty(CIMProperty("Message", String("Class One I1")));
 69            
 70                _instances.append(instance1);
 71                _instanceNames.append(reference1);
 72            
 73 s.soni 1.1 
 74                CIMInstance instance2("TimeOne");
 75                CIMObjectPath reference2("TimeOne.Id=2");
 76            
 77                instance2.addProperty(CIMProperty("Id", Uint8(2)));   // key
 78                instance2.addProperty(CIMProperty("Message", String("Class One I2")));
 79            
 80                _instances.append(instance2);
 81                _instanceNames.append(reference2);
 82            
 83            	// Create Instances for TimeTwo Class
 84            	 CIMInstance instance_1("TimeTwo");
 85            	 CIMObjectPath reference_1("TimeTwo.Srno=22");
 86            
 87                instance_1.addProperty(CIMProperty("Srno", Uint8(1)));   // key
 88                instance_1.addProperty(CIMProperty("TimeVar", Uint16(1111)));
 89                _instances_2.append(instance_1);
 90                _instanceNames_2.append(reference_1);
 91            
 92                CIMInstance instance_2("TimeTwo");
 93                CIMObjectPath reference_2("TimeTwo.Srno=2");
 94 s.soni 1.1 
 95                instance_2.addProperty(CIMProperty("Srno", Uint8(2)));   // key
 96                instance_2.addProperty(CIMProperty("TimeVar", Uint16(2222)));
 97            
 98                _instances_2.append(instance_2);
 99                _instanceNames_2.append(reference_2);
100            }
101            
102            void TimingProvider::terminate(void)
103            {
104            	cout <<" TimingProvider::terminate" << endl;
105            }
106            
107            void TimingProvider::getInstance(
108            	const OperationContext & context,
109            	const CIMObjectPath & instanceReference,
110            	const Boolean includeQualifiers,
111            	const Boolean includeClassOrigin,
112            	const CIMPropertyList & propertyList,
113            	InstanceResponseHandler & handler)
114            {
115 s.soni 1.1 	// convert a potential fully qualified reference into a local reference
116            	// (class name and keys only).
117            	CIMObjectPath localReference = CIMObjectPath(
118            		String(),
119            		String(),
120            		instanceReference.getClassName(),
121            		instanceReference.getKeyBindings());
122            
123            	CIMName className = instanceReference.getClassName();
124            	
125            	// begin processing the request
126            	handler.processing();
127            	
128            	// instance index corresponds to reference index
129            	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
130            	{
131            		if(localReference == _instanceNames[i])
132            		{
133            			// deliver requested instance
134            			handler.deliver(_instances[i]);
135            
136 s.soni 1.1 			break;
137            		}
138            	}
139            	// complete processing the request
140            	handler.complete();
141            }
142            
143            void TimingProvider::enumerateInstances(
144            	const OperationContext & context,
145            	const CIMObjectPath & classReference,
146            	const Boolean includeQualifiers,
147            	const Boolean includeClassOrigin,
148            	const CIMPropertyList & propertyList,
149            	InstanceResponseHandler & handler)
150            {
151            	cout <<"TimingProvider::enumerateInstances" << endl;
152            	CIMName cn = classReference.getClassName();
153            
154            	String className = cn.getString();
155            	sleep(15);
156            	// cout << "className = " << className << endl;
157 s.soni 1.1 	// Create Instances for TimeOne Class
158            	if (String::equalNoCase(className, "TimeOne"))
159            	{
160            		sleep(5);
161            		// announce operation processing.
162            		handler.processing();
163            		for(Uint32 i = 0, n = _instances.size(); i < n; i++)
164            			// deliver instance
165            			handler.deliver(_instances[i]);
166            	}
167            	// Create Instances for SecondClass
168            	if (String::equalNoCase(className, "TimeTwo"))
169            	{
170            		handler.processing();
171            		sleep(5);
172            
173            		for(Uint32 i = 0, n = _instances_2.size(); i < n; i++)
174            			// deliver instance
175            			handler.deliver(_instances_2[i]);
176            	}
177            	// complete processing the request
178 s.soni 1.1 	handler.complete();
179            }
180            
181            void TimingProvider::enumerateInstanceNames(
182            	const OperationContext & context,
183            	const CIMObjectPath & classReference,
184            	ObjectPathResponseHandler & handler)
185            {
186            	// begin processing the request
187            	handler.processing();
188            	cout <<"TimingProvider::enumerateInstanceNames" << endl;
189            	CIMName clName = classReference.getClassName();
190            	
191            	sleep(10);
192            	if (clName == "TimeOne")
193            	{
194            		for(Uint32 i = 0, n = _instances.size(); i < n; i++)
195            			// deliver reference
196            			handler.deliver(_instanceNames[i]);
197            	}	
198            	else if (clName == "TimeTwo")
199 s.soni 1.1 	{
200            		for(Uint32 i = 0, n = _instances_2.size(); i < n; i++)
201            			// deliver reference
202            			handler.deliver(_instanceNames_2[i]);
203            	}	
204            	// complete processing the request
205            	cout <<"TimingProvider::enumerateInstanceNames" << endl;
206            	handler.complete();
207            }
208            
209            void TimingProvider::modifyInstance(
210            	const OperationContext & context,
211            	const CIMObjectPath & instanceReference,
212            	const CIMInstance & instanceObject,
213            	const Boolean includeQualifiers,
214            	const CIMPropertyList & propertyList,
215            	ResponseHandler & handler)
216            {
217            	// convert a potential fully qualified reference into a local reference
218            	// (class name and keys only).
219            	CIMObjectPath localReference = CIMObjectPath(
220 s.soni 1.1 		String(),
221            		String(),
222            		instanceReference.getClassName(),
223            		instanceReference.getKeyBindings());
224            	cout <<"TimingProvider::modifyInstance" << endl;
225            	// begin processing the request
226            	handler.processing();
227            
228            	// instance index corresponds to reference index
229            	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
230            	{
231            		if(localReference == _instanceNames[i])
232            		{
233            			// overwrite existing instance
234            			_instances[i] = instanceObject;
235            
236            			break;
237            		}
238            	}
239            	// complete processing the request
240            	handler.complete();
241 s.soni 1.1 }
242            
243            void TimingProvider::createInstance(
244            	const OperationContext & context,
245            	const CIMObjectPath & instanceReference,
246            	const CIMInstance & instanceObject,
247            	ObjectPathResponseHandler & handler)
248            {
249            	// convert a potential fully qualified reference into a local reference
250            	// (class name and keys only).
251            	CIMObjectPath localReference = CIMObjectPath(
252            		String(),
253            		String(),
254            		instanceReference.getClassName(),
255            		instanceReference.getKeyBindings());
256            
257            	cout <<"TimingProvider::createInstance" << endl;
258            	// instance index corresponds to reference index
259            	for(Uint32 i = 0, n = _instanceNames.size(); i < n; i++)
260            	{
261            		if(localReference == _instanceNames[i])
262 s.soni 1.1 		{
263            			throw CIMObjectAlreadyExistsException(
264                                              localReference.toString());
265            		}
266            	}
267            	// begin processing the request
268            	handler.processing();
269            	// add the new instance to the array
270            	_instances.append(instanceObject);
271            	_instanceNames.append(instanceReference);
272            
273            	cout <<"TimingProvider::createInstance" << endl;
274            	// deliver the new instance
275            	handler.deliver(_instanceNames[_instanceNames.size() - 1]);
276            
277            	// complete processing the request
278            	handler.complete();
279            }
280            
281            void TimingProvider::deleteInstance(
282            	const OperationContext & context,
283 s.soni 1.1 	const CIMObjectPath & instanceReference,
284            	ResponseHandler & handler)
285            {
286            	// convert a potential fully qualified reference into a local reference
287            	// (class name and keys only).
288            	CIMObjectPath localReference = CIMObjectPath(
289            		String(),
290            		String(),
291            		instanceReference.getClassName(),
292            		instanceReference.getKeyBindings());
293            
294            	// begin processing the request
295            	handler.processing();
296            
297            	cout <<"TimingProvider::deleteInstance" << endl;
298            	// instance index corresponds to reference index
299            	for(Uint32 i = 0, n = _instances.size(); i < n; i++)
300            	{
301            		if(localReference == _instanceNames[i])
302            		{
303            			// save the instance locally
304 s.soni 1.1 			CIMInstance cimInstance(_instances[i]);
305            
306            			// remove instance from the array
307            			_instances.remove(i);
308            			_instanceNames.remove(i);
309            
310            			// exit loop
311            			break;
312            		}
313            	}
314            
315            	cout <<"TimingProvider::deleteInstance" << endl;
316            	// complete processing the request
317            	handler.complete();
318            }
319            
320            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2