os-cmpi-xen

view src/Xen_ElementConformsToSVProfile.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 e6a1f148b01b
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"
30 /* Include utility functions */
31 #include "cmpiutil.h"
33 /* Include _SBLIM_TRACE() logging support */
34 #include "cmpitrace.h"
37 // ----------------------------------------------------------------------------
38 // COMMON GLOBAL VARIABLES
39 // ----------------------------------------------------------------------------
41 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
42 static const CMPIBroker *_BROKER;
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_ElementConformsToSVProfile";
55 static char * _LHSCLASSNAME = "Xen_RegisteredSVProfile";
56 static char * _RHSCLASSNAME = "CIM_ComputerSystem";
57 static char * _LHSPROPERTYNAME = "ConformantStandard";
58 static char * _RHSPROPERTYNAME = "ManagedElement";
59 static char * _LHSNAMESPACE = "Interop";
60 static char * _RHSNAMESPACE = "smash";
62 static char * _XEN_DOMU_CLASS = "Xen_ComputerSystem";
64 // ----------------------------------------------------------------------------
65 // AssociationCleanup()
66 // Perform any necessary cleanup immediately before this provider is unloaded.
67 // ----------------------------------------------------------------------------
68 static CMPIStatus AssociationCleanup(
69 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
70 const CMPIContext * context, /* [in] Additional context info, if any. */
71 CMPIBoolean terminating) /* [in] True if MB is terminating */
72 {
73 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
75 _SBLIM_ENTER("AssociationCleanup");
76 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
77 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
79 /* Nothing needs to be done for cleanup. */
80 _SBLIM_RETURNSTATUS(status);
81 }
84 // ----------------------------------------------------------------------------
85 // AssociatorNames()
86 // ----------------------------------------------------------------------------
87 static CMPIStatus AssociatorNames(
88 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
89 const CMPIContext * context, /* [in] Additional context info, if any. */
90 const CMPIResult * results, /* [out] Results of this operation. */
91 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
92 const char * assocClass,
93 const char * resultClass,
94 const char * role,
95 const char * resultRole)
96 {
97 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
98 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
99 char *targetclass; /* Class of the target object(s). */
100 char *targetnamespace;
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, ("--- sourceclass=\"%s\"", sourceclass));
112 /* Ensure the source class is not a virtual computer system */
113 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
114 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
115 goto exit;
116 }
118 /* Determine the target class and namespace from the source class. */
119 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
120 targetclass = _RHSCLASSNAME;
121 targetnamespace = _RHSNAMESPACE;
122 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
123 targetclass = _LHSCLASSNAME;
124 targetnamespace = _LHSNAMESPACE;
125 } else {
126 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
127 goto exit;
128 }
129 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
130 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
132 /* Check that the requested association class, if any, is supported. */
133 if (assocClass != NULL) {
134 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
135 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
136 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
137 goto exit;
138 }
139 }
141 /* Check that the reference matches the required role, if any. */
142 /* TODO: Not sure about this check. IIRC 'role' is a property name. */
143 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
144 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
145 goto exit;
146 }
148 /* Create an object path for the result class. */
149 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
150 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
151 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
152 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
153 goto exit;
154 }
156 /* Get the list of all target class object paths from the CIMOM. */
157 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
158 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
159 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
160 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
161 goto exit;
162 }
164 /* Return all object paths that match resultClass, if specified. */
165 while (CMHasNext(objectpaths, NULL)) {
166 CMPIData data = CMGetNext(objectpaths, NULL);
167 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
169 _SBLIM_TRACE(2, ("--- returning object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
171 /* Ignore possible instances of source class. */
172 if (strcmp(class,sourceclass) &&
173 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
174 _SBLIM_TRACE(2, ("--- returning object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
175 CMReturnObjectPath(results, data.value.ref);
176 }
177 }
179 CMReturnDone(results);
180 exit:
181 _SBLIM_RETURNSTATUS(status);
182 }
185 // ----------------------------------------------------------------------------
186 // Associators()
187 // ----------------------------------------------------------------------------
188 static CMPIStatus Associators(
189 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
190 const CMPIContext * context, /* [in] Additional context info, if any. */
191 const CMPIResult * results, /* [out] Results of this operation. */
192 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
193 const char *assocClass,
194 const char *resultClass,
195 const char *role,
196 const char *resultRole,
197 const char ** properties) /* [in] List of desired properties (NULL=all). */
198 {
199 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
200 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
201 char *targetclass; /* Class of the target object(s). */
202 char *targetnamespace;
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, ("--- sourceclass=\"%s\"", sourceclass));
214 /* Ensure the source class is not a virtual computer system */
215 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
216 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
217 goto exit;
218 }
220 /* Determine the target class from the source class. */
221 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
222 targetclass = _RHSCLASSNAME;
223 targetnamespace = _RHSNAMESPACE;
224 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
225 targetclass = _LHSCLASSNAME;
226 targetnamespace = _LHSNAMESPACE;
227 } else {
228 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
229 goto exit;
230 }
231 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
232 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
234 /* Check that the requested association class, if any, is supported. */
235 if (assocClass != NULL) {
236 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
237 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
238 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
239 goto exit;
240 }
241 }
243 /* Check that the reference matches the required role, if any. */
244 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
245 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
246 goto exit;
247 }
249 /* Create an object path for the result class. */
250 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, 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 match the resultClass, if specified. */
266 while (CMHasNext(instances, NULL)) {
267 CMPIData data = CMGetNext(instances, NULL);
268 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
269 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
271 _SBLIM_TRACE(2, ("--- got inst with object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
273 /* Ignore possible instances of source class. */
274 if (strcmp(class,sourceclass) &&
275 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
276 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
278 CMReturnInstance(results, data.value.inst);
279 }
280 }
282 CMReturnDone(results);
284 exit:
285 _SBLIM_RETURNSTATUS(status);
286 }
289 // ----------------------------------------------------------------------------
290 // ReferenceNames()
291 // ----------------------------------------------------------------------------
292 static CMPIStatus ReferenceNames(
293 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
294 const CMPIContext * context, /* [in] Additional context info, if any. */
295 const CMPIResult * results, /* [out] Results of this operation. */
296 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
297 const char *resultClass,
298 const char *role)
299 {
300 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
301 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
302 char *targetclass; /* Class of the target object(s). */
303 char *targetnamespace;
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, ("--- resultClass=\"%s\"", resultClass));
310 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
311 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
313 /* Ensure the source class is not a virtual computer system */
314 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
315 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
316 goto exit;
317 }
319 /* Need to have object paths for objects on both sides of the returned
320 * association names. We are given one in the reference parameter. Need to
321 * fetch the others from cimom.
322 */
323 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
324 targetclass = _RHSCLASSNAME;
325 targetnamespace = _RHSNAMESPACE;
326 /* Refences of LHS class should always be in LHS namespace. */
327 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
328 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
329 targetclass = _LHSCLASSNAME;
330 targetnamespace = _LHSNAMESPACE;
331 } else {
332 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
333 goto exit;
334 }
335 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
336 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
338 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
339 * Otherwise caller is looking for a different association than what this
340 * code implements.
341 */
342 if (resultClass != NULL) {
343 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, NULL);
344 if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
345 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
346 goto exit;
347 }
348 }
350 /* Check that the reference matches the required role, if any. */
351 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
352 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
353 goto exit;
354 }
356 /* Retrieve object paths of objects on other side of association. */
357 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
358 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
359 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
360 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
361 goto exit;
362 }
364 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
365 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
366 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
367 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
368 goto exit;
369 }
371 /* Already made it past the filters so return an association name
372 * (object path) for each association that exists to the source object.
373 */
374 while (CMHasNext(objectpaths, NULL)) {
375 CMPIData data = CMGetNext(objectpaths, NULL);
377 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
378 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
379 /* Create an object path for the association. Note that the association
380 * objects should exist in 'virt namespace' not the host namespace.
381 */
382 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
383 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
384 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
385 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
386 goto exit;
387 }
389 /* Assign the references in the association appropriately. */
390 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
391 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
392 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
393 } else {
394 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
395 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
396 }
398 CMReturnObjectPath(results, refobjectpath);
399 }
400 }
402 exit:
403 _SBLIM_RETURNSTATUS(status);
404 }
407 // ----------------------------------------------------------------------------
408 // References()
409 // ----------------------------------------------------------------------------
410 static CMPIStatus References(
411 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
412 const CMPIContext * context, /* [in] Additional context info, if any. */
413 const CMPIResult * results, /* [out] Results of this operation. */
414 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
415 const char *resultClass,
416 const char *role,
417 const char **properties) /* [in] List of desired properties (NULL=all). */
418 {
419 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
420 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
421 char *targetclass; /* Class of the target object(s). */
422 char *targetnamespace;
424 _SBLIM_ENTER("References");
425 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
426 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
427 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
428 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
429 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
430 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
432 /* Ensure the source class is not a virtual computer system */
433 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
434 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
435 goto exit;
436 }
438 /* Need to have object paths for objects on both sides of the returned
439 * associations. We are given one in the reference parameter. Need to
440 * fetch the others from cimom.
441 */
442 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
443 targetclass = _RHSCLASSNAME;
444 targetnamespace = _RHSNAMESPACE;
445 /* Refences of LHS class should always be in LHS namespace. */
446 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
447 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
448 targetclass = _LHSCLASSNAME;
449 targetnamespace = _LHSNAMESPACE;
450 } else {
451 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
452 goto exit;
453 }
454 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
455 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
457 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
458 * Otherwise caller is looking for a different association than what this
459 * code implements.
460 */
461 if (resultClass != NULL) {
462 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
463 if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
464 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
465 goto exit;
466 }
467 }
469 /* Check that the reference matches the required role, if any. */
470 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
471 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
472 goto exit;
473 }
475 /* Create an object path for the result class. */
476 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
477 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
478 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
479 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
480 goto exit;
481 }
483 /* Retrieve object paths of objects on other side of association. */
484 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
485 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
486 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
487 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
488 goto exit;
489 }
491 /* Already made it past the filters so return an association instance
492 * for each association that exists to the source object.
493 */
494 while (CMHasNext(objectpaths, NULL)) {
495 CMPIData data = CMGetNext(objectpaths, NULL);
497 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
498 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
499 /* Create an instance for the association. Note that the association
500 * objects should exist in 'virt namespace' not the host namespace.
501 */
502 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
503 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
504 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
505 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
506 goto exit;
507 }
509 /* Assign the references in the association appropriately. */
510 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
511 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
512 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
513 } else {
514 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
515 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
516 }
517 CMReturnInstance(results, refinstance);
518 }
519 }
521 exit:
522 _SBLIM_RETURNSTATUS(status);
523 }
526 // ----------------------------------------------------------------------------
527 // AssociationInitialize()
528 // Perform any necessary initialization immediately after this provider is
529 // first loaded.
530 // ----------------------------------------------------------------------------
531 static void AssociationInitialize(
532 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
533 const CMPIContext * context) /* [in] Additional context info, if any. */
534 {
535 _SBLIM_ENTER("AssociationInitialize");
536 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
537 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
539 /* Nothing needs to be done to initialize this provider */
540 _SBLIM_RETURN();
541 }
544 // ============================================================================
545 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
546 // ============================================================================
547 CMAssociationMIStub( , Xen_ElementConformsToSVProfile, _BROKER, AssociationInitialize(&mi, ctx));