os-cmpi-xen

changeset 127:152ceecb9f39

Moved all providers currently using 'Cmpilr' interface to latest 'Cimplify' interface from sblim cvs.

Removed cmpilr.[ch] and added cmpilify.[ch]. Removed old ProcessorSettingData
resource files that were inadvertently left behind when ProcessorSettingData
was ported to 'Cmpilr' interface.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Mon Jul 16 12:15:30 2007 -0600 (2007-07-16)
parents d1dab4776fed
children 0bf03964b16c
files ChangeLog src/Makefile.am src/Xen_Disk.c src/Xen_DiskSettingData.c src/Xen_Processor.c src/Xen_ProcessorSettingData.c src/Xen_ProcessorSettingData_Resource.c src/Xen_ProcessorSettingData_Resource.h src/Xen_VirtualSystemManagementCapabilities.c src/cmpilify.c src/cmpilify.h src/cmpilr.c src/cmpilr.h src/cmpiutil.h
line diff
     1.1 --- a/ChangeLog	Wed Jun 13 11:18:11 2007 -0600
     1.2 +++ b/ChangeLog	Mon Jul 16 12:15:30 2007 -0600
     1.3 @@ -1,3 +1,10 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Mon Jul 16 12:09:50 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +         - Moved all providers currently using 'Cmpilr' interface
     1.8 +           to latest 'Cimplify' interface from sblim cvs.  Removed
     1.9 +           cmpilr.[ch] and added cmpilify.[ch].
    1.10 +
    1.11  -------------------------------------------------------------------
    1.12  Tue Jun 12 17:50:28 MDT 2007 - jfehlig@novell.com
    1.13  
     2.1 --- a/src/Makefile.am	Wed Jun 13 11:18:11 2007 -0600
     2.2 +++ b/src/Makefile.am	Mon Jul 16 12:15:30 2007 -0600
     2.3 @@ -43,7 +43,7 @@ providerdir=@PROVIDERDIR@
     2.4  noinst_HEADERS = \
     2.5  	cmpiutil.h \
     2.6  	cmpitrace.h \
     2.7 -	cmpilr.h \
     2.8 +	cmpilify.h \
     2.9  	provider_common.h \
    2.10  	xen_utils.h \
    2.11  	Xen_ComputerSystem_Resource.h \
    2.12 @@ -59,8 +59,7 @@ noinst_HEADERS = \
    2.13  	Xen_MemoryPool_Resource.h \
    2.14  	Xen_ProcessorPool_Resource.h \
    2.15  	Xen_ProcessorCapabilitiesSettingData_Resource.h \
    2.16 -	Xen_MemoryCapabilitiesSettingData_Resource.h \
    2.17 -	Xen_ComputerSystemCapabilities_Resource.h
    2.18 +	Xen_MemoryCapabilitiesSettingData_Resource.h
    2.19  
    2.20  # LIST ANY UTILITY LIBRARIES, THEIR SOURCE FILE(S), AND ANY LIBS REQUIRED FOR LINKING HERE
    2.21  # libXen_utils contains Xen API and CMPI wrapper functions for the providers
    2.22 @@ -93,7 +92,7 @@ provider_LTLIBRARIES = \
    2.23  	libXen_ComputerSystemSettingData.la \
    2.24  	libXen_CSSettingsDefineState.la \
    2.25          libXen_CSElementSettingData.la \
    2.26 -        libXen_ProcessorSettingData.la \
    2.27 +	libXen_ProcessorSettingData.la \
    2.28  	libXen_ProcessorSettingsDefineState.la \
    2.29  	libXen_ProcessorElementSettingData.la \
    2.30  	libXen_MemorySettingData.la \
    2.31 @@ -130,7 +129,7 @@ provider_LTLIBRARIES = \
    2.32  #       libXen_HostedNetworkPort.la 
    2.33  
    2.34  
    2.35 -libXen_ProviderCommon_la_SOURCES = cmpitrace.c cmpiutil.c xen_utils.c cmpilr.c
    2.36 +libXen_ProviderCommon_la_SOURCES = cmpitrace.c cmpiutil.c xen_utils.c cmpilify.c
    2.37  libXen_ProviderCommon_la_CFLAGS = @LIBXEN_CFLAGS@ @LIBXML2_CFLAGS@
    2.38  libXen_ProviderCommon_la_LIBADD = @LIBXEN_LIBS@ @LIBXML2_LIBS@ -lpthread
    2.39  libXen_ProviderCommon_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@
     3.1 --- a/src/Xen_Disk.c	Wed Jun 13 11:18:11 2007 -0600
     3.2 +++ b/src/Xen_Disk.c	Mon Jul 16 12:15:30 2007 -0600
     3.3 @@ -21,18 +21,20 @@
     3.4  //
     3.5  // ============================================================================
     3.6  
     3.7 -/* Common declarations for each CMPI "Cimpler" instance provider */
     3.8 +/* Common declarations for each CMPI "cmpilify" instance provider */
     3.9  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    3.10 -#include "cmpidt.h"
    3.11 -#include "cmpimacs.h"
    3.12 -#include "cmpilr.h"
    3.13 +#include <cmpidt.h>
    3.14 +#include <cmpimacs.h>
    3.15 +
    3.16 +#include "cmpilify.h"
    3.17  
    3.18  
    3.19  static const CMPIInstanceMI* mi;
    3.20  
    3.21 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
    3.22 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
    3.23 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
    3.24  
    3.25 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    3.26 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    3.27  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    3.28  
    3.29  #include <stdlib.h>
    3.30 @@ -53,7 +55,7 @@ static const CMPIInstanceMI* mi;
    3.31  typedef struct {
    3.32     xen_vbd_set *disks;
    3.33     unsigned int currentdisknum;
    3.34 -} _RESOURCES;
    3.35 +} vbd_resources;
    3.36  
    3.37  
    3.38  /* Xen session object.  Initialize when the provider is loaded, close when
    3.39 @@ -61,62 +63,58 @@ typedef struct {
    3.40  static xen_utils_session *session = NULL;
    3.41  
    3.42  
    3.43 -static int load()
    3.44 +static CMPIrc load()
    3.45  {
    3.46     /* Initialized Xen session object. */
    3.47     if (!session)
    3.48        xen_utils_xen_init(&session);
    3.49  
    3.50 -   return 1;
    3.51 +   return CMPI_RC_OK;
    3.52  }
    3.53  
    3.54  
    3.55 -static int unload()
    3.56 +static CMPIrc unload(const int terminating)
    3.57  {
    3.58 +   (void)terminating;
    3.59 +   
    3.60 +   /* Close Xen session object. */
    3.61     if (session) {
    3.62        xen_utils_xen_close(session);
    3.63        session = NULL;
    3.64     }
    3.65  
    3.66 -   return 1;
    3.67 +   return CMPI_RC_OK;
    3.68  }
    3.69  
    3.70  
    3.71 -/*
    3.72 - * beginEnum is called before any function that uses the xen session.
    3.73 - * In the event this provider is loaded but has not been invoked for some
    3.74 - * time, the xen session object will be validated in beginEnum.  Functions
    3.75 - * called directly after beginEnum (e.g. get, getNext, modify) should
    3.76 - * set the session 'ok' flag.
    3.77 - */
    3.78 -static int beginEnum(void **res_list, CMPIStatus *status)
    3.79 +static CMPIrc begin(void **res_list, const char **properties)
    3.80  {
    3.81 -   _RESOURCES *resources;
    3.82 -   xen_domain_resources *res = NULL;
    3.83 +   vbd_resources *disk_resources;
    3.84 +   xen_domain_resources *domain_resources = NULL;
    3.85     xen_vbd_set *all_disks = NULL;
    3.86     xen_vm_record *vm_rec = NULL;
    3.87     
    3.88 -   if (res_list == NULL)
    3.89 -      return 0;
    3.90 +   (void)properties;
    3.91     
    3.92 -   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    3.93 -   if (resources == NULL)
    3.94 -      return 0;
    3.95 -
    3.96 +   if (res_list == NULL)
    3.97 +      return CMPI_RC_ERR_FAILED;
    3.98 +   
    3.99     if (!xen_utils_validate_session(&session)) {
   3.100        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.101                     ("--- Unable to establish connection with Xend"));
   3.102 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.103 -                           "Unable to establish connection with Xend");
   3.104 -      return 0;
   3.105 +      return CMPI_RC_ERR_FAILED;
   3.106     }
   3.107  
   3.108 +   disk_resources = (vbd_resources *)calloc(1, sizeof(vbd_resources));
   3.109 +   if (disk_resources == NULL)
   3.110 +      return CMPI_RC_ERR_FAILED;
   3.111 +
   3.112     /* Get a list of domain resources. */
   3.113 -   if (!xen_utils_get_domain_resources(session, &res))
   3.114 +   if (!xen_utils_get_domain_resources(session, &domain_resources))
   3.115        goto Error;
   3.116  
   3.117     /* Create list of disk resources from disks found in each domain. */
   3.118 -   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   3.119 +   while (xen_utils_get_next_domain_resource(session, domain_resources, &vm_rec)) {
   3.120        /* Ignore halted vms */
   3.121        if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) {
   3.122           xen_vm_record_free(vm_rec);
   3.123 @@ -133,107 +131,107 @@ static int beginEnum(void **res_list, CM
   3.124        xen_vm_record_free(vm_rec);
   3.125     }
   3.126     
   3.127 -   xen_utils_free_domain_resources(res);
   3.128 +   xen_utils_free_domain_resources(domain_resources);
   3.129  
   3.130 -   resources->disks = all_disks;
   3.131 -   resources->currentdisknum = 0;
   3.132 +   disk_resources->disks = all_disks;
   3.133 +   disk_resources->currentdisknum = 0;
   3.134     
   3.135 -   *res_list = (void *)resources;
   3.136 -   return 1;
   3.137 +   *res_list = (void *)disk_resources;
   3.138 +   return CMPI_RC_OK;
   3.139     
   3.140   Error:
   3.141 -   if (session && session->xen) {
   3.142 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.143 -                   ("--- failed to retrieve vbd resources from Xend:"));
   3.144 +   _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.145 +                ("--- failed to retrieve vbd resources from Xend:"));
   3.146 +   if (session && session->xen)
   3.147        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.148                              xen_utils_trace_error(session->xen));
   3.149 -   }
   3.150 -
   3.151 -   CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.152 -                        "Failed to retrieve vbd resources from Xend");
   3.153 -
   3.154 +   
   3.155 +   xen_vbd_set_free(all_disks);
   3.156     xen_vm_record_free(vm_rec);
   3.157 -   xen_utils_free_domain_resources(res);
   3.158 -   free(resources);
   3.159 -   return 0;
   3.160 +   xen_utils_free_domain_resources(domain_resources);
   3.161 +   free(disk_resources);
   3.162 +   return CMPI_RC_ERR_FAILED;
   3.163  }
   3.164  
   3.165  
   3.166 -static void endEnum(void *res_list)
   3.167 +static void end(void *res_list)
   3.168  {
   3.169 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   3.170 +   vbd_resources *disk_resources = (vbd_resources *)res_list;
   3.171     
   3.172 -   if (resources) {
   3.173 -      if (resources->disks)
   3.174 -          xen_vbd_set_free(resources->disks);
   3.175 -       free(resources);
   3.176 +   if (disk_resources) {
   3.177 +      if (disk_resources->disks)
   3.178 +          xen_vbd_set_free(disk_resources->disks);
   3.179 +       free(disk_resources);
   3.180     }
   3.181  }
   3.182  
   3.183  
   3.184 -static int getNext(void *res_list, void **res, CMPIStatus *status)
   3.185 +static CMPIrc getnext(void *res_list, void **res, const char **properties)
   3.186  {
   3.187 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   3.188 +   vbd_resources *disk_resources = (vbd_resources *)res_list;
   3.189     xen_vbd_record *vbd_rec;
   3.190  
   3.191 -   if (resources == NULL || resources->disks == NULL || res == NULL)
   3.192 -      return 0;
   3.193 +   (void)properties;
   3.194 +   
   3.195 +   if (disk_resources == NULL || res == NULL)
   3.196 +      return CMPI_RC_ERR_FAILED;
   3.197  
   3.198 -   /* Check if reached the end of the list of disks. */
   3.199 -   if (resources->currentdisknum == resources->disks->size)
   3.200 -      return 0;
   3.201 +   /* Are there any disks or has end of list of disks been reached? */
   3.202 +   if (disk_resources->disks == NULL ||
   3.203 +       disk_resources->currentdisknum == disk_resources->disks->size)
   3.204 +      return CMPI_RC_ERR_NOT_FOUND;
   3.205  
   3.206     /* Get the current disk record. */
   3.207     session->xen->ok = true;
   3.208     if (!xen_vbd_get_record(session->xen, &vbd_rec,
   3.209 -                           resources->disks->contents[resources->currentdisknum])) {
   3.210 +                           disk_resources->disks->contents[disk_resources->currentdisknum])) {
   3.211        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.212                     ("--- failed to retrieve vbd resources from Xend:"));
   3.213        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.214                              xen_utils_trace_error(session->xen));
   3.215 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.216 -                           "Failed to retrieve vbd resource from Xend");
   3.217 -      return 0;
   3.218 +      return CMPI_RC_ERR_FAILED;
   3.219     }
   3.220     
   3.221 -   resources->currentdisknum++;
   3.222 +   disk_resources->currentdisknum++;
   3.223     *res = (void *)vbd_rec;
   3.224 -   return 1;
   3.225 +   return CMPI_RC_OK;
   3.226  }
   3.227  
   3.228  
   3.229 -static int get(void *res_list, const CMPIObjectPath *op,
   3.230 -               void **res, CMPIStatus *status)
   3.231 +static CMPIrc get(const void *res_id, void **res, const char **properties)
   3.232  {
   3.233 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   3.234     CMPIData data;
   3.235 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   3.236     char *dev_uuid;
   3.237 -   int ccode;
   3.238  
   3.239 -   (void)res_list;
   3.240 +   (void)properties;
   3.241     
   3.242 -   if (CMIsNullObject(op) || res == NULL)
   3.243 -      return 0;
   3.244 +   if (CMIsNullObject(inst) || res == NULL)
   3.245 +      return CMPI_RC_ERR_FAILED;
   3.246  
   3.247 -   data = CMGetKey(op, "DeviceID", status);
   3.248 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.249 -      return 0;
   3.250 +   data = CMGetProperty(inst, "DeviceID", &status);
   3.251 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.252 +      return CMPI_RC_ERR_FAILED;
   3.253  
   3.254     /* Extract the domain name string from the CMPIString. */
   3.255     dev_uuid = CMGetCharPtr(data.value.string);
   3.256     if ((dev_uuid == NULL) || (*dev_uuid == '\0'))
   3.257 -      return 0;
   3.258 +      return CMPI_RC_ERR_FAILED;
   3.259  
   3.260 -   session->xen->ok = true;
   3.261 -
   3.262 +   if (!xen_utils_validate_session(&session)) {
   3.263 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.264 +                   ("--- Unable to establish connection with Xend"));
   3.265 +      return CMPI_RC_ERR_FAILED;
   3.266 +   }
   3.267 +    
   3.268     xen_vbd_record *vbd_rec;
   3.269     if (!xen_vbd_get_record(session->xen, &vbd_rec, (xen_vbd)dev_uuid)) {
   3.270        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.271                     ("--- xen_vbd_get_record failed:"));
   3.272        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.273                              xen_utils_trace_error(session->xen));
   3.274 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.275 -                           "xen_vbd_get_record failed");
   3.276 -      return 0;
   3.277 +      return CMPI_RC_ERR_FAILED;
   3.278     }
   3.279  
   3.280     /* TODO:
   3.281 @@ -248,77 +246,97 @@ static int get(void *res_list, const CMP
   3.282                     ("--- xen_vm_get_power_state failed:"));
   3.283        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.284                              xen_utils_trace_error(session->xen));
   3.285 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.286 -                           "Unable to determine vm power state");
   3.287        xen_vbd_record_free(vbd_rec);
   3.288        
   3.289 -      return 0;
   3.290 +      return CMPI_RC_ERR_FAILED;
   3.291     }
   3.292  
   3.293     if (pstate == XEN_VM_POWER_STATE_HALTED) {
   3.294 -         CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);
   3.295 -         xen_vbd_record_free(vbd_rec);
   3.296 -         return 0;
   3.297 +      xen_vbd_record_free(vbd_rec);
   3.298 +      return CMPI_RC_ERR_NOT_FOUND;
   3.299     }
   3.300     
   3.301     *res = (void *)vbd_rec;
   3.302 -   return 1;
   3.303 +   return CMPI_RC_OK;
   3.304  }
   3.305  
   3.306  
   3.307  static void release(void *res)
   3.308  {
   3.309 -   xen_vbd_record_free(res);
   3.310 +   xen_vbd_record_free((xen_vbd_record *)res);
   3.311  }
   3.312  
   3.313  
   3.314 -static int add(void **res_list, void *res, CMPIStatus *status)
   3.315 +static CMPIrc add(const void *res_id, const void *res)
   3.316  {
   3.317 -   return -1; /* unsupported */
   3.318 +   (void)res_id;
   3.319 +   (void)res;
   3.320 +   
   3.321 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   3.322  }
   3.323  
   3.324  
   3.325 -static int delete(void **res_list, void *res, CMPIStatus *status)
   3.326 +static CMPIrc delete(const void *res_id)
   3.327  {
   3.328 -   xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.329 -   
   3.330 -   (void)res_list;
   3.331 -   
   3.332 -   if (vbd_rec == NULL)
   3.333 -      return 0;
   3.334 -   
   3.335 -   session->xen->ok = true;
   3.336 -   if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) {
   3.337 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   3.338 +   CMPIData data;
   3.339 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   3.340 +   char *dev_uuid;
   3.341 +
   3.342 +   if (CMIsNullObject(inst))
   3.343 +      return CMPI_RC_ERR_FAILED;
   3.344 +
   3.345 +   data = CMGetProperty(inst, "DeviceID", &status);
   3.346 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.347 +      return CMPI_RC_ERR_FAILED;
   3.348 +
   3.349 +   /* Extract the domain name string from the CMPIString. */
   3.350 +   dev_uuid = CMGetCharPtr(data.value.string);
   3.351 +   if ((dev_uuid == NULL) || (*dev_uuid == '\0'))
   3.352 +      return CMPI_RC_ERR_FAILED;
   3.353 +
   3.354 +    if (!xen_utils_validate_session(&session)) {
   3.355        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.356 -                   ("--- xen_vbd_create failed:"));
   3.357 +                   ("--- Unable to establish connection with Xend"));
   3.358 +      return CMPI_RC_ERR_FAILED;
   3.359 +   }
   3.360 +
   3.361 +   if (!xen_vbd_destroy(session->xen, (xen_vbd)dev_uuid)) {
   3.362 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.363 +                   ("--- xen_vbd_destroy failed:"));
   3.364        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.365                              xen_utils_trace_error(session->xen));
   3.366 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.367 -                           "xen_vbd_destroy failed");
   3.368 -      return 0;
   3.369 +      return CMPI_RC_ERR_FAILED;
   3.370     }
   3.371  
   3.372 -   return 1;
   3.373 +   return CMPI_RC_OK;
   3.374  }
   3.375  
   3.376  
   3.377 -static int modify(void **res_list, void *target_res,
   3.378 -                  void *modified_res, CMPIStatus *status)
   3.379 +static CMPIrc modify(const void *res_id, const void *modified_res,
   3.380 +                     const char **properties)
   3.381  {
   3.382 -   return -1; /* unsupported */
   3.383 +   (void)res_id;
   3.384 +   (void)modified_res;
   3.385 +   (void)properties;
   3.386 +   
   3.387 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   3.388  }
   3.389  
   3.390  
   3.391  /* Set CMPIInstance properties from the resource data. */
   3.392 -static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   3.393 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   3.394 +                            const char **properties)
   3.395  {
   3.396     xen_vm_record *alloced_vm_rec = NULL;
   3.397     xen_vm_record *vm_rec;
   3.398     xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.399     char buf[MAX_INSTANCEID_LEN];
   3.400     
   3.401 +   (void)properties;
   3.402 +   
   3.403     if (vbd_rec == NULL || CMIsNullObject(inst))
   3.404 -      return 0;
   3.405 +      return CMPI_RC_ERR_FAILED;
   3.406  
   3.407     session->xen->ok = true;
   3.408  
   3.409 @@ -332,9 +350,7 @@ static int res2inst(void *res, CMPIInsta
   3.410                        ("--- xen_vm_get_record failed:"));
   3.411           _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.412                                 xen_utils_trace_error(session->xen));
   3.413 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.414 -                              "xen_vm_get_record failed");
   3.415 -         return 0;
   3.416 +         return CMPI_RC_ERR_FAILED;
   3.417        }
   3.418        alloced_vm_rec = vm_rec;
   3.419     }
   3.420 @@ -395,7 +411,7 @@ static int res2inst(void *res, CMPIInsta
   3.421     if (alloced_vm_rec)
   3.422        xen_vm_record_free(alloced_vm_rec);
   3.423  
   3.424 -   return 1;
   3.425 +   return CMPI_RC_OK;
   3.426  }
   3.427  
   3.428  
   3.429 @@ -403,12 +419,35 @@ static int res2inst(void *res, CMPIInsta
   3.430   * Set resource data from the CMPIInstance properties.  Only needs to
   3.431   * be implemented if add() and/or modify() are supported.
   3.432   */
   3.433 -static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   3.434 +static CMPIrc extract(void **res, const CMPIInstance *inst,
   3.435 +                      const char **properties)
   3.436  {
   3.437 -   return -1;  /* unsupported */
   3.438 +   (void)res;
   3.439 +   (void)inst;
   3.440 +   (void)properties;
   3.441 +   
   3.442 +   return CMPI_RC_ERR_NOT_SUPPORTED;  /* unsupported */
   3.443  }
   3.444  
   3.445  
   3.446 -/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   3.447 -/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   3.448 -CMPILRInstanceMIStub(Xen_Disk, Xen_Disk, mi)
   3.449 +/* Get resource id from CMPIInstance properties. */
   3.450 +static CMPIrc extractid(void **res_id, const CMPIInstance* inst)
   3.451 +{
   3.452 +   *res_id = (void *)inst;
   3.453 +   return CMPI_RC_OK;
   3.454 +}
   3.455 +
   3.456 +
   3.457 +/* Release resource id created in resId4inst(). */
   3.458 +static void releaseid(void* res_id)
   3.459 +{
   3.460 +   (void)res_id;
   3.461 +}
   3.462 +
   3.463 +
   3.464 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   3.465 +/* CMPILIFYInstanceMIStub(<CLASS>,<PROVIDER_NAME>,<keys>,<CMPIInstanceMI_HANDLE>) */
   3.466 +static char * keys[] = {"SystemCreationClassName", "SystemName",
   3.467 +                        "CreationClassName", "DeviceID", NULL};
   3.468 +
   3.469 +CMPILIFYInstanceMIStub(Xen_Disk, Xen_Disk, keys, mi)
     4.1 --- a/src/Xen_DiskSettingData.c	Wed Jun 13 11:18:11 2007 -0600
     4.2 +++ b/src/Xen_DiskSettingData.c	Mon Jul 16 12:15:30 2007 -0600
     4.3 @@ -21,18 +21,20 @@
     4.4  //                inspection/manipulation regardless of domain state.
     4.5  // ============================================================================
     4.6  
     4.7 -/* Common declarations for each CMPI "Cimpler" instance provider */
     4.8 +/* Common declarations for each CMPI "cmpilify" instance provider */
     4.9  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    4.10 -#include "cmpidt.h"
    4.11 -#include "cmpimacs.h"
    4.12 -#include "cmpilr.h"
    4.13 +#include <cmpidt.h>
    4.14 +#include <cmpimacs.h>
    4.15 +
    4.16 +#include "cmpilify.h"
    4.17  
    4.18  
    4.19  static const CMPIInstanceMI* mi;
    4.20  
    4.21 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
    4.22 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
    4.23 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
    4.24  
    4.25 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    4.26 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    4.27  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    4.28  
    4.29  #include <stdlib.h>
    4.30 @@ -56,14 +58,14 @@ typedef struct {
    4.31        xen_vbd_record *vbd_rec;
    4.32        CMPIInstance *cmpi_inst;
    4.33     } u;
    4.34 -} _RESOURCE;
    4.35 +} vbd_resource;
    4.36  
    4.37  
    4.38  /* C struct to store the data for all resources. */
    4.39  typedef struct {
    4.40     xen_vbd_set *disks;
    4.41     unsigned int currentdisknum;
    4.42 -} _RESOURCES;
    4.43 +} vbd_resources;
    4.44  
    4.45  
    4.46  /* Xen session object.  Initialize when the provider is loaded, close when
    4.47 @@ -71,59 +73,58 @@ typedef struct {
    4.48  static xen_utils_session *session = NULL;
    4.49  
    4.50  
    4.51 -static int load()
    4.52 +static CMPIrc load()
    4.53  {
    4.54     /* Initialized Xen session object. */
    4.55     if (!session)
    4.56        xen_utils_xen_init(&session);
    4.57  
    4.58 -   return 1;
    4.59 +   return CMPI_RC_OK;
    4.60  }
    4.61  
    4.62  
    4.63 -static int unload()
    4.64 +static CMPIrc unload(const int terminating)
    4.65  {
    4.66 +   (void)terminating;
    4.67 +   
    4.68 +   /* Close Xen session object. */
    4.69     if (session) {
    4.70        xen_utils_xen_close(session);
    4.71        session = NULL;
    4.72     }
    4.73  
    4.74 -   return 1;
    4.75 +   return CMPI_RC_OK;
    4.76  }
    4.77  
    4.78  
    4.79 -/*
    4.80 - * beginEnum is called before any function that uses the xen session.
    4.81 - * In the event this provider is loaded but has not been invoked for some
    4.82 - * time, the xen session object will be validated in beginEnum.  Functions
    4.83 - * called directly after beginEnum (e.g. get, getNext, modify) should
    4.84 - * set the session 'ok' flag.
    4.85 - */
    4.86 -static int beginEnum(void **res_list, CMPIStatus *status)
    4.87 +static CMPIrc begin(void **res_list, const char **properties)
    4.88  {
    4.89 -   _RESOURCES *resources;
    4.90 -   xen_domain_resources *res = NULL;
    4.91 +   vbd_resources *disk_resources;
    4.92 +   xen_domain_resources *domain_resources = NULL;
    4.93     xen_vbd_set *all_disks = NULL;
    4.94     xen_vm_record *vm_rec = NULL;
    4.95     
    4.96 -   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    4.97 -   if (resources == NULL)
    4.98 -      return 0;
    4.99 -
   4.100 +   (void)properties;
   4.101 +   
   4.102 +   if (res_list == NULL)
   4.103 +      return CMPI_RC_ERR_FAILED;
   4.104 +   
   4.105     if (!xen_utils_validate_session(&session)) {
   4.106        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.107                     ("--- Unable to establish connection with Xend"));
   4.108 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.109 -                           "Unable to establish connection with Xend");
   4.110 -      return 0;
   4.111 +      return CMPI_RC_ERR_FAILED;
   4.112     }
   4.113  
   4.114 +   disk_resources = (vbd_resources *)calloc(1, sizeof(vbd_resources));
   4.115 +   if (disk_resources == NULL)
   4.116 +      return CMPI_RC_ERR_FAILED;
   4.117 +
   4.118     /* Get a list of domain resources. */
   4.119 -   if (!xen_utils_get_domain_resources(session, &res))
   4.120 +   if (!xen_utils_get_domain_resources(session, &domain_resources))
   4.121        goto Error;
   4.122  
   4.123     /* Create list of disk resources from disks found in each domain. */
   4.124 -   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   4.125 +   while (xen_utils_get_next_domain_resource(session, domain_resources, &vm_rec)) {
   4.126        xen_vbd_set *vbd_set;
   4.127        if (!xen_vm_get_vbds(session->xen, &vbd_set, vm_rec->handle))
   4.128           goto Error;
   4.129 @@ -134,281 +135,326 @@ static int beginEnum(void **res_list, CM
   4.130        xen_vm_record_free(vm_rec);
   4.131     }
   4.132     
   4.133 -   resources->disks = all_disks;
   4.134 -   resources->currentdisknum = 0;
   4.135 +   xen_utils_free_domain_resources(domain_resources);
   4.136 +
   4.137 +   disk_resources->disks = all_disks;
   4.138 +   disk_resources->currentdisknum = 0;
   4.139     
   4.140 -   *res_list = (void *)resources;
   4.141 -   return 1;
   4.142 +   *res_list = (void *)disk_resources;
   4.143 +   return CMPI_RC_OK;
   4.144     
   4.145   Error:
   4.146 -   if (session && session->xen) {
   4.147 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.148 -                   ("--- failed to retrieve vbd resource from Xend:"));
   4.149 +   _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.150 +                ("--- failed to retrieve vbd resources from Xend:"));
   4.151 +   if (session && session->xen)
   4.152        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.153                              xen_utils_trace_error(session->xen));
   4.154 -   }
   4.155 -
   4.156 -   CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.157 -                        "Failed to retrieve vbd resources from Xend");
   4.158 -
   4.159 +   
   4.160 +   xen_vbd_set_free(all_disks);
   4.161     xen_vm_record_free(vm_rec);
   4.162 -   xen_utils_free_domain_resources(res);
   4.163 -   free(resources);
   4.164 -   return 0;
   4.165 +   xen_utils_free_domain_resources(domain_resources);
   4.166 +   free(disk_resources);
   4.167 +   return CMPI_RC_ERR_FAILED;
   4.168  }
   4.169  
   4.170  
   4.171 -static void endEnum(void *res_list)
   4.172 +static void end(void *res_list)
   4.173  {
   4.174 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   4.175 +   vbd_resources *disk_resources = (vbd_resources *)res_list;
   4.176     
   4.177 -   if (resources) {
   4.178 -      if (resources->disks)
   4.179 -          xen_vbd_set_free(resources->disks);
   4.180 -       free(resources);
   4.181 +   if (disk_resources) {
   4.182 +      if (disk_resources->disks)
   4.183 +          xen_vbd_set_free(disk_resources->disks);
   4.184 +       free(disk_resources);
   4.185     }
   4.186  }
   4.187  
   4.188  
   4.189 -static int getNext(void *res_list, void **res, CMPIStatus *status)
   4.190 +static CMPIrc getnext(void *res_list, void **res, const char **properties)
   4.191  {
   4.192 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   4.193 -   _RESOURCE *resource;
   4.194 -
   4.195 -   xen_vbd_record *vbd_rec;
   4.196 +   vbd_resources *disk_resources = (vbd_resources *)res_list;
   4.197 +   vbd_resource *disk_resource;
   4.198  
   4.199 -   if (resources == NULL || resources->disks == NULL)
   4.200 -      return 0;
   4.201 +   (void)properties;
   4.202 +   
   4.203 +   if (disk_resources == NULL || res == NULL)
   4.204 +      return CMPI_RC_ERR_FAILED;
   4.205  
   4.206 -   /* Check if reached the end of the list of disks. */
   4.207 -   if (resources->currentdisknum == resources->disks->size)
   4.208 -      return 0;
   4.209 +   /* Are there any disks or has end of list of disks been reached? */
   4.210 +   if (disk_resources->disks == NULL ||
   4.211 +       disk_resources->currentdisknum == disk_resources->disks->size)
   4.212 +      return CMPI_RC_ERR_NOT_FOUND;
   4.213  
   4.214     /* Get memory for resource. */
   4.215 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   4.216 -   if (resource == NULL)
   4.217 -      return 0;
   4.218 +   disk_resource = (vbd_resource *)calloc(1, sizeof(vbd_resource));
   4.219 +   if (disk_resource == NULL)
   4.220 +      return CMPI_RC_ERR_FAILED;
   4.221  
   4.222 -   resource->is_vbd_record = 1;
   4.223 +   disk_resource->is_vbd_record = 1;
   4.224  
   4.225     /* Get the current disk record. */
   4.226     session->xen->ok = true;
   4.227 -   if (!xen_vbd_get_record(session->xen, &(resource->u.vbd_rec),
   4.228 -                           resources->disks->contents[resources->currentdisknum])) {
   4.229 +   if (!xen_vbd_get_record(session->xen, &(disk_resource->u.vbd_rec),
   4.230 +                           disk_resources->disks->contents[disk_resources->currentdisknum])) {
   4.231        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.232 -                   ("--- failed to retrieve vbd resource from Xend:"));
   4.233 +                   ("--- failed to retrieve vbd resources from Xend:"));
   4.234        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.235                              xen_utils_trace_error(session->xen));
   4.236 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.237 -                           "Failed to retrieve vbd resource from Xend");
   4.238 -      return 0;
   4.239 +      return CMPI_RC_ERR_FAILED;
   4.240     }
   4.241     
   4.242 -   resources->currentdisknum++;
   4.243 -   *res = (void *)resource;
   4.244 -   return 1;
   4.245 +   disk_resources->currentdisknum++;
   4.246 +   *res = (void *)disk_resource;
   4.247 +   return CMPI_RC_OK;
   4.248  }
   4.249  
   4.250  
   4.251 -static int get(void *res_list, const CMPIObjectPath *op,
   4.252 -               void **res, CMPIStatus *status)
   4.253 +static CMPIrc get(const void *res_id, void **res, const char **properties)
   4.254  {
   4.255 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   4.256     CMPIData data;
   4.257 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   4.258     char *inst_id;
   4.259     char uuid[MAX_SYSTEM_NAME_LEN];
   4.260 -   _RESOURCE *resource;
   4.261 -
   4.262 -   (void)res_list;
   4.263 +   vbd_resource *disk_resource;
   4.264  
   4.265 -   if (CMIsNullObject(op) || res == NULL)
   4.266 -      return 0;
   4.267 +   (void)properties;
   4.268 +   
   4.269 +   if (CMIsNullObject(inst) || res == NULL)
   4.270 +      return CMPI_RC_ERR_FAILED;
   4.271  
   4.272 -   data = CMGetKey(op, "InstanceID", status);
   4.273 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   4.274 -      return 0;
   4.275 +   data = CMGetProperty(inst, "InstanceID", &status);
   4.276 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   4.277 +      return CMPI_RC_ERR_FAILED;
   4.278  
   4.279     inst_id = CMGetCharPtr(data.value.string);
   4.280     if ((inst_id == NULL) || (*inst_id == '\0'))
   4.281 -      return 0;
   4.282 +      return CMPI_RC_ERR_FAILED;
   4.283  
   4.284     /* Extract the disk uuid from InstanceID property. */
   4.285     if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   4.286 -      return 0;
   4.287 +      return CMPI_RC_ERR_FAILED;
   4.288 +
   4.289 +   if (!xen_utils_validate_session(&session)) {
   4.290 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.291 +                   ("--- Unable to establish connection with Xend"));
   4.292 +      return CMPI_RC_ERR_FAILED;
   4.293 +   }
   4.294  
   4.295     /* Get memory for resource. */
   4.296 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   4.297 -   if (resource == NULL)
   4.298 -      return 0;
   4.299 +   disk_resource = (vbd_resource *)calloc(1, sizeof(vbd_resource));
   4.300 +   if (disk_resource == NULL)
   4.301 +      return CMPI_RC_ERR_FAILED;
   4.302  
   4.303 -   resource->is_vbd_record = 1;
   4.304 +   disk_resource->is_vbd_record = 1;
   4.305  
   4.306 -   session->xen->ok = true;
   4.307 -   if (!xen_vbd_get_record(session->xen, &(resource->u.vbd_rec), (xen_vbd)uuid)) {
   4.308 +   if (!xen_vbd_get_record(session->xen, &(disk_resource->u.vbd_rec),
   4.309 +                           (xen_vbd)uuid)) {
   4.310        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.311                     ("--- xen_vbd_get_record failed:"));
   4.312        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.313                              xen_utils_trace_error(session->xen));
   4.314 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.315 -                           "xen_vbd_get_record failed");
   4.316 -      return 0;
   4.317 +      return CMPI_RC_ERR_FAILED;
   4.318     }
   4.319  
   4.320 -   *res = (void *)resource;
   4.321 -   return 1;
   4.322 +   *res = (void *)disk_resource;
   4.323 +   return CMPI_RC_OK;
   4.324  }
   4.325  
   4.326  
   4.327  static void release(void *res)
   4.328  {
   4.329     if (res) {
   4.330 -      _RESOURCE *resource = (_RESOURCE *)res;
   4.331 -      if (resource->is_vbd_record)
   4.332 -         xen_vbd_record_free(resource->u.vbd_rec);
   4.333 -      free(resource);
   4.334 +      vbd_resource *disk_resource = (vbd_resource *)res;
   4.335 +      if (disk_resource->is_vbd_record)
   4.336 +         xen_vbd_record_free(disk_resource->u.vbd_rec);
   4.337 +      free(disk_resource);
   4.338     }
   4.339  }
   4.340  
   4.341  
   4.342 -static int add(void **res_list, void *res, CMPIStatus *status)
   4.343 +static CMPIrc add(const void *res_id, const void *res)
   4.344  {
   4.345 -   return -1; /* unsupported */
   4.346 +   (void)res_id;
   4.347 +   (void)res;
   4.348 +   
   4.349 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   4.350  }
   4.351  
   4.352  
   4.353 -static int delete(void **res_list, void *res, CMPIStatus *status)
   4.354 +static CMPIrc delete(const void *res_id)
   4.355  {
   4.356 -   (void)res_list;
   4.357 -   
   4.358 -   if (res == NULL || !(((_RESOURCE *)res)->is_vbd_record))
   4.359 -      return 0;
   4.360 -   
   4.361 -   xen_vbd_record *vbd_rec = ((_RESOURCE *)res)->u.vbd_rec;
   4.362 -   
   4.363 -   session->xen->ok = true;
   4.364 -   if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) {
   4.365 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   4.366 +   CMPIData data;
   4.367 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   4.368 +   char *inst_id;
   4.369 +   char uuid[MAX_SYSTEM_NAME_LEN];
   4.370 +
   4.371 +   if (CMIsNullObject(inst))
   4.372 +      return CMPI_RC_ERR_FAILED;
   4.373 +
   4.374 +   data = CMGetProperty(inst, "InstanceID", &status);
   4.375 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   4.376 +      return CMPI_RC_ERR_FAILED;
   4.377 +
   4.378 +   inst_id = CMGetCharPtr(data.value.string);
   4.379 +   if ((inst_id == NULL) || (*inst_id == '\0'))
   4.380 +      return CMPI_RC_ERR_FAILED;
   4.381 +
   4.382 +   /* Extract the disk uuid from InstanceID property. */
   4.383 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   4.384 +      return CMPI_RC_ERR_FAILED;
   4.385 +
   4.386 +    if (!xen_utils_validate_session(&session)) {
   4.387 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.388 +                   ("--- Unable to establish connection with Xend"));
   4.389 +      return CMPI_RC_ERR_FAILED;
   4.390 +   }
   4.391 +
   4.392 +   if (!xen_vbd_destroy(session->xen, (xen_vbd)uuid)) {
   4.393        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.394                     ("--- xen_vbd_destroy failed:"));
   4.395        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.396                              xen_utils_trace_error(session->xen));
   4.397 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.398 -                           "xen_vbd_destroy failed");
   4.399 -      return 0;
   4.400 +      return CMPI_RC_ERR_FAILED;
   4.401     }
   4.402  
   4.403 -   return 1;
   4.404 +   return CMPI_RC_OK;
   4.405  }
   4.406  
   4.407  
   4.408 -static int modify(void **res_list, void *target_res,
   4.409 -                  void *modified_res, CMPIStatus *status)
   4.410 +static CMPIrc modify(const void *res_id, const void *modified_res,
   4.411 +                     const char **properties)
   4.412  {
   4.413 -   CMPIInstance *cmpi_inst;
   4.414 -   xen_vbd_record *vbd_rec;
   4.415 +   CMPIInstance *target_inst = (CMPIInstance *)res_id;
   4.416 +   vbd_resource *disk_resource = (vbd_resource *)modified_res;
   4.417 +   CMPIInstance *modified_inst;
   4.418     CMPIData data;
   4.419 -   char buf[64];
   4.420 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   4.421 +   char *inst_id;
   4.422 +   char uuid[MAX_SYSTEM_NAME_LEN];
   4.423 +   xen_vbd_record *target_vbd_rec;
   4.424 +   char *tmp_str = NULL;
   4.425 +   
   4.426 +   if (CMIsNullObject(target_inst) || disk_resource == NULL ||
   4.427 +       disk_resource->is_vbd_record)
   4.428 +      return CMPI_RC_ERR_FAILED;
   4.429 +
   4.430 +   modified_inst = disk_resource->u.cmpi_inst;
   4.431  
   4.432 -   if (target_res == NULL || modified_res == NULL)
   4.433 -      return 0;
   4.434 +   /* Get target vbd */
   4.435 +   data = CMGetProperty(target_inst, "InstanceID", &status);
   4.436 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   4.437 +      return CMPI_RC_ERR_FAILED;
   4.438 +
   4.439 +   inst_id = CMGetCharPtr(data.value.string);
   4.440 +   if ((inst_id == NULL) || (*inst_id == '\0'))
   4.441 +      return CMPI_RC_ERR_FAILED;
   4.442 +
   4.443 +   /* Extract the disk uuid from InstanceID property. */
   4.444 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   4.445 +      return CMPI_RC_ERR_FAILED;
   4.446  
   4.447 -   session->xen->ok = true;
   4.448 -   
   4.449 -   cmpi_inst = ((_RESOURCE *)modified_res)->u.cmpi_inst;
   4.450 -   vbd_rec = ((_RESOURCE *)target_res)->u.vbd_rec;
   4.451 +   if (!xen_utils_validate_session(&session)) {
   4.452 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.453 +                   ("--- Unable to establish connection with Xend"));
   4.454 +      return CMPI_RC_ERR_FAILED;
   4.455 +   }
   4.456 +
   4.457 +   if (!xen_vbd_get_record(session->xen, &target_vbd_rec, (xen_vbd)uuid)) {
   4.458 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.459 +                   ("--- xen_vbd_get_record failed:"));
   4.460 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.461 +                            xen_utils_trace_error(session->xen));
   4.462 +      return CMPI_RC_ERR_FAILED;
   4.463 +   }
   4.464  
   4.465     /* For now, allow modifying Mode only */
   4.466 -   data = CMGetProperty(cmpi_inst, "DiskConfigInfo", status);
   4.467 -   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   4.468 -      /*
   4.469 -       * Extract mode from the DiskConfigInfo string.  Format is
   4.470 -       * uname,dev,mode,<backend>
   4.471 -       */
   4.472 -      char *tmp_str = NULL;
   4.473 -      char *tok;
   4.474 -      char *next_tok;
   4.475 -      tmp_str = strdup(CMGetCharPtr(data.value.string));
   4.476 -
   4.477 -      /* 
   4.478 -       * Not doing anything with the first 2 tokens now, but we'll have them
   4.479 -       * ready to go
   4.480 -       */
   4.481 -      tok = strtok_r(tmp_str, ",", &next_tok);
   4.482 -      if (tok == NULL) {
   4.483 +   data = CMGetProperty(modified_inst, "DiskConfigInfo", &status);
   4.484 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   4.485 +       _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.486 +                   ("--- Unable to extract DiskConfigInfo from CMPI instance"));
   4.487 +       goto Error;
   4.488 +   }
   4.489 +   /*
   4.490 +    * Extract mode from the DiskConfigInfo string.  Format is
   4.491 +    * uname,dev,mode,<backend>
   4.492 +    */
   4.493 +   char *tok;
   4.494 +   char *next_tok;
   4.495 +   tmp_str = strdup(CMGetCharPtr(data.value.string));
   4.496 +   
   4.497 +   /* 
   4.498 +    * Do nothing with the first 2 tokens for now, but we'll have them
   4.499 +    * ready to go
   4.500 +    */
   4.501 +   tok = strtok_r(tmp_str, ",", &next_tok);
   4.502 +   if (tok == NULL) {
   4.503 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.504 +                   ("--- Malformed DiskConfigInfo property"));
   4.505 +      goto Error;
   4.506 +   }
   4.507 +   
   4.508 +   tok = strtok_r(NULL, ",", &next_tok);
   4.509 +   if (tok == NULL) {
   4.510 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.511 +                   ("--- Malformed DiskConfigInfo property"));
   4.512 +      goto Error;
   4.513 +   }
   4.514 +   
   4.515 +   tok = strtok_r(NULL, ",", &next_tok);
   4.516 +   if (tok == NULL) {
   4.517 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.518 +                   ("--- Malformed DiskConfigInfo property"));
   4.519 +      goto Error;
   4.520 +   }
   4.521 +   
   4.522 +   if ((strcmp(tok, "w") == 0)  && (target_vbd_rec->mode == XEN_VBD_MODE_RO)) {
   4.523 +      if (!xen_vbd_set_mode(session->xen, target_vbd_rec->handle, XEN_VBD_MODE_RW)) {
   4.524           _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.525 -                      ("--- Malformed DiskConfigInfo property"));
   4.526 -         CMSetStatusWithChars(_BROKER, status,
   4.527 -                              CMPI_RC_ERR_FAILED,
   4.528 -                              "Malformed DickConfigInfo property");
   4.529 -         free(tmp_str);
   4.530 -         return 0;
   4.531 +                      ("--- xen_vbd_set_mode failed:"));
   4.532 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.533 +                               xen_utils_trace_error(session->xen));
   4.534 +         goto Error;
   4.535        }
   4.536 -
   4.537 -      tok = strtok_r(NULL, ",", &next_tok);
   4.538 -      if (tok == NULL) {
   4.539 +   }
   4.540 +   else if ((strcmp(tok, "r") == 0)  && (target_vbd_rec->mode == XEN_VBD_MODE_RW)) {
   4.541 +      if (!xen_vbd_set_mode(session->xen, target_vbd_rec->handle, XEN_VBD_MODE_RO)) {
   4.542           _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.543 -                      ("--- Malformed DiskConfigInfo property"));
   4.544 -         CMSetStatusWithChars(_BROKER, status,
   4.545 -                              CMPI_RC_ERR_FAILED,
   4.546 -                              "Malformed DickConfigInfo property");
   4.547 -         free(tmp_str);
   4.548 -         return 0;
   4.549 +                      ("--- xen_vbd_set_mode failed:"));
   4.550 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.551 +                               xen_utils_trace_error(session->xen));
   4.552 +         goto Error;
   4.553        }
   4.554 +   }
   4.555 +   free(tmp_str);
   4.556 +   xen_vbd_record_free(target_vbd_rec);
   4.557 +   return CMPI_RC_OK;
   4.558  
   4.559 -      tok = strtok_r(NULL, ",", &next_tok);
   4.560 -      if (tok == NULL) {
   4.561 -         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.562 -                      ("--- Malformed DiskConfigInfo property"));
   4.563 -         CMSetStatusWithChars(_BROKER, status,
   4.564 -                              CMPI_RC_ERR_FAILED,
   4.565 -                              "Malformed DickConfigInfo property");
   4.566 -         free(tmp_str);
   4.567 -         return 0;
   4.568 -      }
   4.569 -
   4.570 -      if ((strcmp(tok, "w") == 0)  && (vbd_rec->mode == XEN_VBD_MODE_RO)) {
   4.571 -         if (!xen_vbd_set_mode(session->xen, vbd_rec->handle, XEN_VBD_MODE_RW)) {
   4.572 -            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.573 -                         ("--- xen_vbd_set_mode failed:"));
   4.574 -            _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.575 -                                  xen_utils_trace_error(session->xen));
   4.576 -            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.577 -                                 "xen_vbd_set_mode failed");
   4.578 -            free(tmp_str);
   4.579 -            return 0;
   4.580 -         }
   4.581 -      }
   4.582 -      else if ((strcmp(tok, "r") == 0)  && (vbd_rec->mode == XEN_VBD_MODE_RW)) {
   4.583 -         if (!xen_vbd_set_mode(session->xen, vbd_rec->handle, XEN_VBD_MODE_RO)) {
   4.584 -            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.585 -                         ("--- xen_vbd_set_mode failed:"));
   4.586 -            _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   4.587 -                                  xen_utils_trace_error(session->xen));
   4.588 -            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.589 -                                 "xen_vbd_set_mode failed");
   4.590 -            free(tmp_str);
   4.591 -            return 0;
   4.592 -         }
   4.593 -      }
   4.594 -      free(tmp_str);
   4.595 -   }
   4.596 -
   4.597 -   return 1;
   4.598 + Error:
   4.599 +   free(tmp_str);
   4.600 +   xen_vbd_record_free(target_vbd_rec);
   4.601 +   return CMPI_RC_ERR_FAILED;
   4.602 +   
   4.603  }
   4.604  
   4.605  
   4.606  /* Set CMPIInstance properties from the resource data. */
   4.607 -static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   4.608 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   4.609 +                            const char **properties)
   4.610  {
   4.611 +   vbd_resource *disk_resource = (vbd_resource *)res;
   4.612 +   char buf[MAX_INSTANCEID_LEN];
   4.613     xen_vbd_record *vbd_rec;
   4.614 -   char buf[MAX_INSTANCEID_LEN];
   4.615     
   4.616 -   if (res == NULL || CMIsNullObject(inst))
   4.617 -      return 0;
   4.618 +   (void)properties;
   4.619 +   
   4.620 +   if (CMIsNullObject(inst) || disk_resource == NULL ||
   4.621 +       !disk_resource->is_vbd_record)
   4.622 +      return CMPI_RC_ERR_FAILED;
   4.623  
   4.624 -   if (!(((_RESOURCE *)res)->is_vbd_record))
   4.625 -      return 0;
   4.626 -   
   4.627 +   vbd_rec = disk_resource->u.vbd_rec;
   4.628     session->xen->ok = true;
   4.629 -   vbd_rec = ((_RESOURCE *)res)->u.vbd_rec;
   4.630  
   4.631     xen_vm_record_opt *vm_rec_opt = vbd_rec->vm;
   4.632     if (vm_rec_opt->is_record) {
   4.633 @@ -419,7 +465,7 @@ static int res2inst(void *res, CMPIInsta
   4.634        char *name = NULL;
   4.635        
   4.636        if (!xen_vm_get_name_label(session->xen, &name, vm_rec_opt->u.handle))
   4.637 -         return 0;
   4.638 +         return CMPI_RC_ERR_FAILED;
   4.639        snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s",
   4.640                 name, vbd_rec->uuid);
   4.641        free(name);
   4.642 @@ -478,7 +524,7 @@ static int res2inst(void *res, CMPIInsta
   4.643      * PoolID, Weight, HostResource (mapped device in dom0)
   4.644      */
   4.645  
   4.646 -   return 1;
   4.647 +   return CMPI_RC_OK;
   4.648  }
   4.649  
   4.650  
   4.651 @@ -486,22 +532,41 @@ static int res2inst(void *res, CMPIInsta
   4.652   * Set resource data from the CMPIInstance properties.  Only needs to
   4.653   * be implemented if add() and/or modify() are supported.
   4.654   */
   4.655 -static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   4.656 +static CMPIrc extract(void **res, const CMPIInstance *inst,
   4.657 +                      const char **properties)
   4.658  {
   4.659 -   (void)status;
   4.660 -   _RESOURCE *resource;
   4.661 +   vbd_resource *disk_resource;
   4.662 +   
   4.663 +   (void)properties;
   4.664     
   4.665 -   /* Just return the CMPIInstance.  Convert in modify(). */
   4.666 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   4.667 -   if (resource == NULL)
   4.668 -      return 0;
   4.669 +   /* Get memory for resource. */
   4.670 +   disk_resource = (vbd_resource *)calloc(1, sizeof(vbd_resource));
   4.671 +   if (disk_resource == NULL)
   4.672 +      return CMPI_RC_ERR_FAILED;
   4.673  
   4.674 -   resource->u.cmpi_inst = inst;
   4.675 -   *res = (void *)resource;
   4.676 -   return 1;
   4.677 +   disk_resource->u.cmpi_inst = (CMPIInstance *)inst;
   4.678 +   *res = (void *)disk_resource;
   4.679 +   return CMPI_RC_OK;
   4.680  }
   4.681  
   4.682  
   4.683 -/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   4.684 -/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   4.685 -CMPILRInstanceMIStub(Xen_DiskSettingData, Xen_DiskSettingData, mi)
   4.686 +/* Get resource id from CMPIInstance properties. */
   4.687 +static CMPIrc extractid(void **res_id, const CMPIInstance* inst)
   4.688 +{
   4.689 +   *res_id = (void *)inst;
   4.690 +   return CMPI_RC_OK;
   4.691 +}
   4.692 +
   4.693 +
   4.694 +/* Release resource id created in resId4inst(). */
   4.695 +static void releaseid(void* res_id)
   4.696 +{
   4.697 +   (void)res_id;
   4.698 +}
   4.699 +
   4.700 +
   4.701 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   4.702 +/* CMPILIFYInstanceMIStub(<CLASS>,<PROVIDER_NAME>,<keys>,<CMPIInstanceMI_HANDLE>) */
   4.703 +static char * keys[] = {"InstanceID", NULL};
   4.704 +
   4.705 +CMPILIFYInstanceMIStub(Xen_DiskSettingData, Xen_DiskSettingData, keys, mi)
     5.1 --- a/src/Xen_Processor.c	Wed Jun 13 11:18:11 2007 -0600
     5.2 +++ b/src/Xen_Processor.c	Mon Jul 16 12:15:30 2007 -0600
     5.3 @@ -23,16 +23,19 @@
     5.4  
     5.5  /* Common declarations for each CMPI "Cimpler" instance provider */
     5.6  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     5.7 -#include "cmpidt.h"
     5.8 -#include "cmpimacs.h"
     5.9 -#include "cmpilr.h"
    5.10 +#include <cmpidt.h>
    5.11 +#include <cmpimacs.h>
    5.12 +
    5.13 +#include "cmpilify.h"
    5.14  
    5.15  
    5.16  static const CMPIInstanceMI* mi;
    5.17  
    5.18  
    5.19 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    5.20 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    5.21 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
    5.22 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
    5.23 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
    5.24 +
    5.25  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    5.26  
    5.27  #include <stdlib.h>
    5.28 @@ -48,18 +51,18 @@ static const CMPIInstanceMI* mi;
    5.29  
    5.30  
    5.31  /* C struct to store data for a single resource. */
    5.32 -typedef struct _RESOURCE_S {
    5.33 -   struct _RESOURCE_S *next;
    5.34 +typedef struct vcpu_resource_s {
    5.35 +   struct vcpu_resource_s *next;
    5.36     unsigned int vcpu_id;
    5.37     char *domain_name;
    5.38 -} _RESOURCE;
    5.39 +} vcpu_resource;
    5.40  
    5.41  
    5.42  /* C struct to store the data for all resources. */
    5.43  typedef struct {
    5.44 -   _RESOURCE* vcpus;
    5.45 -   _RESOURCE* cur_vcpu;
    5.46 -} _RESOURCES;
    5.47 +   vcpu_resource *vcpus;
    5.48 +   vcpu_resource *cur_vcpu;
    5.49 +} vcpu_resources;
    5.50  
    5.51  
    5.52  /* Xen session object.  Initialize when the provider is loaded, close when
    5.53 @@ -67,37 +70,48 @@ typedef struct {
    5.54  static xen_utils_session *session = NULL;
    5.55  
    5.56  
    5.57 -static int load()
    5.58 +static void free_vcpu_resources(vcpu_resources *resources)
    5.59 +{
    5.60 +   if (resources) {
    5.61 +      vcpu_resource *vcpu = resources->vcpus;
    5.62 +      while (vcpu) {
    5.63 +         free(vcpu->domain_name);
    5.64 +         vcpu_resource *temp = vcpu->next;
    5.65 +         free(vcpu);
    5.66 +         vcpu = temp;
    5.67 +      }
    5.68 +      free(resources);
    5.69 +   }
    5.70 +}
    5.71 +
    5.72 +
    5.73 +static CMPIrc load()
    5.74  {
    5.75     /* Initialized Xen session object. */
    5.76     if (!session)
    5.77        xen_utils_xen_init(&session);
    5.78  
    5.79 -   return 1;
    5.80 +   return CMPI_RC_OK;
    5.81  }
    5.82  
    5.83  
    5.84 -static int unload()
    5.85 +static CMPIrc unload(const int terminating)
    5.86  {
    5.87 +   (void)terminating;
    5.88 +   
    5.89 +   /* Close Xen session object. */
    5.90     if (session) {
    5.91        xen_utils_xen_close(session);
    5.92        session = NULL;
    5.93     }
    5.94  
    5.95 -   return 1;
    5.96 +   return CMPI_RC_OK;
    5.97  }
    5.98  
    5.99  
   5.100 -/*
   5.101 - * beginEnum is called before any function that uses the xen session.
   5.102 - * In the event this provider is loaded but has not been invoked for some
   5.103 - * time, the xen session object will be validated in beginEnum.  Functions
   5.104 - * called directly after beginEnum (e.g. get, getNext, modify) should
   5.105 - * set the session 'ok' flag.
   5.106 - */
   5.107 -static int beginEnum(void **res_list, CMPIStatus *status)
   5.108 +static CMPIrc begin(void **res_list, const char **properties)
   5.109  {
   5.110 -   _RESOURCES *resources;
   5.111 +   vcpu_resources *resources;
   5.112     xen_vm_set *vms;
   5.113     xen_vm_metrics vm_metrics;
   5.114     xen_vm_record *vm_rec;
   5.115 @@ -107,25 +121,21 @@ static int beginEnum(void **res_list, CM
   5.116     if (!xen_utils_validate_session(&session)) {
   5.117        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.118                     ("--- Unable to establish connection with Xend"));
   5.119 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.120 -                           "Unable to establish connection with Xend");
   5.121 -      return 0;
   5.122 +      return CMPI_RC_ERR_FAILED;
   5.123     }
   5.124  
   5.125     /* malloc a new handle for the resources list. */
   5.126 -   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
   5.127 +   resources = (vcpu_resources *)calloc(1, sizeof(vcpu_resources));
   5.128     if (resources == NULL)
   5.129 -      return 0;
   5.130 +      return CMPI_RC_ERR_FAILED;
   5.131  
   5.132     if(!xen_host_get_resident_vms(session->xen, &vms, session->host)) {
   5.133        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.134                     ("--- Failed to retrieve list of domains from host"));
   5.135        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.136                              xen_utils_trace_error(session->xen));
   5.137 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.138 -                           "Failed to retrieve list of domains from host");
   5.139        free(resources);
   5.140 -      return 0;
   5.141 +      return CMPI_RC_ERR_FAILED;
   5.142     }
   5.143  
   5.144     /*
   5.145 @@ -142,8 +152,6 @@ static int beginEnum(void **res_list, CM
   5.146                        ("--- Failed to retrieve VM record from xend"));
   5.147           _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.148                                 xen_utils_trace_error(session->xen));
   5.149 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.150 -                              "Failed to retrieve VM record from xend");
   5.151           goto Error;
   5.152        }
   5.153        
   5.154 @@ -157,13 +165,11 @@ static int beginEnum(void **res_list, CM
   5.155        if (!session->xen->ok) {
   5.156           _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.157                        ("--- Failed to retrieve domain vcpu data from xend"));
   5.158 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.159 -                              "Failed to retrieve domain vcpu data from xend");
   5.160           goto Error;
   5.161        }
   5.162        
   5.163        for (vcpus_ndx = 0; vcpus_ndx < vcpus_number; vcpus_ndx++) {
   5.164 -         _RESOURCE *vcpu = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   5.165 +         vcpu_resource *vcpu = (vcpu_resource *)calloc(1, sizeof(vcpu_resource));
   5.166            if (vcpu == NULL )
   5.167              goto Error;
   5.168              
   5.169 @@ -187,52 +193,42 @@ static int beginEnum(void **res_list, CM
   5.170     /* Set cur_vcpu to beginning of resource list. */
   5.171     resources->cur_vcpu = resources->vcpus;
   5.172     *res_list = (void *)resources;
   5.173 -   return 1;
   5.174 +   return CMPI_RC_OK;
   5.175  
   5.176   Error:
   5.177     xen_vm_record_free(vm_rec);
   5.178     xen_vm_metrics_free(vm_metrics);
   5.179     xen_vm_set_free(vms);
   5.180 -   free(resources);
   5.181 -   return 0;
   5.182 +   free_vcpu_resources(resources);
   5.183 +   return CMPI_RC_ERR_FAILED;
   5.184  }
   5.185  
   5.186  
   5.187 -static void endEnum(void *res_list)
   5.188 +static void end(void *res_list)
   5.189  {
   5.190 -   if (res_list) {
   5.191 -      _RESOURCE *res = ((_RESOURCES *)res_list)->vcpus;
   5.192 -      while (res) {
   5.193 -         free(res->domain_name);
   5.194 -         _RESOURCE *temp = res->next;
   5.195 -         free(res);
   5.196 -         res = temp;
   5.197 -      }
   5.198 -      free(res_list);
   5.199 -   }
   5.200 +   free_vcpu_resources((vcpu_resources *)res_list);
   5.201  }
   5.202  
   5.203  
   5.204  /* Iterator to get the next resource from the resources list. */
   5.205 -static int getNext(void *res_list, void **res, CMPIStatus *status)
   5.206 +static CMPIrc getnext(void *res_list, void **res, const char **properties)
   5.207  {
   5.208 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   5.209 -   _RESOURCE *resource;
   5.210 +   vcpu_resources *resources = (vcpu_resources *)res_list;
   5.211 +   vcpu_resource *resource;
   5.212  
   5.213     if (resources == NULL)
   5.214 -      return 0;
   5.215 +      return CMPI_RC_ERR_FAILED;
   5.216  
   5.217 +   /* Has end of vcpu list been reached? */
   5.218     if (resources->cur_vcpu == NULL)
   5.219 -      return 0;
   5.220 +      return CMPI_RC_ERR_NOT_FOUND;
   5.221  
   5.222     /* A resource's life is independent of resources list.  Make a copy. */
   5.223 -   resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
   5.224 +   resource = (vcpu_resource *)malloc(sizeof(vcpu_resource));
   5.225     if (resource == NULL) {
   5.226         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.227                     ("--- Failed to malloc memory for processor resource"));
   5.228 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.229 -                           "Failed to malloc memory for processor resource");
   5.230 -      return 0;
   5.231 +      return CMPI_RC_ERR_FAILED;
   5.232     }
   5.233       
   5.234     resource->vcpu_id = resources->cur_vcpu->vcpu_id;
   5.235 @@ -242,32 +238,36 @@ static int getNext(void *res_list, void 
   5.236     resources->cur_vcpu = resources->cur_vcpu->next;
   5.237  
   5.238     *res = resource;
   5.239 -   return 1;
   5.240 +   return CMPI_RC_OK;
   5.241  }
   5.242  
   5.243  
   5.244 -static int get(void *res_list, const CMPIObjectPath *op, void **res, CMPIStatus *status)
   5.245 +static CMPIrc get(const void *res_id, void **res, const char **properties)
   5.246  {
   5.247 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   5.248     CMPIData data;
   5.249 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   5.250     char *prop_val;
   5.251 -   _RESOURCE *resource;
   5.252 +   vcpu_resource *resource;
   5.253     
   5.254 -   (void)res_list;
   5.255 -
   5.256 -   if (CMIsNullObject(op) || res == NULL)
   5.257 -      return 0;
   5.258 +   if (CMIsNullObject(inst) || res == NULL)
   5.259 +      return CMPI_RC_ERR_FAILED;
   5.260  
   5.261     /* Obtain the target domain name from instance's "SystemName" property. */
   5.262 -   data = CMGetKey(op, "SystemName", status);
   5.263 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   5.264 -      return 0;
   5.265 +   data = CMGetProperty(inst, "SystemName", &status);
   5.266 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   5.267 +      return CMPI_RC_ERR_FAILED;
   5.268  
   5.269     prop_val = CMGetCharPtr(data.value.string);
   5.270     if ((prop_val == NULL) || (*prop_val == '\0'))
   5.271 -      return 0;
   5.272 +      return CMPI_RC_ERR_FAILED;
   5.273  
   5.274 -   session->xen->ok = true;
   5.275 -
   5.276 +   if (!xen_utils_validate_session(&session)) {
   5.277 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.278 +                   ("--- Unable to establish connection with Xend"));
   5.279 +      return CMPI_RC_ERR_FAILED;
   5.280 +   }
   5.281 +   
   5.282     /* Get the domain data for the target domain name. */
   5.283     xen_vm_set *vms;
   5.284     if (!xen_vm_get_by_name_label(session->xen, &vms, prop_val)) {
   5.285 @@ -275,9 +275,7 @@ static int get(void *res_list, const CMP
   5.286                     ("--- Failed to retrieve domain %s", prop_val));
   5.287        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.288                              xen_utils_trace_error(session->xen));
   5.289 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_NOT_FOUND,
   5.290 -                           "Unable to retrieve domain");
   5.291 -      return 0;
   5.292 +      return CMPI_RC_ERR_FAILED;
   5.293     }
   5.294  
   5.295     assert(vms->size == 1);
   5.296 @@ -287,10 +285,8 @@ static int get(void *res_list, const CMP
   5.297                     ("--- Failed to retrieve domain record for %s", prop_val));
   5.298        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.299                              xen_utils_trace_error(session->xen));
   5.300 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.301 -                           "Unable to retrieve domain record from xend");
   5.302        xen_vm_set_free(vms);
   5.303 -      return 0;
   5.304 +      return CMPI_RC_ERR_FAILED;
   5.305     }
   5.306  
   5.307     xen_vm_set_free(vms);
   5.308 @@ -300,57 +296,54 @@ static int get(void *res_list, const CMP
   5.309      * Incoming object path must be from a previously active domain.
   5.310      */
   5.311     if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) {
   5.312 -         CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);
   5.313           xen_vm_record_free(vm_rec);
   5.314 -         return 0;
   5.315 +         return CMPI_RC_ERR_NOT_FOUND;
   5.316     }
   5.317     xen_vm_record_free(vm_rec);
   5.318     
   5.319     /* Create resource. */
   5.320 -   resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
   5.321 +   resource = (vcpu_resource *)malloc(sizeof(vcpu_resource));
   5.322     if (resource == NULL) {
   5.323        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.324                     ("--- Failed to malloc memory for processor resource"));
   5.325 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.326 -                           "Failed to malloc memory for processor resource");
   5.327 -      return 0;
   5.328 +      return CMPI_RC_ERR_FAILED;
   5.329     }
   5.330  
   5.331     /* Populate domain_name and vcpu_id fields. */
   5.332     resource->domain_name = strdup(prop_val);
   5.333  
   5.334     /* Set the vcpu_id from the DeviceID */
   5.335 -   data = CMGetKey(op, "DeviceID", status);
   5.336 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   5.337 +   data = CMGetProperty(inst, "DeviceID", &status);
   5.338 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   5.339        free(resource->domain_name);
   5.340        free(resource);
   5.341 -      return 0;
   5.342 +      return CMPI_RC_ERR_FAILED;
   5.343     }
   5.344  
   5.345     prop_val = CMGetCharPtr(data.value.string);
   5.346     if ((prop_val == NULL) || (*prop_val == '\0')) {
   5.347        free(resource->domain_name);
   5.348        free(resource);
   5.349 -      return 0;
   5.350 +      return CMPI_RC_ERR_FAILED;
   5.351     }
   5.352  
   5.353     char *p;
   5.354     if ((p = strstr(prop_val, "VCPU")) == NULL) {
   5.355        free(resource->domain_name);
   5.356        free(resource);
   5.357 -      return 0;
   5.358 +      return CMPI_RC_ERR_FAILED;
   5.359     }
   5.360  
   5.361     resource->vcpu_id = atoi(p + 4);
   5.362  
   5.363     *res = (void *)resource;
   5.364 -   return 1;
   5.365 +   return CMPI_RC_OK;
   5.366  }
   5.367  
   5.368  
   5.369  static void release(void *res)
   5.370  {
   5.371 -   _RESOURCE *resource = (_RESOURCE *)res;
   5.372 +   vcpu_resource *resource = (vcpu_resource *)res;
   5.373     
   5.374     if (resource) {
   5.375        if (resource->domain_name)
   5.376 @@ -360,34 +353,44 @@ static void release(void *res)
   5.377  }
   5.378  
   5.379  
   5.380 -static int add(void **res_list, void *res, CMPIStatus *status)
   5.381 +static CMPIrc add(const void *res_id, const void *res)
   5.382  {
   5.383 -   return -1; /* unsupported */
   5.384 +   (void)res_id;
   5.385 +   (void)res;
   5.386 +   
   5.387 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   5.388  }
   5.389  
   5.390  
   5.391 -static int delete(void **res_list, void *res, CMPIStatus *status)
   5.392 +static CMPIrc delete(const void *res_id)
   5.393  {
   5.394 -   return -1; /* unsupported */
   5.395 +   (void)res_id;
   5.396 +   
   5.397 +   return  CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   5.398  }
   5.399  
   5.400  
   5.401 -static int modify(void **res_list, void *target_res,
   5.402 -                  void *modified_res, CMPIStatus *status)
   5.403 +static CMPIrc modify(const void *res_id, const void *modified_res,
   5.404 +                     const char **properties)
   5.405  {
   5.406 -   return -1; /* unsupported */
   5.407 +   (void)res_id;
   5.408 +   (void)modified_res;
   5.409 +   (void)properties;
   5.410 +   
   5.411 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   5.412  }
   5.413  
   5.414  
   5.415  /* Set CMPIInstance properties from the resource data. */
   5.416 -static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   5.417 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   5.418 +                            const char **properties)
   5.419  {
   5.420     if (res == NULL)
   5.421 -      return 0;
   5.422 +      return CMPI_RC_ERR_FAILED;
   5.423     if (CMIsNullObject(inst))
   5.424 -      return 0;
   5.425 +      return CMPI_RC_ERR_FAILED;
   5.426  
   5.427 -   _RESOURCE *resource = (_RESOURCE *)res;
   5.428 +   vcpu_resource *resource = (vcpu_resource *)res;
   5.429  
   5.430     /* Set the CMPIInstance properties from the resource data. */
   5.431     CMSetProperty(inst, "SystemCreationClassName",
   5.432 @@ -408,7 +411,7 @@ static int res2inst(void *res, CMPIInsta
   5.433     CMSetProperty(inst, "Name",(CMPIValue *)deviceid, CMPI_chars);
   5.434     CMSetProperty(inst, "Status", (CMPIValue *)"OK", CMPI_chars);
   5.435  
   5.436 -   return 1;
   5.437 +   return CMPI_RC_OK;
   5.438  }
   5.439  
   5.440  
   5.441 @@ -416,12 +419,35 @@ static int res2inst(void *res, CMPIInsta
   5.442   * Set resource data from the CMPIInstance properties.  Only needs to
   5.443   * be implemented if add() and/or modify() are supported.
   5.444   */
   5.445 -static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   5.446 +static CMPIrc extract(void **res, const CMPIInstance *inst,
   5.447 +                      const char **properties)
   5.448  {
   5.449 -   return -1;  /* unsupported */
   5.450 +   (void)res;
   5.451 +   (void)inst;
   5.452 +   (void)properties;
   5.453 +   
   5.454 +   return CMPI_RC_ERR_NOT_SUPPORTED;  /* unsupported */
   5.455  }
   5.456  
   5.457  
   5.458 -/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   5.459 -/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   5.460 -CMPILRInstanceMIStub(Xen_Processor, Xen_Processor, mi)
   5.461 +/* Get resource id from CMPIInstance properties. */
   5.462 +static CMPIrc extractid(void **res_id, const CMPIInstance* inst)
   5.463 +{
   5.464 +   *res_id = (void *)inst;
   5.465 +   return CMPI_RC_OK;
   5.466 +}
   5.467 +
   5.468 +
   5.469 +/* Release resource id created in resId4inst(). */
   5.470 +static void releaseid(void* res_id)
   5.471 +{
   5.472 +   (void)res_id;
   5.473 +}
   5.474 +
   5.475 +
   5.476 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   5.477 +/* CMPILIFYInstanceMIStub(<CLASS>,<PROVIDER_NAME>,<keys>,<CMPIInstanceMI_HANDLE>) */
   5.478 +static char * keys[] = {"SystemCreationClassName", "SystemName",
   5.479 +                        "CreationClassName", "DeviceID", NULL};
   5.480 +
   5.481 +CMPILIFYInstanceMIStub(Xen_Processor, Xen_Processor, keys, mi)
     6.1 --- a/src/Xen_ProcessorSettingData.c	Wed Jun 13 11:18:11 2007 -0600
     6.2 +++ b/src/Xen_ProcessorSettingData.c	Mon Jul 16 12:15:30 2007 -0600
     6.3 @@ -22,16 +22,19 @@
     6.4  
     6.5  /* Common declarations for each CMPI "Cimpler" instance provider */
     6.6  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     6.7 -#include "cmpidt.h"
     6.8 -#include "cmpimacs.h"
     6.9 -#include "cmpilr.h"
    6.10 +#include <cmpidt.h>
    6.11 +#include <cmpimacs.h>
    6.12 +
    6.13 +#include "cmpilify.h"
    6.14  
    6.15  
    6.16  static const CMPIInstanceMI* mi;
    6.17  
    6.18  
    6.19 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    6.20 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    6.21 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
    6.22 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
    6.23 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
    6.24 +
    6.25  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    6.26  
    6.27  #include <stdlib.h>
    6.28 @@ -57,14 +60,14 @@ typedef struct {
    6.29        xen_vm_record *vm_rec;
    6.30        CMPIInstance *cmpi_inst;
    6.31     } u;
    6.32 -} _RESOURCE;
    6.33 +} vcpu_resource;
    6.34  
    6.35  
    6.36  /* C struct to store the data for all resources. */
    6.37  typedef struct {
    6.38     xen_vm_set *domains;
    6.39     size_t cur_domain;
    6.40 -} _RESOURCES;
    6.41 +} vcpu_resources;
    6.42  
    6.43  
    6.44  /* Xen session object.  Initialize when the provider is loaded, close when
    6.45 @@ -72,50 +75,44 @@ typedef struct {
    6.46  static xen_utils_session *session = NULL;
    6.47  
    6.48  
    6.49 -static int load()
    6.50 +static CMPIrc load()
    6.51  {
    6.52     /* Initialized Xen session object. */
    6.53     if (!session)
    6.54        xen_utils_xen_init(&session);
    6.55  
    6.56 -   return 1;
    6.57 +   return CMPI_RC_OK;
    6.58  }
    6.59  
    6.60  
    6.61 -static int unload()
    6.62 +static CMPIrc unload(const int terminating)
    6.63  {
    6.64 +   (void)terminating;
    6.65 +   
    6.66 +   /* Close Xen session object. */
    6.67     if (session) {
    6.68        xen_utils_xen_close(session);
    6.69        session = NULL;
    6.70     }
    6.71  
    6.72 -   return 1;
    6.73 +   return CMPI_RC_OK;
    6.74  }
    6.75  
    6.76  
    6.77 -/*
    6.78 - * beginEnum is called before any function that uses the xen session.
    6.79 - * In the event this provider is loaded but has not been invoked for some
    6.80 - * time, the xen session object will be validated in beginEnum.  Functions
    6.81 - * called directly after beginEnum (e.g. get, getNext, modify) should
    6.82 - * set the session 'ok' flag.
    6.83 - */
    6.84 -static int beginEnum(void **res_list, CMPIStatus *status)
    6.85 +static CMPIrc begin(void **res_list, const char **properties)
    6.86  {
    6.87 -   _RESOURCES *resources;
    6.88 +   vcpu_resources *resources;
    6.89     
    6.90     if (!xen_utils_validate_session(&session)) {
    6.91        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    6.92                     ("--- Unable to establish connection with Xend"));
    6.93 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    6.94 -                           "Unable to establish connection with Xend");
    6.95 -      return 0;
    6.96 +      return CMPI_RC_ERR_FAILED;
    6.97     }
    6.98  
    6.99     /* malloc a new handle for the resources list. */
   6.100 -   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
   6.101 +   resources = (vcpu_resources *)calloc(1, sizeof(vcpu_resources));
   6.102     if (resources == NULL)
   6.103 -      return 0;
   6.104 +      return CMPI_RC_ERR_FAILED;
   6.105  
   6.106     if(!xen_host_get_resident_vms(session->xen, &(resources->domains),
   6.107                                   session->host)) {
   6.108 @@ -123,42 +120,41 @@ static int beginEnum(void **res_list, CM
   6.109                     ("--- Failed to retrieve list of domains from host"));
   6.110        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.111                              xen_utils_trace_error(session->xen));
   6.112 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.113 -                           "Failed to retrieve list of domains from host");
   6.114        free(resources);
   6.115 -      return 0;
   6.116 +      return CMPI_RC_ERR_FAILED;
   6.117     }
   6.118  
   6.119     *res_list = (void *)resources;
   6.120 -   return 1;
   6.121 +   return CMPI_RC_OK;
   6.122  }
   6.123  
   6.124  
   6.125 -static void endEnum(void *res_list)
   6.126 +static void end(void *res_list)
   6.127  {
   6.128     if (res_list) {
   6.129 -      xen_vm_set_free(((_RESOURCES *)res_list)->domains);
   6.130 +      xen_vm_set_free(((vcpu_resources *)res_list)->domains);
   6.131        free(res_list);
   6.132     }
   6.133  }
   6.134  
   6.135  
   6.136  /* Iterator to get the next resource from the resources list. */
   6.137 -static int getNext(void *res_list, void **res, CMPIStatus *status)
   6.138 +static CMPIrc getnext(void *res_list, void **res, const char **properties)
   6.139  {
   6.140 -   _RESOURCES *resources = (_RESOURCES *)res_list;
   6.141 -   _RESOURCE *resource;
   6.142 +   vcpu_resources *resources = (vcpu_resources *)res_list;
   6.143 +   vcpu_resource *resource;
   6.144  
   6.145     if (resources == NULL)
   6.146 -      return 0;
   6.147 +      return CMPI_RC_ERR_FAILED;
   6.148  
   6.149 +   /* Has end of resource list been reached? */
   6.150     if (resources->cur_domain >= resources->domains->size)
   6.151 -      return 0;
   6.152 +      return CMPI_RC_ERR_NOT_FOUND;
   6.153  
   6.154     /* Get memory for resource. */
   6.155 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   6.156 +   resource = (vcpu_resource *)calloc(1, sizeof(vcpu_resource));
   6.157     if (resource == NULL)
   6.158 -      return 0;
   6.159 +      return CMPI_RC_ERR_FAILED;
   6.160  
   6.161     resource->is_vm_record = 1;
   6.162  
   6.163 @@ -170,44 +166,45 @@ static int getNext(void *res_list, void 
   6.164                     ("--- Failed to retrieve VM record from xend"));
   6.165        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.166                              xen_utils_trace_error(session->xen));
   6.167 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.168 -                           "Failed to retrieve VM record from xend");
   6.169 -      return 0;
   6.170 +      return CMPI_RC_ERR_FAILED;
   6.171     }
   6.172     
   6.173     resources->cur_domain++;
   6.174     *res = (void *)resource;
   6.175 -   return 1;
   6.176 +   return CMPI_RC_OK;
   6.177  }
   6.178  
   6.179  
   6.180 -static int get(void *res_list, const CMPIObjectPath *op,
   6.181 -               void **res, CMPIStatus *status)
   6.182 +static CMPIrc get(const void *res_id, void **res, const char **properties)
   6.183  {
   6.184 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   6.185     CMPIData data;
   6.186 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   6.187     char *prop_val;
   6.188 -   _RESOURCE *resource;
   6.189 +   vcpu_resource *resource;
   6.190     char sys_name[MAX_SYSTEM_NAME_LEN];
   6.191     
   6.192 -   (void)res_list;
   6.193 -   
   6.194 -   if (CMIsNullObject(op) || res == NULL)
   6.195 -      return 0;
   6.196 +   if (CMIsNullObject(inst) || res == NULL)
   6.197 +      return CMPI_RC_ERR_FAILED;
   6.198  
   6.199     /* Obtain the target domain name from instance's "SystemName" property. */
   6.200 -   data = CMGetKey(op, "InstanceID", status);
   6.201 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   6.202 -      return 0;
   6.203 +   data = CMGetProperty(inst, "InstanceID", &status);
   6.204 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   6.205 +      return CMPI_RC_ERR_FAILED;
   6.206  
   6.207     prop_val = CMGetCharPtr(data.value.string);
   6.208     if ((prop_val == NULL) || (*prop_val == '\0'))
   6.209 -      return 0;
   6.210 +      return CMPI_RC_ERR_FAILED;
   6.211  
   6.212     /* Extract the system name from InstanceID property. */
   6.213     if (!_CMPIStrncpySystemNameFromID(sys_name, prop_val, MAX_SYSTEM_NAME_LEN))
   6.214 -      return 0;
   6.215 +      return CMPI_RC_ERR_FAILED;
   6.216  
   6.217 -   session->xen->ok = true;
   6.218 +   if (!xen_utils_validate_session(&session)) {
   6.219 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.220 +                   ("--- Unable to establish connection with Xend"));
   6.221 +      return CMPI_RC_ERR_FAILED;
   6.222 +   }
   6.223  
   6.224     /* Get the domain data for the target domain name. */
   6.225     xen_vm_set *vms;
   6.226 @@ -216,18 +213,16 @@ static int get(void *res_list, const CMP
   6.227                     ("--- Failed to retrieve domain %s", sys_name));
   6.228        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.229                              xen_utils_trace_error(session->xen));
   6.230 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_NOT_FOUND,
   6.231 -                           "Unable to retrieve domain");
   6.232 -      return 0;
   6.233 +      return CMPI_RC_ERR_FAILED;
   6.234     }
   6.235  
   6.236     assert(vms->size == 1);
   6.237  
   6.238     /* Get memory for resource. */
   6.239 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   6.240 +   resource = (vcpu_resource *)calloc(1, sizeof(vcpu_resource));
   6.241     if (resource == NULL) {
   6.242        xen_vm_set_free(vms);
   6.243 -      return 0;
   6.244 +      return CMPI_RC_ERR_FAILED;
   6.245     }
   6.246     
   6.247     resource->is_vm_record = 1;
   6.248 @@ -238,23 +233,21 @@ static int get(void *res_list, const CMP
   6.249                     ("--- Failed to retrieve domain record for %s", prop_val));
   6.250        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.251                              xen_utils_trace_error(session->xen));
   6.252 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.253 -                           "Unable to retrieve domain record from xend");
   6.254        free(resource);
   6.255        xen_vm_set_free(vms);
   6.256 -      return 0;
   6.257 +      return CMPI_RC_ERR_FAILED;
   6.258     }
   6.259  
   6.260     xen_vm_set_free(vms);
   6.261     *res = (void *)resource;
   6.262 -   return 1;
   6.263 +   return CMPI_RC_OK;
   6.264  }
   6.265  
   6.266  
   6.267  static void release(void *res)
   6.268  {
   6.269     if (res) {
   6.270 -      _RESOURCE *resource = (_RESOURCE *)res;
   6.271 +      vcpu_resource *resource = (vcpu_resource *)res;
   6.272        if (resource->is_vm_record)
   6.273           xen_vm_record_free(resource->u.vm_rec);
   6.274        free(resource);
   6.275 @@ -262,37 +255,86 @@ static void release(void *res)
   6.276  }
   6.277  
   6.278  
   6.279 -static int add(void **res_list, void *res, CMPIStatus *status)
   6.280 +static CMPIrc add(const void *res_id, const void *res)
   6.281  {
   6.282 -   return -1; /* unsupported */
   6.283 +   (void)res_id;
   6.284 +   (void)res;
   6.285 +   
   6.286 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   6.287  }
   6.288  
   6.289  
   6.290 -static int delete(void **res_list, void *res, CMPIStatus *status)
   6.291 +static CMPIrc delete(const void *res_id)
   6.292  {
   6.293 -   return -1; /* unsupported */
   6.294 +   (void)res_id;
   6.295 +   
   6.296 +   return  CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   6.297  }
   6.298  
   6.299  
   6.300 -static int modify(void **res_list, void *target_res,
   6.301 -                  void *modified_res, CMPIStatus *status)
   6.302 +static CMPIrc modify(const void *res_id, const void *modified_res,
   6.303 +                     const char **properties)
   6.304  {
   6.305 -   CMPIInstance *cmpi_inst;
   6.306 -   xen_vm_record *vm_rec;
   6.307 +   CMPIInstance *target_inst = (CMPIInstance *)res_id;
   6.308 +   vcpu_resource *resource = (vcpu_resource *)modified_res;
   6.309 +   CMPIInstance *modified_inst;
   6.310 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   6.311     CMPIData data;
   6.312 +   char *inst_id;
   6.313 +   char sys_name[MAX_SYSTEM_NAME_LEN];
   6.314     char buf[64];
   6.315  
   6.316 -   if (target_res == NULL || modified_res == NULL)
   6.317 -      return 0;
   6.318 -   
   6.319 -   session->xen->ok = true;
   6.320 +   if (CMIsNullObject(target_inst) || resource == NULL ||
   6.321 +       resource->is_vm_record)
   6.322 +      return CMPI_RC_ERR_FAILED;
   6.323 +
   6.324 +   modified_inst = resource->u.cmpi_inst;   
   6.325 +
   6.326 +   /* Get target resource */
   6.327 +   data = CMGetProperty(target_inst, "InstanceID", &status);
   6.328 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   6.329 +      return CMPI_RC_ERR_FAILED;
   6.330 +
   6.331 +   inst_id = CMGetCharPtr(data.value.string);
   6.332 +   if ((inst_id == NULL) || (*inst_id == '\0'))
   6.333 +      return CMPI_RC_ERR_FAILED;
   6.334 +
   6.335 +   /* Extract the system name from InstanceID property. */
   6.336 +   if (!_CMPIStrncpySystemNameFromID(sys_name, inst_id, MAX_SYSTEM_NAME_LEN))
   6.337 +      return CMPI_RC_ERR_FAILED;
   6.338  
   6.339 -   cmpi_inst = ((_RESOURCE *)modified_res)->u.cmpi_inst;
   6.340 -   vm_rec = ((_RESOURCE *)target_res)->u.vm_rec;
   6.341 +   if (!xen_utils_validate_session(&session)) {
   6.342 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.343 +                   ("--- Unable to establish connection with Xend"));
   6.344 +      return CMPI_RC_ERR_FAILED;
   6.345 +   }
   6.346 +
   6.347 +   /* Get the domain data for the target domain name. */
   6.348 +   xen_vm_set *vms;
   6.349 +   if (!xen_vm_get_by_name_label(session->xen, &vms, sys_name)) {
   6.350 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_WARNING,
   6.351 +                   ("--- Failed to retrieve domain %s", sys_name));
   6.352 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.353 +                            xen_utils_trace_error(session->xen));
   6.354 +      return CMPI_RC_ERR_FAILED;
   6.355 +   }
   6.356 +
   6.357 +   assert(vms->size == 1);
   6.358 +
   6.359 +   xen_vm_record *vm_rec;
   6.360 +   if (!xen_vm_get_record(session->xen,
   6.361 +                          &vm_rec, vms->contents[0])) {
   6.362 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.363 +                   ("--- Failed to retrieve domain record for %s", sys_name));
   6.364 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.365 +                            xen_utils_trace_error(session->xen));
   6.366 +      xen_vm_set_free(vms);
   6.367 +      return CMPI_RC_ERR_FAILED;
   6.368 +   }
   6.369  
   6.370     /* Allow modifying VirtualQuantity, Limit, Weight */
   6.371 -   data = CMGetProperty(cmpi_inst, "VirtualQuantity", status);
   6.372 -   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.373 +   data = CMGetProperty(modified_inst, "VirtualQuantity", &status);
   6.374 +   if ((status.rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.375        if (vm_rec->vcpus_at_startup != data.value.uint64) {
   6.376           xen_vm_set_vcpus_at_startup(session->xen,
   6.377                                       vm_rec->handle, data.value.uint64);
   6.378 @@ -301,16 +343,16 @@ static int modify(void **res_list, void 
   6.379              _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.380                           ("--- Failed to modify domain's vcpu configuration"));
   6.381              _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.382 -                                  xen_utils_trace_error(session->xen));
   6.383 -            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.384 -                                 "Failed to modify domain's vcpu configuration");
   6.385 -            return 0;
   6.386 +                                  xen_utils_trace_error(session->xen)); 
   6.387 +            xen_vm_set_free(vms);
   6.388 +            xen_vm_record_free(vm_rec);
   6.389 +            return CMPI_RC_ERR_FAILED;
   6.390           }
   6.391        }
   6.392     }
   6.393  
   6.394 -   data = CMGetProperty(cmpi_inst, "Limit", status);
   6.395 -   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.396 +   data = CMGetProperty(modified_inst, "Limit", &status);
   6.397 +   if ((status.rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.398        snprintf(buf, 64, "%lld", data.value.uint64);
   6.399        xen_utils_add_to_string_string_map("cap", buf, &(vm_rec->vcpus_params));
   6.400        if (!xen_vm_set_vcpus_params(session->xen,
   6.401 @@ -319,14 +361,14 @@ static int modify(void **res_list, void 
   6.402                        ("--- Failed to modify domain's vcpu configuration"));
   6.403           _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.404                                 xen_utils_trace_error(session->xen));
   6.405 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.406 -                              "Failed to modify domain's vcpu configuration");
   6.407 -         return 0;
   6.408 +         xen_vm_set_free(vms);
   6.409 +         xen_vm_record_free(vm_rec);
   6.410 +         return CMPI_RC_ERR_FAILED;
   6.411        }
   6.412     }
   6.413  
   6.414 -   data = CMGetProperty(cmpi_inst, "Weight", status);
   6.415 -   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.416 +   data = CMGetProperty(modified_inst, "Weight", &status);
   6.417 +   if ((status.rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   6.418        snprintf(buf, 64, "%d", data.value.uint32);
   6.419        xen_utils_add_to_string_string_map("weight", buf, &(vm_rec->vcpus_params));
   6.420        if (!xen_vm_set_vcpus_params(session->xen,
   6.421 @@ -335,9 +377,9 @@ static int modify(void **res_list, void 
   6.422                        ("--- Failed to modify domain's vcpu configuration"));
   6.423           _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.424                                 xen_utils_trace_error(session->xen));
   6.425 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.426 -                              "Failed to modify domain's vcpu configuration");
   6.427 -         return 0;
   6.428 +         xen_vm_set_free(vms);
   6.429 +         xen_vm_record_free(vm_rec);
   6.430 +         return CMPI_RC_ERR_FAILED;
   6.431        }
   6.432     }
   6.433     
   6.434 @@ -346,27 +388,30 @@ static int modify(void **res_list, void 
   6.435      * vcpu -> pcpu affinity
   6.436      */
   6.437  
   6.438 -   return 1;
   6.439 +   xen_vm_set_free(vms);
   6.440 +   xen_vm_record_free(vm_rec);
   6.441 +   return CMPI_RC_OK;
   6.442  }
   6.443  
   6.444  
   6.445  /* Set CMPIInstance properties from the resource data. */
   6.446 -static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   6.447 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   6.448 +                            const char **properties)
   6.449  {
   6.450     int int_prop_val;
   6.451     int64_t int64_prop_val;
   6.452     char buf[MAX_INSTANCEID_LEN];
   6.453     
   6.454     if (res == NULL)
   6.455 -      return 0;
   6.456 +      return CMPI_RC_ERR_FAILED;
   6.457  
   6.458     if (CMIsNullObject(inst))
   6.459 -      return 0;
   6.460 +      return CMPI_RC_ERR_FAILED;
   6.461  
   6.462 -   if (!((_RESOURCE *)res)->is_vm_record)
   6.463 -      return 0;
   6.464 +   if (!((vcpu_resource *)res)->is_vm_record)
   6.465 +      return CMPI_RC_ERR_FAILED;
   6.466     
   6.467 -   xen_vm_record *vm_rec = ((_RESOURCE *)res)->u.vm_rec;
   6.468 +   xen_vm_record *vm_rec = ((vcpu_resource *)res)->u.vm_rec;
   6.469  
   6.470     /* Set the CMPIInstance properties from the resource data. */
   6.471     snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:Processor", vm_rec->name_label);
   6.472 @@ -400,7 +445,7 @@ static int res2inst(void *res, CMPIInsta
   6.473                   (CMPIValue *)&int64_prop_val, CMPI_uint64);
   6.474  
   6.475     if (vm_rec->vcpus_params == NULL)
   6.476 -      return 1;
   6.477 +      return CMPI_RC_OK;
   6.478     
   6.479     /*
   6.480      * Weight, Limit, and HostResources properties map to
   6.481 @@ -428,7 +473,7 @@ static int res2inst(void *res, CMPIInsta
   6.482      * 2. PoolID
   6.483      */
   6.484  
   6.485 -   return 1;
   6.486 +   return CMPI_RC_OK;
   6.487  }
   6.488  
   6.489  
   6.490 @@ -436,22 +481,41 @@ static int res2inst(void *res, CMPIInsta
   6.491   * Set resource data from the CMPIInstance properties.  Only needs to
   6.492   * be implemented if add() and/or modify() are supported.
   6.493   */
   6.494 -static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   6.495 +static CMPIrc extract(void **res, const CMPIInstance *inst,
   6.496 +                      const char **properties)
   6.497  {
   6.498 -   (void)status;
   6.499 -   _RESOURCE *resource;
   6.500 +   vcpu_resource *resource;
   6.501 +   
   6.502 +   (void)properties;
   6.503     
   6.504 -   /* Just return the CMPIInstance.  Convert in modify(). */
   6.505 -   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   6.506 +   /* Get memory for resource. */
   6.507 +   resource = (vcpu_resource *)calloc(1, sizeof(vcpu_resource));
   6.508     if (resource == NULL)
   6.509 -      return 0;
   6.510 +      return CMPI_RC_ERR_FAILED;
   6.511  
   6.512 -   resource->u.cmpi_inst = inst;
   6.513 +   resource->u.cmpi_inst = (CMPIInstance *)inst;
   6.514     *res = (void *)resource;
   6.515 -   return 1;
   6.516 +   return CMPI_RC_OK;
   6.517  }
   6.518  
   6.519  
   6.520 -/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   6.521 -/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   6.522 -CMPILRInstanceMIStub(Xen_ProcessorSettingData, Xen_ProcessorSettingData, mi)
   6.523 +/* Get resource id from CMPIInstance properties. */
   6.524 +static CMPIrc extractid(void **res_id, const CMPIInstance* inst)
   6.525 +{
   6.526 +   *res_id = (void *)inst;
   6.527 +   return CMPI_RC_OK;
   6.528 +}
   6.529 +
   6.530 +
   6.531 +/* Release resource id created in resId4inst(). */
   6.532 +static void releaseid(void* res_id)
   6.533 +{
   6.534 +   (void)res_id;
   6.535 +}
   6.536 +
   6.537 +
   6.538 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   6.539 +/* CMPILIFYInstanceMIStub(<CLASS>,<PROVIDER_NAME>,<keys>,<CMPIInstanceMI_HANDLE>) */
   6.540 +static char * keys[] = {"InstanceID", NULL};
   6.541 +
   6.542 +CMPILIFYInstanceMIStub(Xen_ProcessorSettingData, Xen_ProcessorSettingData, keys, mi)
     7.1 --- a/src/Xen_ProcessorSettingData_Resource.c	Wed Jun 13 11:18:11 2007 -0600
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,201 +0,0 @@
     7.4 -// Copyright (C) 2006 IBM Corporation
     7.5 -//
     7.6 -//    This library is free software; you can redistribute it and/or
     7.7 -//    modify it under the terms of the GNU Lesser General Public
     7.8 -//    License as published by the Free Software Foundation; either
     7.9 -//    version 2.1 of the License, or (at your option) any later version.
    7.10 -//
    7.11 -//    This library is distributed in the hope that it will be useful,
    7.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.14 -//    Lesser General Public License for more details.
    7.15 -//
    7.16 -//    You should have received a copy of the GNU Lesser General Public
    7.17 -//    License along with this library; if not, write to the Free Software
    7.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.19 -// ============================================================================
    7.20 -// Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    7.21 -// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    7.22 -//		  Raj Subrahmanian <raj.subrahmanian@unisys.com>
    7.23 -// Description:
    7.24 -// ============================================================================
    7.25 -
    7.26 -#include <stdlib.h>
    7.27 -#include <string.h>
    7.28 -#include <assert.h>
    7.29 -
    7.30 -#include <xen_common.h>
    7.31 -#include <xen_vm.h>
    7.32 -#include <xen_vm_metrics.h>
    7.33 -
    7.34 -#include "Xen_ProcessorSettingData_Resource.h"
    7.35 -
    7.36 -/* Include the required CMPI data types, function headers, and macros. */
    7.37 -#include "cmpidt.h"
    7.38 -#include "cmpift.h"
    7.39 -#include "cmpimacs.h"
    7.40 -
    7.41 -#include "xen_utils.h"
    7.42 -#include "provider_common.h"
    7.43 -
    7.44 -// ----------------------------------------------------------------------------
    7.45 -
    7.46 -/* Get a handle to the list of all system resources for this class. */
    7.47 -int Xen_ProcessorSettingData_getResources(xen_utils_session *session,
    7.48 -                                          _RESOURCES ** resources)
    7.49 -{
    7.50 -   return xen_utils_get_domain_resources(session, resources);
    7.51 -}
    7.52 -
    7.53 -// ----------------------------------------------------------------------------
    7.54 -
    7.55 -/* Free/deallocate/cleanup the resources list after use. */
    7.56 -int Xen_ProcessorSettingData_freeResources(_RESOURCES * resources)
    7.57 -{
    7.58 -   return xen_utils_free_domain_resources(resources);
    7.59 -}
    7.60 -
    7.61 -// ----------------------------------------------------------------------------
    7.62 -
    7.63 -/* Iterator to get the next resource from the resources list. */
    7.64 -int Xen_ProcessorSettingData_getNextResource(xen_utils_session *session,
    7.65 -                                             _RESOURCES * resources,
    7.66 -                                             _RESOURCE ** resource)
    7.67 -{
    7.68 -   return xen_utils_get_next_domain_resource(session, resources, resource);
    7.69 -}
    7.70 -
    7.71 -// ----------------------------------------------------------------------------
    7.72 -
    7.73 -/* Get the specific resource that matches the CMPI object path. */
    7.74 -int Xen_ProcessorSettingData_getResourceForObjectPath(xen_utils_session *session,
    7.75 -                                                      _RESOURCES * resources,
    7.76 -                                                      _RESOURCE ** resource,
    7.77 -                                                      const CMPIObjectPath * objectpath)
    7.78 -{
    7.79 -   char *instId;
    7.80 -   char name[MAX_SYSTEM_NAME_LEN];
    7.81 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
    7.82 -
    7.83 -   /* Check input params are valid. */
    7.84 -   if (resources == NULL) return 0;
    7.85 -   if (CMIsNullObject(objectpath)) return 0;
    7.86 -
    7.87 -   /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
    7.88 -   CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
    7.89 -   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
    7.90 -
    7.91 -   /* Extract the id string from the CMPIString. */
    7.92 -   instId = CMGetCharPtr(iddata.value.string);
    7.93 -   if ((instId == NULL) || (*instId == '\0')) return 0;
    7.94 -
    7.95 -   /* Extract the system name from InstanceID property. */
    7.96 -   if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
    7.97 -      return 0;
    7.98 -
    7.99 -   /* Get the domain data for the target domain name. */
   7.100 -   xen_vm_set *vms;
   7.101 -   if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
   7.102 -      /* Error is in session object! */
   7.103 -      *resource = NULL;
   7.104 -      return 0;
   7.105 -   }
   7.106 -
   7.107 -   assert(vms->size == 1);
   7.108 -   if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
   7.109 -      /* Error description in session object! */
   7.110 -      xen_vm_set_free(vms);
   7.111 -      return 0;
   7.112 -   }
   7.113 -
   7.114 -   xen_vm_set_free(vms);
   7.115 -
   7.116 -   return 1;
   7.117 -}
   7.118 -
   7.119 -// ----------------------------------------------------------------------------
   7.120 -
   7.121 -/* Free/deallocate/cleanup the resource after use. */
   7.122 -int Xen_ProcessorSettingData_freeResource(_RESOURCE * resource)
   7.123 -{
   7.124 -   return xen_utils_free_domain_resource(resource);
   7.125 -}
   7.126 -
   7.127 -// ---------------------------------------------------------------------------- 
   7.128 -
   7.129 -/* Set the property values of a CMPI instance from a specific resource. 
   7.130 -   We also pass in the session object so that the metrics class can be accessed when required.
   7.131 -*/
   7.132 -int Xen_ProcessorSettingData_setInstanceFromResource(xen_utils_session *session,
   7.133 -                                                     _RESOURCE * resource,
   7.134 -                                                     const CMPIInstance * instance,
   7.135 -                                                     const CMPIBroker * broker)
   7.136 -{
   7.137 -   char buf[1024];
   7.138 -
   7.139 -   if (resource == NULL) return 0;
   7.140 -   if (CMIsNullObject(instance)) return 0;
   7.141 -
   7.142 -   /* Set the CMPIInstance properties from the resource data. */
   7.143 -   snprintf(buf, 1024, "Xen:%s:Processor", resource->name_label);
   7.144 -   CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
   7.145 -
   7.146 -   CMSetProperty(instance, "ElementName",(CMPIValue *)"Processor", CMPI_chars);
   7.147 -
   7.148 -   int type = 3; /* 3 == CPU */
   7.149 -   CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
   7.150 -
   7.151 -   int consumerVisibility = 3; /* 3 == Virtualized */
   7.152 -   CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
   7.153 -
   7.154 -   int64_t cpus = 1;
   7.155 -   CMSetProperty(instance, "Reservation",(CMPIValue *)&cpus, CMPI_uint64);
   7.156 -   CMSetProperty(instance, "Limit",(CMPIValue *)&cpus, CMPI_uint64);
   7.157 -   CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Cores", CMPI_chars);
   7.158 -   CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&(resource->vcpus_at_startup), CMPI_uint64);
   7.159 -
   7.160 -   int alloctype = 1;
   7.161 -   CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   7.162 -   CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   7.163 -
   7.164 -   /*
   7.165 -    * TODO:
   7.166 -    * PoolID, Weight, HostResource when cpus pinned
   7.167 -    */
   7.168 -
   7.169 -   return 1;
   7.170 -}
   7.171 -
   7.172 -// ----------------------------------------------------------------------------
   7.173 -
   7.174 -/* Delete the specified resource from the system. */
   7.175 -int Xen_ProcessorSettingData_deleteResource(_RESOURCES * resources,
   7.176 -                                            _RESOURCE * resource)
   7.177 -{
   7.178 -   /* Unsupported. */
   7.179 -   return -1;
   7.180 -}
   7.181 -
   7.182 -// ----------------------------------------------------------------------------
   7.183 -
   7.184 -/* Modify the specified resource using the property values of a CMPI instance. */
   7.185 -int Xen_ProcessorSettingData_setResourceFromInstance(_RESOURCE * resource,
   7.186 -                                                     const CMPIInstance * instance,
   7.187 -                                                     const CMPIBroker * broker)
   7.188 -{
   7.189 -   /* Unsupported. */
   7.190 -   return -1;
   7.191 -}
   7.192 -
   7.193 -// ----------------------------------------------------------------------------
   7.194 -
   7.195 -/* Create a new resource using the property values of a CMPI instance. */
   7.196 -int Xen_ProcessorSettingData_createResourceFromInstance(_RESOURCES * resources,
   7.197 -                                                        _RESOURCE ** resource,
   7.198 -                                                        const CMPIInstance * instance,
   7.199 -                                                        const CMPIBroker * broker)
   7.200 -{
   7.201 -   /* Unsupported. */
   7.202 -   return -1;
   7.203 -}
   7.204 -
     8.1 --- a/src/Xen_ProcessorSettingData_Resource.h	Wed Jun 13 11:18:11 2007 -0600
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,100 +0,0 @@
     8.4 -// Copyright (C) 2006 IBM Corporation
     8.5 -//
     8.6 -//    This library is free software; you can redistribute it and/or
     8.7 -//    modify it under the terms of the GNU Lesser General Public
     8.8 -//    License as published by the Free Software Foundation; either
     8.9 -//    version 2.1 of the License, or (at your option) any later version.
    8.10 -//
    8.11 -//    This library is distributed in the hope that it will be useful,
    8.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.14 -//    Lesser General Public License for more details.
    8.15 -//
    8.16 -//    You should have received a copy of the GNU Lesser General Public
    8.17 -//    License along with this library; if not, write to the Free Software
    8.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.19 -// ============================================================================
    8.20 -// Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    8.21 -// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    8.22 -// Description:
    8.23 -// ============================================================================
    8.24 -
    8.25 -/* Include required libxen headers. */
    8.26 -#include <xen_common.h>
    8.27 -#include <xen_vm.h>
    8.28 -
    8.29 -#include "xen_utils.h"
    8.30 -
    8.31 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    8.32 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES.
    8.33 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS
    8.34 -   LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC.
    8.35 -   THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN
    8.36 -   ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */
    8.37 -typedef xen_domain_resources  _RESOURCES;
    8.38 -
    8.39 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    8.40 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE.
    8.41 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH
    8.42 -   RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE
    8.43 -   PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE
    8.44 -   ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */
    8.45 -typedef xen_vm_record  _RESOURCE;
    8.46 -
    8.47 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */
    8.48 -
    8.49 -/* Include the required CMPI data types. */
    8.50 -#include "cmpidt.h"
    8.51 -
    8.52 -// ----------------------------------------------------------------------------
    8.53 -// Generic resource access methods for CMPI providers.
    8.54 -// Return value:
    8.55 -//	-1 = Unsupported
    8.56 -//	 0 = Failed
    8.57 -//	 1 = OK
    8.58 -// ----------------------------------------------------------------------------
    8.59 -
    8.60 -/* Get a handle to the list of all system resources for this class. */
    8.61 -int Xen_ProcessorSettingData_getResources(xen_utils_session *session,
    8.62 -                                          _RESOURCES ** resources);
    8.63 -
    8.64 -/* Free/deallocate/cleanup the resources list after use. */
    8.65 -int Xen_ProcessorSettingData_freeResources(_RESOURCES * resources);
    8.66 -
    8.67 -/* Iterator to get the next resource from the resources list. */
    8.68 -int Xen_ProcessorSettingData_getNextResource(xen_utils_session *session,
    8.69 -                                             _RESOURCES * resources,
    8.70 -                                             _RESOURCE ** resource);
    8.71 -
    8.72 -/* Get the specific resource that matches the CMPI object path. */
    8.73 -int Xen_ProcessorSettingData_getResourceForObjectPath(xen_utils_session *session,
    8.74 -                                                      _RESOURCES * resources,
    8.75 -                                                      _RESOURCE ** resource,
    8.76 -                                                      const CMPIObjectPath * objectpath);
    8.77 -
    8.78 -/* Free/deallocate/cleanup a resource after use. */
    8.79 -int Xen_ProcessorSettingData_freeResource(_RESOURCE * resource);
    8.80 -
    8.81 -/* Set the property values of a CMPI instance from a specific resource. */
    8.82 -int Xen_ProcessorSettingData_setInstanceFromResource(xen_utils_session *session,
    8.83 -						     _RESOURCE * resource,
    8.84 -                                                     const CMPIInstance * instance,
    8.85 -                                                     const CMPIBroker * broker);
    8.86 -
    8.87 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS
    8.88 -
    8.89 -/* Delete the specified resource from the system. */
    8.90 -int Xen_ProcessorSettingData_deleteResource(_RESOURCES * resources,
    8.91 -                                            _RESOURCE * resource);
    8.92 -
    8.93 -/* Modify the specified resource using the property values of a CMPI instance. */
    8.94 -int Xen_ProcessorSettingData_setResourceFromInstance(_RESOURCE * resource,
    8.95 -                                                     const CMPIInstance * instance,
    8.96 -                                                     const CMPIBroker * broker);
    8.97 -
    8.98 -/* Create a new resource using the property values of a CMPI instance. */
    8.99 -int Xen_ProcessorSettingData_createResourceFromInstance(_RESOURCES * resources,
   8.100 -                                                        _RESOURCE ** resource,
   8.101 -                                                        const CMPIInstance * instance,
   8.102 -                                                        const CMPIBroker * broker);
   8.103 -
     9.1 --- a/src/Xen_VirtualSystemManagementCapabilities.c	Wed Jun 13 11:18:11 2007 -0600
     9.2 +++ b/src/Xen_VirtualSystemManagementCapabilities.c	Mon Jul 16 12:15:30 2007 -0600
     9.3 @@ -23,16 +23,19 @@
     9.4  
     9.5  /* Common declarations for each CMPI "Cimpler" instance provider */
     9.6  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     9.7 -#include "cmpidt.h"
     9.8 -#include "cmpimacs.h"
     9.9 -#include "cmpilr.h"
    9.10 +#include <cmpidt.h>
    9.11 +#include <cmpimacs.h>
    9.12 +
    9.13 +#include "cmpilify.h"
    9.14  
    9.15  
    9.16  static const CMPIInstanceMI* mi;
    9.17  
    9.18  
    9.19 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    9.20 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    9.21 +#define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
    9.22 +#define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
    9.23 +#define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
    9.24 +
    9.25  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    9.26  
    9.27  #include <stdlib.h>
    9.28 @@ -44,98 +47,44 @@ static const CMPIInstanceMI* mi;
    9.29  #include "xen_utils.h"
    9.30  
    9.31  
    9.32 -/* C struct to store the data for all resources. */
    9.33 -typedef struct {
    9.34 -   int finished;
    9.35 -} _RESOURCES;
    9.36 -
    9.37 -
    9.38  /* Xen session object.  Initialize when the provider is loaded, close when
    9.39   * provider unloaded. */
    9.40  static xen_utils_session *session = NULL;
    9.41  
    9.42  
    9.43 -static int load()
    9.44 +static CMPIrc load()
    9.45  {
    9.46     /* Initialized Xen session object. */
    9.47     if (!session)
    9.48        xen_utils_xen_init(&session);
    9.49  
    9.50 -   return 1;
    9.51 +   return CMPI_RC_OK;
    9.52  }
    9.53  
    9.54  
    9.55 -static int unload()
    9.56 +static CMPIrc unload(const int terminating)
    9.57  {
    9.58 +   (void)terminating;
    9.59 +   
    9.60 +   /* Close Xen session object. */
    9.61     if (session) {
    9.62        xen_utils_xen_close(session);
    9.63        session = NULL;
    9.64     }
    9.65  
    9.66 -   return 1;
    9.67 -}
    9.68 -
    9.69 -
    9.70 -static int beginEnum(void **res_list, CMPIStatus *status)
    9.71 -{
    9.72 -   *res_list = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    9.73 -   if (*res_list == NULL)
    9.74 -      return 0;
    9.75 -
    9.76 -   return 1;
    9.77 +   return CMPI_RC_OK;
    9.78  }
    9.79  
    9.80  
    9.81 -static void endEnum(void *res_list)
    9.82 -{
    9.83 -   free(res_list);
    9.84 -}
    9.85 -
    9.86 -
    9.87 -static int getNext(void *res_list, void **res, CMPIStatus *status)
    9.88 +/* Get the single instance. */
    9.89 +static CMPIrc get(void **res, const char** properties)
    9.90  {
    9.91     xen_host_record *host_rec;
    9.92  
    9.93 -   if (res_list == NULL || ((_RESOURCES *)res_list)->finished)
    9.94 -      return 0;
    9.95 -   
    9.96 -   ((_RESOURCES *)res_list)->finished = 1;
    9.97 -
    9.98     if (!xen_utils_validate_session(&session)) {
    9.99        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   9.100                     ("--- Unable to establish connection with Xend"));
   9.101 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   9.102 -                           "Unable to establish connection with Xend");
   9.103 -      return 0;
   9.104 -   }
   9.105 -
   9.106 -   if (!xen_host_get_record(session->xen, &host_rec, session->host)) {
   9.107 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   9.108 -                   ("--- failed to retrieve host record from Xend:"));
   9.109 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   9.110 -                            xen_utils_trace_error(session->xen));
   9.111 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   9.112 -                           "Failed to retrieve host record from Xend");
   9.113 -      return 0;
   9.114 -   }
   9.115 -      
   9.116 -   *res = (void *)host_rec;
   9.117 -   return 1;
   9.118 -}
   9.119 -
   9.120 -
   9.121 -static int get(void *res_list, const CMPIObjectPath *op,
   9.122 -               void **res, CMPIStatus *status)
   9.123 -{
   9.124 -   (void)res_list;
   9.125 -   
   9.126 -   xen_host_record *host_rec;
   9.127 -
   9.128 -   if (!xen_utils_validate_session(&session)) {
   9.129 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("--- Unable to establish connection with Xend"));
   9.130 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   9.131 -                           "Unable to establish connection with Xend");
   9.132 -      return 0;
   9.133 +      return CMPI_RC_ERR_FAILED;
   9.134     }
   9.135  
   9.136     xen_host_get_record(session->xen, &host_rec, session->host);
   9.137 @@ -145,13 +94,11 @@ static int get(void *res_list, const CMP
   9.138                     ("--- failed to retrieve host record from Xend:"));
   9.139        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   9.140                              xen_utils_trace_error(session->xen));
   9.141 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   9.142 -                           "Failed to retrieve host record from Xend");
   9.143 -      return 0;
   9.144 +      return CMPI_RC_ERR_FAILED;
   9.145     }
   9.146  
   9.147     *res = (void *)host_rec;
   9.148 -   return 1;
   9.149 +   return CMPI_RC_OK;
   9.150  }
   9.151  
   9.152  
   9.153 @@ -161,36 +108,18 @@ static void release(void *res)
   9.154  }
   9.155  
   9.156  
   9.157 -static int add(void **res_list, void *res, CMPIStatus *status)
   9.158 -{
   9.159 -   return -1; /* unsupported */
   9.160 -}
   9.161 -
   9.162 -
   9.163 -static int delete(void **res_list, void *res, CMPIStatus *status)
   9.164 -{
   9.165 -   return -1; /* unsupported */
   9.166 -}
   9.167 -
   9.168 -
   9.169 -static int modify(void **res_list, void *target_res,
   9.170 -                  void *modified_res, CMPIStatus *status)
   9.171 -{
   9.172 -   return -1; /* unsupported */
   9.173 -}
   9.174 -
   9.175 -
   9.176  /* Set CMPIInstance properties from the resource data. */
   9.177 -static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   9.178 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   9.179 +                            const char **properties)
   9.180  {
   9.181     xen_host_record *host_rec;
   9.182     int supported;
   9.183     
   9.184     if (res == NULL)
   9.185 -      return 0;
   9.186 +      return CMPI_RC_ERR_FAILED;
   9.187  
   9.188     if (CMIsNullObject(inst))
   9.189 -      return 0;
   9.190 +      return CMPI_RC_ERR_FAILED;
   9.191  
   9.192     host_rec = (xen_host_record *)res;
   9.193     
   9.194 @@ -266,20 +195,13 @@ static int res2inst(void *res, CMPIInsta
   9.195     CMSetProperty(inst, "SynchronousMethodsSupported",
   9.196                   (CMPIValue *)&syncMethodsSupported, CMPI_uint16A);
   9.197  
   9.198 -   return 1;
   9.199 +   return CMPI_RC_OK;
   9.200  }
   9.201  
   9.202  
   9.203 -/*
   9.204 - * Set resource data from the CMPIInstance properties.  Only needs to
   9.205 - * be implemented if add() and/or modify() are supported.
   9.206 - */
   9.207 -static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   9.208 -{
   9.209 -   return -1; /* unsupported */
   9.210 -}
   9.211 +/* NULL-terminated list of keys for this class. */
   9.212 +static char * keys[] = {"InstanceID", NULL};
   9.213  
   9.214 -
   9.215 -/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   9.216 -/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   9.217 -CMPILRInstanceMIStub(Xen_VirtualSystemManagementCapabilities, Xen_VirtualSystemManagementCapabilities, mi)
   9.218 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   9.219 +/* CMPILIFYInstance1ROMIStub(<CLASS>,<PROVIDERNAME>,<KEYS>,<MIHANDLE>) */
   9.220 +CMPILIFYInstance1ROMIStub(Xen_VirtualSystemManagementCapabilities, Xen_VirtualSystemManagementCapabilities, keys, mi)
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/cmpilify.c	Mon Jul 16 12:15:30 2007 -0600
    10.3 @@ -0,0 +1,909 @@
    10.4 +/*
    10.5 + * cmpilify.c
    10.6 + *
    10.7 + * © Copyright IBM Corp. 2007
    10.8 + *
    10.9 + * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
   10.10 + * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
   10.11 + * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
   10.12 + * You can obtain a current copy of the Common Public License from
   10.13 + * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
   10.14 + *
   10.15 + * Author:         Dr. Gareth S. Bestor <bestor@us.ibm.com>
   10.16 + * Contributors:
   10.17 + * Interface Type: Common Manageability Programming Interface (CMPI)
   10.18 + * Description:    Generic CMPILIFY instance provider.
   10.19 +*/
   10.20 +
   10.21 +#include <cmpidt.h>
   10.22 +#include <cmpift.h>
   10.23 +#include <cmpimacs.h>
   10.24 +
   10.25 +#include "cmpilify.h"
   10.26 +#include "cmpitrace.h"
   10.27 +#include "cmpiutil.h"
   10.28 +
   10.29 +
   10.30 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
   10.31 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
   10.32 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
   10.33 +#define _FT (((CMPILIFYInstanceMI*)(mi->hdl))->ft)
   10.34 +
   10.35 +
   10.36 +/* ------------------------------------------------------------------------- */
   10.37 +
   10.38 +static int op2inst(const CMPIObjectPath* op, CMPIInstance** inst,
   10.39 +                   CMPIInstanceMI* mi)
   10.40 +{
   10.41 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   10.42 +   CMPIString* keyname;
   10.43 +   int numkeys, i;
   10.44 +   CMPIData key;
   10.45 +   int rc = 0;
   10.46 +
   10.47 +   /* Convert CMPIObjectPath to CMPIInstance. */
   10.48 +   *inst = CMNewInstance(_BROKER, op, &status);
   10.49 +   if (status.rc != CMPI_RC_OK) goto exit;
   10.50 +
   10.51 +   /* Set the CMPIInstance key properties from the CMPIObjectPath keys. */
   10.52 +   numkeys = CMGetKeyCount(op, &status);
   10.53 +   if (status.rc != CMPI_RC_OK) goto exit;
   10.54 +   for (i=0; i<numkeys; i++) {
   10.55 +      key = CMGetKeyAt(op, i, &keyname, &status);
   10.56 +      if (status.rc != CMPI_RC_OK) goto exit;
   10.57 +      status = CMSetProperty(*inst, CMGetCharPtr(keyname),
   10.58 +                             &(key.value), key.type);
   10.59 +      if (status.rc != CMPI_RC_OK) goto exit;
   10.60 +   }
   10.61 +   rc = 1;
   10.62 + exit:
   10.63 +   return rc;
   10.64 +}
   10.65 +
   10.66 +/* ------------------------------------------------------------------------- */
   10.67 +
   10.68 +static int getres4op(void** res, CMPIObjectPath* op, CMPIInstanceMI* mi, 
   10.69 +		     const char** properties)
   10.70 +{
   10.71 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   10.72 +   void* resList = NULL;
   10.73 +   void* resId = NULL;
   10.74 +   *res = NULL;
   10.75 +   CMPIInstance* inst;
   10.76 +   int rc = 0;
   10.77 +
   10.78 +   if (!op2inst(op,&inst,mi)) goto exit;
   10.79 +
   10.80 +   /* Get the ResourceId for the instance */
   10.81 +   status.rc = _FT->extractid(&resId, inst);
   10.82 +   if (status.rc != CMPI_RC_OK) goto exit;
   10.83 +
   10.84 +   /* First try to get the target resource directly. */
   10.85 +   status.rc = _FT->get(resId, res, properties);
   10.86 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED) {
   10.87 +      /* FIXME - if get() unsupported then enumerate and look for match */
   10.88 +      goto exit;
   10.89 +   } else if (status.rc != CMPI_RC_OK) {
   10.90 +      goto exit;
   10.91 +   } 
   10.92 +   rc = 1;
   10.93 +
   10.94 + exit:
   10.95 +   if (resId) _FT->releaseid(resId);
   10.96 +   return rc;
   10.97 +}
   10.98 +
   10.99 +/* ------------------------------------------------------------------------- */
  10.100 +/* Shared CMPILIFY CMPI instance provider functions.                         */
  10.101 +/* ------------------------------------------------------------------------- */
  10.102 +
  10.103 +CMPIStatus CMPILIFYInstance_cleanup
  10.104 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating)
  10.105 +{
  10.106 +   CMPIStatus status = {CMPI_RC_OK, NULL}; 
  10.107 +  _SBLIM_ENTER("CMPILIFYInstance_cleanup");
  10.108 +
  10.109 +   /* Run resource provider's unload(). */
  10.110 +   if (_FT->unload(terminating == CMPI_true) != CMPI_RC_OK)
  10.111 +      CMSetStatusWithChars(_BROKER, &status, (terminating == CMPI_true)?
  10.112 +                           CMPI_RC_ERR_FAILED : CMPI_RC_DO_NOT_UNLOAD,
  10.113 +                           "CMPILIFY unload() failed");
  10.114 +
  10.115 +   _SBLIM_RETURNSTATUS(status);
  10.116 +}
  10.117 +
  10.118 +/* ------------------------------------------------------------------------- */
  10.119 +
  10.120 +CMPIStatus CMPILIFYInstance_enumInstanceNames
  10.121 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.122 +        const CMPIObjectPath* ref)
  10.123 +{
  10.124 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.125 +   void* resList;
  10.126 +   void* res;
  10.127 +   char* ns;
  10.128 +   unsigned int found = 0;
  10.129 +   CMPIObjectPath* op;
  10.130 +   CMPIInstance* inst;
  10.131 +   _SBLIM_ENTER("CMPILIFYInstance_enumInstanceNames");
  10.132 +
  10.133 +   /* Get list of resources. */
  10.134 +   if (_FT->begin(&resList, NULL) != CMPI_RC_OK) {
  10.135 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, 
  10.136 +                           "CMPILIFY begin() failed");
  10.137 +      goto exit;
  10.138 +   }
  10.139 +
  10.140 +   /* Enumerate resources and return CMPIObjectPath for each. */ 
  10.141 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.142 +   while (1) {
  10.143 +      /* Create new CMPIObjectPath for next resource. */
  10.144 +      op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
  10.145 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.146 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.147 +         break;
  10.148 +      }
  10.149 +
  10.150 +      /* Create new CMPIInstance for resource. */
  10.151 +      inst = CMNewInstance(_BROKER, op, &status);
  10.152 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.153 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.154 +         break;
  10.155 +      }
  10.156 +
  10.157 +      /* Get the next resource using the resource provider's getNext(). */
  10.158 +      if (_FT->getnext(resList, &res, NULL) != CMPI_RC_OK)
  10.159 +         break; /* Normal loop exit when CMPI_RC_ERR_NOT_FOUND. */
  10.160 +
  10.161 +      /* Set CMPIInstance properties from resource data. */
  10.162 +      status.rc = _FT->setproperties(inst, res, NULL);
  10.163 +      _FT->release(res);
  10.164 +      if (status.rc != CMPI_RC_OK) {
  10.165 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.166 +                              "CMPILIFY setproperties() failed");
  10.167 +         break;
  10.168 +      }
  10.169 +
  10.170 +      /* Get the CMPIObjectPath for this CMPIInstance. */
  10.171 +      op = CMGetObjectPath(inst, &status);
  10.172 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.173 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.174 +         break;
  10.175 +      }
  10.176 +      status = CMSetNameSpace(op, ns);
  10.177 +      if (status.rc != CMPI_RC_OK) {
  10.178 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.179 +         break;
  10.180 +      }
  10.181 +
  10.182 +      /* Return the CMPIObjectPath for the resource. */
  10.183 +      status = CMReturnObjectPath(rslt, op);
  10.184 +      if (status.rc != CMPI_RC_OK) {
  10.185 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.186 +         break;
  10.187 +      }
  10.188 +      found++;
  10.189 +   } /* while() */
  10.190 +   _FT->end(resList);
  10.191 +
  10.192 +   /* Check if enumeration finished OK. */
  10.193 +   if (found) {
  10.194 +      if ((status.rc == CMPI_RC_OK) || (status.rc == CMPI_RC_ERR_NOT_FOUND)) {
  10.195 +         CMReturnDone(rslt);
  10.196 +         CMSetStatus(&status, CMPI_RC_OK);
  10.197 +      }
  10.198 +   }
  10.199 +
  10.200 + exit:
  10.201 +    _SBLIM_RETURNSTATUS(status);
  10.202 +}
  10.203 +
  10.204 +/* ------------------------------------------------------------------------- */
  10.205 +
  10.206 +CMPIStatus CMPILIFYInstance_enumInstances
  10.207 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.208 +        const CMPIObjectPath* ref, const char** properties)
  10.209 +{
  10.210 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.211 +   void* resList;
  10.212 +   void* res;
  10.213 +   char* ns;
  10.214 +   unsigned int found = 0;
  10.215 +   CMPIObjectPath* op;
  10.216 +   CMPIInstance* inst;
  10.217 +   _SBLIM_ENTER("CMPILIFYInstance_enumInstances");
  10.218 +
  10.219 +   /* Get list of resources. */
  10.220 +   if (_FT->begin(&resList, NULL) != CMPI_RC_OK) {
  10.221 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.222 +                           "CMPILIFY begin() failed");
  10.223 +      goto exit;
  10.224 +   }
  10.225 +
  10.226 +   /* Enumerate resources and return CMPIObjectPath for each. */
  10.227 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.228 +   while (1) {
  10.229 +      /* Create new CMPIObjectPath for next resource. */
  10.230 +      op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
  10.231 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.232 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.233 +         break;
  10.234 +      }
  10.235 +
  10.236 +      /* Create new CMPIInstance for resource. */
  10.237 +      inst = CMNewInstance(_BROKER, op, &status);
  10.238 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.239 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.240 +         break;
  10.241 +      }
  10.242 +
  10.243 +      /* Get the next resource using the resource provider's getNext(). */
  10.244 +      if (_FT->getnext(resList, &res, NULL) != CMPI_RC_OK)
  10.245 +         break; /* Normal loop exit when CMPI_RC_ERR_NOT_FOUND. */
  10.246 +
  10.247 +      /* If specified, set the property filter for CMPIInstance. */
  10.248 +      if (properties) {
  10.249 +         status = CMSetPropertyFilter(inst, properties, NULL);
  10.250 +         if (status.rc != CMPI_RC_OK) {
  10.251 +            CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.252 +            break;
  10.253 +         }
  10.254 +      }
  10.255 +
  10.256 +      /* Set CMPIInstance properties from resource data. */
  10.257 +      status.rc = _FT->setproperties(inst, res, NULL);
  10.258 +      _FT->release(res);
  10.259 +      if (status.rc != CMPI_RC_OK) {
  10.260 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.261 +                              "CMPILIFY setproperties() failed");
  10.262 +         break;
  10.263 +      }
  10.264 +
  10.265 +      /* Return the CMPIInstance for the resource. */
  10.266 +      status = CMReturnInstance(rslt, inst);
  10.267 +      if (status.rc != CMPI_RC_OK) {
  10.268 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.269 +         break;
  10.270 +      }
  10.271 +      found++;
  10.272 +   } /* while() */
  10.273 +   _FT->end(resList);
  10.274 +
  10.275 +   /* Check if enumeration finished OK. */
  10.276 +   if (found) {
  10.277 +      if ((status.rc == CMPI_RC_OK) || (status.rc == CMPI_RC_ERR_NOT_FOUND)) {
  10.278 +         CMReturnDone(rslt);
  10.279 +         CMSetStatus(&status, CMPI_RC_OK);
  10.280 +      }
  10.281 +   }
  10.282 +
  10.283 + exit:
  10.284 +   _SBLIM_RETURNSTATUS(status);
  10.285 +}
  10.286 +
  10.287 +/* ------------------------------------------------------------------------- */
  10.288 +
  10.289 +CMPIStatus CMPILIFYInstance_getInstance
  10.290 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.291 +        const CMPIObjectPath* ref, const char** properties)
  10.292 +{
  10.293 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.294 +   void* res = NULL;
  10.295 +   CMPIInstance* inst;
  10.296 +   _SBLIM_ENTER("CMPILIFYInstance_getInstance");
  10.297 +
  10.298 +   /* Create new CMPIInstance for resource. */
  10.299 +   inst = CMNewInstance(_BROKER, ref, &status);
  10.300 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.301 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.302 +      goto exit;
  10.303 +   }
  10.304 +
  10.305 +   /* If specified, set the property filter for CMPIInstance. */
  10.306 +   if (properties) {
  10.307 +      status = CMSetPropertyFilter(inst, properties, NULL);
  10.308 +      if (status.rc != CMPI_RC_OK) {
  10.309 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.310 +         goto exit;
  10.311 +      }
  10.312 +   }
  10.313 +
  10.314 +   /* Get the target resource. */ 
  10.315 +   if (!getres4op(&res, (CMPIObjectPath*)ref, mi, properties)) {
  10.316 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
  10.317 +      goto exit;
  10.318 +   }
  10.319 +
  10.320 +   /* Set CMPIInstance properties from resource data. */
  10.321 +   status.rc = _FT->setproperties(inst, res, properties);
  10.322 +   _FT->release(res);
  10.323 +   if (status.rc != CMPI_RC_OK) {
  10.324 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.325 +                           "CMPILIFY setproperties() failed");
  10.326 +      goto exit;
  10.327 +   }
  10.328 +
  10.329 +   /* Return the CMPIInstance for the resource. */
  10.330 +   status = CMReturnInstance(rslt, inst);
  10.331 +   if (status.rc != CMPI_RC_OK) {
  10.332 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.333 +      goto exit;
  10.334 +   }
  10.335 +
  10.336 +   CMReturnDone(rslt);
  10.337 + exit:
  10.338 +   _SBLIM_RETURNSTATUS(status);
  10.339 +}
  10.340 +
  10.341 +/* ------------------------------------------------------------------------- */
  10.342 +
  10.343 +CMPIStatus CMPILIFYInstance_createInstance
  10.344 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.345 +        const CMPIObjectPath* ref, const CMPIInstance* inst)
  10.346 +{
  10.347 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.348 +   void* res = NULL;
  10.349 +   void* resId = NULL;
  10.350 +   _SBLIM_ENTER("CMPILIFYInstance_createInstance");
  10.351 +
  10.352 +   /* Check if target resource already exists. */
  10.353 +   if (getres4op(&res, (CMPIObjectPath*)ref, mi, NULL)) {
  10.354 +      _FT->release(res);
  10.355 +      CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS);
  10.356 +      goto exit;
  10.357 +   }
  10.358 +
  10.359 +   /* Get the ResourceId for the new resource instance. */
  10.360 +   if (_FT->extractid(&resId, (CMPIInstance*)inst) != CMPI_RC_OK) {
  10.361 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.362 +                           "CMPILIFY extractid() failed");
  10.363 +      goto exit;
  10.364 +   }
  10.365 +
  10.366 +   /* Create a new resource from the CMPIInstance properties. */
  10.367 +   status.rc = _FT->extract(&res, (CMPIInstance*)inst, NULL);
  10.368 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED) {
  10.369 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED,
  10.370 +                           "CMPILIFY extract() unsupported");
  10.371 +      goto exit;
  10.372 +   } else if (status.rc != CMPI_RC_OK) {
  10.373 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.374 +                           "CMPILIFY extract() failed");
  10.375 +      goto exit;
  10.376 +   }
  10.377 +
  10.378 +   /* Add the target resource. */
  10.379 +   status.rc = _FT->add(resId, res);
  10.380 +   _FT->release(res);
  10.381 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
  10.382 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, 
  10.383 +                           "CMPILIFY add() unsupported")
  10.384 +   else if (status.rc != CMPI_RC_OK)
  10.385 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.386 +                           "CMPILIFY add() failed");
  10.387 +
  10.388 + exit:
  10.389 +   if (resId) _FT->releaseid(resId);
  10.390 +   _SBLIM_RETURNSTATUS(status);
  10.391 +}
  10.392 +
  10.393 +/* ------------------------------------------------------------------------- */
  10.394 +
  10.395 +CMPIStatus CMPILIFYInstance_modifyInstance
  10.396 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.397 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
  10.398 +        const char** properties)
  10.399 +{
  10.400 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.401 +   void* res = NULL;
  10.402 +   void* resId = NULL;
  10.403 +   _SBLIM_ENTER("CMPILIFYInstance_modifyInstance");
  10.404 +
  10.405 +   /* Get the target resource. */
  10.406 +   if (!getres4op(&res, (CMPIObjectPath*)ref, mi, NULL)) {
  10.407 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
  10.408 +      goto exit;
  10.409 +   }
  10.410 +   _FT->release(res);
  10.411 +   res = NULL;
  10.412 +
  10.413 +   /* Get the ResourceId for the new resource instance. */
  10.414 +   if (_FT->extractid(&resId, (CMPIInstance*)inst) != CMPI_RC_OK) {
  10.415 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.416 +                           "CMPILIFY extractid() failed");
  10.417 +      goto exit;
  10.418 +   }
  10.419 +
  10.420 +   /* Create a new resource from the CMPIInstance properties. */
  10.421 +   status.rc = _FT->extract(&res, (CMPIInstance*)inst, NULL);
  10.422 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED) {
  10.423 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED,
  10.424 +                           "CMPILIFY extract() unsupported");
  10.425 +      goto exit;
  10.426 +   } else if (status.rc != CMPI_RC_OK) {
  10.427 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.428 +                           "CMPILIFY extract() failed");
  10.429 +      goto exit;
  10.430 +   }
  10.431 +
  10.432 +   /* Modify the target resource. */
  10.433 +   status.rc = _FT->modify(resId, res, properties);
  10.434 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
  10.435 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED,
  10.436 +                           "CMPILIFY modify() unsupported")
  10.437 +   else if (status.rc != CMPI_RC_OK)
  10.438 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.439 +                           "CMPILIFY modify() failed");
  10.440 +
  10.441 + exit:
  10.442 +   if (res) _FT->release(res);
  10.443 +   if (resId) _FT->releaseid(resId);
  10.444 +   _SBLIM_RETURNSTATUS(status);
  10.445 +}
  10.446 +
  10.447 +/* ------------------------------------------------------------------------- */
  10.448 +
  10.449 +CMPIStatus CMPILIFYInstance_deleteInstance
  10.450 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.451 +        const CMPIObjectPath* ref)
  10.452 +{
  10.453 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.454 +   void* res = NULL;
  10.455 +   void* resId = NULL;
  10.456 +   CMPIInstance* inst;
  10.457 +   _SBLIM_ENTER("CMPILIFYInstance_deleteInstance");
  10.458 +
  10.459 +   /* Get the target resource. */
  10.460 +   if (!getres4op(&res, (CMPIObjectPath*)ref, mi, NULL)) {
  10.461 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
  10.462 +      goto exit;
  10.463 +   }
  10.464 +   _FT->release(res);
  10.465 +   res = NULL;
  10.466 +
  10.467 +   /* Convert the ref CMPIObjectPath to (partial) CMPIInstance. */
  10.468 +   if (!op2inst(ref, &inst, mi)) {
  10.469 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.470 +                           "Internal error: op2inst() failed");
  10.471 +      goto exit;
  10.472 +   }
  10.473 +
  10.474 +   /* Get the ResourceId for the new resource instance. */
  10.475 +   if (_FT->extractid(&resId, (CMPIInstance*)inst) != CMPI_RC_OK) {
  10.476 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.477 +                           "CMPLIFY extractid() failed");
  10.478 +      goto exit;
  10.479 +   }
  10.480 +
  10.481 +   /* Delete the target resource. */
  10.482 +   status.rc = _FT->delete(resId);
  10.483 +   if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
  10.484 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED,
  10.485 +                           "CMPLIFY delete() unsupported")
  10.486 +   else if (status.rc != CMPI_RC_OK)
  10.487 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.488 +                           "CMPLIFY delete() failed");
  10.489 +
  10.490 + exit:
  10.491 +   if (resId) _FT->releaseid(resId);
  10.492 +   _SBLIM_RETURNSTATUS(status);
  10.493 +}
  10.494 +
  10.495 +/* ------------------------------------------------------------------------- */
  10.496 +
  10.497 +CMPIStatus CMPILIFYInstance_execQuery
  10.498 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.499 +        const CMPIObjectPath* ref, const char* query, const char* lang)
  10.500 +{
  10.501 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.502 +   void* resList;
  10.503 +   void* res;
  10.504 +   char* ns;
  10.505 +   unsigned int found = 0;
  10.506 +   CMPISelectExp* expr;
  10.507 +   CMPIObjectPath* op;
  10.508 +   CMPIInstance* inst;
  10.509 +   CMPIBoolean match;
  10.510 +   _SBLIM_ENTER("CMPILIFYInstance_execQuery");
  10.511 +
  10.512 +   /* Create select expression from query. */
  10.513 +   expr = CMNewSelectExp(_BROKER, query, lang, NULL, &status);
  10.514 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(expr)) {
  10.515 +      CMSetStatus(&status, CMPI_RC_ERR_INVALID_QUERY);
  10.516 +      goto exit;
  10.517 +   }
  10.518 +
  10.519 +   /* Get list of resources. */
  10.520 +   if (_FT->begin(&resList, NULL) != CMPI_RC_OK) {
  10.521 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.522 +                           "begin() failed");
  10.523 +      goto exit;
  10.524 +   }
  10.525 +
  10.526 +   /* Enumerate resources and return CMPIObjectPath for each. */
  10.527 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.528 +   while (1) {
  10.529 +      /* Create new CMPIObjectPath for next resource. */
  10.530 +      op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
  10.531 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.532 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.533 +         break;
  10.534 +      }
  10.535 +
  10.536 +      /* Create new CMPIInstance for resource. */
  10.537 +      inst = CMNewInstance(_BROKER, op, &status);
  10.538 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.539 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.540 +         break;
  10.541 +      }
  10.542 +
  10.543 +      /* Get the next resource using the resource provider's getNext(). */
  10.544 +      if (_FT->getnext(resList, &res, NULL) != CMPI_RC_OK)
  10.545 +         break; /* Normal loop exit when CMPI_RC_ERR_NOT_FOUND. */
  10.546 +
  10.547 +      /* Set CMPIInstance properties from resource data. */
  10.548 +      status.rc = _FT->setproperties(inst, res, NULL);
  10.549 +      _FT->release(res);
  10.550 +      if (status.rc != CMPI_RC_OK) {
  10.551 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.552 +                              "setproperties() failed");
  10.553 +         break;
  10.554 +      }
  10.555 +
  10.556 +      /* Evaluate the select expression against this CMPIInstance. */
  10.557 +      match = CMEvaluateSelExp(expr, inst, &status);
  10.558 +      if (status.rc != CMPI_RC_OK) {
  10.559 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.560 +         break;
  10.561 +      }
  10.562 +
  10.563 +      /* Return the CMPIInstance for the resource if it match the query. */
  10.564 +      if (match) {
  10.565 +         status = CMReturnInstance(rslt, inst);
  10.566 +         if (status.rc != CMPI_RC_OK) {
  10.567 +            CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.568 +            break;
  10.569 +         }
  10.570 +         found++;
  10.571 +      }
  10.572 +   } /* while() */
  10.573 +   _FT->end(resList);
  10.574 +
  10.575 +   /* Check if enumeration finished OK. */
  10.576 +   if (found) {
  10.577 +      if ((status.rc == CMPI_RC_OK) || (status.rc == CMPI_RC_ERR_NOT_FOUND)) {
  10.578 +         CMReturnDone(rslt);
  10.579 +         CMSetStatus(&status, CMPI_RC_OK);
  10.580 +      }
  10.581 +   }
  10.582 +
  10.583 + exit:
  10.584 +   _SBLIM_RETURNSTATUS(status);
  10.585 +}
  10.586 +
  10.587 +
  10.588 +/* Need to refine the shortcuts to match the different CMPILIFYInstanceMI */
  10.589 +#undef _BROKER
  10.590 +#define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
  10.591 +#undef _CLASS
  10.592 +#define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
  10.593 +#undef _KEYS
  10.594 +#define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
  10.595 +#undef _FT
  10.596 +#define _FT (((CMPILIFYInstance1ROMI*)(mi->hdl))->ft)
  10.597 +
  10.598 +/* ------------------------------------------------------------------------- */
  10.599 +
  10.600 +CMPIStatus CMPILIFYInstance1RO_cleanup
  10.601 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating)
  10.602 +{
  10.603 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.604 +   _SBLIM_ENTER("CMPILIFYInstance1RO_cleanup");
  10.605 +
  10.606 +   /* Run resource provider's unload(). */
  10.607 +   if (_FT->unload(terminating == CMPI_true) != CMPI_RC_OK)
  10.608 +      CMSetStatusWithChars(_BROKER, &status, (terminating == CMPI_true)?
  10.609 +                           CMPI_RC_ERR_FAILED : CMPI_RC_DO_NOT_UNLOAD,
  10.610 +                           "CMPILIFY unload() failed");
  10.611 +
  10.612 +   _SBLIM_RETURNSTATUS(status);
  10.613 +}
  10.614 +
  10.615 +/* ------------------------------------------------------------------------- */
  10.616 +
  10.617 +CMPIStatus CMPILIFYInstance1RO_enumInstanceNames
  10.618 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.619 +        const CMPIObjectPath* ref)
  10.620 +{
  10.621 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.622 +   void* res = NULL;
  10.623 +   CMPIInstance* inst;
  10.624 +   CMPIObjectPath* op;
  10.625 +   char* ns;
  10.626 +
  10.627 +   _SBLIM_ENTER("CMPILIFYInstance1RO_enumInstanceNames");
  10.628 +
  10.629 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.630 +
  10.631 +   /* Create the new CMPIInstance. */
  10.632 +   inst = CMNewInstance(_BROKER, ref, &status);
  10.633 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.634 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.635 +      goto exit;
  10.636 +   }
  10.637 +
  10.638 +   /* Get the instance data. */
  10.639 +   status.rc = _FT->get(&res, NULL);
  10.640 +   if (status.rc != CMPI_RC_OK)
  10.641 +      goto exit;
  10.642 +
  10.643 +   /* Set the CMPIInstance properties from the instance data. */
  10.644 +   status.rc = _FT->setproperties(inst, res, NULL);
  10.645 +   _FT->release(res);
  10.646 +   if (status.rc != CMPI_RC_OK) {
  10.647 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.648 +                           "CMPILIFY setproperties() failed");
  10.649 +      goto exit;
  10.650 +   }
  10.651 +
  10.652 +   /* Get the CMPIObjectPath for this CMPIInstance. */
  10.653 +   op = CMGetObjectPath(inst, &status);
  10.654 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.655 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.656 +      goto exit;
  10.657 +   }
  10.658 +   status = CMSetNameSpace(op, ns);
  10.659 +   if (status.rc != CMPI_RC_OK) {
  10.660 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.661 +      goto exit;
  10.662 +   }
  10.663 +
  10.664 +   /* Return the CMPIObjectPath for the resource. */
  10.665 +   status = CMReturnObjectPath(rslt, op);
  10.666 +   if (status.rc != CMPI_RC_OK) {
  10.667 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.668 +      goto exit;
  10.669 +   }
  10.670 +
  10.671 +   CMReturnDone(rslt);
  10.672 + exit:
  10.673 +   _SBLIM_RETURNSTATUS(status);
  10.674 +}
  10.675 +
  10.676 +/* ------------------------------------------------------------------------- */
  10.677 +
  10.678 +CMPIStatus CMPILIFYInstance1RO_enumInstances
  10.679 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.680 +        const CMPIObjectPath* ref, const char** properties)
  10.681 +{
  10.682 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.683 +   void* res = NULL;
  10.684 +   CMPIInstance* inst;
  10.685 +   char* ns;
  10.686 +
  10.687 +   _SBLIM_ENTER("CMPILIFYInstance1RO_enumInstances");
  10.688 +
  10.689 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.690 +
  10.691 +   /* Create the new CMPIInstance. */
  10.692 +   inst = CMNewInstance(_BROKER, ref, &status);
  10.693 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.694 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.695 +      goto exit;
  10.696 +   }
  10.697 +
  10.698 +   /* If specified, set the property filter. */
  10.699 +   if (properties) {
  10.700 +      status = CMSetPropertyFilter(inst, properties, NULL);
  10.701 +      if (status.rc != CMPI_RC_OK) {
  10.702 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.703 +         goto exit;
  10.704 +      }
  10.705 +   }
  10.706 +
  10.707 +   /* Get the instance data. */
  10.708 +   status.rc = _FT->get(&res, properties);
  10.709 +   if (status.rc != CMPI_RC_OK)
  10.710 +      goto exit;
  10.711 +
  10.712 +   /* Set the CMPIInstance properties from the instance data. */
  10.713 +   status.rc = _FT->setproperties(inst, res, properties);
  10.714 +   _FT->release(res);
  10.715 +   if (status.rc != CMPI_RC_OK) {
  10.716 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.717 +                           "CMPILIFY setproperties() failed");
  10.718 +      goto exit;
  10.719 +   }
  10.720 +
  10.721 +   /* Return the CMPIInstance for the resource. */
  10.722 +   status = CMReturnInstance(rslt, inst);
  10.723 +   if (status.rc != CMPI_RC_OK) {
  10.724 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.725 +      goto exit;
  10.726 +   }
  10.727 +
  10.728 +   CMReturnDone(rslt);
  10.729 + exit:
  10.730 +   _SBLIM_RETURNSTATUS(status);
  10.731 +}
  10.732 +
  10.733 +/* ------------------------------------------------------------------------- */
  10.734 +
  10.735 +CMPIStatus CMPILIFYInstance1RO_getInstance
  10.736 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.737 +        const CMPIObjectPath* ref, const char** properties)
  10.738 +{
  10.739 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.740 +   void* res = NULL;
  10.741 +   CMPIInstance* inst;
  10.742 +   CMPIObjectPath* op;
  10.743 +   char* ns;
  10.744 +
  10.745 +   _SBLIM_ENTER("CMPILIFYInstance1RO_getInstance");
  10.746 +
  10.747 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.748 +
  10.749 +   /* Create the new CMPIInstance. */
  10.750 +   inst = CMNewInstance(_BROKER, ref, &status);
  10.751 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.752 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.753 +      goto exit;
  10.754 +   }
  10.755 +
  10.756 +   /* If specified, set the property filter. */
  10.757 +   if (properties) {
  10.758 +      status = CMSetPropertyFilter(inst, properties, NULL);
  10.759 +      if (status.rc != CMPI_RC_OK) {
  10.760 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.761 +         goto exit;
  10.762 +      }
  10.763 +   }
  10.764 +
  10.765 +   /* Get the instance data. */
  10.766 +   status.rc = _FT->get(&res, properties);
  10.767 +   if (status.rc != CMPI_RC_OK)
  10.768 +      goto exit;
  10.769 +
  10.770 +   /* Set the CMPIInstance properties from the instance data. */
  10.771 +   status.rc = _FT->setproperties(inst, res, properties);
  10.772 +   _FT->release(res);
  10.773 +   if (status.rc != CMPI_RC_OK) {
  10.774 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.775 +                           "CMPILIFY setproperties() failed");
  10.776 +      goto exit;
  10.777 +   }
  10.778 +
  10.779 +   /* Get the CMPIObjectPath for this CMPIInstance. */
  10.780 +   op = CMGetObjectPath(inst, &status);
  10.781 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  10.782 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.783 +      goto exit;
  10.784 +   }
  10.785 +   status = CMSetNameSpace(op, ns);
  10.786 +   if (status.rc != CMPI_RC_OK) {
  10.787 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.788 +      goto exit;
  10.789 +   }
  10.790 +
  10.791 +   /* Check the CMPIInstance matches the requested reference. */
  10.792 +   if (!_CMSameObject(op, (CMPIObjectPath*)ref)) {
  10.793 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
  10.794 +      goto exit;
  10.795 +   }
  10.796 + 
  10.797 +   /* Return the CMPIInstance for the resource. */
  10.798 +   status = CMReturnInstance(rslt, inst);
  10.799 +   if (status.rc != CMPI_RC_OK) {
  10.800 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.801 +      goto exit;
  10.802 +   }
  10.803 +
  10.804 +   CMReturnDone(rslt);
  10.805 + exit:
  10.806 +   _SBLIM_RETURNSTATUS(status);
  10.807 +}
  10.808 +
  10.809 +/* ------------------------------------------------------------------------- */
  10.810 +
  10.811 +CMPIStatus CMPILIFYInstance1RO_createInstance
  10.812 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.813 +        const CMPIObjectPath* ref, const CMPIInstance* inst)
  10.814 +{
  10.815 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
  10.816 +   _SBLIM_ENTER("CMPILIFYInstance1RO_createInstance");
  10.817 +   _SBLIM_RETURNSTATUS(status);
  10.818 +}
  10.819 +
  10.820 +/* ------------------------------------------------------------------------- */
  10.821 +
  10.822 +CMPIStatus CMPILIFYInstance1RO_modifyInstance
  10.823 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.824 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
  10.825 +        const char** properties)
  10.826 +{
  10.827 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
  10.828 +   _SBLIM_ENTER("CMPILIFYInstance1RO_modifyInstance");
  10.829 +   _SBLIM_RETURNSTATUS(status);
  10.830 +}
  10.831 +
  10.832 +/* ------------------------------------------------------------------------- */
  10.833 +
  10.834 +CMPIStatus CMPILIFYInstance1RO_deleteInstance
  10.835 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.836 +        const CMPIObjectPath* ref)
  10.837 +{
  10.838 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
  10.839 +   _SBLIM_ENTER("CMPILIFYInstance1RO_deleteInstance");
  10.840 +   _SBLIM_RETURNSTATUS(status);
  10.841 +}
  10.842 +
  10.843 +/* ------------------------------------------------------------------------- */
  10.844 +
  10.845 +CMPIStatus CMPILIFYInstance1RO_execQuery
  10.846 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  10.847 +        const CMPIObjectPath* ref, const char* query, const char* lang)
  10.848 +{
  10.849 +   CMPIStatus status = {CMPI_RC_OK, NULL};
  10.850 +   void* resList;
  10.851 +   void* res;
  10.852 +   char* ns;
  10.853 +   unsigned int found = 0;
  10.854 +   CMPISelectExp* expr;
  10.855 +   CMPIObjectPath* op;
  10.856 +   CMPIInstance* inst;
  10.857 +   CMPIBoolean match;
  10.858 +   _SBLIM_ENTER("CMPILIFYInstance1RO_execQuery");
  10.859 +
  10.860 +   /* Create select expression from query. */
  10.861 +   expr = CMNewSelectExp(_BROKER, query, lang, NULL, &status);
  10.862 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(expr)) {
  10.863 +      CMSetStatus(&status, CMPI_RC_ERR_INVALID_QUERY);
  10.864 +      goto exit;
  10.865 +   }
  10.866 +
  10.867 +   ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  10.868 +
  10.869 +   /* Create the new CMPIInstance. */
  10.870 +   inst = CMNewInstance(_BROKER, ref, &status);
  10.871 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  10.872 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.873 +      goto exit;
  10.874 +   }
  10.875 +
  10.876 +   /* Get the instance data. */
  10.877 +   status.rc = _FT->get(&res, NULL);
  10.878 +   if (status.rc != CMPI_RC_OK)
  10.879 +      goto exit;
  10.880 +
  10.881 +   /* Set the CMPIInstance properties from the instance data. */
  10.882 +   status.rc = _FT->setproperties(inst, res, NULL);
  10.883 +   _FT->release(res);
  10.884 +   if (status.rc != CMPI_RC_OK) {
  10.885 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
  10.886 +                           "CMPILIFY setproperties() failed");
  10.887 +      goto exit;
  10.888 +   }
  10.889 +
  10.890 +   /* Evaluate the select expression against this CMPIInstance. */
  10.891 +   match = CMEvaluateSelExp(expr, inst, &status);
  10.892 +   if (status.rc != CMPI_RC_OK) {
  10.893 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.894 +      goto exit;
  10.895 +   }
  10.896 +
  10.897 +   /* Return the CMPIInstance for the resource if it match the query. */
  10.898 +   if (match) {
  10.899 +      status = CMReturnInstance(rslt, inst);
  10.900 +      if (status.rc != CMPI_RC_OK) {
  10.901 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
  10.902 +         goto exit;
  10.903 +      }
  10.904 +      CMSetStatus(&status, CMPI_RC_OK); 
  10.905 +   } else
  10.906 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
  10.907 +
  10.908 +   CMReturnDone(rslt);
  10.909 + exit:
  10.910 +   _SBLIM_RETURNSTATUS(status);
  10.911 +}
  10.912 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/cmpilify.h	Mon Jul 16 12:15:30 2007 -0600
    11.3 @@ -0,0 +1,264 @@
    11.4 +/*
    11.5 + * cmpilify.h
    11.6 + *
    11.7 + * © Copyright IBM Corp. 2007
    11.8 + *
    11.9 + * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
   11.10 + * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
   11.11 + * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
   11.12 + * You can obtain a current copy of the Common Public License from
   11.13 + * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
   11.14 + *
   11.15 + * Author:         Dr. Gareth S. Bestor <bestor@us.ibm.com>
   11.16 + * Contributors:
   11.17 + * Interface Type: Common Manageability Programming Interface (CMPI)
   11.18 + * Description:    Generic CMPILIFY instance provider.
   11.19 +*/
   11.20 +
   11.21 +#ifndef _CMPILIFY_H_
   11.22 +#define _CMPILIFY_H_
   11.23 +
   11.24 +#include <cmpidt.h>
   11.25 +
   11.26 +
   11.27 +/* ------------------------------------------------------------------------- */
   11.28 +/* Generic CMPILIFY instance provider abstract resource API.                 */
   11.29 +/* ------------------------------------------------------------------------- */
   11.30 +typedef struct {
   11.31 +   CMPIrc (*load)();
   11.32 +   CMPIrc (*unload)(const int terminating);
   11.33 +   CMPIrc (*begin)(void** enm, const char** properties);
   11.34 +   void   (*end)(void* enm);
   11.35 +   CMPIrc (*getnext)(void* enm, void** inst, const char** properties);
   11.36 +   CMPIrc (*get)(const void* id, void** inst, const char** properties);
   11.37 +   void   (*release)(void* inst);
   11.38 +   CMPIrc (*add)(const void* id, const void* inst);
   11.39 +   CMPIrc (*delete)(const void* id);
   11.40 +   CMPIrc (*modify)(const void* id, const void* inst, const char** properties);
   11.41 +   CMPIrc (*setproperties)(CMPIInstance* instance, const void* inst,
   11.42 +                           const char** properties);
   11.43 +   CMPIrc (*extract)(void** inst, const CMPIInstance* instance,
   11.44 +                     const char** properties);
   11.45 +   CMPIrc (*extractid)(void** id, const CMPIInstance* instance);
   11.46 +   void   (*releaseid)(void* id);
   11.47 +} CMPILIFYInstanceMIFT;
   11.48 +
   11.49 +/* ------------------------------------------------------------------------- */
   11.50 +/* Generic CMPILIFY instance provider encapsulated object.                   */
   11.51 +/* ------------------------------------------------------------------------- */
   11.52 +typedef struct {
   11.53 +   void* hdl;                     /* Handle to implementation-specific data. */
   11.54 +   const CMPIBroker* brkr;    /* CIMOM handle, initialized on provider load. */
   11.55 +   char* cn;                               /* Instance provider's CIM class. */
   11.56 +   char** kys;                    /* NULL terminated list of CIM class keys. */
   11.57 +   CMPILIFYInstanceMIFT* ft;        /* Abstract resource API function table. */
   11.58 +} CMPILIFYInstanceMI;
   11.59 +
   11.60 +/* ------------------------------------------------------------------------- */
   11.61 +/* Generic CMPILIFY instance provider intrinsic CMPI functions.              */
   11.62 +/* ------------------------------------------------------------------------- */
   11.63 +CMPIStatus CMPILIFYInstance_cleanup
   11.64 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating);
   11.65 +
   11.66 +CMPIStatus CMPILIFYInstance_enumInstanceNames
   11.67 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.68 +        const CMPIObjectPath* ref);
   11.69 +
   11.70 +CMPIStatus CMPILIFYInstance_enumInstances
   11.71 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.72 +        const CMPIObjectPath* ref, const char** properties);
   11.73 +
   11.74 +CMPIStatus CMPILIFYInstance_getInstance
   11.75 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.76 +        const CMPIObjectPath* ref, const char** properties);
   11.77 +
   11.78 +CMPIStatus CMPILIFYInstance_createInstance
   11.79 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.80 +        const CMPIObjectPath* ref, const CMPIInstance* inst);
   11.81 +
   11.82 +CMPIStatus CMPILIFYInstance_modifyInstance
   11.83 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.84 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
   11.85 +        const char** properties);
   11.86 +
   11.87 +CMPIStatus CMPILIFYInstance_deleteInstance
   11.88 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.89 +        const CMPIObjectPath* ref);
   11.90 +
   11.91 +CMPIStatus CMPILIFYInstance_execQuery
   11.92 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   11.93 +        const CMPIObjectPath* ref, const char* lang, const char* query);
   11.94 +
   11.95 +/* ------------------------------------------------------------------------- */
   11.96 +/* Macro to generate _Create_InstanceMI entry point, setup function table to */
   11.97 +/* the shared CMPILIFY instance provider intrinsic CMPI functions, and setup */
   11.98 +/* function table to the provider-specific resource access API functions.    */
   11.99 +/* ------------------------------------------------------------------------- */
  11.100 +#define CMPILIFYInstanceMIStub(cn,pn,kys,mi) \
  11.101 +static CMPILIFYInstanceMIFT _CMPILIFYMIFT = { \
  11.102 +   load, \
  11.103 +   unload, \
  11.104 +   begin, \
  11.105 +   end, \
  11.106 +   getnext, \
  11.107 +   get, \
  11.108 +   release, \
  11.109 +   add, \
  11.110 +   delete, \
  11.111 +   modify, \
  11.112 +   setproperties, \
  11.113 +   extract, \
  11.114 +   extractid, \
  11.115 +   releaseid, \
  11.116 +}; \
  11.117 +\
  11.118 +static CMPILIFYInstanceMI _CMPILIFYMI = { \
  11.119 +   NULL, \
  11.120 +   NULL, \
  11.121 +   #cn, \
  11.122 +   kys, \
  11.123 +   &_CMPILIFYMIFT, \
  11.124 +}; \
  11.125 +\
  11.126 +static CMPIInstanceMIFT _CMPIMIFT = { \
  11.127 +   CMPICurrentVersion, \
  11.128 +   CMPICurrentVersion, \
  11.129 +   #pn, \
  11.130 +   CMPILIFYInstance_cleanup, \
  11.131 +   CMPILIFYInstance_enumInstanceNames, \
  11.132 +   CMPILIFYInstance_enumInstances, \
  11.133 +   CMPILIFYInstance_getInstance, \
  11.134 +   CMPILIFYInstance_createInstance, \
  11.135 +   CMPILIFYInstance_modifyInstance, \
  11.136 +   CMPILIFYInstance_deleteInstance, \
  11.137 +   CMPILIFYInstance_execQuery, \
  11.138 +}; \
  11.139 +\
  11.140 +EXTERN_C \
  11.141 +CMPIInstanceMI* pn##_Create_InstanceMI(const CMPIBroker* brkr, \
  11.142 +                                       const CMPIContext* ctx, \
  11.143 +                                       CMPIStatus* rc) { \
  11.144 +   static CMPIInstanceMI _CMPIMI = { \
  11.145 +      (void*)&_CMPILIFYMI, \
  11.146 +      &_CMPIMIFT, \
  11.147 +   }; \
  11.148 +   mi = &_CMPIMI; \
  11.149 +   ((CMPILIFYInstanceMI*)(mi->hdl))->brkr = brkr; \
  11.150 +   if (((CMPILIFYInstanceMI*)(mi->hdl))->ft->load() != CMPI_RC_OK) \
  11.151 +      mi = NULL; \
  11.152 +   return (CMPIInstanceMI*)mi; \
  11.153 +};
  11.154 +
  11.155 +
  11.156 +
  11.157 +/* ------------------------------------------------------------------------- */
  11.158 +/* Optimized CMPILIFY 1RO instance provider abstract resource API.           */
  11.159 +/* ------------------------------------------------------------------------- */
  11.160 +typedef struct {
  11.161 +   CMPIrc (*load)();
  11.162 +   CMPIrc (*unload)(const int terminating);
  11.163 +   CMPIrc (*get)(void** inst, const char** properties);
  11.164 +   void (*release)(void* inst);
  11.165 +   CMPIrc (*setproperties)(CMPIInstance* instance, const void* inst,
  11.166 +                           const char** properties);
  11.167 +} CMPILIFYInstance1ROMIFT;
  11.168 +
  11.169 +/* ------------------------------------------------------------------------- */
  11.170 +/* Optimized CMPILIFY 1RO instance provider encapsulated object.             */
  11.171 +/* ------------------------------------------------------------------------- */
  11.172 +typedef struct {
  11.173 +   void* hdl;                     /* Handle to implementation-specific data. */
  11.174 +   const CMPIBroker* brkr;    /* CIMOM handle, initialized on provider load. */
  11.175 +   char* cn;                               /* Instance provider's CIM class. */
  11.176 +   char** kys;                    /* NULL terminated list of CIM class keys. */
  11.177 +   CMPILIFYInstance1ROMIFT* ft;     /* Abstract resource API function table. */
  11.178 +} CMPILIFYInstance1ROMI;
  11.179 +
  11.180 +/* ------------------------------------------------------------------------- */
  11.181 +/* Optimized CMPILIFY 1RO instance provider intrinsic CMPI functions.        */
  11.182 +/* ------------------------------------------------------------------------- */
  11.183 +CMPIStatus CMPILIFYInstance1RO_cleanup
  11.184 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating);
  11.185 +
  11.186 +CMPIStatus CMPILIFYInstance1RO_enumInstanceNames
  11.187 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.188 +        const CMPIObjectPath* ref);
  11.189 +
  11.190 +CMPIStatus CMPILIFYInstance1RO_enumInstances
  11.191 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.192 +        const CMPIObjectPath* ref, const char** properties);
  11.193 +
  11.194 +CMPIStatus CMPILIFYInstance1RO_getInstance
  11.195 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.196 +        const CMPIObjectPath* ref, const char** properties);
  11.197 +
  11.198 +CMPIStatus CMPILIFYInstance1RO_createInstance
  11.199 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.200 +        const CMPIObjectPath* ref, const CMPIInstance* inst);
  11.201 +
  11.202 +CMPIStatus CMPILIFYInstance1RO_modifyInstance
  11.203 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.204 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
  11.205 +        const char** properties);
  11.206 +
  11.207 +CMPIStatus CMPILIFYInstance1RO_deleteInstance
  11.208 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.209 +        const CMPIObjectPath* ref);
  11.210 +
  11.211 +CMPIStatus CMPILIFYInstance1RO_execQuery
  11.212 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  11.213 +        const CMPIObjectPath* ref, const char* lang, const char* query);
  11.214 +
  11.215 +/* ------------------------------------------------------------------------- */
  11.216 +/* Macro to generate _Create_InstanceMI entry point, setup function table to */
  11.217 +/* the shared CMPILIFY instance provider intrinsic CMPI functions, and setup */
  11.218 +/* function table to the provider-specific resource access API functions.    */
  11.219 +/* ------------------------------------------------------------------------- */
  11.220 +#define CMPILIFYInstance1ROMIStub(cn,pn,kys,mi) \
  11.221 +static CMPILIFYInstance1ROMIFT _CMPILIFYMIFT = { \
  11.222 +   load, \
  11.223 +   unload, \
  11.224 +   get, \
  11.225 +   release, \
  11.226 +   setproperties, \
  11.227 +}; \
  11.228 +\
  11.229 +static CMPILIFYInstance1ROMI _CMPILIFYMI = { \
  11.230 +   NULL, \
  11.231 +   NULL, \
  11.232 +   #cn, \
  11.233 +   kys, \
  11.234 +   &_CMPILIFYMIFT, \
  11.235 +}; \
  11.236 +\
  11.237 +static CMPIInstanceMIFT _CMPIMIFT = { \
  11.238 +   CMPICurrentVersion, \
  11.239 +   CMPICurrentVersion, \
  11.240 +   #pn, \
  11.241 +   CMPILIFYInstance1RO_cleanup, \
  11.242 +   CMPILIFYInstance1RO_enumInstanceNames, \
  11.243 +   CMPILIFYInstance1RO_enumInstances, \
  11.244 +   CMPILIFYInstance1RO_getInstance, \
  11.245 +   CMPILIFYInstance1RO_createInstance, \
  11.246 +   CMPILIFYInstance1RO_modifyInstance, \
  11.247 +   CMPILIFYInstance1RO_deleteInstance, \
  11.248 +   CMPILIFYInstance1RO_execQuery, \
  11.249 +}; \
  11.250 +\
  11.251 +EXTERN_C \
  11.252 +CMPIInstanceMI* pn##_Create_InstanceMI(const CMPIBroker* brkr, \
  11.253 +                                       const CMPIContext* ctx, \
  11.254 +                                       CMPIStatus* rc) { \
  11.255 +   static CMPIInstanceMI _CMPIMI = { \
  11.256 +      (void*)&_CMPILIFYMI, \
  11.257 +      &_CMPIMIFT, \
  11.258 +   }; \
  11.259 +   mi = &_CMPIMI; \
  11.260 +   ((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr = brkr; \
  11.261 +   if (((CMPILIFYInstance1ROMI*)(mi->hdl))->ft->load() != CMPI_RC_OK) \
  11.262 +      mi = NULL; \
  11.263 +   return (CMPIInstanceMI*)mi; \
  11.264 +};
  11.265 +
  11.266 +
  11.267 +#endif /* _CMPILIFY_H_ */
    12.1 --- a/src/cmpilr.c	Wed Jun 13 11:18:11 2007 -0600
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,527 +0,0 @@
    12.4 -// Copyright (C) 2007 IBM Corp.
    12.5 -//
    12.6 -//    This library is free software; you can redistribute it and/or
    12.7 -//    modify it under the terms of the GNU Lesser General Public
    12.8 -//    License as published by the Free Software Foundation; either
    12.9 -//    version 2.1 of the License, or (at your option) any later version.
   12.10 -//
   12.11 -//    This library is distributed in the hope that it will be useful,
   12.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.14 -//    Lesser General Public License for more details.
   12.15 -//
   12.16 -//    You should have received a copy of the GNU Lesser General Public
   12.17 -//    License along with this library; if not, write to the Free Software
   12.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.19 -// ============================================================================
   12.20 -// Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
   12.21 -// ============================================================================
   12.22 -
   12.23 -#include "cmpidt.h"
   12.24 -#include "cmpift.h"
   12.25 -#include "cmpimacs.h"
   12.26 -#include "cmpilr.h"
   12.27 -
   12.28 -#include "cmpitrace.h"
   12.29 -
   12.30 -
   12.31 -/* Redefine the CMGetCharPtr() macro to better handle NULL CMPI_strings. */
   12.32 -#undef CMGetCharPtr
   12.33 -#define CMGetCharPtr(s) (((s)==NULL || *((void**)(s))==NULL)? NULL : (char*)((s)->hdl))
   12.34 -
   12.35 -/* Shortcuts to the resource specific implementation data and function table. */
   12.36 -#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
   12.37 -#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
   12.38 -#define _FT (((CMPIResource*)(mi->hdl))->ft)
   12.39 -
   12.40 -
   12.41 -/* ------------------------------------------------------------------------- */
   12.42 -/* The generic CMPILR resource-agnostic CMPI instance provider functions.    */
   12.43 -/* ------------------------------------------------------------------------- */
   12.44 -
   12.45 -CMPIStatus CMPILR_cleanup
   12.46 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating)
   12.47 -{
   12.48 -   _SBLIM_ENTER("CMPILR_cleanup");
   12.49 -   CMPIStatus status = {CMPI_RC_OK, NULL}; 
   12.50 -
   12.51 -   /* Run the provider's unload() routine. */
   12.52 -   if (!_FT->unload()) {
   12.53 -      if (!terminating) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_DO_NOT_UNLOAD, "unload() failed")
   12.54 -      else CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unload() failed");
   12.55 -   }
   12.56 -
   12.57 -    _SBLIM_RETURNSTATUS(status);
   12.58 -}
   12.59 -
   12.60 -/* ------------------------------------------------------------------------- */
   12.61 -
   12.62 -CMPIStatus CMPILR_enumInstanceNames
   12.63 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   12.64 -	const CMPIObjectPath* ref)
   12.65 -{
   12.66 -   _SBLIM_ENTER("CMPILR_enumInstanceNames");
   12.67 -   CMPIStatus status = {CMPI_RC_OK, NULL};
   12.68 -
   12.69 -   /* Get handle to the list of resources. */
   12.70 -   void* resList = NULL;
   12.71 -   if (!_FT->beginEnum(&resList, &status)) {
   12.72 -      /* Set status to FAILED if beginEnum didn't update */
   12.73 -      if (status.rc == CMPI_RC_OK)
   12.74 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
   12.75 -      _SBLIM_RETURNSTATUS(status);
   12.76 -   }
   12.77 -
   12.78 -   /* Enumerate all the resources and return a CMPIObjectPath for each. */ 
   12.79 -   char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
   12.80 -   int found = 0;
   12.81 -   while (1) {
   12.82 -      /* Create a new CMPIObjectPath for the next resource. */
   12.83 -      CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
   12.84 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
   12.85 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed");
   12.86 -         break;
   12.87 -      }
   12.88 -
   12.89 -      /* Create a new CMPIInstance for the next resource. */
   12.90 -      CMPIInstance* inst = CMNewInstance(_BROKER, op, &status);
   12.91 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
   12.92 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed");
   12.93 -         break;
   12.94 -      }
   12.95 -
   12.96 -      /* Get the next resource. */
   12.97 -      void* res = NULL;
   12.98 -      if (!_FT->getNext(resList, &res, &status))
   12.99 -         break; /* while() loop exit! */
  12.100 -
  12.101 -      /* Set the CMPIInstance properties from the resource data. */
  12.102 -      int rc = _FT->res2inst(res, inst, &status);
  12.103 -      _FT->release(res);
  12.104 -      if (!rc) {
  12.105 -         /* Honor status set by resource. */
  12.106 -         if (status.rc == CMPI_RC_OK)
  12.107 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed");
  12.108 -         break;
  12.109 -      }
  12.110 -
  12.111 -      /* Get the CMPIObjectPath for this CMPIInstance. */
  12.112 -      op = CMGetObjectPath(inst, &status);
  12.113 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  12.114 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMGetObjectPath() failed");
  12.115 -         break;
  12.116 -      }
  12.117 -      status = CMSetNameSpace(op, ns); /* CMGetObjectPath() does not preserve the instance's namespace! */
  12.118 -      if (status.rc != CMPI_RC_OK) {
  12.119 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetNameSpace() failed");
  12.120 -         break;
  12.121 -      }
  12.122 -
  12.123 -      /* Return the CMPIObjectPath for the resource. */
  12.124 -      status = CMReturnObjectPath(rslt, op);
  12.125 -      if (status.rc != CMPI_RC_OK) {
  12.126 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnObjectPath() failed");
  12.127 -         break;
  12.128 -      }
  12.129 -      found++;
  12.130 -   } /* while() */
  12.131 -   _FT->endEnum(resList);
  12.132 -
  12.133 -   _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("--- %d instance names found", found));
  12.134 -
  12.135 -   if (status.rc == CMPI_RC_OK)
  12.136 -      CMReturnDone(rslt);
  12.137 -
  12.138 -    _SBLIM_RETURNSTATUS(status);
  12.139 -}
  12.140 -
  12.141 -/* ------------------------------------------------------------------------- */
  12.142 -
  12.143 -CMPIStatus CMPILR_enumInstances
  12.144 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.145 -	const CMPIObjectPath* ref, const char** properties)
  12.146 -{
  12.147 -   _SBLIM_ENTER("CMPILR_enumInstances");
  12.148 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.149 -
  12.150 -   /* Get handle to the list of resources. */
  12.151 -   void* resList = NULL;
  12.152 -   if (!_FT->beginEnum(&resList, &status)) {
  12.153 -      /* Set status to FAILED if beginEnum didn't update */
  12.154 -      if (status.rc == CMPI_RC_OK)
  12.155 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.156 -      _SBLIM_RETURNSTATUS(status);
  12.157 -   }
  12.158 -
  12.159 -   /* Enumerate all the resources and return a CMPIObjectPath for each. */
  12.160 -   char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  12.161 -   int found = 0;
  12.162 -   while (1) {
  12.163 -      /* Create a new CMPIObjectPath for the next resource. */
  12.164 -      CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
  12.165 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  12.166 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed");
  12.167 -         break;
  12.168 -      }
  12.169 -
  12.170 -      /* Create a new CMPIInstance for the next resource. */
  12.171 -      CMPIInstance* inst = CMNewInstance(_BROKER, op, &status);
  12.172 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  12.173 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed");
  12.174 -         break;
  12.175 -      }
  12.176 -
  12.177 -      /* Get the next resource. */
  12.178 -      void* res = NULL;
  12.179 -      if (!_FT->getNext(resList, &res, &status))
  12.180 -         break; /* while() loop exit! */
  12.181 -
  12.182 -      /* Set the property filter for this CMPIInstance, if specified. */
  12.183 -      if (properties != NULL) {
  12.184 -         status = CMSetPropertyFilter(inst, properties, NULL);
  12.185 -         if (status.rc != CMPI_RC_OK) {
  12.186 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetPropertyFilter() failed");
  12.187 -            break;
  12.188 -         }
  12.189 -      }
  12.190 -
  12.191 -      /* Set the CMPIInstance properties from the resource data. */
  12.192 -      int rc = _FT->res2inst(res, inst, &status);
  12.193 -      _FT->release(res);
  12.194 -      if (!rc) {
  12.195 -         /* Honor status set by resource. */
  12.196 -         if (status.rc == CMPI_RC_OK)
  12.197 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed");
  12.198 -         break;
  12.199 -      }
  12.200 -
  12.201 -      /* Return the CMPIInstance for the resource. */
  12.202 -      status = CMReturnInstance(rslt, inst);
  12.203 -      if (status.rc != CMPI_RC_OK) {
  12.204 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed");
  12.205 -         break;
  12.206 -      }
  12.207 -      found++;
  12.208 -   } /* while() */
  12.209 -   _FT->endEnum(resList);
  12.210 -
  12.211 -   _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("--- %d instances found", found));
  12.212 -
  12.213 -   if (status.rc == CMPI_RC_OK)
  12.214 -      CMReturnDone(rslt);
  12.215 -
  12.216 -    _SBLIM_RETURNSTATUS(status);
  12.217 -}
  12.218 -
  12.219 -/* ------------------------------------------------------------------------- */
  12.220 -
  12.221 -CMPIStatus CMPILR_getInstance
  12.222 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.223 -	const CMPIObjectPath* ref, const char** properties)
  12.224 -{
  12.225 -   _SBLIM_ENTER("CMPILR_getInstance");
  12.226 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.227 -
  12.228 -   /* Create a new CMPIInstance for the resource. */
  12.229 -   CMPIInstance* inst = CMNewInstance(_BROKER, ref, &status);
  12.230 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  12.231 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed");
  12.232 -      _SBLIM_RETURNSTATUS(status);
  12.233 -   }
  12.234 -
  12.235 -   /* Set the property filter for this CMPIInstance, if specified. */
  12.236 -   if (properties != NULL) {
  12.237 -      status = CMSetPropertyFilter(inst, properties, NULL);
  12.238 -      if (status.rc != CMPI_RC_OK) {
  12.239 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetPropertyFilter() failed");
  12.240 -         _SBLIM_RETURNSTATUS(status);
  12.241 -      }
  12.242 -   }
  12.243 -
  12.244 -   /* Get handle to the list of resources. */
  12.245 -   void* resList = NULL;
  12.246 -   if (!_FT->beginEnum(&resList, &status)) {
  12.247 -      /* Set status to FAILED if beginEnum didn't update */
  12.248 -      if (status.rc == CMPI_RC_OK)
  12.249 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.250 -      _SBLIM_RETURNSTATUS(status);
  12.251 -   }
  12.252 -
  12.253 -   /* Try to get the target resource. */ 
  12.254 -   void* res;
  12.255 -   int rc = _FT->get(resList, ref, &res, &status);
  12.256 -   _FT->endEnum(resList);
  12.257 -   if (!rc) {
  12.258 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
  12.259 -      _SBLIM_RETURNSTATUS(status);
  12.260 -   } 
  12.261 -
  12.262 -   /* Set the CMPIInstance properties from the resource data. */
  12.263 -   rc = _FT->res2inst(res, inst, &status);
  12.264 -   _FT->release(res);
  12.265 -   if (!rc) {
  12.266 -      /* Honor status set by resource. */
  12.267 -      if (status.rc == CMPI_RC_OK)
  12.268 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed");
  12.269 -      _SBLIM_RETURNSTATUS(status);
  12.270 -   }
  12.271 -
  12.272 -   /* Return the CMPIInstance for the resource. */
  12.273 -   status = CMReturnInstance(rslt, inst);
  12.274 -   if (status.rc != CMPI_RC_OK) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed");
  12.275 -
  12.276 -   if (status.rc == CMPI_RC_OK) CMReturnDone(rslt);
  12.277 -
  12.278 -    _SBLIM_RETURNSTATUS(status);
  12.279 -}
  12.280 -
  12.281 -/* ------------------------------------------------------------------------- */
  12.282 -
  12.283 -CMPIStatus CMPILR_createInstance
  12.284 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.285 -	const CMPIObjectPath* ref, const CMPIInstance* inst)
  12.286 -{
  12.287 -   _SBLIM_ENTER("CMPILR_createInstance");
  12.288 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.289 -
  12.290 -   /* Get handle to the list of resources. */
  12.291 -   void* resList = NULL;
  12.292 -   if (!_FT->beginEnum(&resList, &status)) {
  12.293 -      /* Set status to FAILED if beginEnum didn't update */
  12.294 -      if (status.rc == CMPI_RC_OK)
  12.295 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.296 -      _SBLIM_RETURNSTATUS(status);
  12.297 -   }
  12.298 -
  12.299 -   /* Try to get the target resource. */
  12.300 -   void* res = NULL;
  12.301 -   int rc = _FT->get(resList, ref, &res, &status);
  12.302 -   _FT->release(res);
  12.303 -   if (rc) {
  12.304 -      _FT->endEnum(resList);
  12.305 -      CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS);
  12.306 -      _SBLIM_RETURNSTATUS(status);
  12.307 -   }
  12.308 -
  12.309 -   rc = _FT->inst2res((CMPIInstance*)inst, &res, &status);
  12.310 -   if (!rc || !res) {
  12.311 -      /* Honor status set by resource. */
  12.312 -      if (status.rc == CMPI_RC_OK)
  12.313 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "inst2res() failed");
  12.314 -      _SBLIM_RETURNSTATUS(status);
  12.315 -   }
  12.316 -
  12.317 -   /* Add the target resource. */
  12.318 -   rc = _FT->add(&resList, res, &status);
  12.319 -   if (rc != 1) {
  12.320 -      /* Honor status set by resource. */
  12.321 -      if (status.rc == CMPI_RC_OK) {
  12.322 -         if (rc == -1) {
  12.323 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, "add() unsupported");
  12.324 -         }
  12.325 -         else {
  12.326 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "add() failed");
  12.327 -         }
  12.328 -      }
  12.329 -   }
  12.330 -      
  12.331 -   _FT->release(res);
  12.332 -   _FT->endEnum(resList);
  12.333 -
  12.334 -    _SBLIM_RETURNSTATUS(status);
  12.335 -}
  12.336 -
  12.337 -/* ------------------------------------------------------------------------- */
  12.338 -
  12.339 -CMPIStatus CMPILR_modifyInstance
  12.340 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.341 -	const CMPIObjectPath* ref, const CMPIInstance* inst, const char** properties)
  12.342 -{
  12.343 -   _SBLIM_ENTER("CMPILR_modifyInstance");
  12.344 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.345 -
  12.346 -   /* Get handle to the list of resources. */
  12.347 -   void* resList = NULL;
  12.348 -   if (!_FT->beginEnum(&resList, &status)) {
  12.349 -      /* Set status to FAILED if beginEnum didn't update */
  12.350 -      if (status.rc == CMPI_RC_OK)
  12.351 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.352 -      _SBLIM_RETURNSTATUS(status);
  12.353 -   }
  12.354 -
  12.355 -   /* Try to get the target resource. */
  12.356 -   void* targetRes;
  12.357 -   int rc = _FT->get(resList, ref, &targetRes, &status);
  12.358 -   if (!rc) {
  12.359 -      _FT->endEnum(resList);
  12.360 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
  12.361 -      _SBLIM_RETURNSTATUS(status);
  12.362 -   }
  12.363 -
  12.364 -   void *modifiedRes;
  12.365 -   rc = _FT->inst2res((CMPIInstance*)inst, &modifiedRes, &status);
  12.366 -   if (!rc || !modifiedRes) {
  12.367 -      _FT->release(targetRes);
  12.368 -      _FT->endEnum(resList);
  12.369 -      /* Honor status set by resource. */
  12.370 -      if (status.rc == CMPI_RC_OK)
  12.371 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "inst2res() failed");
  12.372 -      _SBLIM_RETURNSTATUS(status);
  12.373 -   }
  12.374 -
  12.375 -
  12.376 -   /* Modify the resource. */
  12.377 -   rc = _FT->modify(&resList, targetRes, modifiedRes, &status);
  12.378 -   if (rc != 1) {
  12.379 -      /* Honor status set by resource. */
  12.380 -      if (status.rc == CMPI_RC_OK) {
  12.381 -         if (rc == -1) {
  12.382 -            CMSetStatusWithChars(_BROKER, &status,
  12.383 -                                 CMPI_RC_ERR_NOT_SUPPORTED, "add() unsupported");
  12.384 -         }
  12.385 -         else {
  12.386 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "add() failed");
  12.387 -         }
  12.388 -      }
  12.389 -   }
  12.390 -   
  12.391 -   _FT->release(targetRes);
  12.392 -   _FT->release(modifiedRes);
  12.393 -   _FT->endEnum(resList);
  12.394 -
  12.395 -    _SBLIM_RETURNSTATUS(status);
  12.396 -}
  12.397 -
  12.398 -/* ------------------------------------------------------------------------- */
  12.399 -
  12.400 -CMPIStatus CMPILR_deleteInstance
  12.401 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.402 -	const CMPIObjectPath* ref)
  12.403 -{
  12.404 -   _SBLIM_ENTER("CMPILR_deleteInstance");
  12.405 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.406 -
  12.407 -   /* Get handle to the list of resources. */
  12.408 -   void* resList = NULL;
  12.409 -   if (!_FT->beginEnum(&resList, &status)) {
  12.410 -      /* Set status to FAILED if beginEnum didn't update */
  12.411 -      if (status.rc == CMPI_RC_OK)
  12.412 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.413 -      _SBLIM_RETURNSTATUS(status);
  12.414 -   }
  12.415 -
  12.416 -   /* Try to get the target resource. */
  12.417 -   void* res;
  12.418 -   int rc = _FT->get(resList, ref, &res, &status);
  12.419 -   if (!rc) {
  12.420 -      _FT->endEnum(resList);
  12.421 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
  12.422 -      _SBLIM_RETURNSTATUS(status);
  12.423 -   }
  12.424 -
  12.425 -   /* Delete the target resource. */
  12.426 -   rc = _FT->delete(&resList, res, &status);
  12.427 -   if (rc != 1) {
  12.428 -      /* Honor status set by resource. */
  12.429 -      if (status.rc == CMPI_RC_OK) {
  12.430 -         if (rc == -1) {
  12.431 -            CMSetStatusWithChars(_BROKER, &status,
  12.432 -                                 CMPI_RC_ERR_NOT_SUPPORTED, "add() unsupported");
  12.433 -         }
  12.434 -         else {
  12.435 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "add() failed");
  12.436 -         }
  12.437 -      }
  12.438 -   }
  12.439 -
  12.440 -   _FT->release(res);
  12.441 -   _FT->endEnum(resList);
  12.442 -
  12.443 -    _SBLIM_RETURNSTATUS(status);
  12.444 -}
  12.445 -
  12.446 -/* ------------------------------------------------------------------------- */
  12.447 -
  12.448 -CMPIStatus CMPILR_execQuery
  12.449 -	(CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
  12.450 -	const CMPIObjectPath* ref, const char* query, const char* lang)
  12.451 -{
  12.452 -   _SBLIM_ENTER("CMPILR_execQuery");
  12.453 -   CMPIStatus status = {CMPI_RC_OK, NULL};
  12.454 -
  12.455 -   /* Create a new select expression from the query. */
  12.456 -   CMPISelectExp* expr = CMNewSelectExp(_BROKER, query, lang, NULL, &status);
  12.457 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(expr)) {
  12.458 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_QUERY, "CMNewSelectExp() failed");
  12.459 -      _SBLIM_RETURNSTATUS(status);
  12.460 -   }
  12.461 -
  12.462 -   /* Get handle to the list of resources. */
  12.463 -   void* resList = NULL;
  12.464 -   if (!_FT->beginEnum(&resList, &status)) {
  12.465 -      /* Set status to FAILED if beginEnum didn't update */
  12.466 -      if (status.rc == CMPI_RC_OK)
  12.467 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
  12.468 -      _SBLIM_RETURNSTATUS(status);
  12.469 -   }
  12.470 -
  12.471 -   /* Enumerate all the resources and return a CMPIInstance for any that match the query. */
  12.472 -   char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL));
  12.473 -   int found = 0;
  12.474 -   while (1) {
  12.475 -      /* Create a new CMPIObjectPath for the next resource. */
  12.476 -      CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
  12.477 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
  12.478 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed");
  12.479 -         break;
  12.480 -      }
  12.481 -
  12.482 -      /* Create a new CMPIInstance for the next resource. */
  12.483 -      CMPIInstance* inst = CMNewInstance(_BROKER, op, &status);
  12.484 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) {
  12.485 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed");
  12.486 -         break;
  12.487 -      }
  12.488 -
  12.489 -      /* Get the next resource. */
  12.490 -      void* res = NULL;
  12.491 -      if (!_FT->getNext(resList, &res, &status))
  12.492 -         break; /* while() loop exit! */
  12.493 -
  12.494 -      /* Set the CMPIInstance properties from the resource data. */
  12.495 -      int rc = _FT->res2inst(res, inst, &status);
  12.496 -      _FT->release(res);
  12.497 -      if (!rc) {
  12.498 -         /* Honor status set by resource. */
  12.499 -         if (status.rc == CMPI_RC_OK)
  12.500 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed");
  12.501 -         break;
  12.502 -      }
  12.503 -
  12.504 -      /* Evaluate the select expression against this CMPIInstance. */
  12.505 -      rc = CMEvaluateSelExp(expr, inst, &status);
  12.506 -      if (status.rc != CMPI_RC_OK) {
  12.507 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMEvaluateSelExp() failed");
  12.508 -         break;
  12.509 -      }
  12.510 -
  12.511 -      /* Return the CMPIInstance for the resource if it matches the original query. */
  12.512 -      if (rc) {
  12.513 -         status = CMReturnInstance(rslt, inst);
  12.514 -         if (status.rc != CMPI_RC_OK) {
  12.515 -            CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed");
  12.516 -            break;
  12.517 -         }
  12.518 -         found++;
  12.519 -      }
  12.520 -   } /* while() */
  12.521 -   _FT->endEnum(resList);
  12.522 -
  12.523 -   _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("--- %d instances found", found));
  12.524 -
  12.525 -   if (status.rc == CMPI_RC_OK)
  12.526 -      CMReturnDone(rslt);
  12.527 -
  12.528 -    _SBLIM_RETURNSTATUS(status);
  12.529 -}
  12.530 -
    13.1 --- a/src/cmpilr.h	Wed Jun 13 11:18:11 2007 -0600
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,150 +0,0 @@
    13.4 -// Copyright (C) 2007 IBM Corp.
    13.5 -//
    13.6 -//    This library is free software; you can redistribute it and/or
    13.7 -//    modify it under the terms of the GNU Lesser General Public
    13.8 -//    License as published by the Free Software Foundation; either
    13.9 -//    version 2.1 of the License, or (at your option) any later version.
   13.10 -//
   13.11 -//    This library is distributed in the hope that it will be useful,
   13.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.14 -//    Lesser General Public License for more details.
   13.15 -//
   13.16 -//    You should have received a copy of the GNU Lesser General Public
   13.17 -//    License along with this library; if not, write to the Free Software
   13.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   13.19 -// ============================================================================
   13.20 -// Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
   13.21 -// ============================================================================
   13.22 -
   13.23 -#if !defined(__CMPITLR_H__)
   13.24 -#define __CMPILR_H__
   13.25 -
   13.26 -#include "cmpidt.h"
   13.27 -
   13.28 -/* ------------------------------------------------------------------------- */
   13.29 -/* The generic CMPILR function table to manage system resources.             */
   13.30 -/* ------------------------------------------------------------------------- */
   13.31 -
   13.32 -typedef struct _CMPIResourceFT {
   13.33 -   int (*load)();
   13.34 -   int (*unload)();
   13.35 -   int (*beginEnum)(void **resList, CMPIStatus *status);
   13.36 -   void (*endEnum)(void* resList);
   13.37 -   int (*getNext)(void* resList, void **res, CMPIStatus *status);
   13.38 -   int (*get)(void* resList, const CMPIObjectPath *res_key,
   13.39 -              void** res, CMPIStatus *status);
   13.40 -   void (*release)(void* res);
   13.41 -   int (*add)(void** resList, void* res, CMPIStatus *status);
   13.42 -   int (*delete)(void** resList, void* res, CMPIStatus *status);
   13.43 -   int (*modify)(void** resList, void* target_res,
   13.44 -                 void *modified_res, CMPIStatus *status);
   13.45 -   int (*res2inst)(void* res, CMPIInstance* inst, CMPIStatus *status);
   13.46 -   int (*inst2res)(CMPIInstance* inst, void** res, CMPIStatus *status);
   13.47 -} CMPIResourceFT;
   13.48 -
   13.49 -/* ------------------------------------------------------------------------- */
   13.50 -/* The generic CMPIPR encapsulated object for system resources.              */
   13.51 -/* ------------------------------------------------------------------------- */
   13.52 -
   13.53 -typedef struct _CMPIResource {
   13.54 -   void* hdl;		/* Opaque pointer to any resource specific implementation data. */
   13.55 -   const CMPIBroker* brkr;	/* Handle to the CIM broker/CIMOM. */
   13.56 -   char* cn;		/* The resource provider's CIM class */
   13.57 -   CMPIResourceFT* ft;	/* Pointer to the resource specific function table. */
   13.58 -} CMPIResource;
   13.59 -
   13.60 -/* ------------------------------------------------------------------------- */
   13.61 -/* The generic CMPILR resource-agnostic CMPI instance provider functions.    */
   13.62 -/* ------------------------------------------------------------------------- */
   13.63 -
   13.64 -CMPIStatus CMPILR_cleanup
   13.65 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating);
   13.66 -
   13.67 -CMPIStatus CMPILR_enumInstanceNames
   13.68 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.69 -        const CMPIObjectPath* ref);
   13.70 -
   13.71 -CMPIStatus CMPILR_enumInstanceNames
   13.72 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.73 -        const CMPIObjectPath* ref);
   13.74 -
   13.75 -CMPIStatus CMPILR_enumInstances
   13.76 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.77 -        const CMPIObjectPath* ref, const char** properties);
   13.78 -
   13.79 -CMPIStatus CMPILR_getInstance
   13.80 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.81 -        const CMPIObjectPath* ref, const char** properties);
   13.82 -
   13.83 -CMPIStatus CMPILR_createInstance
   13.84 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.85 -        const CMPIObjectPath* ref, const CMPIInstance* inst);
   13.86 -
   13.87 -CMPIStatus CMPILR_modifyInstance
   13.88 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.89 -        const CMPIObjectPath* ref, const CMPIInstance* inst, const char** properties);
   13.90 -
   13.91 -CMPIStatus CMPILR_deleteInstance
   13.92 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.93 -        const CMPIObjectPath* ref);
   13.94 -
   13.95 -CMPIStatus CMPILR_execQuery
   13.96 -        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   13.97 -        const CMPIObjectPath* ref, const char* lang, const char* query);
   13.98 -
   13.99 -/* ------------------------------------------------------------------------- */
  13.100 -/* Macro generates the function table and _Create_InstanceMI provider entry  */
  13.101 -/* point for a CMPILR instance provider.                                    */
  13.102 -/* ------------------------------------------------------------------------- */
  13.103 -
  13.104 -#define CMPILRInstanceMIStub(cn,pn,mi) \
  13.105 -static CMPIResourceFT resFT = {\
  13.106 -   load,\
  13.107 -   unload,\
  13.108 -   beginEnum,\
  13.109 -   endEnum,\
  13.110 -   getNext,\
  13.111 -   get,\
  13.112 -   release,\
  13.113 -   add,\
  13.114 -   delete,\
  13.115 -   modify,\
  13.116 -   res2inst,\
  13.117 -   inst2res,\
  13.118 -};\
  13.119 -static CMPIResource res = {\
  13.120 -   NULL,\
  13.121 -   NULL,\
  13.122 -   #cn,\
  13.123 -   &resFT,\
  13.124 -};\
  13.125 -static CMPIInstanceMIFT instMIFT = {\
  13.126 -   CMPICurrentVersion,\
  13.127 -   CMPICurrentVersion,\
  13.128 -   "instance" #pn,\
  13.129 -   CMPILR_cleanup,\
  13.130 -   CMPILR_enumInstanceNames,\
  13.131 -   CMPILR_enumInstances,\
  13.132 -   CMPILR_getInstance,\
  13.133 -   CMPILR_createInstance,\
  13.134 -   CMPILR_modifyInstance,\
  13.135 -   CMPILR_deleteInstance,\
  13.136 -   CMPILR_execQuery,\
  13.137 -};\
  13.138 -EXTERN_C \
  13.139 -CMPIInstanceMI* pn##_Create_InstanceMI(const CMPIBroker* brkr, const CMPIContext* ctx){\
  13.140 -   static CMPIInstanceMI instMI = {\
  13.141 -      (void*)&res,\
  13.142 -      &instMIFT,\
  13.143 -   };\
  13.144 -   mi = &instMI;\
  13.145 -   ((CMPIResource*)instMI.hdl)->brkr = brkr;\
  13.146 -   if (!((CMPIResource*)instMI.hdl)->ft->load()) {\
  13.147 -      return NULL;\
  13.148 -   }\
  13.149 -   return &instMI;\
  13.150 -};
  13.151 -
  13.152 -
  13.153 -#endif /* __CMPILR_H__ */
    14.1 --- a/src/cmpiutil.h	Wed Jun 13 11:18:11 2007 -0600
    14.2 +++ b/src/cmpiutil.h	Mon Jul 16 12:15:30 2007 -0600
    14.3 @@ -24,7 +24,7 @@
    14.4  // ============================================================================
    14.5  
    14.6  #ifndef _CMPIUTIL_H_
    14.7 -# define _CMPIUTIL_H_
    14.8 +#define _CMPIUTIL_H_
    14.9  
   14.10  /* Include the required CMPI data types. */
   14.11  #include "cmpidt.h"
   14.12 @@ -32,7 +32,7 @@
   14.13  /* Redefine the CMGetCharPtr() macro to better handle NULL strings. */
   14.14  #ifdef CMGetCharPtr
   14.15  # undef CMGetCharPtr
   14.16 -# define CMGetCharPtr(s) (((s)==NULL || *((void**)(s))==NULL)? NULL : (char*)s->hdl)
   14.17 +# define CMGetCharPtr(s) (((s)==NULL || *((void**)(s))==NULL)? NULL : (char*)((s)->hdl))
   14.18  #endif
   14.19  
   14.20  /* Useful shortcut for CMNewInstance(broker, CMNewObjectPath(broker,ns,cn,rc), rc). */