os-cmpi-xen

view src/Xen_ProcessorPool.c @ 31:33d4316c01a2

Fixed compilation warings throughout the project. Nearly all files touched.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author jfehlig@jfehlig3.provo.novell.com
date Tue Oct 24 11:30:03 2006 -0600 (2006-10-24)
parents 16d625984bc4
children 75b18359b74d
line source
1 // Copyright (C) 2006 IBM Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
18 // Jim Fehlig, <jfehlig@novell.com>
19 // Contributors:
20 // Description:
21 // ============================================================================
23 /* Include the required CMPI data types, function headers, and macros */
24 #include "cmpidt.h"
25 #include "cmpift.h"
26 #include "cmpimacs.h"
28 #include "provider_common.h"
30 // ----------------------------------------------------------------------------
31 // COMMON GLOBAL VARIABLES
32 // ----------------------------------------------------------------------------
34 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
35 static const CMPIBroker *_BROKER;
37 /* Include utility functions */
38 #include "cmpiutil.h"
40 /* Include _SBLIM_TRACE() logging support */
41 #include "cmpitrace.h"
43 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
44 #include "Xen_ProcessorPool_Resource.h"
47 // ============================================================================
48 // CMPI INSTANCE PROVIDER FUNCTION TABLE
49 // ============================================================================
51 // ----------------------------------------------------------------------------
52 // Info for the class supported by the instance provider
53 // ----------------------------------------------------------------------------
55 /* Name of the class implemented by this instance provider. */
56 /*** CUSTOMIZE FOR EACH PROVIDER ***/
57 static char * _CLASSNAME = "Xen_ProcessorPool";
59 /* NULL terminated list of key properties of this class. */
60 /*** CUSTOMIZE FOR EACH PROVIDER ***/
61 const static char * _KEYNAMES[] = {"InstanceID", NULL};
63 // ----------------------------------------------------------------------------
64 // Cleanup()
65 // Perform any necessary cleanup immediately before this provider is unloaded.
66 // ----------------------------------------------------------------------------
67 static CMPIStatus Cleanup(
68 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
69 const CMPIContext * context, /* [in] Additional context info, if any. */
70 CMPIBoolean terminating) /* [in] True if MB is terminating */
71 {
72 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
74 _SBLIM_ENTER("Cleanup");
75 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
76 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
78 /* Nothing needs to be done for cleanup. */
79 _SBLIM_RETURNSTATUS(status);
80 }
82 // ----------------------------------------------------------------------------
83 // EnumInstanceNames()
84 // Return a list of all the instances names (return their object paths only).
85 // ----------------------------------------------------------------------------
86 static CMPIStatus EnumInstanceNames(
87 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
88 const CMPIContext * context, /* [in] Additional context info, if any. */
89 const CMPIResult * results, /* [out] Results of this operation. */
90 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
91 {
92 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
93 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
94 _RESOURCE * resource; /* Handle to each system resource. */
95 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
96 int found = 0; /* Found any instances? */
98 _SBLIM_ENTER("EnumInstanceNames");
99 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
100 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
101 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
102 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
104 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
105 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
106 goto exit;
107 }
109 /* Get a handle to the list of system resources. */
110 if (!Xen_ProcessorPool_getResources(&resources)) {
111 _SBLIM_TRACE(1,("--- _getResources() failed"));
112 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
113 goto exit;
114 }
116 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
117 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
118 /* Create a new CMPIInstance to store this resource. */
119 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
120 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
121 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
122 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
123 goto exit;
124 }
126 /* Set the instance property values from the resource data. */
127 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
128 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
129 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
130 goto exit;
131 }
133 /* Free the resource data. */
134 if (!Xen_ProcessorPool_freeResource(resource)) {
135 _SBLIM_TRACE(1,("--- _freeResource() failed"));
136 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
137 goto exit;
138 }
140 /* Return the CMPIObjectPath for this instance. */
141 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
142 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
143 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
144 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
145 goto exit;
146 }
147 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
149 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
150 CMReturnObjectPath(results, objectpath);
151 found++;
152 }
154 _SBLIM_TRACE(2,("--- %d object paths found", found));
155 CMReturnDone(results);
157 exit:
158 /* Free the list of system resources. */
159 if (!Xen_ProcessorPool_freeResources(resources)) {
160 _SBLIM_TRACE(1,("--- _freeResources() failed"));
161 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
162 }
164 _SBLIM_RETURNSTATUS(status);
165 }
167 // ----------------------------------------------------------------------------
168 // EnumInstances()
169 // Return a list of all the instances (return all the instance data).
170 // ----------------------------------------------------------------------------
171 static CMPIStatus EnumInstances(
172 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
173 const CMPIContext * context, /* [in] Additional context info, if any. */
174 const CMPIResult * results, /* [out] Results of this operation. */
175 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
176 const char ** properties) /* [in] List of desired properties (NULL=all). */
177 {
178 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
179 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
180 _RESOURCE * resource; /* Handle to each system resource. */
181 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
182 int found = 0; /* Found any resource instances? */
184 _SBLIM_ENTER("EnumInstances");
185 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
186 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
187 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
188 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
190 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
191 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
192 goto exit;
193 }
195 /* Get a handle to the list of system resources. */
196 if (!Xen_ProcessorPool_getResources(&resources)) {
197 _SBLIM_TRACE(1,("--- _getResources() failed"));
198 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
199 goto exit;
200 }
202 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
203 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
204 /* Create a new CMPIInstance to store this resource. */
205 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
206 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
207 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
208 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
209 goto exit;
210 }
212 /* Setup a filter to only return the desired properties. */
213 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
214 if (status.rc != CMPI_RC_OK) {
215 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
216 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
217 goto exit;
218 }
220 /* Set the instance property values from the resource data. */
221 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
222 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
223 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
224 goto exit;
225 }
227 /* Free the resource data. */
228 if (!Xen_ProcessorPool_freeResource(resource)) {
229 _SBLIM_TRACE(1,("--- _freeResource() failed"));
230 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
231 goto exit;
232 }
234 /* Return the CMPIInstance for this instance. */
235 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
236 CMReturnInstance(results, instance);
237 found++;
238 }
240 _SBLIM_TRACE(2,("--- %d instances found", found));
241 CMReturnDone(results);
243 exit:
244 /* Free the list of system resources. */
245 if (!Xen_ProcessorPool_freeResources(resources)) {
246 _SBLIM_TRACE(1,("--- _freeResources() failed"));
247 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
248 }
250 _SBLIM_RETURNSTATUS(status);
251 }
253 // ----------------------------------------------------------------------------
254 // GetInstance()
255 // Return the instance data for the specified instance only.
256 // ----------------------------------------------------------------------------
257 static CMPIStatus GetInstance(
258 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
259 const CMPIContext * context, /* [in] Additional context info, if any. */
260 const CMPIResult * results, /* [out] Results of this operation. */
261 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
262 const char ** properties) /* [in] List of desired properties (NULL=all). */
263 {
264 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
265 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
266 _RESOURCE * resource; /* Handle to the system resource. */
267 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
268 int found = 0; /* Found the target instance? */
270 _SBLIM_ENTER("GetInstance");
271 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
272 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
273 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
274 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
276 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
277 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
278 goto exit;
279 }
281 /* Get a handle to the list of system resources. */
282 if (!Xen_ProcessorPool_getResources(&resources)) {
283 _SBLIM_TRACE(1,("--- _getResources() failed"));
284 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
285 goto exit;
286 }
288 /* Get the target resource. */
289 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
290 if (!found || (resource == NULL)) {
291 _SBLIM_TRACE(1,("--- Target instance not found"));
292 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
293 goto exit;
294 }
296 /* Create a new CMPIInstance to store this resource. */
297 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
298 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
299 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
300 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
301 goto exit;
302 }
304 /* Setup a filter to only return the desired properties. */
305 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
306 if (status.rc != CMPI_RC_OK) {
307 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
308 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
309 goto exit;
310 }
312 /* Set the instance property values from the resource data. */
313 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
314 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
315 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
316 goto exit;
317 }
319 /* Free the resource data. */
320 if (!Xen_ProcessorPool_freeResource(resource)) {
321 _SBLIM_TRACE(1,("--- _freeResource() failed"));
322 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
323 goto exit;
324 }
326 /* Return the CMPIInstance for this instance. */
327 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
328 CMReturnInstance(results, instance);
330 _SBLIM_TRACE(2,("--- instance found"));
331 CMReturnDone(results);
333 exit:
334 /* Free the list of system resources. */
335 if (!Xen_ProcessorPool_freeResources(resources)) {
336 _SBLIM_TRACE(1,("--- _freeResources() failed"));
337 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
338 }
340 _SBLIM_RETURNSTATUS(status);
341 }
343 // ----------------------------------------------------------------------------
344 // SetInstance()
345 // Save modified instance data for the specified instance.
346 // ----------------------------------------------------------------------------
347 static CMPIStatus SetInstance(
348 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
349 const CMPIContext * context, /* [in] Additional context info, if any. */
350 const CMPIResult * results, /* [out] Results of this operation. */
351 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
352 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
353 const char **properties)
354 {
355 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
356 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
357 _RESOURCE * resource; /* Handle to the system resource. */
358 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
359 int found = 0; /* Found the target instance? */
361 _SBLIM_ENTER("SetInstance");
362 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
363 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
364 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
365 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
366 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
368 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
369 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
370 goto exit;
371 }
373 /* Get a handle to the list of system resources. */
374 if (!Xen_ProcessorPool_getResources(&resources)) {
375 _SBLIM_TRACE(1,("--- _getResources() failed"));
376 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
377 goto exit;
378 }
380 /* Get the target resource. */
381 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
382 if (!found || (resource == NULL)) {
383 _SBLIM_TRACE(1,("--- Target instance not found"));
384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
385 goto exit;
386 }
388 _SBLIM_TRACE(2,("--- instance found", found));
390 /* Update the target resource data with the new instance property values. */
391 int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER);
393 /* Free the resource data. */
394 if (!Xen_ProcessorPool_freeResource(resource)) {
395 _SBLIM_TRACE(1,("--- _freeResource() failed"));
396 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
397 goto exit;
398 }
400 if (rc != 1) {
401 if (rc == -1) {
402 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
403 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
404 } else {
405 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
406 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
407 }
408 goto exit;
409 }
411 exit:
412 /* Free the list of system resources. */
413 if (!Xen_ProcessorPool_freeResources(resources)) {
414 _SBLIM_TRACE(1,("--- _freeResources() failed"));
415 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
416 }
418 _SBLIM_RETURNSTATUS(status);
419 }
421 // ----------------------------------------------------------------------------
422 // CreateInstance()
423 // Create a new instance from the specified instance data.
424 // ----------------------------------------------------------------------------
425 static CMPIStatus CreateInstance(
426 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
427 const CMPIContext * context, /* [in] Additional context info, if any. */
428 const CMPIResult * results, /* [out] Results of this operation. */
429 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
430 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
431 {
432 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
433 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
434 _RESOURCE * resource; /* Handle to the system resource. */
435 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
436 int found = 0; /* Found the target instance? */
438 _SBLIM_ENTER("CreateInstance");
439 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
440 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
441 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
442 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
443 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
445 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
446 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
447 goto exit;
448 }
450 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
451 reference = CMGetObjectPath(newinstance, NULL);
453 /* Get a handle to the list of system resources. */
454 if (!Xen_ProcessorPool_getResources(&resources)) {
455 _SBLIM_TRACE(1,("--- _getResources() failed"));
456 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
457 goto exit;
458 }
460 /* Get the target resource. */
461 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
463 /* Free the resource data. */
464 if (!Xen_ProcessorPool_freeResource(resource)) {
465 _SBLIM_TRACE(1,("--- _freeResource() failed"));
466 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
467 goto exit;
468 }
470 if (found) {
471 _SBLIM_TRACE(1,("--- Target instance already exists"));
472 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
473 goto exit;
474 }
476 /* Create a new resource with the new instance property values. */
477 int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
478 if (rc != 1) {
479 if (rc == -1) {
480 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
481 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
482 } else {
483 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
484 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
485 }
486 goto exit;
487 }
489 /* Return the object path for the newly created instance. */
490 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
491 CMSetNameSpace(objectpath, namespace);
492 CMReturnObjectPath(results, objectpath);
493 CMReturnDone(results);
495 exit:
496 /* Free the list of system resources. */
497 if (!Xen_ProcessorPool_freeResources(resources)) {
498 _SBLIM_TRACE(1,("--- _freeResources() failed"));
499 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
500 }
502 _SBLIM_RETURNSTATUS(status);
503 }
505 // ----------------------------------------------------------------------------
506 // DeleteInstance()
507 // Delete or remove the specified instance from the system.
508 // ----------------------------------------------------------------------------
509 static CMPIStatus DeleteInstance(
510 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
511 const CMPIContext * context, /* [in] Additional context info, if any. */
512 const CMPIResult * results, /* [out] Results of this operation. */
513 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
514 {
515 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
516 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
517 _RESOURCE * resource; /* Handle to the system resource. */
518 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
519 int found = 0; /* Found the target instance? */
521 _SBLIM_ENTER("DeleteInstance");
522 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
523 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
524 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
525 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
527 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
528 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
529 goto exit;
530 }
532 /* Get a handle to the list of system resources. */
533 if (!Xen_ProcessorPool_getResources(&resources)) {
534 _SBLIM_TRACE(1,("--- _getResources() failed"));
535 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
536 goto exit;
537 }
539 /* Get the target resource. */
540 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
541 if (!found || (resource == NULL)) {
542 _SBLIM_TRACE(1,("--- Target instance not found"));
543 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
544 goto exit;
545 }
547 _SBLIM_TRACE(2,("--- instance found", found));
549 /* Delete the target resource. */
550 int rc = Xen_ProcessorPool_deleteResource(resources, resource);
552 /* Free the resource data. */
553 if (!Xen_ProcessorPool_freeResource(resource)) {
554 _SBLIM_TRACE(1,("--- _freeResource() failed"));
555 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
556 goto exit;
557 }
559 if (rc != 1) {
560 if (rc == -1) {
561 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
562 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
563 } else {
564 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
565 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
566 }
567 goto exit;
568 }
570 exit:
571 /* Free the list of system resources. */
572 if (!Xen_ProcessorPool_freeResources(resources)) {
573 _SBLIM_TRACE(1,("--- _freeResources() failed"));
574 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
575 }
577 _SBLIM_RETURNSTATUS(status);
578 }
581 // ----------------------------------------------------------------------------
582 // ExecQuery()
583 // Return a list of all the instances that satisfy the specified query filter.
584 // ----------------------------------------------------------------------------
585 static CMPIStatus ExecQuery(
586 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
587 const CMPIContext * context, /* [in] Additional context info, if any. */
588 const CMPIResult * results, /* [out] Results of this operation. */
589 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
590 const char * language, /* [in] Name of the query language. */
591 const char * query) /* [in] Text of the query written in the query language. */
592 {
593 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
594 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
596 _SBLIM_ENTER("ExecQuery");
597 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
598 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
599 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
600 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
601 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
602 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
604 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
605 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
606 goto exit;
607 }
609 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
610 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
612 CMReturnDone(results);
614 exit:
615 _SBLIM_RETURNSTATUS(status);
616 }
618 // ----------------------------------------------------------------------------
619 // Initialize()
620 // Perform any necessary initialization immediately after this provider is
621 // first loaded.
622 // ----------------------------------------------------------------------------
623 static void Initialize(
624 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
625 const CMPIContext * context) /* [in] Additional context info, if any. */
626 {
627 _SBLIM_ENTER("Initialize");
628 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
629 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
631 /* Nothing needs to be done to initialize this provider */
632 _SBLIM_RETURN();
633 }
635 // ============================================================================
636 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
637 // ============================================================================
638 CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));