os-cmpi-xen

view src/Xen_MemoryPoolComponent.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents ab8e99c757f5
children
line source
1 // Copyright (C) 2006 Novell, Inc
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Jim Fehlig, <jfehlig@novell.com>
18 // Contributors:
19 // Description:
20 // ============================================================================
22 #include <string.h>
24 /* Include the required CMPI data types, function headers, and macros */
25 #include "cmpidt.h"
26 #include "cmpift.h"
27 #include "cmpimacs.h"
30 // ----------------------------------------------------------------------------
31 // COMMON GLOBAL VARIABLES
32 // ----------------------------------------------------------------------------
34 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
35 static const CMPIBroker *_BROKER;
37 /* Include utility functions */
38 #include "cmpiutil.h"
40 /* Include _SBLIM_TRACE() logging support */
41 #include "cmpitrace.h"
44 // ============================================================================
45 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
46 // ============================================================================
48 // ----------------------------------------------------------------------------
49 // Info for the class supported by the association provider
50 // ----------------------------------------------------------------------------
52 /* Name of the left and right hand side classes of this association. */
53 static char * _ASSOCCLASS = "Xen_MemoryPoolComponent";
54 static char * _LHSCLASSNAME = "Xen_MemoryPool";
55 static char * _RHSCLASSNAME = "CIM_Memory";
56 static char * _LHSPROPERTYNAME = "GroupComponent";
57 static char * _RHSPROPERTYNAME = "PartComponent";
58 static char * _LHSNAMESPACE = "root/cimv2";
59 static char * _RHSNAMESPACE = "smash";
61 static char * _XEN_DOMU_MEMORY_CLASS = "Xen_Memory";
63 /*
64 * TODO:
65 * When enumerating classes of CIM_Memory it is possible to get OMC_Memory
66 * and OMC_CacheMemory. How do we filter without explicitly stating "I
67 * don't want OMC_CacheMemory"? I suggest moving to a config file. But
68 * should it be at build, install or runtime?
69 */
71 static char * _OMC_CACHE_MEMORY_CLASS = "OMC_CacheMemory";
74 // ----------------------------------------------------------------------------
75 // AssociationCleanup()
76 // Perform any necessary cleanup immediately before this provider is unloaded.
77 // ----------------------------------------------------------------------------
78 static CMPIStatus AssociationCleanup(
79 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
80 const CMPIContext * context, /* [in] Additional context info, if any. */
81 CMPIBoolean terminating) /* [in] True if MB is terminating */
82 {
83 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
85 _SBLIM_ENTER("AssociationCleanup");
86 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
87 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
89 /* Nothing needs to be done for cleanup. */
90 _SBLIM_RETURNSTATUS(status);
91 }
94 // ----------------------------------------------------------------------------
95 // AssociatorNames()
96 // ----------------------------------------------------------------------------
97 static CMPIStatus AssociatorNames(
98 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
99 const CMPIContext * context, /* [in] Additional context info, if any. */
100 const CMPIResult * results, /* [out] Results of this operation. */
101 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
102 const char * assocClass,
103 const char * resultClass,
104 const char * role,
105 const char * resultRole)
106 {
107 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
108 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
109 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
110 char *targetclass; /* Class of the target object(s). */
111 char *targetnamespace;
113 _SBLIM_ENTER("AssociatorNames");
114 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
115 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
116 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
117 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
118 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
119 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
120 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
121 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
122 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
124 /* Ensure the source class is not a virtual processor */
125 if (strcmp(sourceclass, _XEN_DOMU_MEMORY_CLASS) == 0) {
126 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_MEMORY_CLASS));
127 goto exit;
128 }
130 /* Check that the requested association class, if any, is supported. */
131 if (assocClass != NULL) {
132 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
133 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
134 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
135 goto exit;
136 }
137 }
139 /* Check that the reference matches the required role, if any. */
140 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
141 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
142 goto exit;
143 }
145 /* Determine the target class from the source class. */
146 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
147 targetclass = _RHSCLASSNAME;
148 targetnamespace = _RHSNAMESPACE;
149 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
150 targetclass = _LHSCLASSNAME;
151 targetnamespace = _LHSNAMESPACE;
152 } else {
153 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
154 goto exit;
155 }
156 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
157 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
159 /* Create an object path for the result class. */
160 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
161 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
162 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
163 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
164 goto exit;
165 }
167 /* Get the list of all target class object paths from the CIMOM. */
168 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
169 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
170 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
171 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
172 goto exit;
173 }
175 /* Return all object paths that exactly match the target class and resultClass, if specified. */
176 while (CMHasNext(objectpaths, NULL)) {
177 CMPIData data = CMGetNext(objectpaths, NULL);
178 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
180 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
182 /* Ignore possible instances of source class. */
183 /*
184 * TODO: _OMC_CACHE_MEMORY_CLASS
185 */
186 if (strcmp(class, _OMC_CACHE_MEMORY_CLASS) &&
187 strcmp(class,sourceclass) &&
188 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) {
190 CMReturnObjectPath(results, data.value.ref);
191 }
192 }
194 CMReturnDone(results);
196 exit:
197 _SBLIM_RETURNSTATUS(status);
198 }
201 // ----------------------------------------------------------------------------
202 // Associators()
203 // ----------------------------------------------------------------------------
204 static CMPIStatus Associators(
205 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
206 const CMPIContext * context, /* [in] Additional context info, if any. */
207 const CMPIResult * results, /* [out] Results of this operation. */
208 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
209 const char *assocClass,
210 const char *resultClass,
211 const char *role,
212 const char *resultRole,
213 const char ** properties) /* [in] List of desired properties (NULL=all). */
214 {
215 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
216 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
217 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
218 char *targetclass; /* Class of the target object(s). */
219 char *targetnamespace;
221 _SBLIM_ENTER("Associators");
222 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
223 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
224 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
225 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
226 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
227 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
228 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
229 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
230 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
232 /* Ensure the source class is not a virtual processor */
233 if (strcmp(sourceclass, _XEN_DOMU_MEMORY_CLASS) == 0) {
234 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_MEMORY_CLASS));
235 goto exit;
236 }
238 /* Check that the requested association class, if any, is supported. */
239 if (assocClass != NULL) {
240 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
241 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
242 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
243 goto exit;
244 }
245 }
247 /* Check that the reference matches the required role, if any. */
248 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
249 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
250 goto exit;
251 }
253 /* Determine the target class from the source class. */
254 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
255 targetclass = _RHSCLASSNAME;
256 targetnamespace = _RHSNAMESPACE;
257 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
258 targetclass = _LHSCLASSNAME;
259 targetnamespace = _LHSNAMESPACE;
260 } else {
261 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
262 goto exit;
263 }
264 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
265 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
267 /* Create an object path for the result class. */
268 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
269 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
270 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
271 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
272 goto exit;
273 }
275 /* Get the list of all target class instances from the CIMOM. */
276 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status);
277 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
278 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg)));
279 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
280 goto exit;
281 }
283 /* Return all instances that exactly match the target class and resultClass, if specified. */
284 while (CMHasNext(instances, NULL)) {
285 CMPIData data = CMGetNext(instances, NULL);
286 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
287 char *class = CMGetCharPtr(CMGetClassName(op, NULL));
289 CMSetNameSpace(op, targetnamespace);
290 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL))));
291 _SBLIM_TRACE(2, ("--- got class=\"%s\"", class));
293 /* Ignore possible instances of source class. */
294 if (strcmp(class, _OMC_CACHE_MEMORY_CLASS) &&
295 strcmp(class,sourceclass) &&
296 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) {
297 _SBLIM_TRACE(2, ("--- returning instance"));
298 CMReturnInstance(results, data.value.inst);
299 }
300 }
302 CMReturnDone(results);
304 exit:
305 _SBLIM_RETURNSTATUS(status);
306 }
309 // ----------------------------------------------------------------------------
310 // ReferenceNames()
311 // ----------------------------------------------------------------------------
312 static CMPIStatus ReferenceNames(
313 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
314 const CMPIContext * context, /* [in] Additional context info, if any. */
315 const CMPIResult * results, /* [out] Results of this operation. */
316 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
317 const char *assocClass,
318 const char *role)
319 {
320 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
321 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
322 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
323 char *targetclass; /* Class of the target object(s). */
324 char *targetnamespace;
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 /* Ensure the source class is not a virtual processor */
336 if (strcmp(sourceclass, _XEN_DOMU_MEMORY_CLASS) == 0) {
337 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_MEMORY_CLASS));
338 goto exit;
339 }
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 (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
358 targetclass = _RHSCLASSNAME;
359 targetnamespace = _RHSNAMESPACE;
360 /* Refences of LHS class should always be in LHS namespace. */
361 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
362 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
363 targetclass = _LHSCLASSNAME;
364 targetnamespace = _LHSNAMESPACE;
365 } else {
366 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
367 goto exit;
368 }
369 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
370 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
372 /* Create an object path for the result class. */
373 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
374 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
375 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
376 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
377 goto exit;
378 }
380 /* Get the list of all target class object paths from the CIMOM. */
381 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
382 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
383 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
385 goto exit;
386 }
388 /* Return all object paths that exactly match the target class and resultClass, if specified. */
389 while (CMHasNext(objectpaths, NULL)) {
390 CMPIData data = CMGetNext(objectpaths, NULL);
391 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
393 /* Ignore possible instances of source class. */
394 if (strcmp(class, _OMC_CACHE_MEMORY_CLASS) &&
395 strcmp(class,sourceclass)) {
396 /* Create an object path for the association. Note that the association
397 * objects should exist in 'virt namespace' not the host namespace.
398 */
399 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status);
400 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
401 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
402 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
403 goto exit;
404 }
406 /* Assign the references in the association appropriately. */
407 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) {
408 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
409 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref);
410 } else {
411 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref);
412 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
413 }
415 CMReturnObjectPath(results, refobjectpath);
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 *targetnamespace;
442 _SBLIM_ENTER("References");
443 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
444 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
445 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
446 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
447 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
448 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
449 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
451 /* Ensure the source class is not a virtual processor */
452 if (strcmp(sourceclass, _XEN_DOMU_MEMORY_CLASS) == 0) {
453 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_MEMORY_CLASS));
454 goto exit;
455 }
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 (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
474 targetclass = _RHSCLASSNAME;
475 targetnamespace = _RHSNAMESPACE;
476 /* Refences of LHS class should always be in LHS namespace. */
477 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE);
478 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
479 targetclass = _LHSCLASSNAME;
480 targetnamespace = _LHSNAMESPACE;
481 } else {
482 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
483 goto exit;
484 }
485 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
486 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
488 /* Create an object path for the result class. */
489 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status);
490 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
491 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
492 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
493 goto exit;
494 }
496 /* Get the list of all target class object paths from the CIMOM. */
497 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status);
498 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
499 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg)));
500 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class");
501 goto exit;
502 }
504 /* Return all object paths that exactly match the target class and resultClass, if specified. */
505 while (CMHasNext(objectpaths, NULL)) {
506 CMPIData data = CMGetNext(objectpaths, NULL);
507 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
509 /* Ignore possible instances of source class. */
510 if (strcmp(class, _OMC_CACHE_MEMORY_CLASS) &&
511 strcmp(class,sourceclass)) {
512 /* Create an instance for the association. Note that the association
513 * objects should exist in 'virt namespace' not the host namespace.
514 */
515 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _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 CMReturnInstance(results, refinstance);
532 }
533 }
534 exit:
535 _SBLIM_RETURNSTATUS(status);
536 }
539 // ----------------------------------------------------------------------------
540 // AssociationInitialize()
541 // Perform any necessary initialization immediately after this provider is
542 // first loaded.
543 // ----------------------------------------------------------------------------
544 static void AssociationInitialize(
545 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
546 const CMPIContext * context) /* [in] Additional context info, if any. */
547 {
548 _SBLIM_ENTER("AssociationInitialize");
549 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
550 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
552 /* Nothing needs to be done to initialize this provider */
553 _SBLIM_RETURN();
554 }
557 // ============================================================================
558 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
559 // ============================================================================
560 CMAssociationMIStub( , Xen_MemoryPoolComponent, _BROKER, AssociationInitialize(&mi, ctx));