os-cmpi-xen

view src/Xen_ComputerSystemProcessor.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents ab8e99c757f5
children
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 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Description:
20 // ============================================================================
22 #include <string.h>
24 /* Include the required CMPI data types, function headers, and macros */
25 #include "cmpidt.h"
26 #include "cmpift.h"
27 #include "cmpimacs.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"
44 // ============================================================================
45 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
46 // ============================================================================
48 // ----------------------------------------------------------------------------
49 // Info for the class supported by the association provider
50 // ----------------------------------------------------------------------------
52 /* Name of the left and right hand side classes of this association. */
53 static char * _ASSOCCLASS = "Xen_ComputerSystemProcessor";
54 static char * _LHSCLASSNAME = "Xen_Processor";
55 static char * _RHSCLASSNAME = "Xen_ComputerSystem";
56 static char * _LHSPROPERTYNAME = "PartComponent";
57 static char * _RHSPROPERTYNAME = "GroupComponent";
58 static char * _LHSKEYNAME = "SystemName";
59 static char * _RHSKEYNAME = "Name";
61 // ----------------------------------------------------------------------------
62 // AssociationCleanup()
63 // Perform any necessary cleanup immediately before this provider is unloaded.
64 // ----------------------------------------------------------------------------
65 static CMPIStatus AssociationCleanup(
66 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
67 const CMPIContext * context, /* [in] Additional context info, if any. */
68 CMPIBoolean terminating) /* [in] True if MB is terminating */
69 {
70 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
72 _SBLIM_ENTER("AssociationCleanup");
73 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
74 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
76 /* Nothing needs to be done for cleanup. */
77 _SBLIM_RETURNSTATUS(status);
78 }
81 // ----------------------------------------------------------------------------
82 // AssociatorNames()
83 // ----------------------------------------------------------------------------
84 static CMPIStatus AssociatorNames(
85 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
86 const CMPIContext * context, /* [in] Additional context info, if any. */
87 const CMPIResult * results, /* [out] Results of this operation. */
88 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
89 const char * assocClass,
90 const char * resultClass,
91 const char * role,
92 const char * resultRole)
93 {
94 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
95 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
96 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
97 char *targetclass; /* Class of the target object(s). */
99 char *sourcekeyname;
100 char *targetkeyname;
102 _SBLIM_ENTER("AssociatorNames");
103 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
104 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
105 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
106 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
107 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
108 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
109 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
110 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
111 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
113 /* Check that the requested association class, if any, is supported. */
114 if (assocClass != NULL) {
115 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
116 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
117 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
118 goto exit;
119 }
120 }
122 /* Check that the reference matches the required role, if any. */
123 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
124 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
125 goto exit;
126 }
128 /* Determine the target class from the source class. */
129 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
130 sourcekeyname = _LHSKEYNAME;
131 targetclass = _RHSCLASSNAME;
132 targetkeyname = _RHSKEYNAME;
133 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
134 sourcekeyname = _RHSKEYNAME;
135 targetclass = _LHSCLASSNAME;
136 targetkeyname = _LHSKEYNAME;
137 } else {
138 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
139 goto exit;
140 }
141 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
143 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
144 char * sourcename = CMGetCharPtr(namedata.value.string);
145 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
147 /* Create an object path for the result class. */
148 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
149 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
150 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
151 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
152 goto exit;
153 }
155 /* Get the list of all target class object paths from the CIMOM. */
156 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
157 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
158 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
159 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
160 goto exit;
161 }
163 /* Return all object paths that exactly match the target class and resultClass, if specified. */
164 while (CMHasNext(objectpaths, NULL)) {
165 CMPIData data = CMGetNext(objectpaths, NULL);
166 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
167 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
168 /* Only return entries whose name matches the reference. */
169 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
170 char * resultname = CMGetCharPtr(namedata.value.string);
171 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref);
172 }
173 }
175 CMReturnDone(results);
177 exit:
178 _SBLIM_RETURNSTATUS(status);
179 }
182 // ----------------------------------------------------------------------------
183 // Associators()
184 // ----------------------------------------------------------------------------
185 static CMPIStatus Associators(
186 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
187 const CMPIContext * context, /* [in] Additional context info, if any. */
188 const CMPIResult * results, /* [out] Results of this operation. */
189 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
190 const char *assocClass,
191 const char *resultClass,
192 const char *role,
193 const char *resultRole,
194 const char ** properties) /* [in] List of desired properties (NULL=all). */
195 {
196 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
197 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
198 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
199 char *targetclass; /* Class of the target object(s). */
201 char *sourcekeyname;
202 char *targetkeyname;
204 _SBLIM_ENTER("Associators");
205 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
206 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
207 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
208 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
209 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
210 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
211 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
212 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
213 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
215 /* Check that the requested association class, if any, is supported. */
216 if (assocClass != NULL) {
217 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
218 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
219 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
220 goto exit;
221 }
222 }
224 /* Check that the reference matches the required role, if any. */
225 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
226 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
227 goto exit;
228 }
230 /* Determine the target class from the source class. */
231 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
232 sourcekeyname = _LHSKEYNAME;
233 targetclass = _RHSCLASSNAME;
234 targetkeyname = _RHSKEYNAME;
235 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
236 sourcekeyname = _RHSKEYNAME;
237 targetclass = _LHSCLASSNAME;
238 targetkeyname = _LHSKEYNAME;
239 } else {
240 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
241 goto exit;
242 }
243 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
245 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
246 char * sourcename = CMGetCharPtr(namedata.value.string);
247 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
249 /* Create an object path for the result class. */
250 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
251 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
252 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
253 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
254 goto exit;
255 }
257 /* Get the list of all target class instances from the CIMOM. */
258 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
259 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
260 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
261 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
262 goto exit;
263 }
265 /* Return all instances that exactly match the target class and resultClass, if specified. */
266 while (CMHasNext(instances, NULL)) {
267 CMPIData data = CMGetNext(instances, NULL);
268 char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
269 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
270 /* Only return entries whose name matches the reference. */
271 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
272 char * resultname = CMGetCharPtr(namedata.value.string);
273 // BUG - returning data causes crash !?!
274 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
275 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, data.value.inst);
276 }
277 }
279 CMReturnDone(results);
281 exit:
282 _SBLIM_RETURNSTATUS(status);
283 }
286 // ----------------------------------------------------------------------------
287 // ReferenceNames()
288 // ----------------------------------------------------------------------------
289 static CMPIStatus ReferenceNames(
290 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
291 const CMPIContext * context, /* [in] Additional context info, if any. */
292 const CMPIResult * results, /* [out] Results of this operation. */
293 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
294 const char *assocClass,
295 const char *role)
296 {
297 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
298 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
299 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
300 char *targetclass; /* Class of the target object(s). */
302 char *sourcekeyname;
303 char *targetkeyname;
305 _SBLIM_ENTER("ReferenceNames");
306 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
307 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
308 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
309 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
310 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
311 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
312 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
314 /* Check that the requested association class, if any, is supported. */
315 if (assocClass != NULL) {
316 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
317 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
318 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
319 goto exit;
320 }
321 }
323 /* Check that the reference matches the required role, if any. */
324 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
325 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
326 goto exit;
327 }
329 /* Determine the target class from the source class. */
330 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
331 sourcekeyname = _LHSKEYNAME;
332 targetclass = _RHSCLASSNAME;
333 targetkeyname = _RHSKEYNAME;
334 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
335 sourcekeyname = _RHSKEYNAME;
336 targetclass = _LHSCLASSNAME;
337 targetkeyname = _LHSKEYNAME;
338 } else {
339 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
340 goto exit;
341 }
342 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
344 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
345 char * sourcename = CMGetCharPtr(namedata.value.string);
346 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
348 /* Create an object path for the result class. */
349 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
350 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
351 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
352 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
353 goto exit;
354 }
356 /* Get the list of all target class object paths from the CIMOM. */
357 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
358 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
359 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
360 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
361 goto exit;
362 }
364 /* Return all object paths that exactly match the target class and resultClass, if specified. */
365 while (CMHasNext(objectpaths, NULL)) {
366 CMPIData data = CMGetNext(objectpaths, NULL);
367 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
368 if (strcmp(class,targetclass) == 0) {
370 /* Create an object path for the association. */
371 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
372 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
373 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
374 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
375 goto exit;
376 }
378 /* Assign the references in the association appropriately. */
379 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
380 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
381 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
382 } else {
383 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
384 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
385 }
387 /* Only return entries whose name matches the reference. */
388 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
389 char * resultname = CMGetCharPtr(namedata.value.string);
390 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath);
391 }
392 }
394 exit:
395 _SBLIM_RETURNSTATUS(status);
396 }
399 // ----------------------------------------------------------------------------
400 // References()
401 // ----------------------------------------------------------------------------
402 static CMPIStatus References(
403 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
404 const CMPIContext * context, /* [in] Additional context info, if any. */
405 const CMPIResult * results, /* [out] Results of this operation. */
406 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
407 const char *assocClass,
408 const char *role,
409 const char **properties) /* [in] List of desired properties (NULL=all). */
410 {
411 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
412 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
413 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
414 char *targetclass; /* Class of the target object(s). */
416 char *sourcekeyname;
417 char *targetkeyname;
419 _SBLIM_ENTER("References");
420 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
421 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
422 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
423 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
424 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
425 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
426 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
428 /* Check that the requested association class, if any, is supported. */
429 if (assocClass != NULL) {
430 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
431 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
432 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
433 goto exit;
434 }
435 }
437 /* Check that the reference matches the required role, if any. */
438 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
439 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
440 goto exit;
441 }
443 /* Determine the target class from the source class. */
444 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
445 sourcekeyname = _LHSKEYNAME;
446 targetclass = _RHSCLASSNAME;
447 targetkeyname = _RHSKEYNAME;
448 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
449 sourcekeyname = _RHSKEYNAME;
450 targetclass = _LHSCLASSNAME;
451 targetkeyname = _LHSKEYNAME;
452 } else {
453 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
454 goto exit;
455 }
456 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
458 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
459 char * sourcename = CMGetCharPtr(namedata.value.string);
460 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
462 /* Create an object path for the result class. */
463 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
464 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
465 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
466 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
467 goto exit;
468 }
470 /* Get the list of all target class object paths from the CIMOM. */
471 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
472 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
473 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
474 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
475 goto exit;
476 }
478 /* Return all object paths that exactly match the target class and resultClass, if specified. */
479 while (CMHasNext(objectpaths, NULL)) {
480 CMPIData data = CMGetNext(objectpaths, NULL);
481 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
482 if (strcmp(class,targetclass) == 0) {
484 /* Create an instance for the association. */
485 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
486 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
487 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
488 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
489 goto exit;
490 }
492 /* Assign the references in the association appropriately. */
493 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
494 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
495 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
496 } else {
497 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
498 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
499 }
501 /* Only return entries whose name matches the reference. */
502 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
503 char * resultname = CMGetCharPtr(namedata.value.string);
504 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
505 }
506 }
507 exit:
508 _SBLIM_RETURNSTATUS(status);
509 }
512 // ----------------------------------------------------------------------------
513 // AssociationInitialize()
514 // Perform any necessary initialization immediately after this provider is
515 // first loaded.
516 // ----------------------------------------------------------------------------
517 static void AssociationInitialize(
518 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
519 const CMPIContext * context) /* [in] Additional context info, if any. */
520 {
521 _SBLIM_ENTER("AssociationInitialize");
522 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
523 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
525 /* Nothing needs to be done to initialize this provider */
526 _SBLIM_RETURN();
527 }
530 // ============================================================================
531 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
532 // ============================================================================
533 CMAssociationMIStub( , Xen_ComputerSystemProcessor, _BROKER, AssociationInitialize(&mi, ctx));