os-cmpi-xen

view src/Xen_ProcessorPoolComponent.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 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>
18 // Contributors:
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_ProcessorPoolComponent";
54 static char * _LHSCLASSNAME = "Xen_ProcessorPool";
55 static char * _RHSCLASSNAME = "CIM_Processor";
56 static char * _LHSPROPERTYNAME = "GroupComponent";
57 static char * _RHSPROPERTYNAME = "PartComponent";
58 static char * _LHSNAMESPACE = "root/cimv2";
59 static char * _RHSNAMESPACE = "smash";
61 static char * _XEN_DOMU_PROCESSOR_CLASS = "Xen_Processor";
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 *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
99 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
100 char *targetclass; /* Class of the target object(s). */
101 char *targetnamespace;
103 _SBLIM_ENTER("AssociatorNames");
104 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
105 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
106 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
107 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
108 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
109 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
110 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
111 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
112 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
114 /* Ensure the source class is not a virtual processor */
115 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) {
116 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS));
117 goto exit;
118 }
120 /* Check that the requested association class, if any, is supported. */
121 if (assocClass != NULL) {
122 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
123 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
124 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
125 goto exit;
126 }
127 }
129 /* Check that the reference matches the required role, if any. */
130 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
131 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
132 goto exit;
133 }
135 /* Determine the target class from the source class. */
136 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
137 targetclass = _RHSCLASSNAME;
138 targetnamespace = _RHSNAMESPACE;
139 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
140 targetclass = _LHSCLASSNAME;
141 targetnamespace = _LHSNAMESPACE;
142 } else {
143 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
144 goto exit;
145 }
146 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
147 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
149 /* Create an object path for the result class. */
150 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
151 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
152 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
153 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
154 goto exit;
155 }
157 /* Get the list of all target class object paths from the CIMOM. */
158 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
159 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
160 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
161 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
162 goto exit;
163 }
165 /* Return all object paths that exactly match the target class and resultClass, if specified. */
166 while (CMHasNext(objectpaths, NULL)) {
167 CMPIData data = CMGetNext(objectpaths, NULL);
168 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
170 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
172 /* Ignore possible instances of source class. */
173 if (strcmp(class,sourceclass) &&
174 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
176 CMReturnObjectPath(results, data.value.ref);
177 }
178 }
180 CMReturnDone(results);
182 exit:
183 _SBLIM_RETURNSTATUS(status);
184 }
187 // ----------------------------------------------------------------------------
188 // Associators()
189 // ----------------------------------------------------------------------------
190 static CMPIStatus Associators(
191 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
192 const CMPIContext * context, /* [in] Additional context info, if any. */
193 const CMPIResult * results, /* [out] Results of this operation. */
194 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
195 const char *assocClass,
196 const char *resultClass,
197 const char *role,
198 const char *resultRole,
199 const char ** properties) /* [in] List of desired properties (NULL=all). */
200 {
201 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
202 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
203 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
204 char *targetclass; /* Class of the target object(s). */
205 char *targetnamespace;
207 _SBLIM_ENTER("Associators");
208 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
209 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
210 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
211 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
212 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
213 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
214 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
215 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
216 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
218 /* Ensure the source class is not a virtual processor */
219 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) {
220 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS));
221 goto exit;
222 }
224 /* Check that the requested association class, if any, is supported. */
225 if (assocClass != NULL) {
226 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
227 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
228 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
229 goto exit;
230 }
231 }
233 /* Check that the reference matches the required role, if any. */
234 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
235 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
236 goto exit;
237 }
239 /* Determine the target class from the source class. */
240 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
241 targetclass = _RHSCLASSNAME;
242 targetnamespace = _RHSNAMESPACE;
243 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
244 targetclass = _LHSCLASSNAME;
245 targetnamespace = _LHSNAMESPACE;
246 } else {
247 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
248 goto exit;
249 }
250 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
251 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
253 /* Create an object path for the result class. */
254 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
255 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
256 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
257 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
258 goto exit;
259 }
261 /* Get the list of all target class instances from the CIMOM. */
262 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
263 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
264 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
265 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
266 goto exit;
267 }
269 /* Return all instances that exactly match the target class and resultClass, if specified. */
270 while (CMHasNext(instances, NULL)) {
271 CMPIData data = CMGetNext(instances, NULL);
272 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
273 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
275 CMSetNameSpace(op, targetnamespace);
276 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
277 _SBLIM_TRACE(2, ("--- got class=\"%s\"", class));
279 /* Ignore possible instances of source class. */
280 if (strcmp(class,sourceclass) &&
281 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
282 _SBLIM_TRACE(2, ("--- returning instance"));
283 CMReturnInstance(results, data.value.inst);
284 }
285 }
287 CMReturnDone(results);
289 exit:
290 _SBLIM_RETURNSTATUS(status);
291 }
294 // ----------------------------------------------------------------------------
295 // ReferenceNames()
296 // ----------------------------------------------------------------------------
297 static CMPIStatus ReferenceNames(
298 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
299 const CMPIContext * context, /* [in] Additional context info, if any. */
300 const CMPIResult * results, /* [out] Results of this operation. */
301 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
302 const char *assocClass,
303 const char *role)
304 {
305 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
306 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
307 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
308 char *targetclass; /* Class of the target object(s). */
309 char *targetnamespace;
311 _SBLIM_ENTER("ReferenceNames");
312 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
313 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
314 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
315 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
316 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
317 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
318 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
320 /* Ensure the source class is not a virtual processor */
321 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) {
322 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS));
323 goto exit;
324 }
326 /* Check that the requested association class, if any, is supported. */
327 if (assocClass != NULL) {
328 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
329 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
330 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
331 goto exit;
332 }
333 }
335 /* Check that the reference matches the required role, if any. */
336 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
337 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
338 goto exit;
339 }
341 /* Determine the target class from the source class. */
342 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
343 targetclass = _RHSCLASSNAME;
344 targetnamespace = _RHSNAMESPACE;
345 /* Refences of LHS class should always be in LHS namespace. */
346 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
347 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
348 targetclass = _LHSCLASSNAME;
349 targetnamespace = _LHSNAMESPACE;
350 } else {
351 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
352 goto exit;
353 }
354 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
355 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
357 /* Create an object path for the result class. */
358 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
359 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
360 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
361 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
362 goto exit;
363 }
365 /* Get the list of all target class object paths from the CIMOM. */
366 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
367 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
368 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
369 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
370 goto exit;
371 }
373 /* Return all object paths that exactly match the target class and resultClass, if specified. */
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, _RHSCLASSNAME) == 0) {
391 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
392 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
393 } else {
394 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
395 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, 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 *assocClass,
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 *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
421 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
422 char *targetclass; /* Class of the target object(s). */
423 char *targetnamespace;
425 _SBLIM_ENTER("References");
426 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
427 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
428 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
429 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
430 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
431 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
432 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
434 /* Ensure the source class is not a virtual processor */
435 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) {
436 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS));
437 goto exit;
438 }
440 /* Check that the requested association class, if any, is supported. */
441 if (assocClass != NULL) {
442 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
443 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
444 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
445 goto exit;
446 }
447 }
449 /* Check that the reference matches the required role, if any. */
450 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
451 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
452 goto exit;
453 }
455 /* Determine the target class from the source class. */
456 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
457 targetclass = _RHSCLASSNAME;
458 targetnamespace = _RHSNAMESPACE;
459 /* Refences of LHS class should always be in LHS namespace. */
460 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
461 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
462 targetclass = _LHSCLASSNAME;
463 targetnamespace = _LHSNAMESPACE;
464 } else {
465 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
466 goto exit;
467 }
468 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
469 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
471 /* Create an object path for the result class. */
472 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
473 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
474 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
475 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
476 goto exit;
477 }
479 /* Get the list of all target class object paths from the CIMOM. */
480 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
481 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
482 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
483 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
484 goto exit;
485 }
487 /* Return all object paths that exactly match the target class and resultClass, if specified. */
488 while (CMHasNext(objectpaths, NULL)) {
489 CMPIData data = CMGetNext(objectpaths, NULL);
491 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
492 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
493 /* Create an instance for the association. Note that the association
494 * objects should exist in 'virt namespace' not the host namespace.
495 */
496 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
497 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
498 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
499 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
500 goto exit;
501 }
503 /* Assign the references in the association appropriately. */
504 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
505 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
506 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
507 } else {
508 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
509 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
510 }
512 CMReturnInstance(results, refinstance);
513 }
514 }
515 exit:
516 _SBLIM_RETURNSTATUS(status);
517 }
520 // ----------------------------------------------------------------------------
521 // AssociationInitialize()
522 // Perform any necessary initialization immediately after this provider is
523 // first loaded.
524 // ----------------------------------------------------------------------------
525 static void AssociationInitialize(
526 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
527 const CMPIContext * context) /* [in] Additional context info, if any. */
528 {
529 _SBLIM_ENTER("AssociationInitialize");
530 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
531 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
533 /* Nothing needs to be done to initialize this provider */
534 _SBLIM_RETURN();
535 }
538 // ============================================================================
539 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
540 // ============================================================================
541 CMAssociationMIStub( , Xen_ProcessorPoolComponent, _BROKER, AssociationInitialize(&mi, ctx));