os-cmpi-xen

view src/Xen_ElementConformsToVSProfile.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 33d4316c01a2
children
line source
1 // Copyright (C) 2006 Novell, Inc.
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: Jim Fehlig <jfehlig@novell.com>
19 // Contributors:
20 // Description:
21 // ============================================================================
23 #include <string.h>
25 /* Include the required CMPI data types, function headers, and macros */
26 #include "cmpidt.h"
27 #include "cmpift.h"
28 #include "cmpimacs.h"
31 // ----------------------------------------------------------------------------
32 // COMMON GLOBAL VARIABLES
33 // ----------------------------------------------------------------------------
35 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
36 static const CMPIBroker *_BROKER;
38 /* Include utility functions */
39 #include "cmpiutil.h"
41 /* Include _SBLIM_TRACE() logging support */
42 #include "cmpitrace.h"
45 // ============================================================================
46 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
47 // ============================================================================
49 // ----------------------------------------------------------------------------
50 // Info for the class supported by the association provider
51 // ----------------------------------------------------------------------------
53 /* Name of the left and right hand side classes of this association. */
54 static char * _ASSOCCLASS = "Xen_ElementConformsToVSProfile";
55 static char * _LHSCLASSNAME = "Xen_RegisteredVSProfile";
56 static char * _RHSCLASSNAME = "Xen_ComputerSystem";
57 static char * _LHSPROPERTYNAME = "ConformantStandard";
58 static char * _RHSPROPERTYNAME = "ManagedElement";
59 static char * _LHSNAMESPACE = "Interop";
60 static char * _RHSNAMESPACE = "root/cimv2";
62 // ----------------------------------------------------------------------------
63 // AssociationCleanup()
64 // Perform any necessary cleanup immediately before this provider is unloaded.
65 // ----------------------------------------------------------------------------
66 static CMPIStatus AssociationCleanup(
67 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
68 const CMPIContext * context, /* [in] Additional context info, if any. */
69 CMPIBoolean terminating) /* [in] True if MB is terminating */
70 {
71 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
73 _SBLIM_ENTER("AssociationCleanup");
74 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
75 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
77 /* Nothing needs to be done for cleanup. */
78 _SBLIM_RETURNSTATUS(status);
79 }
82 // ----------------------------------------------------------------------------
83 // AssociatorNames()
84 // ----------------------------------------------------------------------------
85 static CMPIStatus AssociatorNames(
86 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
87 const CMPIContext * context, /* [in] Additional context info, if any. */
88 const CMPIResult * results, /* [out] Results of this operation. */
89 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
90 const char * assocClass,
91 const char * resultClass,
92 const char * role,
93 const char * resultRole)
94 {
95 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
96 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
97 char *targetclass; /* Class of the target object(s). */
98 char *targetnamespace;
100 _SBLIM_ENTER("AssociatorNames");
101 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
102 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
103 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
104 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
105 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
106 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
107 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
108 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
110 /* Determine the target class and namespace from the source class. */
111 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
112 targetclass = _RHSCLASSNAME;
113 targetnamespace = _RHSNAMESPACE;
114 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
115 targetclass = _LHSCLASSNAME;
116 targetnamespace = _LHSNAMESPACE;
117 } else {
118 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
119 goto exit;
120 }
121 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
122 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
124 /* Check that the requested association class, if any, is supported. */
125 if (assocClass != NULL) {
126 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
127 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
128 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
129 goto exit;
130 }
131 }
133 /* Check that the reference matches the required role, if any. */
134 /* TODO: Not sure about this check. IIRC 'role' is a property name. */
135 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
136 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
137 goto exit;
138 }
140 /* Create an object path for the result class. */
141 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
142 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
143 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
144 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
145 goto exit;
146 }
148 /* Get the list of all target class object paths from the CIMOM. */
149 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
150 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
151 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
152 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
153 goto exit;
154 }
156 /* Return all object paths that match resultClass, if specified. */
157 while (CMHasNext(objectpaths, NULL)) {
158 CMPIData data = CMGetNext(objectpaths, NULL);
159 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
161 _SBLIM_TRACE(2, ("--- returning object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
163 /* Ignore possible instances of source class. */
164 if (strcmp(class,sourceclass) &&
165 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
166 _SBLIM_TRACE(2, ("--- returning object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
167 CMReturnObjectPath(results, data.value.ref);
168 }
169 }
171 CMReturnDone(results);
172 exit:
173 _SBLIM_RETURNSTATUS(status);
174 }
177 // ----------------------------------------------------------------------------
178 // Associators()
179 // ----------------------------------------------------------------------------
180 static CMPIStatus Associators(
181 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
182 const CMPIContext * context, /* [in] Additional context info, if any. */
183 const CMPIResult * results, /* [out] Results of this operation. */
184 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
185 const char *assocClass,
186 const char *resultClass,
187 const char *role,
188 const char *resultRole,
189 const char ** properties) /* [in] List of desired properties (NULL=all). */
190 {
191 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
192 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
193 char *targetclass; /* Class of the target object(s). */
194 char *targetnamespace;
196 _SBLIM_ENTER("Associators");
197 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
198 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
199 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
200 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
201 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
202 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
203 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
204 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
206 /* Determine the target class from the source class. */
207 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
208 targetclass = _RHSCLASSNAME;
209 targetnamespace = _RHSNAMESPACE;
210 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
211 targetclass = _LHSCLASSNAME;
212 targetnamespace = _LHSNAMESPACE;
213 } else {
214 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
215 goto exit;
216 }
217 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
218 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
220 /* Check that the requested association class, if any, is supported. */
221 if (assocClass != NULL) {
222 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
223 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
224 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
225 goto exit;
226 }
227 }
229 /* Check that the reference matches the required role, if any. */
230 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
231 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
232 goto exit;
233 }
235 /* Create an object path for the result class. */
236 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
237 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
238 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
239 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
240 goto exit;
241 }
243 /* Get the list of all target class instances from the CIMOM. */
244 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
245 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
246 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
247 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
248 goto exit;
249 }
251 /* Return all instances that match the resultClass, if specified. */
252 while (CMHasNext(instances, NULL)) {
253 CMPIData data = CMGetNext(instances, NULL);
254 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
255 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
257 _SBLIM_TRACE(2, ("--- got inst with object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
259 /* Ignore possible instances of source class. */
260 if (strcmp(class,sourceclass) &&
261 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
262 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
264 CMReturnInstance(results, data.value.inst);
265 }
266 }
268 CMReturnDone(results);
270 exit:
271 _SBLIM_RETURNSTATUS(status);
272 }
275 // ----------------------------------------------------------------------------
276 // ReferenceNames()
277 // ----------------------------------------------------------------------------
278 static CMPIStatus ReferenceNames(
279 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
280 const CMPIContext * context, /* [in] Additional context info, if any. */
281 const CMPIResult * results, /* [out] Results of this operation. */
282 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
283 const char *resultClass,
284 const char *role)
285 {
286 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
287 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
288 char *targetclass; /* Class of the target object(s). */
289 char *targetnamespace;
291 _SBLIM_ENTER("ReferenceNames");
292 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
293 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
294 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
295 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
296 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
297 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
299 /* Need to have object paths for objects on both sides of the returned
300 * association names. We are given one in the reference parameter. Need to
301 * fetch the others from cimom.
302 */
303 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
304 targetclass = _RHSCLASSNAME;
305 targetnamespace = _RHSNAMESPACE;
306 /* Refences of LHS class should always be in LHS namespace. */
307 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
308 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
309 targetclass = _LHSCLASSNAME;
310 targetnamespace = _LHSNAMESPACE;
311 } else {
312 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
313 goto exit;
314 }
315 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
316 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
318 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
319 * Otherwise caller is looking for a different association than what this
320 * code implements.
321 */
322 if (resultClass != NULL) {
323 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, NULL);
324 if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
325 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
326 goto exit;
327 }
328 }
330 /* Check that the reference matches the required role, if any. */
331 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
332 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
333 goto exit;
334 }
336 /* Retrieve object paths of objects on other side of association. */
337 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
338 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
339 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
340 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
341 goto exit;
342 }
344 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
345 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
346 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
347 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
348 goto exit;
349 }
351 /* Already made it past the filters so return an association name
352 * (object path) for each association that exists to the source object.
353 */
354 while (CMHasNext(objectpaths, NULL)) {
355 CMPIData data = CMGetNext(objectpaths, NULL);
357 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
358 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
359 /* Create an object path for the association. Note that the association
360 * objects should exist in 'virt namespace' not the host namespace.
361 */
362 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
363 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
364 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
365 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
366 goto exit;
367 }
369 /* Assign the references in the association appropriately. */
370 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
371 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
372 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
373 } else {
374 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
375 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
376 }
378 CMReturnObjectPath(results, refobjectpath);
379 }
380 }
382 exit:
383 _SBLIM_RETURNSTATUS(status);
384 }
387 // ----------------------------------------------------------------------------
388 // References()
389 // ----------------------------------------------------------------------------
390 static CMPIStatus References(
391 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
392 const CMPIContext * context, /* [in] Additional context info, if any. */
393 const CMPIResult * results, /* [out] Results of this operation. */
394 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
395 const char *resultClass,
396 const char *role,
397 const char **properties) /* [in] List of desired properties (NULL=all). */
398 {
399 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
400 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
401 char *targetclass; /* Class of the target object(s). */
402 char *targetnamespace;
404 _SBLIM_ENTER("References");
405 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
406 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
407 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
408 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
409 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
410 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
412 /* Need to have object paths for objects on both sides of the returned
413 * associations. We are given one in the reference parameter. Need to
414 * fetch the others from cimom.
415 */
416 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
417 targetclass = _RHSCLASSNAME;
418 targetnamespace = _RHSNAMESPACE;
419 /* Refences of LHS class should always be in LHS namespace. */
420 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
421 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
422 targetclass = _LHSCLASSNAME;
423 targetnamespace = _LHSNAMESPACE;
424 } else {
425 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
426 goto exit;
427 }
428 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
429 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
431 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
432 * Otherwise caller is looking for a different association than what this
433 * code implements.
434 */
435 if (resultClass != NULL) {
436 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
437 if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
438 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
439 goto exit;
440 }
441 }
443 /* Check that the reference matches the required role, if any. */
444 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
445 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
446 goto exit;
447 }
449 /* Create an object path for the result class. */
450 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
451 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
452 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
453 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
454 goto exit;
455 }
457 /* Retrieve object paths of objects on other side of association. */
458 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
459 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
460 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
461 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
462 goto exit;
463 }
465 /* Already made it past the filters so return an association instance
466 * for each association that exists to the source object.
467 */
468 while (CMHasNext(objectpaths, NULL)) {
469 CMPIData data = CMGetNext(objectpaths, NULL);
471 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
472 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
473 /* Create an instance for the association. Note that the association
474 * objects should exist in 'virt namespace' not the host namespace.
475 */
476 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
477 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
478 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
479 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
480 goto exit;
481 }
483 /* Assign the references in the association appropriately. */
484 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
485 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
486 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
487 } else {
488 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
489 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
490 }
491 CMReturnInstance(results, refinstance);
492 }
493 }
495 exit:
496 _SBLIM_RETURNSTATUS(status);
497 }
500 // ----------------------------------------------------------------------------
501 // AssociationInitialize()
502 // Perform any necessary initialization immediately after this provider is
503 // first loaded.
504 // ----------------------------------------------------------------------------
505 static void AssociationInitialize(
506 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
507 const CMPIContext * context) /* [in] Additional context info, if any. */
508 {
509 _SBLIM_ENTER("AssociationInitialize");
510 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
511 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
513 /* Nothing needs to be done to initialize this provider */
514 _SBLIM_RETURN();
515 }
518 // ============================================================================
519 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
520 // ============================================================================
521 CMAssociationMIStub( , Xen_ElementConformsToVSProfile, _BROKER, AssociationInitialize(&mi, ctx));