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 "LargeDataProvider.h"
41 #include <Pegasus/Common/Config.h>
42 #include <Pegasus/Common/Constants.h>
43 #include <Pegasus/Common/CIMDateTime.h>
44
45 PEGASUS_USING_STD;
46 #ifndef NO_OF_INSTANCES
47 #define NO_OF_INSTANCES 100
48 #endif
49
50 PEGASUS_NAMESPACE_BEGIN
51
52 LargeDataProvider::LargeDataProvider(void)
53 {
54 }
55 s.soni 1.1
56 LargeDataProvider::~LargeDataProvider(void)
57 {
58 }
59
60 void LargeDataProvider::initialize(CIMOMHandle & cimom)
61 {
62 cout << "-----------------------------" << endl;
63 cout << "LargeDataProvider::initialize" << endl;
64 cout << "-----------------------------" << endl;
65 }
66
67 void LargeDataProvider::terminate(void)
68 {
69 // Supporting Large data handling.
70 }
71
72 void LargeDataProvider::getInstance(
73 const OperationContext & context,
74 const CIMObjectPath & instanceReference,
75 const Boolean includeQualifiers,
76 s.soni 1.1 const Boolean includeClassOrigin,
77 const CIMPropertyList & propertyList,
78 InstanceResponseHandler & handler)
79 {
80 cout << "------------------------------" << endl;
81 cout << "LargeDataProvider::getInstance" << endl;
82 cout << "------------------------------" << endl;
83 // convert a potential fully qualified reference into a local reference
84 // (class name and keys only).
85 CIMObjectPath localReference = CIMObjectPath(
86 String(),
87 String(),
88 instanceReference.getClassName(),
89 instanceReference.getKeyBindings());
90
91 // begin processing the request
92 handler.processing();
93
94 // instance index corresponds to reference index
95 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
96 {
97 s.soni 1.1 if(localReference == _instanceNames[i])
98 {
99 // deliver requested instance
100 handler.deliver(_instances[i]);
101 break;
102 }
103 }
104 // complete processing the request
105 handler.complete();
106 }
107
108 void LargeDataProvider::enumerateInstances(
109 const OperationContext & context,
110 const CIMObjectPath & classReference,
111 const Boolean includeQualifiers,
112 const Boolean includeClassOrigin,
113 const CIMPropertyList & propertyList,
114 InstanceResponseHandler & handler)
115 {
116 char buffer[NO_OF_INSTANCES];
117 CIMInstance Instances[NO_OF_INSTANCES];
118 s.soni 1.1 CIMObjectPath References[NO_OF_INSTANCES];
119
120 cout << "-------------------------------------" << endl;
121 cout << "LargeDataProvider::enumerateInstances" << endl;
122 cout << "-------------------------------------" << endl;
123
124 // announce operation processing.
125 handler.processing();
126
127 // creating some instances in a loop for generating a large amount of data
128 // The number of instances is controlled by the macro var. NO_OF_INSTANCES.
129 // TODO:: Need to fix the way in which the value of this variable is passed
130
131 cout << "Number of Instances = " << NO_OF_INSTANCES << endl;
132 for (Uint32 i = 0; i < NO_OF_INSTANCES; i++)
133 {
134 sprintf(buffer, "%d", i);
135
136 Instances[i] = CIMInstance("SampleClass");
137 References[i] = CIMObjectPath("SampleClass.Id="+String(buffer));
138
139 s.soni 1.1 Instances[i].addProperty(CIMProperty("Id", Uint16(i)));
140 Instances[i].addProperty(CIMProperty("Message", String(buffer)));
141 Instances[i].addProperty(CIMProperty("ReqType", String("Local")));
142 Instances[i].addProperty(CIMProperty("RequestNumber", Uint16(i+10)));
143 Instances[i].addProperty(CIMProperty("TimeSpent", Uint16(i+2)));
144 Instances[i].addProperty(CIMProperty("TimeIdeal", Uint16(100)));
145 Instances[i].addProperty(CIMProperty("Performance", String("OK \00><\00")));
146 Instances[i].addProperty(CIMProperty("EndPoint",
147 String("Instance "+String(buffer)+" Ends")));
148
149 _instances.append(Instances[i]);
150 _instanceNames.append(References[i]);
151 }
152
153 for(Uint32 i = 0; i < NO_OF_INSTANCES; i++)
154 // deliver instance
155 handler.deliver(_instances[i]);
156
157 // complete processing the request
158 handler.complete();
159 }
160 s.soni 1.1
161 void LargeDataProvider::enumerateInstanceNames(
162 const OperationContext & context,
163 const CIMObjectPath & classReference,
164 ObjectPathResponseHandler & handler)
165 {
166 cout << "-----------------------------------------" << endl;
167 cout << "LargeDataProvider::enumerateInstanceNames" << endl;
168 cout << "-----------------------------------------" << endl;
169 // begin processing the request
170 handler.processing();
171 cout << "_instances.size = " << _instances.size() << endl;
172 for(Uint32 i = 0; i < _instances.size(); i++)
173 // deliver references
174 handler.deliver(_instanceNames[i]);
175
176 // complete processing the request
177 handler.complete();
178 }
179
180 void LargeDataProvider::modifyInstance(
181 s.soni 1.1 const OperationContext & context,
182 const CIMObjectPath & instanceReference,
183 const CIMInstance & instanceObject,
184 const Boolean includeQualifiers,
185 const CIMPropertyList & propertyList,
186 ResponseHandler & handler)
187 {
188 cout << "---------------------------------" << endl;
189 cout << "LargeDataProvider::modifyInstance" << endl;
190 cout << "---------------------------------" << endl;
191 // convert a potential fully qualified reference into a local reference
192 // (class name and keys only).
193 CIMObjectPath localReference = CIMObjectPath(
194 String(),
195 String(),
196 instanceReference.getClassName(),
197 instanceReference.getKeyBindings());
198
199 // begin processing the request
200 handler.processing();
201
202 s.soni 1.1 // instance index corresponds to reference index
203 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
204 {
205 if(localReference == _instanceNames[i])
206 {
207 // overwrite existing instance
208 _instances[i] = instanceObject;
209 break;
210 }
211 }
212
213 // complete processing the request
214 handler.complete();
215 }
216
217 void LargeDataProvider::createInstance(
218 const OperationContext & context,
219 const CIMObjectPath & instanceReference,
220 const CIMInstance & instanceObject,
221 ObjectPathResponseHandler & handler)
222 {
223 s.soni 1.1 cout << "---------------------------------" << endl;
224 cout << "LargeDataProvider::createInstance" << endl;
225 cout << "---------------------------------" << endl;
226
227 // convert a potential fully qualified reference into a local reference
228 // (class name and keys only).
229 CIMObjectPath localReference = CIMObjectPath(
230 String(),
231 String(),
232 instanceReference.getClassName(),
233 instanceReference.getKeyBindings());
234
235 // instance index corresponds to reference index
236 for(Uint32 i = 0, n = _instanceNames.size(); i < n; i++)
237 {
238 if(localReference == _instanceNames[i])
239 {
240 throw CIMObjectAlreadyExistsException(
241 localReference.toString());
242 }
243 }
244 s.soni 1.1
245 // begin processing the request
246 handler.processing();
247
248 // add the new instance to the array
249 _instances.append(instanceObject);
250 _instanceNames.append(instanceReference);
251
252 // deliver the new instance
253 handler.deliver(_instanceNames[_instanceNames.size() - 1]);
254
255 // complete processing the request
256 handler.complete();
257 }
258
259 void LargeDataProvider::deleteInstance(
260 const OperationContext & context,
261 const CIMObjectPath & instanceReference,
262 ResponseHandler & handler)
263 {
264 cout << "---------------------------------" << endl;
265 s.soni 1.1 cout << "LargeDataProvider::deleteInstance" << endl;
266 cout << "---------------------------------" << endl;
267 // convert a potential fully qualified reference into a local reference
268 // (class name and keys only).
269 CIMObjectPath localReference = CIMObjectPath(
270 String(),
271 String(),
272 instanceReference.getClassName(),
273 instanceReference.getKeyBindings());
274
275 // begin processing the request
276 handler.processing();
277
278 // instance index corresponds to reference index
279 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
280 {
281 if(localReference == _instanceNames[i])
282 {
283 // save the instance locally
284 CIMInstance cimInstance(_instances[i]);
285
286 s.soni 1.1 // remove instance from the array
287 _instances.remove(i);
288 _instanceNames.remove(i);
289
290 // exit loop
291 break;
292 }
293 }
294
295 // complete processing the request
296 handler.complete();
297 }
298
299 PEGASUS_NAMESPACE_END
|