os-cmpi-xen

view src/Xen_DiskSettingsDefineState.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 92a3b51298ab
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 // Description:
19 // ============================================================================
21 #include <string.h>
23 /* Include the required CMPI data types, function headers, and macros */
24 #include "cmpidt.h"
25 #include "cmpift.h"
26 #include "cmpimacs.h"
28 /* Include utility functions */
29 #include "cmpiutil.h"
30 #include "provider_common.h"
32 /* Include _SBLIM_TRACE() logging support */
33 #include "cmpitrace.h"
36 // ----------------------------------------------------------------------------
37 // COMMON GLOBAL VARIABLES
38 // ----------------------------------------------------------------------------
40 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
41 static const CMPIBroker *_BROKER;
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_DiskSettingsDefineState";
54 static char * _LHSCLASSNAME = "Xen_DiskSettingData";
55 static char * _RHSCLASSNAME = "Xen_Disk";
56 static char * _LHSPROPERTYNAME = "SettingData";
57 static char * _RHSPROPERTYNAME = "ManagedElement";
58 static char * _LHSKEYNAME = "InstanceID";
59 static char * _RHSKEYNAME = "DeviceID";
61 // ----------------------------------------------------------------------------
62 // AssociationCleanup()
63 // Perform any necessary cleanup immediately before this provider is unloaded.
64 // ----------------------------------------------------------------------------
65 static CMPIStatus AssociationCleanup(
66 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
67 const CMPIContext * context, /* [in] Additional context info, if any. */
68 CMPIBoolean terminating) /* [in] True if MB is terminating */
69 {
70 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
72 _SBLIM_ENTER("AssociationCleanup");
73 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
74 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
76 /* Nothing needs to be done for cleanup. */
77 _SBLIM_RETURNSTATUS(status);
78 }
81 // ----------------------------------------------------------------------------
82 // AssociatorNames()
83 // ----------------------------------------------------------------------------
84 static CMPIStatus AssociatorNames(
85 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
86 const CMPIContext * context, /* [in] Additional context info, if any. */
87 const CMPIResult * results, /* [out] Results of this operation. */
88 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
89 const char * assocClass,
90 const char * resultClass,
91 const char * role,
92 const char * resultRole)
93 {
94 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
95 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
96 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
97 CMPIData namedata;
98 char *targetclass; /* Class of the target object(s). */
99 char sourcename[MAX_SYSTEM_NAME_LEN];
100 char *sourcekeyname;
101 char *targetkeyname;
102 _CMPIKeyValExtractFunc_t sourcekeyfunc;
103 _CMPIKeyValExtractFunc_t targetkeyfunc;
105 _SBLIM_ENTER("AssociatorNames");
106 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
107 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
108 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
109 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
110 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
111 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
112 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
113 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
114 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
116 /* Check that the requested association class, if any, is supported. */
117 if (assocClass != NULL) {
118 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
119 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
120 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
121 goto exit;
122 }
123 }
125 /* Check that the reference matches the required role, if any. */
126 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
127 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
128 goto exit;
129 }
131 /* Determine the target class from the source class. */
132 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
133 sourcekeyname = _LHSKEYNAME;
134 sourcekeyfunc = _CMPIStrncpyDeviceNameFromID;
135 targetclass = _RHSCLASSNAME;
136 targetkeyname = _RHSKEYNAME;
137 targetkeyfunc = strncpy;
138 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
139 sourcekeyname = _RHSKEYNAME;
140 sourcekeyfunc = strncpy;
141 targetclass = _LHSCLASSNAME;
142 targetkeyname = _LHSKEYNAME;
143 targetkeyfunc = _CMPIStrncpyDeviceNameFromID;
144 } else {
145 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
146 goto exit;
147 }
148 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
150 namedata = CMGetKey(reference, sourcekeyname, NULL);
151 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
152 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
154 /* Create an object path for the result class. */
155 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
156 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
157 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
158 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
159 goto exit;
160 }
162 /* Get the list of all target class object paths from the CIMOM. */
163 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
164 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
165 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
166 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
167 goto exit;
168 }
170 /* Return all object paths that exactly match the target class and resultClass, if specified. */
171 while (CMHasNext(objectpaths, NULL)) {
172 CMPIData data = CMGetNext(objectpaths, NULL);
173 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
174 if ((strcmp(class,targetclass) == 0) &&
175 ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
176 /* Only return entries whose name matches the reference. */
177 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
178 char resultname[MAX_SYSTEM_NAME_LEN];
179 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string),
180 MAX_SYSTEM_NAME_LEN)) {
181 if (strcmp(sourcename, resultname) == 0)
182 CMReturnObjectPath(results, data.value.ref);
183 }
184 }
185 }
187 CMReturnDone(results);
189 exit:
190 _SBLIM_RETURNSTATUS(status);
191 }
194 // ----------------------------------------------------------------------------
195 // Associators()
196 // ----------------------------------------------------------------------------
197 static CMPIStatus Associators(
198 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
199 const CMPIContext * context, /* [in] Additional context info, if any. */
200 const CMPIResult * results, /* [out] Results of this operation. */
201 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
202 const char *assocClass,
203 const char *resultClass,
204 const char *role,
205 const char *resultRole,
206 const char ** properties) /* [in] List of desired properties (NULL=all). */
207 {
208 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
209 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
210 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
211 CMPIData namedata;
212 char *targetclass; /* Class of the target object(s). */
213 char sourcename[MAX_SYSTEM_NAME_LEN];
214 char *sourcekeyname;
215 char *targetkeyname;
216 _CMPIKeyValExtractFunc_t sourcekeyfunc;
217 _CMPIKeyValExtractFunc_t targetkeyfunc;
219 _SBLIM_ENTER("Associators");
220 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
221 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
222 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
223 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
224 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
225 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
226 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
227 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
228 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
230 /* Check that the requested association class, if any, is supported. */
231 if (assocClass != NULL) {
232 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
233 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
234 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
235 goto exit;
236 }
237 }
239 /* Check that the reference matches the required role, if any. */
240 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
241 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
242 goto exit;
243 }
245 /* Determine the target class from the source class. */
246 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
247 sourcekeyname = _LHSKEYNAME;
248 sourcekeyfunc = _CMPIStrncpyDeviceNameFromID;
249 targetclass = _RHSCLASSNAME;
250 targetkeyname = _RHSKEYNAME;
251 targetkeyfunc = strncpy;
252 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
253 sourcekeyname = _RHSKEYNAME;
254 sourcekeyfunc = strncpy;
255 targetclass = _LHSCLASSNAME;
256 targetkeyname = _LHSKEYNAME;
257 targetkeyfunc = _CMPIStrncpyDeviceNameFromID;
258 } else {
259 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
260 goto exit;
261 }
262 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
264 namedata = CMGetKey(reference, sourcekeyname, NULL);
265 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
266 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
268 /* Create an object path for the result class. */
269 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
270 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
271 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
272 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
273 goto exit;
274 }
276 /* Get the list of all target class instances from the CIMOM. */
277 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
278 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
279 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
280 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
281 goto exit;
282 }
284 /* Return all instances that exactly match the target class and resultClass, if specified. */
285 while (CMHasNext(instances, NULL)) {
286 CMPIData data = CMGetNext(instances, NULL);
287 char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
288 if ((strcmp(class,targetclass) == 0) &&
289 ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
290 /* Only return entries whose name matches the reference. */
291 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
292 char resultname[MAX_SYSTEM_NAME_LEN];
293 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string),
294 MAX_SYSTEM_NAME_LEN)) {
295 // BUG - returning data causes crash !?!
296 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
297 if (strcmp(sourcename, resultname) == 0)
298 CMReturnInstance(results, data.value.inst);
299 }
300 }
301 }
303 CMReturnDone(results);
305 exit:
306 _SBLIM_RETURNSTATUS(status);
307 }
310 // ----------------------------------------------------------------------------
311 // ReferenceNames()
312 // ----------------------------------------------------------------------------
313 static CMPIStatus ReferenceNames(
314 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
315 const CMPIContext * context, /* [in] Additional context info, if any. */
316 const CMPIResult * results, /* [out] Results of this operation. */
317 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
318 const char *assocClass,
319 const char *role)
320 {
321 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
322 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
323 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
324 CMPIData namedata;
325 char *targetclass; /* Class of the target object(s). */
326 char sourcename[MAX_SYSTEM_NAME_LEN];
327 char *sourcekeyname;
328 char *targetkeyname;
329 _CMPIKeyValExtractFunc_t sourcekeyfunc;
330 _CMPIKeyValExtractFunc_t targetkeyfunc;
332 _SBLIM_ENTER("ReferenceNames");
333 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
334 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
335 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
336 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
337 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
338 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
339 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
341 /* Check that the requested association class, if any, is supported. */
342 if (assocClass != NULL) {
343 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
344 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
345 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
346 goto exit;
347 }
348 }
350 /* Check that the reference matches the required role, if any. */
351 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
352 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
353 goto exit;
354 }
356 /* Determine the target class from the source class. */
357 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
358 sourcekeyname = _LHSKEYNAME;
359 sourcekeyfunc = _CMPIStrncpyDeviceNameFromID;
360 targetclass = _RHSCLASSNAME;
361 targetkeyname = _RHSKEYNAME;
362 targetkeyfunc = strncpy;
363 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
364 sourcekeyname = _RHSKEYNAME;
365 sourcekeyfunc = strncpy;
366 targetclass = _LHSCLASSNAME;
367 targetkeyname = _LHSKEYNAME;
368 targetkeyfunc = _CMPIStrncpyDeviceNameFromID;
369 } else {
370 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
371 goto exit;
372 }
373 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
375 namedata = CMGetKey(reference, sourcekeyname, NULL);
376 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
377 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
379 /* Create an object path for the result class. */
380 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
381 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
382 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
383 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
384 goto exit;
385 }
387 /* Get the list of all target class object paths from the CIMOM. */
388 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
389 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
390 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
391 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
392 goto exit;
393 }
395 /* Return all object paths that exactly match the target class and resultClass, if specified. */
396 while (CMHasNext(objectpaths, NULL)) {
397 CMPIData data = CMGetNext(objectpaths, NULL);
398 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
399 if (strcmp(class,targetclass) == 0) {
401 /* Create an object path for the association. */
402 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
403 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
404 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
405 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
406 goto exit;
407 }
409 /* Assign the references in the association appropriately. */
410 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
411 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
412 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
413 } else {
414 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
415 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
416 }
418 /* Only return entries whose name matches the reference. */
419 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
420 char resultname[MAX_SYSTEM_NAME_LEN];
421 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string),
422 MAX_SYSTEM_NAME_LEN)) {
423 if (strcmp(sourcename, resultname) == 0)
424 CMReturnObjectPath(results, refobjectpath);
425 }
426 }
427 }
429 exit:
430 _SBLIM_RETURNSTATUS(status);
431 }
434 // ----------------------------------------------------------------------------
435 // References()
436 // ----------------------------------------------------------------------------
437 static CMPIStatus References(
438 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
439 const CMPIContext * context, /* [in] Additional context info, if any. */
440 const CMPIResult * results, /* [out] Results of this operation. */
441 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
442 const char *assocClass,
443 const char *role,
444 const char **properties) /* [in] List of desired properties (NULL=all). */
445 {
446 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
447 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
448 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
449 CMPIData namedata;
450 char *targetclass; /* Class of the target object(s). */
451 char sourcename[MAX_SYSTEM_NAME_LEN];
452 char *sourcekeyname;
453 char *targetkeyname;
454 _CMPIKeyValExtractFunc_t sourcekeyfunc;
455 _CMPIKeyValExtractFunc_t targetkeyfunc;
457 _SBLIM_ENTER("References");
458 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
459 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
460 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
461 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
462 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
463 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
464 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
466 /* Check that the requested association class, if any, is supported. */
467 if (assocClass != NULL) {
468 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
469 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
470 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
471 goto exit;
472 }
473 }
475 /* Check that the reference matches the required role, if any. */
476 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
477 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
478 goto exit;
479 }
481 /* Determine the target class from the source class. */
482 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
483 sourcekeyname = _LHSKEYNAME;
484 sourcekeyfunc = _CMPIStrncpyDeviceNameFromID;
485 targetclass = _RHSCLASSNAME;
486 targetkeyname = _RHSKEYNAME;
487 targetkeyfunc = strncpy;
488 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
489 sourcekeyname = _RHSKEYNAME;
490 sourcekeyfunc = strncpy;
491 targetclass = _LHSCLASSNAME;
492 targetkeyname = _LHSKEYNAME;
493 targetkeyfunc = _CMPIStrncpyDeviceNameFromID;
494 } else {
495 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
496 goto exit;
497 }
498 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
500 namedata = CMGetKey(reference, sourcekeyname, NULL);
501 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
502 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
504 /* Create an object path for the result class. */
505 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
506 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
507 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
508 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
509 goto exit;
510 }
512 /* Get the list of all target class object paths from the CIMOM. */
513 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
514 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
515 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
516 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
517 goto exit;
518 }
520 /* Return all object paths that exactly match the target class and resultClass, if specified. */
521 while (CMHasNext(objectpaths, NULL)) {
522 CMPIData data = CMGetNext(objectpaths, NULL);
523 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
524 if (strcmp(class,targetclass) == 0) {
526 /* Create an instance for the association. */
527 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
528 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
529 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
530 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
531 goto exit;
532 }
534 /* Assign the references in the association appropriately. */
535 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
536 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
537 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
538 } else {
539 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
540 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
541 }
543 /* Only return entries whose name matches the reference. */
544 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
545 char resultname[MAX_SYSTEM_NAME_LEN];
546 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string),
547 MAX_SYSTEM_NAME_LEN)) {
548 if (strcmp(sourcename, resultname) == 0)
549 CMReturnInstance(results, refinstance);
550 }
551 }
552 }
554 exit:
555 _SBLIM_RETURNSTATUS(status);
556 }
559 // ----------------------------------------------------------------------------
560 // AssociationInitialize()
561 // Perform any necessary initialization immediately after this provider is
562 // first loaded.
563 // ----------------------------------------------------------------------------
564 static void AssociationInitialize(
565 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
566 const CMPIContext * context) /* [in] Additional context info, if any. */
567 {
568 _SBLIM_ENTER("AssociationInitialize");
569 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
570 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
572 /* Nothing needs to be done to initialize this provider */
573 _SBLIM_RETURN();
574 }
577 // ============================================================================
578 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
579 // ============================================================================
580 CMAssociationMIStub( , Xen_DiskSettingsDefineState, _BROKER, AssociationInitialize(&mi, ctx));