os-cmpi-xen

view src/Xen_RunningOS.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 /* Info about the left and right hand side classes of this association. */
53 static char * _ASSOCCLASS = "Xen_RunningOS";
55 static char * _LHSCLASSNAME = "Xen_ComputerSystem";
56 static char * _LHSPROPERTYNAME = "Dependent";
58 static char * _RHSCLASSNAME = "Xen_OperatingSystem";
59 static char * _RHSPROPERTYNAME = "Antecedent";
61 /* Key property of the LHS and RHS objects that must match to make the association. */
62 static char * _LHSKEYNAME = "Name";
63 static char * _RHSKEYNAME = "CSName";
65 // ----------------------------------------------------------------------------
66 // AssociationCleanup()
67 // Perform any necessary cleanup immediately before this provider is unloaded.
68 // ----------------------------------------------------------------------------
69 static CMPIStatus AssociationCleanup(
70 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
71 const CMPIContext * context, /* [in] Additional context info, if any. */
72 CMPIBoolean terminating) /* [in] True if MB is terminating */
73 {
74 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
76 _SBLIM_ENTER("AssociationCleanup");
77 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
78 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
80 /* Nothing needs to be done for cleanup. */
81 _SBLIM_RETURNSTATUS(status);
82 }
85 // ----------------------------------------------------------------------------
86 // AssociatorNames()
87 // ----------------------------------------------------------------------------
88 static CMPIStatus AssociatorNames(
89 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
90 const CMPIContext * context, /* [in] Additional context info, if any. */
91 const CMPIResult * results, /* [out] Results of this operation. */
92 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
93 const char * assocClass,
94 const char * resultClass,
95 const char * role,
96 const char * resultRole)
97 {
98 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
99 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
100 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
101 char *targetclass; /* Class of the target object(s). */
103 char *sourcekeyname;
104 char *targetkeyname;
106 _SBLIM_ENTER("AssociatorNames");
107 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
108 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
109 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
110 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
111 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
112 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
113 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
114 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
115 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
117 /* Check that the requested association class, if any, is supported. */
118 if (assocClass != NULL) {
119 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
120 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
121 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
122 goto exit;
123 }
124 }
126 /* Check that the reference matches the required role, if any. */
127 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
128 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
129 goto exit;
130 }
132 /* Determine the target class from the source class. */
133 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
134 sourcekeyname = _LHSKEYNAME;
135 targetclass = _RHSCLASSNAME;
136 targetkeyname = _RHSKEYNAME;
137 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
138 sourcekeyname = _RHSKEYNAME;
139 targetclass = _LHSCLASSNAME;
140 targetkeyname = _LHSKEYNAME;
141 } else {
142 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
143 goto exit;
144 }
145 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
147 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
148 char * sourcename = CMGetCharPtr(namedata.value.string);
149 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
151 /* Create an object path for the result class. */
152 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
153 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
154 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
155 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
156 goto exit;
157 }
159 /* Get the list of all target class object paths from the CIMOM. */
160 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
161 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
162 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
163 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
164 goto exit;
165 }
167 /* Return all object paths that exactly match the target class and resultClass, if specified. */
168 while (CMHasNext(objectpaths, NULL)) {
169 CMPIData data = CMGetNext(objectpaths, NULL);
170 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
171 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
172 /* Only return entries whose name matches the reference. */
173 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
174 char * resultname = CMGetCharPtr(namedata.value.string);
175 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref);
176 }
177 }
179 CMReturnDone(results);
181 exit:
182 _SBLIM_RETURNSTATUS(status);
183 }
186 // ----------------------------------------------------------------------------
187 // Associators()
188 // ----------------------------------------------------------------------------
189 static CMPIStatus Associators(
190 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
191 const CMPIContext * context, /* [in] Additional context info, if any. */
192 const CMPIResult * results, /* [out] Results of this operation. */
193 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
194 const char *assocClass,
195 const char *resultClass,
196 const char *role,
197 const char *resultRole,
198 const char ** properties) /* [in] List of desired properties (NULL=all). */
199 {
200 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
201 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
202 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
203 char *targetclass; /* Class of the target object(s). */
205 char *sourcekeyname;
206 char *targetkeyname;
208 _SBLIM_ENTER("Associators");
209 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
210 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
211 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
212 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
213 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
214 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
215 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
216 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
217 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
219 /* Check that the requested association class, if any, is supported. */
220 if (assocClass != NULL) {
221 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
222 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
223 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
224 goto exit;
225 }
226 }
228 /* Check that the reference matches the required role, if any. */
229 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
230 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
231 goto exit;
232 }
234 /* Determine the target class from the source class. */
235 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
236 sourcekeyname = _LHSKEYNAME;
237 targetclass = _RHSCLASSNAME;
238 targetkeyname = _RHSKEYNAME;
239 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
240 sourcekeyname = _RHSKEYNAME;
241 targetclass = _LHSCLASSNAME;
242 targetkeyname = _LHSKEYNAME;
243 } else {
244 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
245 goto exit;
246 }
247 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
249 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
250 char * sourcename = CMGetCharPtr(namedata.value.string);
251 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
253 /* Create an object path for the result class. */
254 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
255 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
256 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
257 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
258 goto exit;
259 }
261 /* Get the list of all target class instances from the CIMOM. */
262 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
263 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
264 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
265 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
266 goto exit;
267 }
269 /* Return all instances that exactly match the target class and resultClass, if specified. */
270 while (CMHasNext(instances, NULL)) {
271 CMPIData data = CMGetNext(instances, NULL);
272 char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
273 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
274 /* Only return entries whose name matches the reference. */
275 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
276 char * resultname = CMGetCharPtr(namedata.value.string);
277 // BUG - returning data causes crash !?!
278 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
279 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, data.value.inst);
280 }
281 }
283 CMReturnDone(results);
285 exit:
286 _SBLIM_RETURNSTATUS(status);
287 }
290 // ----------------------------------------------------------------------------
291 // ReferenceNames()
292 // ----------------------------------------------------------------------------
293 static CMPIStatus ReferenceNames(
294 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
295 const CMPIContext * context, /* [in] Additional context info, if any. */
296 const CMPIResult * results, /* [out] Results of this operation. */
297 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
298 const char *assocClass,
299 const char *role)
300 {
301 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
302 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
303 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
304 char *targetclass; /* Class of the target object(s). */
306 char *sourcekeyname;
307 char *targetkeyname;
309 _SBLIM_ENTER("ReferenceNames");
310 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
311 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
312 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
313 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
314 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
315 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
316 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
318 /* Check that the requested association class, if any, is supported. */
319 if (assocClass != NULL) {
320 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
321 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
322 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
323 goto exit;
324 }
325 }
327 /* Check that the reference matches the required role, if any. */
328 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
329 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
330 goto exit;
331 }
333 /* Determine the target class from the source class. */
334 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
335 sourcekeyname = _LHSKEYNAME;
336 targetclass = _RHSCLASSNAME;
337 targetkeyname = _RHSKEYNAME;
338 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
339 sourcekeyname = _RHSKEYNAME;
340 targetclass = _LHSCLASSNAME;
341 targetkeyname = _LHSKEYNAME;
342 } else {
343 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
344 goto exit;
345 }
346 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
348 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
349 char * sourcename = CMGetCharPtr(namedata.value.string);
350 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
352 /* Create an object path for the result class. */
353 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
354 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
355 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
356 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
357 goto exit;
358 }
360 /* Get the list of all target class object paths from the CIMOM. */
361 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
362 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
363 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
364 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
365 goto exit;
366 }
368 /* Return all object paths that exactly match the target class and resultClass, if specified. */
369 while (CMHasNext(objectpaths, NULL)) {
370 CMPIData data = CMGetNext(objectpaths, NULL);
371 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
372 if (strcmp(class,targetclass) == 0) {
374 /* Create an object path for the association. */
375 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
376 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
377 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
378 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
379 goto exit;
380 }
382 /* Assign the references in the association appropriately. */
383 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
384 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
385 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
386 } else {
387 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
388 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
389 }
391 /* Only return entries whose name matches the reference. */
392 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
393 char * resultname = CMGetCharPtr(namedata.value.string);
394 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath);
395 }
396 }
398 exit:
399 _SBLIM_RETURNSTATUS(status);
400 }
403 // ----------------------------------------------------------------------------
404 // References()
405 // ----------------------------------------------------------------------------
406 static CMPIStatus References(
407 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
408 const CMPIContext * context, /* [in] Additional context info, if any. */
409 const CMPIResult * results, /* [out] Results of this operation. */
410 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
411 const char *assocClass,
412 const char *role,
413 const char **properties) /* [in] List of desired properties (NULL=all). */
414 {
415 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
416 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
417 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
418 char *targetclass; /* Class of the target object(s). */
420 char *sourcekeyname;
421 char *targetkeyname;
423 _SBLIM_ENTER("References");
424 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
425 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
426 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
427 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
428 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
429 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
430 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
432 /* Check that the requested association class, if any, is supported. */
433 if (assocClass != NULL) {
434 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
435 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
436 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
437 goto exit;
438 }
439 }
441 /* Check that the reference matches the required role, if any. */
442 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
443 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
444 goto exit;
445 }
447 /* Determine the target class from the source class. */
448 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
449 sourcekeyname = _LHSKEYNAME;
450 targetclass = _RHSCLASSNAME;
451 targetkeyname = _RHSKEYNAME;
452 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
453 sourcekeyname = _RHSKEYNAME;
454 targetclass = _LHSCLASSNAME;
455 targetkeyname = _LHSKEYNAME;
456 } else {
457 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
458 goto exit;
459 }
460 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
462 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
463 char * sourcename = CMGetCharPtr(namedata.value.string);
464 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
466 /* Create an object path for the result class. */
467 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
468 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
469 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
470 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
471 goto exit;
472 }
474 /* Get the list of all target class object paths from the CIMOM. */
475 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
476 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
477 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
478 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
479 goto exit;
480 }
482 /* Return all object paths that exactly match the target class and resultClass, if specified. */
483 while (CMHasNext(objectpaths, NULL)) {
484 CMPIData data = CMGetNext(objectpaths, NULL);
485 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
486 if (strcmp(class,targetclass) == 0) {
488 /* Create an instance for the association. */
489 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
490 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
491 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
492 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
493 goto exit;
494 }
496 /* Assign the references in the association appropriately. */
497 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
498 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
499 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
500 } else {
501 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
502 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
503 }
505 /* Only return entries whose name matches the reference. */
506 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
507 char * resultname = CMGetCharPtr(namedata.value.string);
508 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
509 }
510 }
511 exit:
512 _SBLIM_RETURNSTATUS(status);
513 }
516 // ----------------------------------------------------------------------------
517 // AssociationInitialize()
518 // Perform any necessary initialization immediately after this provider is
519 // first loaded.
520 // ----------------------------------------------------------------------------
521 static void AssociationInitialize(
522 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
523 const CMPIContext * context) /* [in] Additional context info, if any. */
524 {
525 _SBLIM_ENTER("AssociationInitialize");
526 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
527 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
529 /* Nothing needs to be done to initialize this provider */
530 _SBLIM_RETURN();
531 }
534 // ============================================================================
535 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
536 // ============================================================================
537 CMAssociationMIStub( , Xen_RunningOS, _BROKER, AssociationInitialize(&mi, ctx));