os-cmpi-xen

view src/Xen_HostedComputerSystem.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 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 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
19 // Contributors: Jim Fehlig, <jfehlig@novell.com>
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_HostedComputerSystem";
55 static char * _LHSCLASSNAME = "Xen_ComputerSystem";
56 static char * _RHSCLASSNAME = "CIM_ComputerSystem";
57 static char * _LHSPROPERTYNAME = "Dependent";
58 static char * _RHSPROPERTYNAME = "Antecedent";
59 static char * _LHSNAMESPACE = "root/cimv2";
60 static char * _RHSNAMESPACE = "smash";
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 /* Ignore possible instances of source class. */
162 if (strcmp(class,sourceclass) &&
163 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
164 _SBLIM_TRACE(2, ("--- returning object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
165 CMReturnObjectPath(results, data.value.ref);
166 }
167 }
169 CMReturnDone(results);
170 exit:
171 _SBLIM_RETURNSTATUS(status);
172 }
175 // ----------------------------------------------------------------------------
176 // Associators()
177 // ----------------------------------------------------------------------------
178 static CMPIStatus Associators(
179 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
180 const CMPIContext * context, /* [in] Additional context info, if any. */
181 const CMPIResult * results, /* [out] Results of this operation. */
182 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
183 const char *assocClass,
184 const char *resultClass,
185 const char *role,
186 const char *resultRole,
187 const char ** properties) /* [in] List of desired properties (NULL=all). */
188 {
189 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
190 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
191 char *targetclass; /* Class of the target object(s). */
192 char *targetnamespace;
194 _SBLIM_ENTER("Associators");
195 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
196 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
197 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
198 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
199 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
200 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
201 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
202 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
204 /* Determine the target class from the source class. */
205 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
206 targetclass = _RHSCLASSNAME;
207 targetnamespace = _RHSNAMESPACE;
208 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
209 targetclass = _LHSCLASSNAME;
210 targetnamespace = _LHSNAMESPACE;
211 } else {
212 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
213 goto exit;
214 }
215 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
216 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
218 /* Check that the requested association class, if any, is supported. */
219 if (assocClass != NULL) {
220 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
221 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
222 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
223 goto exit;
224 }
225 }
227 /* Check that the reference matches the required role, if any. */
228 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
229 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
230 goto exit;
231 }
233 /* Create an object path for the result class. */
234 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
235 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
236 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
237 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
238 goto exit;
239 }
241 /* Get the list of all target class instances from the CIMOM. */
242 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
243 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
244 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
245 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
246 goto exit;
247 }
249 /* Return all instances that match the resultClass, if specified. */
250 while (CMHasNext(instances, NULL)) {
251 CMPIData data = CMGetNext(instances, NULL);
252 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
253 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
255 _SBLIM_TRACE(2, ("--- got inst with object path = \"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
257 /* Ignore possible instances of source class. */
258 if (strcmp(class,sourceclass) &&
259 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
260 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
262 CMReturnInstance(results, data.value.inst);
263 }
264 }
266 CMReturnDone(results);
268 exit:
269 _SBLIM_RETURNSTATUS(status);
270 }
273 // ----------------------------------------------------------------------------
274 // ReferenceNames()
275 // ----------------------------------------------------------------------------
276 static CMPIStatus ReferenceNames(
277 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
278 const CMPIContext * context, /* [in] Additional context info, if any. */
279 const CMPIResult * results, /* [out] Results of this operation. */
280 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
281 const char *resultClass,
282 const char *role)
283 {
284 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
285 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
286 char *targetclass; /* Class of the target object(s). */
287 char *targetnamespace;
289 _SBLIM_ENTER("ReferenceNames");
290 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
291 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
292 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
293 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
294 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
295 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
297 /* Need to have object paths for objects on both sides of the returned
298 * association names. We are given one in the reference parameter. Need to
299 * fetch the others from cimom.
300 */
301 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
302 targetclass = _RHSCLASSNAME;
303 targetnamespace = _RHSNAMESPACE;
304 /* Refences of LHS class should always be in LHS namespace. */
305 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
306 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
307 targetclass = _LHSCLASSNAME;
308 targetnamespace = _LHSNAMESPACE;
309 } else {
310 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
311 goto exit;
312 }
313 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
314 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
316 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
317 * Otherwise caller is looking for a different association than what this
318 * code implements.
319 */
320 if (resultClass != NULL) {
321 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, NULL);
322 if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
323 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
324 goto exit;
325 }
326 }
328 /* Check that the reference matches the required role, if any. */
329 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
330 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
331 goto exit;
332 }
334 /* Retrieve object paths of objects on other side of association. */
335 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
336 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
337 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
338 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
339 goto exit;
340 }
342 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
343 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
344 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
345 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
346 goto exit;
347 }
349 /* Already made it past the filters so return an association name
350 * (object path) for each association that exists to the source object.
351 */
352 while (CMHasNext(objectpaths, NULL)) {
353 CMPIData data = CMGetNext(objectpaths, NULL);
355 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
356 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
357 /* Create an object path for the association. Note that the association
358 * objects should exist in 'virt namespace' not the host namespace.
359 */
360 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
361 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
362 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
363 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
364 goto exit;
365 }
367 /* Assign the references in the association appropriately. */
368 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
369 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
370 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
371 } else {
372 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
373 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
374 }
376 CMReturnObjectPath(results, refobjectpath);
377 }
378 }
380 exit:
381 _SBLIM_RETURNSTATUS(status);
382 }
385 // ----------------------------------------------------------------------------
386 // References()
387 // ----------------------------------------------------------------------------
388 static CMPIStatus References(
389 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
390 const CMPIContext * context, /* [in] Additional context info, if any. */
391 const CMPIResult * results, /* [out] Results of this operation. */
392 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
393 const char *resultClass,
394 const char *role,
395 const char **properties) /* [in] List of desired properties (NULL=all). */
396 {
397 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
398 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
399 char *targetclass; /* Class of the target object(s). */
400 char *targetnamespace;
402 _SBLIM_ENTER("References");
403 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
404 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
405 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
406 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
407 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
408 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
410 /* Need to have object paths for objects on both sides of the returned
411 * associations. We are given one in the reference parameter. Need to
412 * fetch the others from cimom.
413 */
414 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
415 targetclass = _RHSCLASSNAME;
416 targetnamespace = _RHSNAMESPACE;
417 /* Refences of LHS class should always be in LHS namespace. */
418 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
419 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
420 targetclass = _LHSCLASSNAME;
421 targetnamespace = _LHSNAMESPACE;
422 } else {
423 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
424 goto exit;
425 }
426 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
427 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
429 /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
430 * Otherwise caller is looking for a different association than what this
431 * code implements.
432 */
433 if (resultClass != NULL) {
434 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace, _ASSOCCLASS, NULL);
435 if (!CMClassPathIsA(_BROKER, assoc, resultClass, 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 /* Create an object path for the result class. */
448 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
449 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
450 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
451 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
452 goto exit;
453 }
455 /* Retrieve object paths of objects on other side of association. */
456 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
457 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
458 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
459 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
460 goto exit;
461 }
463 /* Already made it past the filters so return an association instance
464 * for each association that exists to the source object.
465 */
466 while (CMHasNext(objectpaths, NULL)) {
467 CMPIData data = CMGetNext(objectpaths, NULL);
469 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
470 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
471 /* Create an instance for the association. Note that the association
472 * objects should exist in 'virt namespace' not the host namespace.
473 */
474 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
475 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
476 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
477 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
478 goto exit;
479 }
481 /* Assign the references in the association appropriately. */
482 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
483 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
484 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
485 } else {
486 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
487 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
488 }
489 CMReturnInstance(results, refinstance);
490 }
491 }
493 exit:
494 _SBLIM_RETURNSTATUS(status);
495 }
498 // ----------------------------------------------------------------------------
499 // AssociationInitialize()
500 // Perform any necessary initialization immediately after this provider is
501 // first loaded.
502 // ----------------------------------------------------------------------------
503 static void AssociationInitialize(
504 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
505 const CMPIContext * context) /* [in] Additional context info, if any. */
506 {
507 _SBLIM_ENTER("AssociationInitialize");
508 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
509 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
511 /* Nothing needs to be done to initialize this provider */
512 _SBLIM_RETURN();
513 }
516 // ============================================================================
517 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
518 // ============================================================================
519 CMAssociationMIStub( , Xen_HostedComputerSystem, _BROKER, AssociationInitialize(&mi, ctx));