os-cmpi-xen

view src/Xen_CSElementCapabilities.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: Association provider for Xen_CSElementCapabilities.
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_CSElementCapabilities";
54 static char * _LHSCLASSNAME = "Xen_ComputerSystem";
55 static char * _RHSCLASSNAME = "Xen_ComputerSystemCapabilities";
56 static char * _LHSPROPERTYNAME = "ManagedElement";
57 static char * _RHSPROPERTYNAME = "Capabilities";
58 static char * _LHSNAMESPACE = "root/cimv2";
59 static char * _RHSNAMESPACE = "root/cimv2";
60 static char * _LHSKEYNAME = "Name";
61 static char * _RHSKEYNAME = "InstanceID";
63 // ----------------------------------------------------------------------------
64 // AssociationCleanup()
65 // Perform any necessary cleanup immediately before this provider is unloaded.
66 // ----------------------------------------------------------------------------
67 static CMPIStatus AssociationCleanup(
68 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
69 const CMPIContext * context, /* [in] Additional context info, if any. */
70 CMPIBoolean terminating) /* [in] True if MB is terminating */
71 {
72 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
74 _SBLIM_ENTER("AssociationCleanup");
75 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
76 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
78 /* Nothing needs to be done for cleanup. */
79 _SBLIM_RETURNSTATUS(status);
80 }
83 // ----------------------------------------------------------------------------
84 // AssociatorNames()
85 // ----------------------------------------------------------------------------
86 static CMPIStatus AssociatorNames(
87 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
88 const CMPIContext * context, /* [in] Additional context info, if any. */
89 const CMPIResult * results, /* [out] Results of this operation. */
90 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
91 const char * assocClass,
92 const char * resultClass,
93 const char * role,
94 const char * resultRole)
95 {
96 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
97 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
98 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
99 char *targetclass; /* Class of the target object(s). */
101 char *sourcekeyname;
102 char *targetkeyname;
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 /* Check that the requested association class, if any, is supported. */
116 if (assocClass != NULL) {
117 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
118 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
119 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
120 goto exit;
121 }
122 }
124 /* Check that the reference matches the required role, if any. */
125 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
126 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
127 goto exit;
128 }
130 /* Determine the target class from the source class. */
131 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
132 sourcekeyname = _LHSKEYNAME;
133 targetclass = _RHSCLASSNAME;
134 targetkeyname = _RHSKEYNAME;
135 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
136 sourcekeyname = _RHSKEYNAME;
137 targetclass = _LHSCLASSNAME;
138 targetkeyname = _LHSKEYNAME;
139 } else {
140 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
141 goto exit;
142 }
143 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
145 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
146 char * sourcename = CMGetCharPtr(namedata.value.string);
147 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
149 /* Create an object path for the result class. */
150 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, 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));
169 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
170 /* Only return entries whose name matches the reference. */
171 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
172 char * resultname = CMGetCharPtr(namedata.value.string);
173 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref);
174 }
175 }
177 CMReturnDone(results);
179 exit:
180 _SBLIM_RETURNSTATUS(status);
181 }
184 // ----------------------------------------------------------------------------
185 // Associators()
186 // ----------------------------------------------------------------------------
187 static CMPIStatus Associators(
188 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
189 const CMPIContext * context, /* [in] Additional context info, if any. */
190 const CMPIResult * results, /* [out] Results of this operation. */
191 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
192 const char *assocClass,
193 const char *resultClass,
194 const char *role,
195 const char *resultRole,
196 const char ** properties) /* [in] List of desired properties (NULL=all). */
197 {
198 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
199 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
200 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
201 char *targetclass; /* Class of the target object(s). */
203 char *sourcekeyname;
204 char *targetkeyname;
206 _SBLIM_ENTER("Associators");
207 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
208 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
209 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
210 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
211 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
212 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
213 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
214 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
215 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
217 /* Check that the requested association class, if any, is supported. */
218 if (assocClass != NULL) {
219 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
220 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
221 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
222 goto exit;
223 }
224 }
226 /* Check that the reference matches the required role, if any. */
227 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
228 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
229 goto exit;
230 }
232 /* Determine the target class from the source class. */
233 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
234 sourcekeyname = _LHSKEYNAME;
235 targetclass = _RHSCLASSNAME;
236 targetkeyname = _RHSKEYNAME;
237 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
238 sourcekeyname = _RHSKEYNAME;
239 targetclass = _LHSCLASSNAME;
240 targetkeyname = _LHSKEYNAME;
241 } else {
242 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
243 goto exit;
244 }
245 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
247 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
248 char * sourcename = CMGetCharPtr(namedata.value.string);
249 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
251 /* Create an object path for the result class. */
252 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, 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(CMGetObjectPath(data.value.inst,NULL), NULL));
272 /* Ignore possible instances of source class. */
273 if (strcmp(class,sourceclass) &&
274 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
275 /* Only return entries whose name matches the reference. */
276 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
277 char * resultname = CMGetCharPtr(namedata.value.string);
278 if (strcmp(sourcename, resultname) == 0)
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). */
306 char *sourcekeyname;
307 char *targetkeyname;
309 _SBLIM_ENTER("ReferenceNames");
310 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
311 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
312 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
313 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
314 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
315 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
316 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
318 /* Check that the requested association class, if any, is supported. */
319 if (assocClass != NULL) {
320 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
321 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
322 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
323 goto exit;
324 }
325 }
327 /* Check that the reference matches the required role, if any. */
328 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
329 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
330 goto exit;
331 }
333 /* Determine the target class from the source class. */
334 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
335 sourcekeyname = _LHSKEYNAME;
336 targetclass = _RHSCLASSNAME;
337 targetkeyname = _RHSKEYNAME;
338 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
339 sourcekeyname = _RHSKEYNAME;
340 targetclass = _LHSCLASSNAME;
341 targetkeyname = _LHSKEYNAME;
342 } else {
343 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
344 goto exit;
345 }
346 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
348 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
349 char * sourcename = CMGetCharPtr(namedata.value.string);
350 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
352 /* Create an object path for the result class. */
353 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
354 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
355 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
356 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
357 goto exit;
358 }
360 /* Get the list of all target class object paths from the CIMOM. */
361 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
362 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
363 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
364 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
365 goto exit;
366 }
368 /* Return all object paths that exactly match the target class and resultClass, if specified. */
369 while (CMHasNext(objectpaths, NULL)) {
370 CMPIData data = CMGetNext(objectpaths, NULL);
371 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, 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 /* Only return entries whose name matches the reference. */
395 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
396 char * resultname = CMGetCharPtr(namedata.value.string);
397 if (strcmp(sourcename, resultname) == 0)
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). */
424 char *sourcekeyname;
425 char *targetkeyname;
427 _SBLIM_ENTER("References");
428 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
429 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
430 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
431 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
432 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
433 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
434 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
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 (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
453 sourcekeyname = _LHSKEYNAME;
454 targetclass = _RHSCLASSNAME;
455 targetkeyname = _RHSKEYNAME;
456 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
457 sourcekeyname = _RHSKEYNAME;
458 targetclass = _LHSCLASSNAME;
459 targetkeyname = _LHSKEYNAME;
460 } else {
461 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
462 goto exit;
463 }
464 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
466 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
467 char * sourcename = CMGetCharPtr(namedata.value.string);
468 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
470 /* Create an object path for the result class. */
471 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, 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 /* Only return entries whose name matches the reference. */
512 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
513 char * resultname = CMGetCharPtr(namedata.value.string);
514 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
515 }
516 }
517 exit:
518 _SBLIM_RETURNSTATUS(status);
519 }
522 // ----------------------------------------------------------------------------
523 // AssociationInitialize()
524 // Perform any necessary initialization immediately after this provider is
525 // first loaded.
526 // ----------------------------------------------------------------------------
527 static void AssociationInitialize(
528 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
529 const CMPIContext * context) /* [in] Additional context info, if any. */
530 {
531 _SBLIM_ENTER("AssociationInitialize");
532 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
533 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
535 /* Nothing needs to be done to initialize this provider */
536 _SBLIM_RETURN();
537 }
540 // ============================================================================
541 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
542 // ============================================================================
543 CMAssociationMIStub( , Xen_CSElementCapabilities, _BROKER, AssociationInitialize(&mi, ctx));