os-cmpi-xen

view src/Xen_CSSettingDataComponent.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 9e7979884fb5
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"
29 /* Include utility functions */
30 #include "cmpiutil.h"
32 /* Include _SBLIM_TRACE() logging support */
33 #include "cmpitrace.h"
35 #include "provider_common.h"
38 // ----------------------------------------------------------------------------
39 // COMMON GLOBAL VARIABLES
40 // ----------------------------------------------------------------------------
42 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
43 static const CMPIBroker *_BROKER;
46 // ============================================================================
47 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
48 // ============================================================================
50 // ----------------------------------------------------------------------------
51 // Info for the class supported by the association provider
52 // ----------------------------------------------------------------------------
54 /* Name of the left and right hand side classes of this association. */
55 static char * _ASSOCCLASS = "Xen_CSSettingDataComponent";
56 static char * _LHSCLASSNAME = "CIM_ResourceAllocationSettingData";
57 static char * _RHSCLASSNAME = "Xen_ComputerSystemSettingData";
58 static char * _LHSPROPERTYNAME = "PartComponent";
59 static char * _RHSPROPERTYNAME = "GroupComponent";
60 static char * _LHSKEYNAME = "InstanceID";
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. */
80 exit:
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). */
103 char *sourcekeyname;
104 char *targetkeyname;
106 _SBLIM_ENTER("AssociatorNames");
107 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
108 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
109 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
110 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
111 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
112 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
113 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
114 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
115 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
117 /* Check that the requested association class, if any, is supported. */
118 if (assocClass != NULL) {
119 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
120 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
121 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
122 goto exit;
123 }
124 }
126 /* Check that the reference matches the required role, if any. */
127 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
128 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
129 goto exit;
130 }
132 /* Determine the target class from the source class. */
133 // if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
134 CMPIObjectPath * source = CMNewObjectPath(_BROKER, namespace, sourceclass, NULL);
135 if (CMClassPathIsA(_BROKER, source, _LHSCLASSNAME, NULL)) {
136 sourcekeyname = _LHSKEYNAME;
137 targetclass = _RHSCLASSNAME;
138 targetkeyname = _RHSKEYNAME;
139 // } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
140 } else if (CMClassPathIsA(_BROKER, source, _RHSCLASSNAME, NULL)) {
141 sourcekeyname = _RHSKEYNAME;
142 targetclass = _LHSCLASSNAME;
143 targetkeyname = _LHSKEYNAME;
144 } else {
145 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
146 goto exit;
147 }
148 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
150 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
151 char sourcename[MAX_SYSTEM_NAME_LEN];
152 _CMPIStrncpySystemNameFromID(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
153 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
155 /* Create an object path for the result class. */
156 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
157 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
158 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
159 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
160 goto exit;
161 }
163 /* Get the list of all target class object paths from the CIMOM. */
164 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
165 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
166 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
167 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
168 goto exit;
169 }
171 /* Return all object paths that exactly match the target class and resultClass, if specified. */
172 while (CMHasNext(objectpaths, NULL)) {
173 CMPIData data = CMGetNext(objectpaths, NULL);
174 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
175 CMPIObjectPath * result = CMNewObjectPath(_BROKER, namespace, class, NULL);
176 if (CMClassPathIsA(_BROKER, result, targetclass, NULL) &&
177 ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
178 /* Only return entries whose name matches the reference. */
179 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
180 char resultname[MAX_SYSTEM_NAME_LEN];
181 if (_CMPIStrncpySystemNameFromID(resultname,CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
183 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref);
184 }
185 }
186 }
188 CMReturnDone(results);
190 exit:
191 _SBLIM_RETURNSTATUS(status);
192 }
195 // ----------------------------------------------------------------------------
196 // Associators()
197 // ----------------------------------------------------------------------------
198 static CMPIStatus Associators(
199 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
200 const CMPIContext * context, /* [in] Additional context info, if any. */
201 const CMPIResult * results, /* [out] Results of this operation. */
202 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
203 const char *assocClass,
204 const char *resultClass,
205 const char *role,
206 const char *resultRole,
207 const char ** properties) /* [in] List of desired properties (NULL=all). */
208 {
209 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
210 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
211 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
212 char *targetclass; /* Class of the target object(s). */
214 char *sourcekeyname;
215 char *targetkeyname;
217 _SBLIM_ENTER("Associators");
218 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
219 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
220 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
221 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
222 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
223 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
224 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
225 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
226 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
228 /* Check that the requested association class, if any, is supported. */
229 if (assocClass != NULL) {
230 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
231 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
232 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
233 goto exit;
234 }
235 }
237 /* Check that the reference matches the required role, if any. */
238 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
239 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
240 goto exit;
241 }
243 /* Determine the target class from the source class. */
244 // if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
245 CMPIObjectPath * source = CMNewObjectPath(_BROKER, namespace, sourceclass, NULL);
246 if (CMClassPathIsA(_BROKER, source, _LHSCLASSNAME, NULL)) {
247 sourcekeyname = _LHSKEYNAME;
248 targetclass = _RHSCLASSNAME;
249 targetkeyname = _RHSKEYNAME;
250 // } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
251 } else if (CMClassPathIsA(_BROKER, source, _RHSCLASSNAME, NULL)) {
252 sourcekeyname = _RHSKEYNAME;
253 targetclass = _LHSCLASSNAME;
254 targetkeyname = _LHSKEYNAME;
255 } else {
256 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
257 goto exit;
258 }
259 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
261 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
262 char sourcename[MAX_SYSTEM_NAME_LEN];
263 _CMPIStrncpySystemNameFromID(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
264 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
266 /* Create an object path for the result class. */
267 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
268 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
269 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
270 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
271 goto exit;
272 }
274 /* Get the list of all target class instances from the CIMOM. */
275 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
276 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
277 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
278 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
279 goto exit;
280 }
282 /* Return all instances that exactly match the target class and resultClass, if specified. */
283 while (CMHasNext(instances, NULL)) {
284 CMPIData data = CMGetNext(instances, NULL);
285 char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
286 // if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
287 CMPIObjectPath * result = CMNewObjectPath(_BROKER, namespace, class, NULL);
288 if (CMClassPathIsA(_BROKER, result, targetclass, NULL) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
289 /* Only return entries whose name matches the reference. */
290 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
291 char resultname[MAX_SYSTEM_NAME_LEN];
292 if (_CMPIStrncpySystemNameFromID(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
293 // BUG - returning data causes crash !?!
294 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
295 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, data.value.inst);
296 }
297 }
298 }
300 CMReturnDone(results);
302 exit:
303 _SBLIM_RETURNSTATUS(status);
304 }
307 // ----------------------------------------------------------------------------
308 // ReferenceNames()
309 // ----------------------------------------------------------------------------
310 static CMPIStatus ReferenceNames(
311 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
312 const CMPIContext * context, /* [in] Additional context info, if any. */
313 const CMPIResult * results, /* [out] Results of this operation. */
314 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
315 const char *assocClass,
316 const char *role)
317 {
318 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
319 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
320 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
321 char *targetclass; /* Class of the target object(s). */
323 char *sourcekeyname;
324 char *targetkeyname;
326 _SBLIM_ENTER("ReferenceNames");
327 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
328 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
329 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
330 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
331 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
332 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
333 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
335 /* Check that the requested association class, if any, is supported. */
336 if (assocClass != NULL) {
337 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
338 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
339 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
340 goto exit;
341 }
342 }
344 /* Check that the reference matches the required role, if any. */
345 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
346 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
347 goto exit;
348 }
350 /* Determine the target class from the source class. */
351 // if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
352 CMPIObjectPath * source = CMNewObjectPath(_BROKER, namespace, sourceclass, NULL);
353 if (CMClassPathIsA(_BROKER, source, _LHSCLASSNAME, NULL)) {
354 sourcekeyname = _LHSKEYNAME;
355 targetclass = _RHSCLASSNAME;
356 targetkeyname = _RHSKEYNAME;
357 // } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
358 } else if (CMClassPathIsA(_BROKER, source, _RHSCLASSNAME, NULL)) {
359 sourcekeyname = _RHSKEYNAME;
360 targetclass = _LHSCLASSNAME;
361 targetkeyname = _LHSKEYNAME;
362 } else {
363 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
364 goto exit;
365 }
366 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
368 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
369 char sourcename[MAX_SYSTEM_NAME_LEN];
370 _CMPIStrncpySystemNameFromID(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
371 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
373 /* Create an object path for the result class. */
374 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
375 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
376 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
377 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
378 goto exit;
379 }
381 /* Get the list of all target class object paths from the CIMOM. */
382 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
383 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
384 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
385 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
386 goto exit;
387 }
389 /* Return all object paths that exactly match the target class and resultClass, if specified. */
390 while (CMHasNext(objectpaths, NULL)) {
391 CMPIData data = CMGetNext(objectpaths, NULL);
392 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
393 // if (strcmp(class,targetclass) == 0) {
394 CMPIObjectPath * result = CMNewObjectPath(_BROKER, namespace, class, NULL);
395 if (CMClassPathIsA(_BROKER, result, targetclass, NULL)) {
397 /* Create an object path for the association. */
398 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
399 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
400 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
401 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
402 goto exit;
403 }
405 /* Assign the references in the association appropriately. */
406 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
407 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
408 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
409 } else {
410 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
411 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
412 }
414 /* Only return entries whose name matches the reference. */
415 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
416 char resultname[MAX_SYSTEM_NAME_LEN];
417 if (_CMPIStrncpySystemNameFromID(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
418 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath);
419 }
420 }
421 }
423 exit:
424 _SBLIM_RETURNSTATUS(status);
425 }
428 // ----------------------------------------------------------------------------
429 // References()
430 // ----------------------------------------------------------------------------
431 static CMPIStatus References(
432 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
433 const CMPIContext * context, /* [in] Additional context info, if any. */
434 const CMPIResult * results, /* [out] Results of this operation. */
435 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
436 const char *assocClass,
437 const char *role,
438 const char **properties) /* [in] List of desired properties (NULL=all). */
439 {
440 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
441 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
442 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
443 char *targetclass; /* Class of the target object(s). */
445 char *sourcekeyname;
446 char *targetkeyname;
448 _SBLIM_ENTER("References");
449 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
450 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
451 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
452 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
453 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
454 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
455 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
457 /* Check that the requested association class, if any, is supported. */
458 if (assocClass != NULL) {
459 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
460 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
461 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
462 goto exit;
463 }
464 }
466 /* Check that the reference matches the required role, if any. */
467 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
468 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
469 goto exit;
470 }
472 /* Determine the target class from the source class. */
473 // if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
474 CMPIObjectPath * source = CMNewObjectPath(_BROKER, namespace, sourceclass, NULL);
475 if (CMClassPathIsA(_BROKER, source, _LHSCLASSNAME, NULL)) {
476 sourcekeyname = _LHSKEYNAME;
477 targetclass = _RHSCLASSNAME;
478 targetkeyname = _RHSKEYNAME;
479 // } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
480 } else if (CMClassPathIsA(_BROKER, source, _RHSCLASSNAME, NULL)) {
481 sourcekeyname = _RHSKEYNAME;
482 targetclass = _LHSCLASSNAME;
483 targetkeyname = _LHSKEYNAME;
484 } else {
485 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
486 goto exit;
487 }
488 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
490 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
491 char sourcename[MAX_SYSTEM_NAME_LEN];
492 _CMPIStrncpySystemNameFromID(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
493 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
495 /* Create an object path for the result class. */
496 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
497 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
498 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
499 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
500 goto exit;
501 }
503 /* Get the list of all target class object paths from the CIMOM. */
504 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
505 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
506 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
507 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
508 goto exit;
509 }
511 /* Return all object paths that exactly match the target class and resultClass, if specified. */
512 while (CMHasNext(objectpaths, NULL)) {
513 CMPIData data = CMGetNext(objectpaths, NULL);
514 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
515 // if (strcmp(class,targetclass) == 0) {
516 CMPIObjectPath * result = CMNewObjectPath(_BROKER, namespace, class, NULL);
517 if (CMClassPathIsA(_BROKER, result, targetclass, NULL)) {
519 /* Create an instance for the association. */
520 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
521 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
522 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
523 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
524 goto exit;
525 }
527 /* Assign the references in the association appropriately. */
528 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
529 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
530 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
531 } else {
532 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
533 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
534 }
536 /* Only return entries whose name matches the reference. */
537 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
538 char resultname[MAX_SYSTEM_NAME_LEN];
539 if (_CMPIStrncpySystemNameFromID(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
540 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
541 }
542 }
543 }
545 exit:
546 _SBLIM_RETURNSTATUS(status);
547 }
550 // ----------------------------------------------------------------------------
551 // AssociationInitialize()
552 // Perform any necessary initialization immediately after this provider is
553 // first loaded.
554 // ----------------------------------------------------------------------------
555 static void AssociationInitialize(
556 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
557 const CMPIContext * context) /* [in] Additional context info, if any. */
558 {
559 _SBLIM_ENTER("AssociationInitialize");
560 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
561 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
563 /* Nothing needs to be done to initialize this provider */
564 _SBLIM_RETURN();
565 }
568 // ============================================================================
569 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
570 // ============================================================================
571 CMAssociationMIStub( , Xen_CSSettingDataComponent, _BROKER, AssociationInitialize(&mi, ctx));