os-cmpi-xen

view src/Xen_HostedMemoryPool.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 // 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_HostedMemoryPool";
55 static char * _LHSCLASSNAME = "Xen_MemoryPool";
56 static char * _RHSCLASSNAME = "CIM_ComputerSystem";
57 static char * _LHSPROPERTYNAME = "PartComponent";
58 static char * _RHSPROPERTYNAME = "GroupComponent";
59 static char * _LHSKEYNAME = "SystemName";
60 static char * _RHSKEYNAME = "Name";
61 static char * _LHSNAMESPACE = "root/cimv2";
62 static char * _RHSNAMESPACE = "smash";
64 static char * _XEN_DOMU_CLASS = "Xen_ComputerSystem";
66 // ----------------------------------------------------------------------------
67 // AssociationCleanup()
68 // Perform any necessary cleanup immediately before this provider is unloaded.
69 // ----------------------------------------------------------------------------
70 static CMPIStatus AssociationCleanup(
71 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
72 const CMPIContext * context, /* [in] Additional context info, if any. */
73 CMPIBoolean terminating) /* [in] True if MB is terminating */
74 {
75 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
77 _SBLIM_ENTER("AssociationCleanup");
78 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
79 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
81 /* Nothing needs to be done for cleanup. */
83 exit:
84 _SBLIM_RETURNSTATUS(status);
85 }
88 // ----------------------------------------------------------------------------
89 // AssociatorNames()
90 // ----------------------------------------------------------------------------
91 static CMPIStatus AssociatorNames(
92 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
93 const CMPIContext * context, /* [in] Additional context info, if any. */
94 const CMPIResult * results, /* [out] Results of this operation. */
95 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
96 const char * assocClass,
97 const char * resultClass,
98 const char * role,
99 const char * resultRole)
100 {
101 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
102 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
103 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
104 char *targetclass; /* Class of the target object(s). */
105 char *targetnamespace;
107 _SBLIM_ENTER("AssociatorNames");
108 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
109 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
110 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
111 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
112 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
113 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
114 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
115 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
116 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
118 /* Ensure the source class is not a virtual computer system */
119 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
120 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
121 goto exit;
122 }
124 /* Check that the requested association class, if any, is supported. */
125 if (assocClass != NULL) {
126 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _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 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
135 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
136 goto exit;
137 }
139 /* Determine the target class and namespace from the source class. */
140 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
141 targetclass = _RHSCLASSNAME;
142 targetnamespace = _RHSNAMESPACE;
143 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
144 targetclass = _LHSCLASSNAME;
145 targetnamespace = _LHSNAMESPACE;
146 } else {
147 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
148 goto exit;
149 }
150 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
151 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
153 /* Create an object path for the result class. */
154 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
155 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
156 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
157 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
158 goto exit;
159 }
161 /* Get the list of all target class object paths from the CIMOM. */
162 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
163 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
164 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
165 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
166 goto exit;
167 }
169 /* Return all object paths that exactly match the target class and resultClass, if specified. */
170 while (CMHasNext(objectpaths, NULL)) {
171 CMPIData data = CMGetNext(objectpaths, NULL);
172 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
174 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
176 /* Ignore possible instances of source class. */
177 if (strcmp(class,sourceclass) &&
178 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
180 CMReturnObjectPath(results, data.value.ref);
181 }
182 }
184 CMReturnDone(results);
186 exit:
187 _SBLIM_RETURNSTATUS(status);
188 }
191 // ----------------------------------------------------------------------------
192 // Associators()
193 // ----------------------------------------------------------------------------
194 static CMPIStatus Associators(
195 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
196 const CMPIContext * context, /* [in] Additional context info, if any. */
197 const CMPIResult * results, /* [out] Results of this operation. */
198 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
199 const char *assocClass,
200 const char *resultClass,
201 const char *role,
202 const char *resultRole,
203 const char ** properties) /* [in] List of desired properties (NULL=all). */
204 {
205 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
206 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
207 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
208 char *targetclass; /* Class of the target object(s). */
209 char *targetnamespace;
211 _SBLIM_ENTER("Associators");
212 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
213 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
214 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
215 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
216 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
217 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
218 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
219 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
220 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
222 /* Ensure the source class is not a virtual computer system */
223 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
224 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
225 goto exit;
226 }
228 /* Check that the requested association class, if any, is supported. */
229 if (assocClass != NULL) {
230 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
231 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
232 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
233 goto exit;
234 }
235 }
237 /* Check that the reference matches the required role, if any. */
238 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
239 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
240 goto exit;
241 }
243 /* Determine the target class from the source class. */
244 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
245 targetclass = _RHSCLASSNAME;
246 targetnamespace = _RHSNAMESPACE;
247 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
248 targetclass = _LHSCLASSNAME;
249 targetnamespace = _LHSNAMESPACE;
250 } else {
251 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
252 goto exit;
253 }
254 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
255 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
257 /* Create an object path for the result class. */
258 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
259 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
260 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
261 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
262 goto exit;
263 }
265 /* Get the list of all target class instances from the CIMOM. */
266 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
267 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
268 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
269 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
270 goto exit;
271 }
274 /* Return all instances that exactly match the target class and resultClass, if specified. */
275 while (CMHasNext(instances, NULL)) {
276 CMPIData data = CMGetNext(instances, NULL);
277 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
278 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
280 //CMSetNameSpace(op, targetnamespace);
281 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
283 /* Ignore possible instances of source class. */
284 if (strcmp(class,sourceclass) &&
285 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
286 CMReturnInstance(results, data.value.inst);
287 }
288 }
290 CMReturnDone(results);
292 exit:
293 _SBLIM_RETURNSTATUS(status);
294 }
297 // ----------------------------------------------------------------------------
298 // ReferenceNames()
299 // ----------------------------------------------------------------------------
300 static CMPIStatus ReferenceNames(
301 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
302 const CMPIContext * context, /* [in] Additional context info, if any. */
303 const CMPIResult * results, /* [out] Results of this operation. */
304 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
305 const char *assocClass,
306 const char *role)
307 {
308 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
309 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
310 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
311 char *targetclass; /* Class of the target object(s). */
312 char *targetnamespace;
314 _SBLIM_ENTER("ReferenceNames");
315 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
316 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
317 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
318 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
319 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
320 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
321 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
323 /* Ensure the source class is not a virtual computer system */
324 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
325 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
326 goto exit;
327 }
329 /* Check that the requested association class, if any, is supported. */
330 if (assocClass != NULL) {
331 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
332 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
333 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
334 goto exit;
335 }
336 }
338 /* Check that the reference matches the required role, if any. */
339 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
340 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
341 goto exit;
342 }
344 /* Determine the target class from the source class. */
345 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
346 targetclass = _RHSCLASSNAME;
347 targetnamespace = _RHSNAMESPACE;
348 /* Refences of LHS class should always be in LHS namespace. */
349 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
350 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
351 targetclass = _LHSCLASSNAME;
352 targetnamespace = _LHSNAMESPACE;
353 } else {
354 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
355 goto exit;
356 }
357 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
358 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
360 /* Create an object path for the result class. */
361 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
362 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
363 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
364 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
365 goto exit;
366 }
368 /* Get the list of all target class object paths from the CIMOM. */
369 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
370 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
371 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
372 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
373 goto exit;
374 }
376 /* Return all object paths that exactly match the target class and resultClass, if specified. */
377 while (CMHasNext(objectpaths, NULL)) {
378 CMPIData data = CMGetNext(objectpaths, NULL);
380 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
381 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
382 /* Create an object path for the association. Note that the association
383 * objects should exist in 'virt namespace' not the host namespace.
384 */
385 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
386 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
387 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
388 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
389 goto exit;
390 }
392 /* Assign the references in the association appropriately. */
393 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
394 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
395 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
396 } else {
397 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
398 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
399 }
401 CMReturnObjectPath(results, refobjectpath);
402 }
403 }
406 exit:
407 _SBLIM_RETURNSTATUS(status);
408 }
411 // ----------------------------------------------------------------------------
412 // References()
413 // ----------------------------------------------------------------------------
414 static CMPIStatus References(
415 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
416 const CMPIContext * context, /* [in] Additional context info, if any. */
417 const CMPIResult * results, /* [out] Results of this operation. */
418 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
419 const char *assocClass,
420 const char *role,
421 const char **properties) /* [in] List of desired properties (NULL=all). */
422 {
423 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
424 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
425 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
426 char *targetclass; /* Class of the target object(s). */
427 char *targetnamespace;
429 _SBLIM_ENTER("References");
430 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
431 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
432 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
433 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
434 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
435 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
436 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
438 /* Ensure the source class is not a virtual computer system */
439 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
440 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
441 goto exit;
442 }
444 /* Check that the requested association class, if any, is supported. */
445 if (assocClass != NULL) {
446 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
447 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
448 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
449 goto exit;
450 }
451 }
453 /* Check that the reference matches the required role, if any. */
454 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
455 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
456 goto exit;
457 }
459 /* Determine the target class from the source class. */
460 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
461 targetclass = _RHSCLASSNAME;
462 targetnamespace = _RHSNAMESPACE;
463 /* Refences of LHS class should always be in LHS namespace. */
464 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
465 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
466 targetclass = _LHSCLASSNAME;
467 targetnamespace = _LHSNAMESPACE;
468 } else {
469 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
470 goto exit;
471 }
472 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
473 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
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 /* Get the list of all target class object paths from the CIMOM. */
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 /* Return all object paths that exactly match the target class and resultClass, if specified. */
492 while (CMHasNext(objectpaths, NULL)) {
493 CMPIData data = CMGetNext(objectpaths, NULL);
495 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
496 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
497 /* Create an instance for the association. Note that the association
498 * objects should exist in 'virt namespace' not the host namespace.
499 */
500 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
501 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
502 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
503 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
504 goto exit;
505 }
507 /* Assign the references in the association appropriately. */
508 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
509 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
510 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
511 } else {
512 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
513 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
514 }
516 CMReturnInstance(results, refinstance);
517 }
518 }
520 exit:
521 _SBLIM_RETURNSTATUS(status);
522 }
525 // ----------------------------------------------------------------------------
526 // AssociationInitialize()
527 // Perform any necessary initialization immediately after this provider is
528 // first loaded.
529 // ----------------------------------------------------------------------------
530 static void AssociationInitialize(
531 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
532 const CMPIContext * context) /* [in] Additional context info, if any. */
533 {
534 _SBLIM_ENTER("AssociationInitialize");
535 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
536 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
538 /* Nothing needs to be done to initialize this provider */
539 _SBLIM_RETURN();
540 }
543 // ============================================================================
544 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
545 // ============================================================================
546 CMAssociationMIStub( , Xen_HostedMemoryPool, _BROKER, AssociationInitialize(&mi, ctx));