os-cmpi-xen

view src/Xen_HostedVirtualSystemManagementService.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_HostedVirtualSystemManagementService";
54 static char * _LHSCLASSNAME = "Xen_VirtualSystemManagementService";
55 static char * _RHSCLASSNAME = "CIM_ComputerSystem";
56 static char * _LHSPROPERTYNAME = "Dependent";
57 static char * _RHSPROPERTYNAME = "Antecedent";
58 static char * _LHSNAMESPACE = "root/cimv2";
59 static char * _RHSNAMESPACE = "smash";
61 static char * _XEN_DOMU_CLASS = "Xen_ComputerSystem";
64 // ----------------------------------------------------------------------------
65 // AssociationCleanup()
66 // Perform any necessary cleanup immediately before this provider is unloaded.
67 // ----------------------------------------------------------------------------
68 static CMPIStatus AssociationCleanup(
69 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
70 const CMPIContext * context, /* [in] Additional context info, if any. */
71 CMPIBoolean terminating) /* [in] True if MB is terminating */
72 {
73 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
75 _SBLIM_ENTER("AssociationCleanup");
76 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
77 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
79 /* Nothing needs to be done for cleanup. */
80 _SBLIM_RETURNSTATUS(status);
81 }
84 // ----------------------------------------------------------------------------
85 // AssociatorNames()
86 // ----------------------------------------------------------------------------
87 static CMPIStatus AssociatorNames(
88 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
89 const CMPIContext * context, /* [in] Additional context info, if any. */
90 const CMPIResult * results, /* [out] Results of this operation. */
91 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
92 const char * assocClass,
93 const char * resultClass,
94 const char * role,
95 const char * resultRole)
96 {
97 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
98 char *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 computer system */
115 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
116 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_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 /* Ignore possible instances of source class. */
171 if (strcmp(class,sourceclass) &&
172 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
174 CMReturnObjectPath(results, data.value.ref);
175 }
176 }
178 CMReturnDone(results);
180 exit:
181 _SBLIM_RETURNSTATUS(status);
182 }
185 // ----------------------------------------------------------------------------
186 // Associators()
187 // ----------------------------------------------------------------------------
188 static CMPIStatus Associators(
189 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
190 const CMPIContext * context, /* [in] Additional context info, if any. */
191 const CMPIResult * results, /* [out] Results of this operation. */
192 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
193 const char *assocClass,
194 const char *resultClass,
195 const char *role,
196 const char *resultRole,
197 const char ** properties) /* [in] List of desired properties (NULL=all). */
198 {
199 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
200 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
201 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
202 char *targetclass; /* Class of the target object(s). */
203 char *targetnamespace;
205 _SBLIM_ENTER("Associators");
206 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
207 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
208 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
209 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
210 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
211 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
212 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
213 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
214 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
216 /* Ensure the source class is not a virtual computer system */
217 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
218 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
219 goto exit;
220 }
222 /* Check that the requested association class, if any, is supported. */
223 if (assocClass != NULL) {
224 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
225 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
226 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
227 goto exit;
228 }
229 }
231 /* Check that the reference matches the required role, if any. */
232 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
233 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
234 goto exit;
235 }
237 /* Determine the target class from the source class. */
238 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
239 targetclass = _RHSCLASSNAME;
240 targetnamespace = _RHSNAMESPACE;
241 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
242 targetclass = _LHSCLASSNAME;
243 targetnamespace = _LHSNAMESPACE;
244 } else {
245 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
246 goto exit;
247 }
248 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
249 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
251 /* Create an object path for the result class. */
252 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
253 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
254 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
255 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
256 goto exit;
257 }
259 /* Get the list of all target class instances from the CIMOM. */
260 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
261 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
262 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
263 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
264 goto exit;
265 }
267 /* Return all instances that exactly match the target class and resultClass, if specified. */
268 while (CMHasNext(instances, NULL)) {
269 CMPIData data = CMGetNext(instances, NULL);
270 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
271 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
273 //CMSetNameSpace(op, targetnamespace);
274 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
276 /* Ignore possible instances of source class. */
277 if (strcmp(class,sourceclass) &&
278 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
279 CMReturnInstance(results, data.value.inst);
280 }
281 }
283 CMReturnDone(results);
285 exit:
286 _SBLIM_RETURNSTATUS(status);
287 }
290 // ----------------------------------------------------------------------------
291 // ReferenceNames()
292 // ----------------------------------------------------------------------------
293 static CMPIStatus ReferenceNames(
294 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
295 const CMPIContext * context, /* [in] Additional context info, if any. */
296 const CMPIResult * results, /* [out] Results of this operation. */
297 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
298 const char *assocClass,
299 const char *role)
300 {
301 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
302 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
303 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
304 char *targetclass; /* Class of the target object(s). */
305 char *targetnamespace;
307 _SBLIM_ENTER("ReferenceNames");
308 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
309 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
310 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
311 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
312 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
313 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
314 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
316 /* Ensure the source class is not a virtual computer system */
317 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
318 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
319 goto exit;
320 }
322 /* Check that the requested association class, if any, is supported. */
323 if (assocClass != NULL) {
324 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
325 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
326 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
327 goto exit;
328 }
329 }
331 /* Check that the reference matches the required role, if any. */
332 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
333 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
334 goto exit;
335 }
337 /* Determine the target class from the source class. */
338 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
339 targetclass = _RHSCLASSNAME;
340 targetnamespace = _RHSNAMESPACE;
341 /* Refences of LHS class should always be in LHS namespace. */
342 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
343 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
344 targetclass = _LHSCLASSNAME;
345 targetnamespace = _LHSNAMESPACE;
346 } else {
347 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
348 goto exit;
349 }
350 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
351 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
353 /* Create an object path for the result class. */
354 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
355 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
356 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
357 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
358 goto exit;
359 }
361 /* Get the list of all target class object paths from the CIMOM. */
362 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
363 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
364 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
365 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
366 goto exit;
367 }
369 /* Return all object paths that exactly match the target class and resultClass, if specified. */
370 while (CMHasNext(objectpaths, NULL)) {
371 CMPIData data = CMGetNext(objectpaths, NULL);
373 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
374 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
375 /* Create an object path for the association. Note that the association
376 * objects should exist in 'virt namespace' not the host namespace.
377 */
378 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
379 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
380 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
381 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
382 goto exit;
383 }
385 /* Assign the references in the association appropriately. */
386 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
387 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
388 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
389 } else {
390 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
391 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
392 }
394 CMReturnObjectPath(results, refobjectpath);
395 }
396 }
398 exit:
399 _SBLIM_RETURNSTATUS(status);
400 }
403 // ----------------------------------------------------------------------------
404 // References()
405 // ----------------------------------------------------------------------------
406 static CMPIStatus References(
407 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
408 const CMPIContext * context, /* [in] Additional context info, if any. */
409 const CMPIResult * results, /* [out] Results of this operation. */
410 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
411 const char *assocClass,
412 const char *role,
413 const char **properties) /* [in] List of desired properties (NULL=all). */
414 {
415 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
416 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
417 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
418 char *targetclass; /* Class of the target object(s). */
419 char *targetnamespace;
421 _SBLIM_ENTER("References");
422 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
423 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
424 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
425 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
426 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
427 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
428 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
430 /* Ensure the source class is not a virtual computer system */
431 if (strcmp(sourceclass, _XEN_DOMU_CLASS) == 0) {
432 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_CLASS));
433 goto exit;
434 }
436 /* Check that the requested association class, if any, is supported. */
437 if (assocClass != NULL) {
438 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
439 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
440 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
441 goto exit;
442 }
443 }
445 /* Check that the reference matches the required role, if any. */
446 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
447 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
448 goto exit;
449 }
451 /* Determine the target class from the source class. */
452 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
453 targetclass = _RHSCLASSNAME;
454 targetnamespace = _RHSNAMESPACE;
455 /* Refences of LHS class should always be in LHS namespace. */
456 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
457 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
458 targetclass = _LHSCLASSNAME;
459 targetnamespace = _LHSNAMESPACE;
460 } else {
461 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
462 goto exit;
463 }
464 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
465 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
467 /* Create an object path for the result class. */
468 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
469 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
470 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
471 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
472 goto exit;
473 }
475 /* Get the list of all target class object paths from the CIMOM. */
476 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
477 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
478 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
479 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
480 goto exit;
481 }
483 /* Return all object paths that exactly match the target class and resultClass, if specified. */
484 while (CMHasNext(objectpaths, NULL)) {
485 CMPIData data = CMGetNext(objectpaths, NULL);
487 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
488 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
489 /* Create an instance for the association. Note that the association
490 * objects should exist in 'virt namespace' not the host namespace.
491 */
492 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
493 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
494 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
495 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
496 goto exit;
497 }
499 /* Assign the references in the association appropriately. */
500 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
501 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
502 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
503 } else {
504 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
505 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
506 }
508 CMReturnInstance(results, refinstance);
509 }
510 }
511 exit:
512 _SBLIM_RETURNSTATUS(status);
513 }
516 // ----------------------------------------------------------------------------
517 // AssociationInitialize()
518 // Perform any necessary initialization immediately after this provider is
519 // first loaded.
520 // ----------------------------------------------------------------------------
521 static void AssociationInitialize(
522 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
523 const CMPIContext * context) /* [in] Additional context info, if any. */
524 {
525 _SBLIM_ENTER("AssociationInitialize");
526 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
527 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
529 /* Nothing needs to be done to initialize this provider */
530 _SBLIM_RETURN();
531 }
534 // ============================================================================
535 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
536 // ============================================================================
537 CMAssociationMIStub( , Xen_HostedVirtualSystemManagementService, _BROKER, AssociationInitialize(&mi, ctx));