os-cmpi-xen

annotate src/Xen_ProcessorPool.c @ 1:bdf24cd56bed

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