os-cmpi-xen

view src/Xen_HostedProcessorPool.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents ab8e99c757f5
children
line source
1 // Copyright (C) 2006 IBM Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Description:
20 // ============================================================================
22 #include <string.h>
24 /* Include the required CMPI data types, function headers, and macros */
25 #include "cmpidt.h"
26 #include "cmpift.h"
27 #include "cmpimacs.h"
30 // ----------------------------------------------------------------------------
31 // COMMON GLOBAL VARIABLES
32 // ----------------------------------------------------------------------------
34 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
35 static const CMPIBroker *_BROKER;
37 /* Include utility functions */
38 #include "cmpiutil.h"
40 /* Include _SBLIM_TRACE() logging support */
41 #include "cmpitrace.h"
44 // ============================================================================
45 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
46 // ============================================================================
48 // ----------------------------------------------------------------------------
49 // Info for the class supported by the association provider
50 // ----------------------------------------------------------------------------
52 /* Name of the left and right hand side classes of this association. */
53 static char * _ASSOCCLASS = "Xen_HostedProcessorPool";
54 static char * _LHSCLASSNAME = "Xen_ProcessorPool";
55 static char * _RHSCLASSNAME = "CIM_ComputerSystem";
56 static char * _LHSPROPERTYNAME = "PartComponent";
57 static char * _RHSPROPERTYNAME = "GroupComponent";
58 static char * _LHSNAMESPACE = "root/cimv2";
59 static char * _RHSNAMESPACE = "smash";
61 static char * _XEN_DOMU_CLASS = "Xen_ComputerSystem";
65 // ----------------------------------------------------------------------------
66 // AssociationCleanup()
67 // Perform any necessary cleanup immediately before this provider is unloaded.
68 // ----------------------------------------------------------------------------
69 static CMPIStatus AssociationCleanup(
70 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
71 const CMPIContext * context, /* [in] Additional context info, if any. */
72 CMPIBoolean terminating) /* [in] True if MB is terminating */
73 {
74 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
76 _SBLIM_ENTER("AssociationCleanup");
77 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
78 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
80 /* Nothing needs to be done for cleanup. */
81 _SBLIM_RETURNSTATUS(status);
82 }
85 // ----------------------------------------------------------------------------
86 // AssociatorNames()
87 // ----------------------------------------------------------------------------
88 static CMPIStatus AssociatorNames(
89 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
90 const CMPIContext * context, /* [in] Additional context info, if any. */
91 const CMPIResult * results, /* [out] Results of this operation. */
92 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
93 const char * assocClass,
94 const char * resultClass,
95 const char * role,
96 const char * resultRole)
97 {
98 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
99 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
100 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
101 char *targetclass; /* Class of the target object(s). */
102 char *targetnamespace;
104 _SBLIM_ENTER("AssociatorNames");
105 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
106 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
107 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
108 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
109 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
110 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
111 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
112 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
113 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
115 /* Ensure the source class is not a virtual computer system */
116 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
117 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
118 goto exit;
119 }
121 /* Check that the requested association class, if any, is supported. */
122 if (assocClass != NULL) {
123 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
124 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
125 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
126 goto exit;
127 }
128 }
130 /* Check that the reference matches the required role, if any. */
131 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
132 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
133 goto exit;
134 }
136 /* Determine the target class and namespace from the source class. */
137 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
138 targetclass = _RHSCLASSNAME;
139 targetnamespace = _RHSNAMESPACE;
140 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
141 targetclass = _LHSCLASSNAME;
142 targetnamespace = _LHSNAMESPACE;
143 } else {
144 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
145 goto exit;
146 }
147 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
148 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
150 /* Create an object path for the result class. */
151 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
152 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
153 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
154 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
155 goto exit;
156 }
158 /* Get the list of all target class object paths from the CIMOM. */
159 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
160 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
161 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
162 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
163 goto exit;
164 }
166 /* Return all object paths that exactly match the target class and resultClass, if specified. */
167 while (CMHasNext(objectpaths, NULL)) {
168 CMPIData data = CMGetNext(objectpaths, NULL);
169 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
171 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
173 /* Ignore possible instances of source class. */
174 if (strcmp(class,sourceclass) &&
175 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
177 CMReturnObjectPath(results, data.value.ref);
178 }
179 }
181 CMReturnDone(results);
183 exit:
184 _SBLIM_RETURNSTATUS(status);
185 }
188 // ----------------------------------------------------------------------------
189 // Associators()
190 // ----------------------------------------------------------------------------
191 static CMPIStatus Associators(
192 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
193 const CMPIContext * context, /* [in] Additional context info, if any. */
194 const CMPIResult * results, /* [out] Results of this operation. */
195 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
196 const char *assocClass,
197 const char *resultClass,
198 const char *role,
199 const char *resultRole,
200 const char ** properties) /* [in] List of desired properties (NULL=all). */
201 {
202 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
203 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
204 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
205 char *targetclass; /* Class of the target object(s). */
206 char *targetnamespace;
208 _SBLIM_ENTER("Associators");
209 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
210 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
211 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
212 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
213 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
214 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
215 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
216 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
217 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
219 /* Ensure the source class is not a virtual computer system */
220 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
221 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
222 goto exit;
223 }
225 /* Check that the requested association class, if any, is supported. */
226 if (assocClass != NULL) {
227 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
228 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
229 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
230 goto exit;
231 }
232 }
234 /* Check that the reference matches the required role, if any. */
235 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
236 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
237 goto exit;
238 }
240 /* Determine the target class from the source class. */
241 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
242 targetclass = _RHSCLASSNAME;
243 targetnamespace = _RHSNAMESPACE;
244 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
245 targetclass = _LHSCLASSNAME;
246 targetnamespace = _LHSNAMESPACE;
247 } else {
248 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
249 goto exit;
250 }
251 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
252 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
254 /* Create an object path for the result class. */
255 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
256 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
257 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
258 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
259 goto exit;
260 }
262 /* Get the list of all target class instances from the CIMOM. */
263 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
264 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
265 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
266 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
267 goto exit;
268 }
270 /* Return all instances that exactly match the target class and resultClass, if specified. */
271 while (CMHasNext(instances, NULL)) {
272 CMPIData data = CMGetNext(instances, NULL);
273 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
274 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
276 //CMSetNameSpace(op, targetnamespace);
277 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
279 /* Ignore possible instances of source class. */
280 if (strcmp(class,sourceclass) &&
281 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
282 CMReturnInstance(results, data.value.inst);
283 }
284 }
286 CMReturnDone(results);
288 exit:
289 _SBLIM_RETURNSTATUS(status);
290 }
293 // ----------------------------------------------------------------------------
294 // ReferenceNames()
295 // ----------------------------------------------------------------------------
296 static CMPIStatus ReferenceNames(
297 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
298 const CMPIContext * context, /* [in] Additional context info, if any. */
299 const CMPIResult * results, /* [out] Results of this operation. */
300 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
301 const char *assocClass,
302 const char *role)
303 {
304 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
305 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
306 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
307 char *targetclass; /* Class of the target object(s). */
308 char *targetnamespace;
310 _SBLIM_ENTER("ReferenceNames");
311 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
312 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
313 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
314 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
315 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
316 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
317 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
319 /* Ensure the source class is not a virtual computer system */
320 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
321 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
322 goto exit;
323 }
325 /* Check that the requested association class, if any, is supported. */
326 if (assocClass != NULL) {
327 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
328 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
329 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
330 goto exit;
331 }
332 }
334 /* Check that the reference matches the required role, if any. */
335 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
336 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
337 goto exit;
338 }
340 /* Determine the target class from the source class. */
341 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
342 targetclass = _RHSCLASSNAME;
343 targetnamespace = _RHSNAMESPACE;
344 /* Refences of LHS class should always be in LHS namespace. */
345 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
346 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
347 targetclass = _LHSCLASSNAME;
348 targetnamespace = _LHSNAMESPACE;
349 } else {
350 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
351 goto exit;
352 }
353 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
354 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
356 /* Create an object path for the result class. */
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 /* Get the list of all target class object paths from the CIMOM. */
365 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
366 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
367 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
368 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
369 goto exit;
370 }
372 /* Return all object paths that exactly match the target class and resultClass, if specified. */
373 while (CMHasNext(objectpaths, NULL)) {
374 CMPIData data = CMGetNext(objectpaths, NULL);
376 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
377 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
378 /* Create an object path for the association. Note that the association
379 * objects should exist in 'virt namespace' not the host namespace.
380 */
381 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
382 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
383 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
385 goto exit;
386 }
388 /* Assign the references in the association appropriately. */
389 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
390 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
391 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
392 } else {
393 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
394 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
395 }
397 CMReturnObjectPath(results, refobjectpath);
398 }
399 }
401 exit:
402 _SBLIM_RETURNSTATUS(status);
403 }
406 // ----------------------------------------------------------------------------
407 // References()
408 // ----------------------------------------------------------------------------
409 static CMPIStatus References(
410 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
411 const CMPIContext * context, /* [in] Additional context info, if any. */
412 const CMPIResult * results, /* [out] Results of this operation. */
413 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
414 const char *assocClass,
415 const char *role,
416 const char **properties) /* [in] List of desired properties (NULL=all). */
417 {
418 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
419 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
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, ("--- assocClass=\"%s\"", assocClass));
429 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
430 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
431 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
433 /* Ensure the source class is not a virtual computer system */
434 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
435 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
436 goto exit;
437 }
439 /* Check that the requested association class, if any, is supported. */
440 if (assocClass != NULL) {
441 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
442 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
443 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
444 goto exit;
445 }
446 }
448 /* Check that the reference matches the required role, if any. */
449 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
450 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
451 goto exit;
452 }
454 /* Determine the target class from the source class. */
455 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
456 targetclass = _RHSCLASSNAME;
457 targetnamespace = _RHSNAMESPACE;
458 /* Refences of LHS class should always be in LHS namespace. */
459 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
460 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
461 targetclass = _LHSCLASSNAME;
462 targetnamespace = _LHSNAMESPACE;
463 } else {
464 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
465 goto exit;
466 }
467 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
468 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
470 /* Create an object path for the result class. */
471 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
472 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
473 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
474 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
475 goto exit;
476 }
478 /* Get the list of all target class object paths from the CIMOM. */
479 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
480 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
481 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
482 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
483 goto exit;
484 }
486 /* Return all object paths that exactly match the target class and resultClass, if specified. */
487 while (CMHasNext(objectpaths, NULL)) {
488 CMPIData data = CMGetNext(objectpaths, NULL);
490 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
491 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
492 /* Create an instance for the association. Note that the association
493 * objects should exist in 'virt namespace' not the host namespace.
494 */
495 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
496 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
497 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
498 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
499 goto exit;
500 }
502 /* Assign the references in the association appropriately. */
503 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
504 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
505 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
506 } else {
507 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
508 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
509 }
511 CMReturnInstance(results, refinstance);
512 }
513 }
514 exit:
515 _SBLIM_RETURNSTATUS(status);
516 }
519 // ----------------------------------------------------------------------------
520 // AssociationInitialize()
521 // Perform any necessary initialization immediately after this provider is
522 // first loaded.
523 // ----------------------------------------------------------------------------
524 static void AssociationInitialize(
525 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
526 const CMPIContext * context) /* [in] Additional context info, if any. */
527 {
528 _SBLIM_ENTER("AssociationInitialize");
529 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
530 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
532 /* Nothing needs to be done to initialize this provider */
533 _SBLIM_RETURN();
534 }
537 // ============================================================================
538 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
539 // ============================================================================
540 CMAssociationMIStub( , Xen_HostedProcessorPool, _BROKER, AssociationInitialize(&mi, ctx));