os-cmpi-xen

view src/Xen_MemorySettingsDefineState.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 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_MemorySettingsDefineState";
54 static char * _LHSCLASSNAME = "Xen_MemorySettingData";
55 static char * _RHSCLASSNAME = "Xen_Memory";
56 static char * _LHSPROPERTYNAME = "SettingData";
57 static char * _RHSPROPERTYNAME = "ManagedElement";
58 static char * _LHSKEYNAME = "InstanceID";
59 static char * _RHSKEYNAME = "SystemName";
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 char *targetclass; /* Class of the target object(s). */
98 char sourcename[MAX_SYSTEM_NAME_LEN];
99 char *sourcekeyname;
100 char *targetkeyname;
101 _CMPIKeyValExtractFunc_t sourcekeyfunc;
102 _CMPIKeyValExtractFunc_t targetkeyfunc;
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 sourcekeyfunc = _CMPIStrncpySystemNameFromID;
134 targetclass = _RHSCLASSNAME;
135 targetkeyname = _RHSKEYNAME;
136 targetkeyfunc = strncpy;
137 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
138 sourcekeyname = _RHSKEYNAME;
139 sourcekeyfunc = strncpy;
140 targetclass = _LHSCLASSNAME;
141 targetkeyname = _LHSKEYNAME;
142 targetkeyfunc = _CMPIStrncpySystemNameFromID;
143 } else {
144 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
145 goto exit;
146 }
147 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
149 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
150 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
151 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
153 /* Create an object path for the result class. */
154 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
155 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
156 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
157 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
158 goto exit;
159 }
161 /* Get the list of all target class object paths from the CIMOM. */
162 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
163 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
164 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
165 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
166 goto exit;
167 }
169 /* Return all object paths that exactly match the target class and resultClass, if specified. */
170 while (CMHasNext(objectpaths, NULL)) {
171 CMPIData data = CMGetNext(objectpaths, NULL);
172 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
173 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
174 /* Only return entries whose name matches the reference. */
175 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
176 char resultname[MAX_SYSTEM_NAME_LEN];
177 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
178 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, data.value.ref);
179 }
180 }
181 }
183 CMReturnDone(results);
185 exit:
186 _SBLIM_RETURNSTATUS(status);
187 }
190 // ----------------------------------------------------------------------------
191 // Associators()
192 // ----------------------------------------------------------------------------
193 static CMPIStatus Associators(
194 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
195 const CMPIContext * context, /* [in] Additional context info, if any. */
196 const CMPIResult * results, /* [out] Results of this operation. */
197 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
198 const char *assocClass,
199 const char *resultClass,
200 const char *role,
201 const char *resultRole,
202 const char ** properties) /* [in] List of desired properties (NULL=all). */
203 {
204 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
205 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
206 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
207 char *targetclass; /* Class of the target object(s). */
208 char sourcename[MAX_SYSTEM_NAME_LEN];
209 char *sourcekeyname;
210 char *targetkeyname;
211 _CMPIKeyValExtractFunc_t sourcekeyfunc;
212 _CMPIKeyValExtractFunc_t targetkeyfunc;
214 _SBLIM_ENTER("Associators");
215 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
216 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
217 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
218 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
219 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
220 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
221 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
222 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
223 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
225 /* Check that the requested association class, if any, is supported. */
226 if (assocClass != NULL) {
227 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
228 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
229 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
230 goto exit;
231 }
232 }
234 /* Check that the reference matches the required role, if any. */
235 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
236 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
237 goto exit;
238 }
240 /* Determine the target class from the source class. */
241 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
242 sourcekeyname = _LHSKEYNAME;
243 sourcekeyfunc = _CMPIStrncpySystemNameFromID;
244 targetclass = _RHSCLASSNAME;
245 targetkeyname = _RHSKEYNAME;
246 targetkeyfunc = strncpy;
247 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
248 sourcekeyname = _RHSKEYNAME;
249 sourcekeyfunc = strncpy;
250 targetclass = _LHSCLASSNAME;
251 targetkeyname = _LHSKEYNAME;
252 targetkeyfunc = _CMPIStrncpySystemNameFromID;
253 } else {
254 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
255 goto exit;
256 }
257 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
259 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
260 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
261 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
263 /* Create an object path for the result class. */
264 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
265 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
266 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
267 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
268 goto exit;
269 }
271 /* Get the list of all target class instances from the CIMOM. */
272 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
273 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
274 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
275 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
276 goto exit;
277 }
279 /* Return all instances that exactly match the target class and resultClass, if specified. */
280 while (CMHasNext(instances, NULL)) {
281 CMPIData data = CMGetNext(instances, NULL);
282 char *class = CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
283 if ((strcmp(class,targetclass) == 0) && ((resultClass == NULL) || (strcmp(class,resultClass) == 0))) {
284 /* Only return entries whose name matches the reference. */
285 namedata = CMGetProperty(data.value.inst, targetkeyname, NULL);
286 char resultname[MAX_SYSTEM_NAME_LEN];
287 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
288 // BUG - returning data causes crash !?!
289 _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
290 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, data.value.inst);
291 }
292 }
293 }
295 CMReturnDone(results);
297 exit:
298 _SBLIM_RETURNSTATUS(status);
299 }
302 // ----------------------------------------------------------------------------
303 // ReferenceNames()
304 // ----------------------------------------------------------------------------
305 static CMPIStatus ReferenceNames(
306 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
307 const CMPIContext * context, /* [in] Additional context info, if any. */
308 const CMPIResult * results, /* [out] Results of this operation. */
309 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
310 const char *assocClass,
311 const char *role)
312 {
313 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
314 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
315 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
316 char *targetclass; /* Class of the target object(s). */
317 char sourcename[MAX_SYSTEM_NAME_LEN];
318 char *sourcekeyname;
319 char *targetkeyname;
320 _CMPIKeyValExtractFunc_t sourcekeyfunc;
321 _CMPIKeyValExtractFunc_t targetkeyfunc;
323 _SBLIM_ENTER("ReferenceNames");
324 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
325 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
326 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
327 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
328 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
329 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
330 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
332 /* Check that the requested association class, if any, is supported. */
333 if (assocClass != NULL) {
334 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
335 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
336 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
337 goto exit;
338 }
339 }
341 /* Check that the reference matches the required role, if any. */
342 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
343 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
344 goto exit;
345 }
347 /* Determine the target class from the source class. */
348 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
349 sourcekeyname = _LHSKEYNAME;
350 sourcekeyfunc = _CMPIStrncpySystemNameFromID;
351 targetclass = _RHSCLASSNAME;
352 targetkeyname = _RHSKEYNAME;
353 targetkeyfunc = strncpy;
354 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
355 sourcekeyname = _RHSKEYNAME;
356 sourcekeyfunc = strncpy;
357 targetclass = _LHSCLASSNAME;
358 targetkeyname = _LHSKEYNAME;
359 targetkeyfunc = _CMPIStrncpySystemNameFromID;
360 } else {
361 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
362 goto exit;
363 }
364 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
365 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
367 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
368 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
369 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
371 /* Create an object path for the result class. */
372 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
373 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
374 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
375 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
376 goto exit;
377 }
379 /* Get the list of all target class object paths from the CIMOM. */
380 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
381 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
382 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
383 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
384 goto exit;
385 }
387 /* Return all object paths that exactly match the target class and resultClass, if specified. */
388 while (CMHasNext(objectpaths, NULL)) {
389 CMPIData data = CMGetNext(objectpaths, NULL);
390 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
391 if (strcmp(class,targetclass) == 0) {
393 /* Create an object path for the association. */
394 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
395 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
396 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
397 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
398 goto exit;
399 }
401 /* Assign the references in the association appropriately. */
402 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
403 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
404 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
405 } else {
406 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
407 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
408 }
410 /* Only return entries whose name matches the reference. */
411 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
412 char resultname[MAX_SYSTEM_NAME_LEN];
413 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
414 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath);
415 }
416 }
417 }
419 exit:
420 _SBLIM_RETURNSTATUS(status);
421 }
424 // ----------------------------------------------------------------------------
425 // References()
426 // ----------------------------------------------------------------------------
427 static CMPIStatus References(
428 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
429 const CMPIContext * context, /* [in] Additional context info, if any. */
430 const CMPIResult * results, /* [out] Results of this operation. */
431 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
432 const char *assocClass,
433 const char *role,
434 const char **properties) /* [in] List of desired properties (NULL=all). */
435 {
436 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
437 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
438 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
439 char *targetclass; /* Class of the target object(s). */
440 char sourcename[MAX_SYSTEM_NAME_LEN];
441 char *sourcekeyname;
442 char *targetkeyname;
443 _CMPIKeyValExtractFunc_t sourcekeyfunc;
444 _CMPIKeyValExtractFunc_t targetkeyfunc;
446 _SBLIM_ENTER("References");
447 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
448 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
449 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
450 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
451 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
452 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
453 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
455 /* Check that the requested association class, if any, is supported. */
456 if (assocClass != NULL) {
457 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
458 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
459 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
460 goto exit;
461 }
462 }
464 /* Check that the reference matches the required role, if any. */
465 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
466 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
467 goto exit;
468 }
470 /* Determine the target class from the source class. */
471 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
472 sourcekeyname = _LHSKEYNAME;
473 sourcekeyfunc = _CMPIStrncpySystemNameFromID;
474 targetclass = _RHSCLASSNAME;
475 targetkeyname = _RHSKEYNAME;
476 targetkeyfunc = strncpy;
477 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
478 sourcekeyname = _RHSKEYNAME;
479 sourcekeyfunc = strncpy;
480 targetclass = _LHSCLASSNAME;
481 targetkeyname = _LHSKEYNAME;
482 targetkeyfunc = _CMPIStrncpySystemNameFromID;
483 } else {
484 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
485 goto exit;
486 }
487 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
489 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
490 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
491 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
493 /* Create an object path for the result class. */
494 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
495 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
496 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
497 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
498 goto exit;
499 }
501 /* Get the list of all target class object paths from the CIMOM. */
502 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
503 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
504 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
505 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
506 goto exit;
507 }
509 /* Return all object paths that exactly match the target class and resultClass, if specified. */
510 while (CMHasNext(objectpaths, NULL)) {
511 CMPIData data = CMGetNext(objectpaths, NULL);
512 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
513 if (strcmp(class,targetclass) == 0) {
515 /* Create an instance for the association. */
516 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
517 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
518 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
519 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
520 goto exit;
521 }
523 /* Assign the references in the association appropriately. */
524 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
525 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
526 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
527 } else {
528 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
529 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
530 }
532 /* Only return entries whose name matches the reference. */
533 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
534 char resultname[MAX_SYSTEM_NAME_LEN];
535 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
536 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
537 }
538 }
539 }
541 exit:
542 _SBLIM_RETURNSTATUS(status);
543 }
546 // ----------------------------------------------------------------------------
547 // AssociationInitialize()
548 // Perform any necessary initialization immediately after this provider is
549 // first loaded.
550 // ----------------------------------------------------------------------------
551 static void AssociationInitialize(
552 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
553 const CMPIContext * context) /* [in] Additional context info, if any. */
554 {
555 _SBLIM_ENTER("AssociationInitialize");
556 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
557 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
559 /* Nothing needs to be done to initialize this provider */
560 _SBLIM_RETURN();
561 }
564 // ============================================================================
565 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
566 // ============================================================================
567 CMAssociationMIStub( , Xen_MemorySettingsDefineState, _BROKER, AssociationInitialize(&mi, ctx));