os-cmpi-xen

view src/Xen_CSSettingsDefineState.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_CSSettingsDefineState";
54 static char * _LHSCLASSNAME = "Xen_ComputerSystemSettingData";
55 static char * _RHSCLASSNAME = "Xen_ComputerSystem";
56 static char * _LHSPROPERTYNAME = "SettingData";
57 static char * _RHSPROPERTYNAME = "ManagedElement";
58 static char * _LHSKEYNAME = "InstanceID";
59 static char * _RHSKEYNAME = "Name";
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));
366 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
367 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
368 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
370 /* Create an object path for the result class. */
371 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
372 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
373 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
374 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
375 goto exit;
376 }
378 /* Get the list of all target class object paths from the CIMOM. */
379 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
380 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
381 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
382 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
383 goto exit;
384 }
386 /* Return all object paths that exactly match the target class and resultClass, if specified. */
387 while (CMHasNext(objectpaths, NULL)) {
388 CMPIData data = CMGetNext(objectpaths, NULL);
389 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
390 if (strcmp(class,targetclass) == 0) {
392 /* Create an object path for the association. */
393 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
394 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
395 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
396 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
397 goto exit;
398 }
400 /* Assign the references in the association appropriately. */
401 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
402 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
403 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
404 } else {
405 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
406 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
407 }
409 /* Only return entries whose name matches the reference. */
410 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
411 char resultname[MAX_SYSTEM_NAME_LEN];
412 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
413 if (strcmp(sourcename, resultname) == 0) CMReturnObjectPath(results, refobjectpath);
414 }
415 }
416 }
418 exit:
419 _SBLIM_RETURNSTATUS(status);
420 }
423 // ----------------------------------------------------------------------------
424 // References()
425 // ----------------------------------------------------------------------------
426 static CMPIStatus References(
427 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
428 const CMPIContext * context, /* [in] Additional context info, if any. */
429 const CMPIResult * results, /* [out] Results of this operation. */
430 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
431 const char *assocClass,
432 const char *role,
433 const char **properties) /* [in] List of desired properties (NULL=all). */
434 {
435 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
436 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
437 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
438 char *targetclass; /* Class of the target object(s). */
439 char sourcename[MAX_SYSTEM_NAME_LEN];
440 char *sourcekeyname;
441 char *targetkeyname;
442 _CMPIKeyValExtractFunc_t sourcekeyfunc;
443 _CMPIKeyValExtractFunc_t targetkeyfunc;
445 _SBLIM_ENTER("References");
446 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
447 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
448 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
449 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
450 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
451 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
452 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
454 /* Check that the requested association class, if any, is supported. */
455 if (assocClass != NULL) {
456 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
457 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
458 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
459 goto exit;
460 }
461 }
463 /* Check that the reference matches the required role, if any. */
464 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
465 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
466 goto exit;
467 }
469 /* Determine the target class from the source class. */
470 if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
471 sourcekeyname = _LHSKEYNAME;
472 sourcekeyfunc = _CMPIStrncpySystemNameFromID;
473 targetclass = _RHSCLASSNAME;
474 targetkeyname = _RHSKEYNAME;
475 targetkeyfunc = strncpy;
476 } else if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
477 sourcekeyname = _RHSKEYNAME;
478 sourcekeyfunc = strncpy;
479 targetclass = _LHSCLASSNAME;
480 targetkeyname = _LHSKEYNAME;
481 targetkeyfunc = _CMPIStrncpySystemNameFromID;
482 } else {
483 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
484 goto exit;
485 }
486 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
488 CMPIData namedata = CMGetKey(reference, sourcekeyname, NULL);
489 sourcekeyfunc(sourcename, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
490 _SBLIM_TRACE(2, ("--- sourcename=\"%s\"", sourcename));
492 /* Create an object path for the result class. */
493 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace, targetclass, &status);
494 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
495 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
496 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
497 goto exit;
498 }
500 /* Get the list of all target class object paths from the CIMOM. */
501 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
502 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
503 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
504 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
505 goto exit;
506 }
508 /* Return all object paths that exactly match the target class and resultClass, if specified. */
509 while (CMHasNext(objectpaths, NULL)) {
510 CMPIData data = CMGetNext(objectpaths, NULL);
511 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
512 if (strcmp(class,targetclass) == 0) {
514 /* Create an instance for the association. */
515 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
516 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
517 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
518 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
519 goto exit;
520 }
522 /* Assign the references in the association appropriately. */
523 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
524 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
525 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
526 } else {
527 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
528 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
529 }
531 /* Only return entries whose name matches the reference. */
532 namedata = CMGetKey(data.value.ref, targetkeyname, &status);
533 char resultname[MAX_SYSTEM_NAME_LEN];
534 if (targetkeyfunc(resultname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN)) {
535 if (strcmp(sourcename, resultname) == 0) CMReturnInstance(results, refinstance);
536 }
537 }
538 }
540 exit:
541 _SBLIM_RETURNSTATUS(status);
542 }
545 // ----------------------------------------------------------------------------
546 // AssociationInitialize()
547 // Perform any necessary initialization immediately after this provider is
548 // first loaded.
549 // ----------------------------------------------------------------------------
550 static void AssociationInitialize(
551 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
552 const CMPIContext * context) /* [in] Additional context info, if any. */
553 {
554 _SBLIM_ENTER("AssociationInitialize");
555 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
556 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
558 /* Nothing needs to be done to initialize this provider */
559 _SBLIM_RETURN();
560 }
563 // ============================================================================
564 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
565 // ============================================================================
566 CMAssociationMIStub( , Xen_CSSettingsDefineState, _BROKER, AssociationInitialize(&mi, ctx));