os-cmpi-xen

changeset 135:da5a3ccd0c25

Ported Xen_ConsoleSettingData to 'Cmpilify' interface.

Implemented ModifyInstance for Xen_ConsoleSettingData to support changing such
options as vncdisplay, vncpasswd, etc.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Thu Jul 26 16:47:21 2007 -0600 (2007-07-26)
parents 3a6f2019ef11
children 86c5f863cf9d
files ChangeLog src/Makefile.am src/Xen_ConsoleSettingData.c src/Xen_ConsoleSettingData_Resource.c src/Xen_ConsoleSettingData_Resource.h src/xen_utils.c src/xen_utils.h
line diff
     1.1 --- a/ChangeLog	Thu Jul 19 18:04:38 2007 -0600
     1.2 +++ b/ChangeLog	Thu Jul 26 16:47:21 2007 -0600
     1.3 @@ -1,3 +1,11 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Thu Jul 26 16:44:30 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +         - Ported Xen_ConsoleSettingData to 'Cmpilify' interface.
     1.8 +         - Implemented ModifyInstance for Xen_ConsoleSettingData
     1.9 +           to support changing such options as vncdisplay,
    1.10 +           vncpasswd, etc.
    1.11 +
    1.12  -------------------------------------------------------------------
    1.13  Thu Jul 19 18:02:01 MDT 2007 - jfehlig@novell.com
    1.14  
     2.1 --- a/src/Makefile.am	Thu Jul 19 18:04:38 2007 -0600
     2.2 +++ b/src/Makefile.am	Thu Jul 26 16:47:21 2007 -0600
     2.3 @@ -51,7 +51,6 @@ noinst_HEADERS = \
     2.4  	Xen_NetworkPort_Resource.h \
     2.5  	Xen_VirtualizationCapabilities_Resource.h \
     2.6  	Xen_NetworkPortSettingData_Resource.h \
     2.7 -	Xen_ConsoleSettingData_Resource.h \
     2.8  	Xen_MemoryPool_Resource.h \
     2.9  	Xen_ProcessorPool_Resource.h \
    2.10  	Xen_ProcessorCapabilitiesSettingData_Resource.h \
    2.11 @@ -290,7 +289,7 @@ libXen_DiskElementSettingData_la_CFLAGS 
    2.12  libXen_DiskElementSettingData_la_LIBADD = libXen_ProviderCommon.la
    2.13  libXen_DiskElementSettingData_la_LDFLAGS = -module -avoid-version -no-undefined
    2.14  
    2.15 -libXen_ConsoleSettingData_la_SOURCES = Xen_ConsoleSettingData.c Xen_ConsoleSettingData_Resource.c
    2.16 +libXen_ConsoleSettingData_la_SOURCES = Xen_ConsoleSettingData.c
    2.17  libXen_ConsoleSettingData_la_CFLAGS = -I../ @LIBXEN_CFLAGS@
    2.18  libXen_ConsoleSettingData_la_LIBADD = libXen_ProviderCommon.la
    2.19  libXen_ConsoleSettingData_la_LDFLAGS = -module -avoid-version -no-undefined
     3.1 --- a/src/Xen_ConsoleSettingData.c	Thu Jul 19 18:04:38 2007 -0600
     3.2 +++ b/src/Xen_ConsoleSettingData.c	Thu Jul 26 16:47:21 2007 -0600
     3.3 @@ -1,4 +1,4 @@
     3.4 -// Copyright (C) 2007 Novell, Inc.
     3.5 +// Copyright (C) 2006 IBM Corporation
     3.6  //
     3.7  //    This library is free software; you can redistribute it and/or
     3.8  //    modify it under the terms of the GNU Lesser General Public
     3.9 @@ -16,630 +16,475 @@
    3.10  // ============================================================================
    3.11  // Authors:       Jim Fehlig <jfehlig@novell.com>
    3.12  // Contributors:  
    3.13 -// Description:   This file implements the WBEM operations for Xen console
    3.14 -//                setting data.
    3.15 +//
    3.16 +// Description:   Implementation of console RASD.
    3.17  // ============================================================================
    3.18  
    3.19 -/* Include the required CMPI data types, function headers, and macros */
    3.20 -#include "cmpidt.h"
    3.21 -#include "cmpift.h"
    3.22 -#include "cmpimacs.h"
    3.23 -
    3.24 -/* Include utility functions */
    3.25 -#include "cmpiutil.h"
    3.26 +/* Common declarations for each CMPI "Cimpler" instance provider */
    3.27 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    3.28 +#include <cmpidt.h>
    3.29 +#include <cmpimacs.h>
    3.30  
    3.31 -/* Include _SBLIM_TRACE() logging support */
    3.32 -#include "cmpitrace.h"
    3.33 +#include "cmpilify.h"
    3.34  
    3.35 -/* Include Xen utilities */
    3.36 -#include "xen_utils.h"
    3.37  
    3.38 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    3.39 -#include "Xen_ConsoleSettingData_Resource.h"
    3.40 +static const CMPIInstanceMI* mi;
    3.41  
    3.42  
    3.43 -// ----------------------------------------------------------------------------
    3.44 -// COMMON GLOBAL VARIABLES
    3.45 -// ----------------------------------------------------------------------------
    3.46 +#define _BROKER (((CMPILIFYInstanceMI*)(mi->hdl))->brkr)
    3.47 +#define _CLASS (((CMPILIFYInstanceMI*)(mi->hdl))->cn)
    3.48 +#define _KEYS (((CMPILIFYInstanceMI*)(mi->hdl))->kys)
    3.49 +
    3.50 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    3.51 +
    3.52 +#include <stdlib.h>
    3.53 +
    3.54 +#include <xen_common.h>
    3.55 +#include <xen_vm.h>
    3.56 +#include <xen_console.h>
    3.57 +#include <xen_string_string_map.h>
    3.58 +
    3.59 +#include "cmpitrace.h"
    3.60 +#include "xen_utils.h"
    3.61 +#include "provider_common.h"
    3.62 +
    3.63  
    3.64 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    3.65 -static const CMPIBroker *_BROKER;
    3.66 +/* C struct to store the data for a single resource. */
    3.67 +typedef struct {
    3.68 +   int is_console_record;
    3.69 +   union
    3.70 +   {
    3.71 +      xen_console_record *con_rec;
    3.72 +      CMPIInstance *cmpi_inst;
    3.73 +   } u;
    3.74 +} console_resource;
    3.75 +
    3.76 +
    3.77 +/* C struct to store data for a single resource. */
    3.78 +typedef struct {
    3.79 +   xen_console_set *consoles;
    3.80 +   unsigned int cur_console;
    3.81 +} console_resources;
    3.82 +
    3.83 +
    3.84 +/* Class keys */
    3.85 +static const char *keys[] = {"InstanceID", NULL};
    3.86 +
    3.87  
    3.88  /* Xen session object.  Initialize when the provider is loaded, close when
    3.89   * provider unloaded. */
    3.90  static xen_utils_session *session = NULL;
    3.91  
    3.92  
    3.93 -// ============================================================================
    3.94 -// CMPI INSTANCE PROVIDER FUNCTION TABLE
    3.95 -// ============================================================================
    3.96 -
    3.97 -// ----------------------------------------------------------------------------
    3.98 -// Info for the class supported by the instance provider
    3.99 -// ----------------------------------------------------------------------------
   3.100 -
   3.101 -/* Name of the class implemented by this instance provider. */
   3.102 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
   3.103 -static char * _CLASSNAME = "Xen_ConsoleSettingData";
   3.104 +static CMPIrc load()
   3.105 +{
   3.106 +   /* Initialized Xen session object. */
   3.107 +   if (!session)
   3.108 +      xen_utils_xen_init(&session);
   3.109  
   3.110 -/* NULL terminated list of key properties of this class. */
   3.111 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
   3.112 -const static char * _KEYNAMES[] = {"InstanceID", NULL};
   3.113 -                                   
   3.114 -// ----------------------------------------------------------------------------
   3.115 -// Cleanup()
   3.116 -// Perform any necessary cleanup immediately before this provider is unloaded.
   3.117 -// ----------------------------------------------------------------------------
   3.118 -static CMPIStatus Cleanup(
   3.119 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.120 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.121 -        CMPIBoolean terminating)   /* [in] True if MB is terminating */
   3.122 +   return CMPI_RC_OK;
   3.123 +}
   3.124 +
   3.125 +
   3.126 +static CMPIrc unload(const int terminating)
   3.127  {
   3.128 -   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
   3.129 -
   3.130 -   _SBLIM_ENTER("Cleanup");
   3.131 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.132 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.133 -
   3.134 +   (void)terminating;
   3.135 +   
   3.136 +   /* Close Xen session object. */
   3.137     if (session) {
   3.138        xen_utils_xen_close(session);
   3.139        session = NULL;
   3.140     }
   3.141 -   _SBLIM_RETURNSTATUS(status);
   3.142 +
   3.143 +   return CMPI_RC_OK;
   3.144  }
   3.145  
   3.146 -// ----------------------------------------------------------------------------
   3.147 -// EnumInstanceNames()
   3.148 -// Return a list of all the instances names (return their object paths only).
   3.149 -// ----------------------------------------------------------------------------
   3.150 -static CMPIStatus EnumInstanceNames(
   3.151 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.152 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.153 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.154 -		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   3.155 +
   3.156 +static CMPIrc begin(void **res_list, const char **properties)
   3.157  {
   3.158 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.159 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.160 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.161 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.162 -   int found = 0;				/* Found any instances? */
   3.163 -  
   3.164 -   _SBLIM_ENTER("EnumInstanceNames");
   3.165 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.166 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.167 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.168 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.169 -
   3.170 +   console_resources *resources;
   3.171 +   
   3.172 +   (void)properties;
   3.173 +   
   3.174     if (!xen_utils_validate_session(&session)) {
   3.175 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.176 -      goto exit;
   3.177 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.178 +                   ("--- Unable to establish connection with Xend"));
   3.179 +      return CMPI_RC_ERR_FAILED;
   3.180     }
   3.181  
   3.182 -   /* Get a handle to the list of system resources. */
   3.183 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.184 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.185 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.186 -      goto exit;
   3.187 +   /* malloc a new handle for the resources list. */
   3.188 +   resources = (console_resources *)calloc(1, sizeof(console_resources));
   3.189 +   if (resources == NULL)
   3.190 +      return CMPI_RC_ERR_FAILED;
   3.191 +
   3.192 +   if(!xen_console_get_all(session->xen, &(resources->consoles))) {
   3.193 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.194 +                   ("--- Failed to retrieve list of consoles from xend"));
   3.195 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.196 +                            xen_utils_trace_error(session->xen));
   3.197 +      free(resources);
   3.198 +      return CMPI_RC_ERR_FAILED;
   3.199     }
   3.200  
   3.201 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.202 -   while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
   3.203 -      /* Create a new CMPIInstance to store this resource. */
   3.204 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.205 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.206 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.207 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.208 -         goto exit;
   3.209 -      }
   3.210 +   *res_list = (void *)resources;
   3.211 +   return CMPI_RC_OK;
   3.212 +}
   3.213 +
   3.214  
   3.215 -      /* Set the instance property values from the resource data. */
   3.216 -      if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.217 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.218 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.219 -         goto exit;
   3.220 -      }
   3.221 +static void end(void *res_list)
   3.222 +{
   3.223 +   if (res_list) {
   3.224 +      xen_console_set_free(((console_resources *)res_list)->consoles);
   3.225 +      free(res_list);
   3.226 +   }
   3.227 +}
   3.228 +
   3.229 +
   3.230 +/* Iterator to get the next resource from the resources list. */
   3.231 +static CMPIrc getnext(void *res_list, void **res, const char **properties)
   3.232 +{
   3.233 +   console_resources *resources = (console_resources *)res_list;
   3.234 +   console_resource *con_resource;
   3.235  
   3.236 -      /* Free the resource data. */
   3.237 -      if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.238 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.239 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.240 -         goto exit;
   3.241 -      }
   3.242 +   (void)properties;
   3.243 +   
   3.244 +   if (resources == NULL)
   3.245 +      return CMPI_RC_ERR_FAILED;
   3.246 +
   3.247 +   /* Has end of resource list been reached? */
   3.248 +   if (resources->cur_console >= resources->consoles->size)
   3.249 +      return CMPI_RC_ERR_NOT_FOUND;
   3.250  
   3.251 -      /* Return the CMPIObjectPath for this instance. */
   3.252 -      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   3.253 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   3.254 -         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   3.255 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   3.256 -         goto exit;
   3.257 -      }
   3.258 -      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   3.259 -     
   3.260 -      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   3.261 -      CMReturnObjectPath(results, objectpath);
   3.262 -      found++;
   3.263 +   /* Get memory for resource. */
   3.264 +   con_resource = (console_resource *)malloc(sizeof(console_resource));
   3.265 +   if (con_resource == NULL)
   3.266 +      return CMPI_RC_ERR_FAILED;
   3.267 +
   3.268 +   con_resource->is_console_record = 1;
   3.269 +
   3.270 +   session->xen->ok = true;
   3.271 +   if (!xen_console_get_record(session->xen, &(con_resource->u.con_rec),
   3.272 +                               resources->consoles->contents[resources->cur_console])) {
   3.273 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.274 +                   ("--- Failed to retrieve Console record from xend"));
   3.275 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.276 +                            xen_utils_trace_error(session->xen));
   3.277 +      return CMPI_RC_ERR_FAILED;
   3.278     }
   3.279  
   3.280 -   _SBLIM_TRACE(2,("--- %d object paths found", found));
   3.281 -   CMReturnDone(results);
   3.282 -
   3.283 -exit:
   3.284 -   /* Free the list of system resources. */
   3.285 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.286 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.287 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.288 -   }
   3.289 -  
   3.290 -   _SBLIM_RETURNSTATUS(status);
   3.291 +   resources->cur_console++;
   3.292 +   *res = (void *)con_resource;
   3.293 +   return CMPI_RC_OK;
   3.294  }
   3.295  
   3.296 -// ----------------------------------------------------------------------------
   3.297 -// EnumInstances()
   3.298 -// Return a list of all the instances (return all the instance data).
   3.299 -// ----------------------------------------------------------------------------
   3.300 -static CMPIStatus EnumInstances(
   3.301 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.302 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.303 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.304 -		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   3.305 -		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   3.306 +
   3.307 +static CMPIrc get(const void *res_id, void **res, const char **properties)
   3.308  {
   3.309 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.310 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.311 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.312 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.313 -   int found = 0;				/* Found any resource instances? */
   3.314 +   CMPIInstance *inst = (CMPIInstance *)res_id;
   3.315 +   CMPIData data;
   3.316 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   3.317 +   char *prop_val;
   3.318 +   char uuid[MAX_SYSTEM_NAME_LEN];
   3.319 +   console_resource *con_resource;
   3.320 +   
   3.321 +   (void)properties;
   3.322 +   
   3.323 +   if (CMIsNullObject(inst) || res == NULL)
   3.324 +      return CMPI_RC_ERR_FAILED;
   3.325  
   3.326 -   _SBLIM_ENTER("EnumInstances");
   3.327 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.328 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.329 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.330 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.331 +   data = CMGetProperty(inst, "InstanceID", &status);
   3.332 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.333 +      return CMPI_RC_ERR_FAILED;
   3.334 +
   3.335 +   prop_val = CMGetCharPtr(data.value.string);
   3.336 +   if ((prop_val == NULL) || (*prop_val == '\0'))
   3.337 +      return CMPI_RC_ERR_FAILED;
   3.338 +
   3.339 +   /* Extract the disk uuid from InstanceID property. */
   3.340 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, prop_val, MAX_SYSTEM_NAME_LEN))
   3.341 +      return CMPI_RC_ERR_FAILED;
   3.342  
   3.343     if (!xen_utils_validate_session(&session)) {
   3.344 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.345 -      goto exit;
   3.346 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.347 +                   ("--- Unable to establish connection with Xend"));
   3.348 +      return CMPI_RC_ERR_FAILED;
   3.349     }
   3.350  
   3.351 -   /* Get a handle to the list of system resources. */
   3.352 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.353 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.354 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.355 -      goto exit;
   3.356 +   /* Get memory for resource. */
   3.357 +   con_resource = (console_resource *)malloc(sizeof(console_resource));
   3.358 +   if (con_resource == NULL)
   3.359 +      return CMPI_RC_ERR_FAILED;
   3.360 +
   3.361 +   con_resource->is_console_record = 1;
   3.362 +
   3.363 +   xen_console console = NULL;
   3.364 +   xen_console_record *con_rec;
   3.365 +   xen_console_get_by_uuid(session->xen, &console, uuid);
   3.366 +   xen_console_get_record(session->xen, &(con_resource->u.con_rec), console);
   3.367 +   xen_console_free(console);
   3.368 +   if (!session->xen->ok) {
   3.369 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.370 +                   ("--- Failed to retrieve console record for domain"));
   3.371 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.372 +                            xen_utils_trace_error(session->xen));
   3.373 +      return CMPI_RC_ERR_FAILED;
   3.374     }
   3.375  
   3.376 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.377 -   while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
   3.378 -      /* Create a new CMPIInstance to store this resource. */
   3.379 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.380 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.381 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.382 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.383 -         goto exit;
   3.384 -      }
   3.385 +   *res = (void *)con_resource;
   3.386 +   return CMPI_RC_OK;
   3.387 +}
   3.388 +
   3.389 +
   3.390 +static void release(void *res)
   3.391 +{
   3.392 +   if (res) {
   3.393 +      console_resource *con_resource = (console_resource *)res;
   3.394 +      if (con_resource->is_console_record)
   3.395 +         xen_console_record_free(con_resource->u.con_rec);
   3.396 +      free(con_resource);
   3.397 +   }
   3.398 +}
   3.399 +
   3.400  
   3.401 -      /* Setup a filter to only return the desired properties. */
   3.402 -      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.403 -      if (status.rc != CMPI_RC_OK) {
   3.404 -         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.405 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.406 -         goto exit;
   3.407 -      }
   3.408 +static CMPIrc add(const void *res_id, const void *res)
   3.409 +{
   3.410 +   (void)res_id;
   3.411 +   (void)res;
   3.412 +   
   3.413 +   return CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   3.414 +}
   3.415 +
   3.416 +
   3.417 +static CMPIrc delete(const void *res_id)
   3.418 +{
   3.419 +   (void)res_id;
   3.420 +   
   3.421 +   return  CMPI_RC_ERR_NOT_SUPPORTED; /* unsupported */
   3.422 +}
   3.423 +
   3.424  
   3.425 -      /* Set the instance property values from the resource data. */
   3.426 -      if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.427 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.428 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.429 -         goto exit;
   3.430 -      }
   3.431 +static CMPIrc modify(const void *res_id, const void *modified_res,
   3.432 +                     const char **properties)
   3.433 +{
   3.434 +   CMPIInstance *target_inst = (CMPIInstance *)res_id;
   3.435 +   console_resource *con_resource = (console_resource *)modified_res;
   3.436 +   CMPIInstance *modified_inst;
   3.437 +   CMPIData data;
   3.438 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   3.439 +   char *inst_id;
   3.440 +   char uuid[MAX_SYSTEM_NAME_LEN];
   3.441 +   xen_console_record *target_con_rec;
   3.442 +   char *tmp_str = NULL;
   3.443 +   
   3.444 +   (void)properties;
   3.445 +   
   3.446 +   if (CMIsNullObject(target_inst) || con_resource == NULL ||
   3.447 +       con_resource->is_console_record)
   3.448 +      return CMPI_RC_ERR_FAILED;
   3.449  
   3.450 -      /* Free the resource data. */
   3.451 -      if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.452 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.453 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.454 -         goto exit;
   3.455 -      }
   3.456 +   modified_inst = con_resource->u.cmpi_inst;
   3.457 +
   3.458 +   /* Get target console */
   3.459 +   data = CMGetProperty(target_inst, "InstanceID", &status);
   3.460 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.461 +      return CMPI_RC_ERR_FAILED;
   3.462  
   3.463 -      /* Return the CMPIInstance for this instance. */
   3.464 -      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.465 -      CMReturnInstance(results, instance);
   3.466 -      found++;
   3.467 +   inst_id = CMGetCharPtr(data.value.string);
   3.468 +   if ((inst_id == NULL) || (*inst_id == '\0'))
   3.469 +      return CMPI_RC_ERR_FAILED;
   3.470 +
   3.471 +   /* Extract the console uuid from InstanceID property. */
   3.472 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   3.473 +      return CMPI_RC_ERR_FAILED;
   3.474 +
   3.475 +   if (!xen_utils_validate_session(&session)) {
   3.476 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.477 +                   ("--- Unable to establish connection with Xend"));
   3.478 +      return CMPI_RC_ERR_FAILED;
   3.479     }
   3.480  
   3.481 -   _SBLIM_TRACE(2,("--- %d instances found", found));
   3.482 -   CMReturnDone(results);
   3.483 +   if (!xen_console_get_record(session->xen, &target_con_rec, (xen_console)uuid)) {
   3.484 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.485 +                   ("--- xen_console_get_record failed:"));
   3.486 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.487 +                            xen_utils_trace_error(session->xen));
   3.488 +      return CMPI_RC_ERR_FAILED;
   3.489 +   }
   3.490  
   3.491 -exit:
   3.492 -   /* Free the list of system resources. */
   3.493 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.494 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.495 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.496 +   /* For now, allow modifying ConsoleConfigInfo only, e.g. vncunused= */
   3.497 +   data = CMGetProperty(modified_inst, "ConsoleConfigInfo", &status);
   3.498 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   3.499 +       _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.500 +                   ("--- Unable to extract ConsoleConfigInfo from CMPI instance"));
   3.501 +       goto Error;
   3.502     }
   3.503  
   3.504 -   _SBLIM_RETURNSTATUS(status);
   3.505 +   /* 
   3.506 +    * The instance is being modified and ConsoleConfigInfo is a property
   3.507 +    * of the instance, thus whatever we find in ConsoleConfigInfo will
   3.508 +    * be the new value of Console.other_config.
   3.509 +    */
   3.510 +   xen_string_string_map_free(target_con_rec->other_config);
   3.511 +   target_con_rec->other_config = NULL;
   3.512 +   
   3.513 +   /* Extract key/value from the ConsoleConfigInfo string. */
   3.514 +   char *tok;
   3.515 +   char *next_tok;
   3.516 +   tmp_str = strdup(CMGetCharPtr(data.value.string));
   3.517 +   
   3.518 +   tok = strtok_r(tmp_str, ",", &next_tok);
   3.519 +   /* If tok is NULL, then tmp_str contains only 1 key/value pair */
   3.520 +   if (tok == NULL)
   3.521 +      tok = tmp_str;
   3.522 +   
   3.523 +   while (tok) {
   3.524 +      char *val = strchr(tok, '=');
   3.525 +      if (val == NULL) {
   3.526 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.527 +                      ("--- Invalid console option specified in console setting data"));
   3.528 +         goto Error;
   3.529 +      }
   3.530 +      *val = '\0';
   3.531 +      val++;
   3.532 +      xen_utils_add_to_string_string_map(tok, val,
   3.533 +                                         &(target_con_rec->other_config ));
   3.534 +      tok = strtok_r(NULL, ",", &next_tok);
   3.535 +   }
   3.536 +   
   3.537 +   if (!xen_console_set_other_config(session->xen, target_con_rec->handle,
   3.538 +                                     target_con_rec->other_config)) {
   3.539 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.540 +                   ("--- xen_console_set_other_config failed"));
   3.541 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.542 +                            xen_utils_trace_error(session->xen));
   3.543 +      
   3.544 +      goto Error;
   3.545 +   }
   3.546 +   
   3.547 +   free(tmp_str);
   3.548 +   xen_console_record_free(target_con_rec);
   3.549 +   return CMPI_RC_OK;
   3.550 +   
   3.551 + Error:
   3.552 +   free(tmp_str);
   3.553 +   xen_console_record_free(target_con_rec);
   3.554 +   return CMPI_RC_ERR_FAILED;
   3.555  }
   3.556  
   3.557 -// ----------------------------------------------------------------------------
   3.558 -// GetInstance()
   3.559 -// Return the instance data for the specified instance only.
   3.560 -// ----------------------------------------------------------------------------
   3.561 -static CMPIStatus GetInstance(
   3.562 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.563 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.564 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.565 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.566 -		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   3.567 +
   3.568 +/* Set CMPIInstance properties from the resource data. */
   3.569 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   3.570 +                            const char **properties)
   3.571  {
   3.572 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.573 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.574 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.575 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.576 -   int found = 0;				/* Found the target instance? */
   3.577 -
   3.578 -   _SBLIM_ENTER("GetInstance");
   3.579 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.580 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.581 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.582 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.583 +   console_resource *con_resource = (console_resource *)res;
   3.584 +   xen_console_record *con_rec;
   3.585 +   char buf[MAX_INSTANCEID_LEN];
   3.586 +   
   3.587 +   if (CMIsNullObject(inst) || con_resource == NULL ||
   3.588 +       !con_resource->is_console_record)
   3.589 +      return CMPI_RC_ERR_FAILED;
   3.590  
   3.591 -   if (!xen_utils_validate_session(&session)) {
   3.592 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.593 -      goto exit;
   3.594 -   }
   3.595 -
   3.596 -   /* Get a handle to the list of system resources. */
   3.597 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.598 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.599 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.600 -      goto exit;
   3.601 -   }
   3.602 +   con_rec = con_resource->u.con_rec;
   3.603 +   session->xen->ok = true;
   3.604  
   3.605 -   /* Get the target resource. */
   3.606 -   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   3.607 -   if (!found || (resource == NULL)) {
   3.608 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.609 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.610 -      goto exit;
   3.611 +   xen_vm_record_opt *vm_rec_opt = con_rec->vm;
   3.612 +   if (vm_rec_opt->is_record) {
   3.613 +      snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s",
   3.614 +               vm_rec_opt->u.record->name_label, con_rec->uuid);
   3.615     }
   3.616 -
   3.617 -   /* Create a new CMPIInstance to store this resource. */
   3.618 -   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.619 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.620 -      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.621 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.622 -      goto exit;
   3.623 +   else {
   3.624 +      char *name = NULL;
   3.625 +      
   3.626 +      if (!xen_vm_get_name_label(session->xen, &name, vm_rec_opt->u.handle))
   3.627 +         return CMPI_RC_ERR_FAILED;
   3.628 +      snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s",
   3.629 +               name, con_rec->uuid);
   3.630 +      free(name);
   3.631     }
   3.632  
   3.633     /* Setup a filter to only return the desired properties. */
   3.634 -   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.635 -   if (status.rc != CMPI_RC_OK) {
   3.636 -      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.637 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.638 -      goto exit;
   3.639 -   }
   3.640 -
   3.641 -   /* Set the instance property values from the resource data. */
   3.642 -   if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.643 -      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.644 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.645 -      goto exit;
   3.646 -   }
   3.647 +   CMSetPropertyFilter(inst, properties, keys);
   3.648  
   3.649 -   /* Free the resource data. */
   3.650 -   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.651 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.652 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.653 -      goto exit;
   3.654 -   }
   3.655 +   /* Set the CMPIInstance properties from the resource data. */
   3.656 +   CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
   3.657 +   CMSetProperty(inst, "ElementName", (CMPIValue *)"Console", CMPI_chars);
   3.658  
   3.659 -   /* Return the CMPIInstance for this instance. */
   3.660 -   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.661 -   CMReturnInstance(results, instance);
   3.662 -
   3.663 -   _SBLIM_TRACE(2,("--- instance found"));
   3.664 -   CMReturnDone(results);
   3.665 +   int type = 24; /* 24 == Graphics Controller */
   3.666 +   CMSetProperty(inst, "ResourceType", (CMPIValue *)&type, CMPI_uint16);
   3.667  
   3.668 -exit:
   3.669 -   /* Free the list of system resources. */
   3.670 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.671 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.672 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.673 -   }
   3.674 -
   3.675 -   _SBLIM_RETURNSTATUS(status);
   3.676 -}
   3.677 +   int consumerVisibility = 3; /* 3 == Virtualized */
   3.678 +   CMSetProperty(inst, "ConsumerVisibility",
   3.679 +                 (CMPIValue *)&consumerVisibility, CMPI_uint16);
   3.680  
   3.681 -// ----------------------------------------------------------------------------
   3.682 -// SetInstance()
   3.683 -// Save modified instance data for the specified instance.
   3.684 -// ----------------------------------------------------------------------------
   3.685 -static CMPIStatus SetInstance(
   3.686 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.687 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.688 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.689 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.690 -		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   3.691 -        const char **properties)
   3.692 -{
   3.693 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.694 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.695 -   _RESOURCE * resource;	       		/* Handle to the system resource. */
   3.696 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.697 -   int found = 0;				/* Found the target instance? */
   3.698 +   uint64_t consoles = 1;
   3.699 +   CMSetProperty(inst, "Reservation", (CMPIValue *)&consoles, CMPI_uint64);
   3.700 +   CMSetProperty(inst, "Limit", (CMPIValue *)&consoles, CMPI_uint64);
   3.701 +   CMSetProperty(inst, "AllocationUnits",
   3.702 +                 (CMPIValue *)"Console Devices", CMPI_chars);
   3.703 +   CMSetProperty(inst, "VirtualQuantity", (CMPIValue *)&consoles, CMPI_uint64);
   3.704  
   3.705 -   _SBLIM_ENTER("SetInstance");
   3.706 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.707 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.708 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.709 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.710 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.711 -
   3.712 -   if (!xen_utils_validate_session(&session)) {
   3.713 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.714 -      goto exit;
   3.715 -   }
   3.716 +   int alloctype = 1;
   3.717 +   CMSetProperty(inst, "AutomaticAllocation",
   3.718 +                 (CMPIValue *)&alloctype, CMPI_boolean);
   3.719 +   CMSetProperty(inst, "AutomaticDeallocation",
   3.720 +                 (CMPIValue *)&alloctype, CMPI_boolean);
   3.721  
   3.722 -   /* Get a handle to the list of system resources. */
   3.723 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.724 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.725 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.726 -      goto exit;
   3.727 -   }
   3.728 -
   3.729 -   /* Get the target resource. */
   3.730 -   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   3.731 -   if (!found || (resource == NULL)) {
   3.732 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.733 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.734 -      goto exit;
   3.735 -   }
   3.736 +   CMSetProperty(inst, "Protocol",
   3.737 +                 (CMPIValue *)&(con_rec->protocol), CMPI_uint16);
   3.738  
   3.739 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.740 -
   3.741 -   /* Update the target resource data with the new instance property values. */
   3.742 -   int rc = Xen_ConsoleSettingData_setResourceFromInstance(resource, newinstance, _BROKER);
   3.743 -
   3.744 -   /* Free the resource data. */
   3.745 -   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.746 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.747 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.748 -      goto exit;
   3.749 -   }
   3.750 +   if (con_rec->location && con_rec->location[0] != '\0')
   3.751 +      CMSetProperty(inst, "URI", (CMPIValue *)con_rec->location, CMPI_chars);
   3.752  
   3.753 -   if (rc != 1) {
   3.754 -      if (rc == -1) {
   3.755 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   3.756 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.757 -      } else {
   3.758 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   3.759 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   3.760 +   if (con_rec->other_config) {
   3.761 +      char *flat_map = xen_utils_flatten_string_string_map(con_rec->other_config);
   3.762 +      if (flat_map) {
   3.763 +         CMSetProperty(inst, "ConsoleConfigInfo",
   3.764 +                       (CMPIValue *)flat_map, CMPI_chars);
   3.765 +         free(flat_map);
   3.766        }
   3.767 -      goto exit;
   3.768 -   }
   3.769 -
   3.770 -exit:
   3.771 -   /* Free the list of system resources. */
   3.772 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.773 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.774 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.775     }
   3.776  
   3.777 -   _SBLIM_RETURNSTATUS(status);
   3.778 -}
   3.779 -
   3.780 -// ----------------------------------------------------------------------------
   3.781 -// CreateInstance()
   3.782 -// Create a new instance from the specified instance data.
   3.783 -// ----------------------------------------------------------------------------
   3.784 -static CMPIStatus CreateInstance(
   3.785 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.786 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.787 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.788 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.789 -		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   3.790 -{
   3.791 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.792 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.793 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.794 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.795 -   int found = 0;				/* Found the target instance? */
   3.796 -
   3.797 -   _SBLIM_ENTER("CreateInstance");
   3.798 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.799 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.800 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.801 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.802 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.803 -
   3.804 -   if (!xen_utils_validate_session(&session)) {
   3.805 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.806 -      goto exit;
   3.807 -   }
   3.808 -
   3.809 -   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   3.810 -   reference = CMGetObjectPath(newinstance, NULL);
   3.811 -
   3.812 -   /* Get a handle to the list of system resources. */
   3.813 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.814 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.815 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.816 -      goto exit;
   3.817 -   }
   3.818 -
   3.819 -   /* Get the target resource. */
   3.820 -   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   3.821 -
   3.822 -   /* Free the resource data. */
   3.823 -   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.824 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.825 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.826 -      goto exit;
   3.827 -   }
   3.828 -
   3.829 -   if (found) {
   3.830 -      _SBLIM_TRACE(1,("--- Target instance already exists"));
   3.831 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   3.832 -      goto exit;
   3.833 -   }
   3.834 -
   3.835 -   /* Create a new resource with the new instance property values. */
   3.836 -   int rc = Xen_ConsoleSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   3.837 -   if (rc != 1) {
   3.838 -      if (rc == -1) {
   3.839 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   3.840 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.841 -      } else {
   3.842 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   3.843 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   3.844 -      }
   3.845 -      goto exit;
   3.846 -   }
   3.847 -
   3.848 -   /* Return the object path for the newly created instance. */
   3.849 -   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   3.850 -   CMSetNameSpace(objectpath, namespace);
   3.851 -   CMReturnObjectPath(results, objectpath);
   3.852 -   CMReturnDone(results);
   3.853 -
   3.854 -exit:
   3.855 -   /* Free the list of system resources. */
   3.856 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.857 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.858 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.859 -   }
   3.860 -
   3.861 -   _SBLIM_RETURNSTATUS(status);
   3.862 -}
   3.863 -
   3.864 -// ----------------------------------------------------------------------------
   3.865 -// DeleteInstance()
   3.866 -// Delete or remove the specified instance from the system.
   3.867 -// ----------------------------------------------------------------------------
   3.868 -static CMPIStatus DeleteInstance(
   3.869 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.870 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.871 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.872 -		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   3.873 -{
   3.874 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.875 -   _RESOURCES * resources;			/* Handle to the list of system resources. */
   3.876 -   _RESOURCE * resource;		/* Handle to the system resource. */
   3.877 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.878 -   int found = 0;				/* Found the target instance? */
   3.879 -
   3.880 -   _SBLIM_ENTER("DeleteInstance");
   3.881 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.882 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.883 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.884 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.885 -
   3.886 -   if (!xen_utils_validate_session(&session)) {
   3.887 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.888 -      goto exit;
   3.889 -   }
   3.890 -
   3.891 -   /* Get a handle to the list of system resources. */
   3.892 -   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   3.893 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.894 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.895 -      goto exit;
   3.896 -   }
   3.897 -
   3.898 -   /* Get the target resource. */
   3.899 -   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   3.900 -   if (!found || (resource == NULL)) {
   3.901 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.902 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.903 -      goto exit;
   3.904 -   }
   3.905 -
   3.906 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.907 -
   3.908 -   /* Delete the target resource. */
   3.909 -   int rc = Xen_ConsoleSettingData_deleteResource(resources, resource);
   3.910 -
   3.911 -   /* Free the resource data. */
   3.912 -   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   3.913 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.914 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.915 -      goto exit;
   3.916 -   }
   3.917 -
   3.918 -   if (rc != 1) {
   3.919 -      if (rc == -1) {
   3.920 -         _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
   3.921 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.922 -      } else {
   3.923 -         _SBLIM_TRACE(1,("--- _deleteResource() failed"));
   3.924 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
   3.925 -      }
   3.926 -      goto exit;
   3.927 -   }
   3.928 -
   3.929 -exit:
   3.930 -   /* Free the list of system resources. */
   3.931 -   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   3.932 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.933 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.934 -   }
   3.935 -
   3.936 -   _SBLIM_RETURNSTATUS(status);
   3.937 +   return CMPI_RC_OK;
   3.938  }
   3.939  
   3.940  
   3.941 -// ----------------------------------------------------------------------------
   3.942 -// ExecQuery()
   3.943 -// Return a list of all the instances that satisfy the specified query filter.
   3.944 -// ----------------------------------------------------------------------------
   3.945 -static CMPIStatus ExecQuery(
   3.946 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.947 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.948 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.949 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   3.950 -		const char * language,		/* [in] Name of the query language. */
   3.951 -		const char * query)			/* [in] Text of the query written in the query language. */
   3.952 +/*
   3.953 + * Set resource data from the CMPIInstance properties.  Only needs to
   3.954 + * be implemented if add() and/or modify() are supported.
   3.955 + */
   3.956 +static CMPIrc extract(void **res, const CMPIInstance *inst,
   3.957 +                      const char **properties)
   3.958  {
   3.959 -   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   3.960 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.961 +   console_resource *con_resource;
   3.962 +   
   3.963 +   (void)properties;
   3.964 +   
   3.965 +   /* Get memory for resource. */
   3.966 +   con_resource = (console_resource *)calloc(1, sizeof(console_resource));
   3.967 +   if (con_resource == NULL)
   3.968 +      return CMPI_RC_ERR_FAILED;
   3.969  
   3.970 -   _SBLIM_ENTER("ExecQuery");
   3.971 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.972 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.973 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.974 -   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   3.975 -   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   3.976 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.977 -
   3.978 -   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   3.979 -   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.980 -
   3.981 -   CMReturnDone(results);
   3.982 -
   3.983 -exit:
   3.984 -   _SBLIM_RETURNSTATUS(status);
   3.985 +   con_resource->u.cmpi_inst = (CMPIInstance *)inst;
   3.986 +   *res = (void *)con_resource;
   3.987 +   return CMPI_RC_OK;
   3.988  }
   3.989  
   3.990 -// ----------------------------------------------------------------------------
   3.991 -// Initialize()
   3.992 -// Perform any necessary initialization immediately after this provider is
   3.993 -// first loaded.
   3.994 -// ----------------------------------------------------------------------------
   3.995 -static void Initialize(
   3.996 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.997 -		const CMPIContext * context)		/* [in] Additional context info, if any. */
   3.998 +
   3.999 +/* Get resource id from CMPIInstance properties. */
  3.1000 +static CMPIrc extractid(void **res_id, const CMPIInstance* inst)
  3.1001  {
  3.1002 -   _SBLIM_ENTER("Initialize");
  3.1003 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
  3.1004 -   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
  3.1005 -
  3.1006 -   /* Initialized Xen session object. */
  3.1007 -   if (session == NULL)
  3.1008 -      xen_utils_xen_init(&session);
  3.1009 -   
  3.1010 -   _SBLIM_RETURN();
  3.1011 +   *res_id = (void *)inst;
  3.1012 +   return CMPI_RC_OK;
  3.1013  }
  3.1014  
  3.1015 -// ============================================================================
  3.1016 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
  3.1017 -// ============================================================================
  3.1018 -CMInstanceMIStub( , Xen_ConsoleSettingData, _BROKER, Initialize(&mi, ctx));
  3.1019 +
  3.1020 +/* Release resource id created in resId4inst(). */
  3.1021 +static void releaseid(void* res_id)
  3.1022 +{
  3.1023 +   (void)res_id;
  3.1024 +}
  3.1025 +
  3.1026 +
  3.1027 +/* Setup CMPILIFY function tables and instance provider entry point.*/
  3.1028 +/* CMPILIFYInstanceMIStub(<CLASS>,<PROVIDER_NAME>,<keys>,<CMPIInstanceMI_HANDLE>) */
  3.1029 +CMPILIFYInstanceMIStub(Xen_ConsoleSettingData, Xen_ConsoleSettingData, keys, mi)
     4.1 --- a/src/Xen_ConsoleSettingData_Resource.c	Thu Jul 19 18:04:38 2007 -0600
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,305 +0,0 @@
     4.4 -// Copyright (C) 2007 Novell, Inc
     4.5 -//
     4.6 -//    This library is free software; you can redistribute it and/or
     4.7 -//    modify it under the terms of the GNU Lesser General Public
     4.8 -//    License as published by the Free Software Foundation; either
     4.9 -//    version 2.1 of the License, or (at your option) any later version.
    4.10 -//
    4.11 -//    This library is distributed in the hope that it will be useful,
    4.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.14 -//    Lesser General Public License for more details.
    4.15 -//
    4.16 -//    You should have received a copy of the GNU Lesser General Public
    4.17 -//    License along with this library; if not, write to the Free Software
    4.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.19 -// ============================================================================
    4.20 -// Authors:       Jim Fehlig <jfehlig@novell.com>
    4.21 -//
    4.22 -// Contributors:
    4.23 -//
    4.24 -// Description:
    4.25 -// ============================================================================
    4.26 -
    4.27 -#include <stdlib.h>
    4.28 -#include <string.h>
    4.29 -#include <assert.h>
    4.30 -
    4.31 -#include <xen_common.h>
    4.32 -#include <xen_vm.h>
    4.33 -#include <xen_console.h>
    4.34 -
    4.35 -#include "Xen_ConsoleSettingData_Resource.h"
    4.36 -
    4.37 -/* Include the required CMPI data types, function headers, and macros. */
    4.38 -#include "cmpidt.h"
    4.39 -#include "cmpift.h"
    4.40 -#include "cmpimacs.h"
    4.41 -
    4.42 -#include "xen_utils.h"
    4.43 -#include "provider_common.h"
    4.44 -
    4.45 -/* Include _SBLIM_TRACE() logging support */
    4.46 -#include "cmpitrace.h"
    4.47 -
    4.48 -// ----------------------------------------------------------------------------
    4.49 -
    4.50 -static int concat_console_lists(xen_console_set **target, xen_console_set *source)
    4.51 -{
    4.52 -
    4.53 -   int total_size;
    4.54 -   int i, j;
    4.55 -   
    4.56 -   /* Nothing to concatenate if source is empty */
    4.57 -   if (source == NULL || source->size == 0)
    4.58 -      return 1;
    4.59 -   
    4.60 -   /* If targe is empty, assign source to target */
    4.61 -   if (*target == NULL) {
    4.62 -      *target = source;
    4.63 -      return 1;
    4.64 -   }
    4.65 -   
    4.66 -   /* realloc memory and append source to target */
    4.67 -   total_size = (*target)->size + source->size;
    4.68 -   *target = realloc(*target, sizeof(xen_console_set) + (total_size * sizeof(xen_console)));
    4.69 -   if (*target == NULL)
    4.70 -      return 0;
    4.71 -   
    4.72 -   for (j = (*target)->size, i = 0; i < source->size; i++) {
    4.73 -      (*target)->contents[j + i] = source->contents[i];
    4.74 -      source->contents[i] = NULL;
    4.75 -   }
    4.76 -   (*target)->size = total_size;
    4.77 -   
    4.78 -   /* Free source list - it has been copied to target */
    4.79 -   xen_console_set_free(source);
    4.80 -   return 1;
    4.81 -}
    4.82 -
    4.83 -
    4.84 -/* Get a handle to the list of all system resources for this class. */
    4.85 -int Xen_ConsoleSettingData_getResources(xen_utils_session *session,
    4.86 -                                        _RESOURCES ** resources)
    4.87 -{
    4.88 -   xen_domain_resources *res;
    4.89 -   xen_console_set *all_consoles = NULL;
    4.90 -   xen_vm_record *vm_rec = NULL;
    4.91 -   
    4.92 -   /* malloc a new handle for the resources list. */
    4.93 -   *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    4.94 -   if (*resources == NULL)
    4.95 -      return 0;
    4.96 -
    4.97 -   /* Get a list of domain resources. */
    4.98 -   if (!xen_utils_get_domain_resources(session, &res)) {
    4.99 -      *resources = NULL;
   4.100 -      return 0;
   4.101 -   }
   4.102 -
   4.103 -   /* Create list of console resources from consoles found in each domain. */
   4.104 -   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   4.105 -      xen_console_set *console_set;
   4.106 -      if (!xen_vm_get_consoles(session->xen, &console_set, vm_rec->handle))
   4.107 -         goto Error;
   4.108 -      
   4.109 -      if (!concat_console_lists(&all_consoles, console_set))
   4.110 -         goto Error;
   4.111 -      
   4.112 -      xen_vm_record_free(vm_rec);
   4.113 -   }
   4.114 -   
   4.115 -   (*resources)->consoles = all_consoles;
   4.116 -   (*resources)->currentconsolenum = 0;
   4.117 -   
   4.118 -   return 1;
   4.119 -   
   4.120 - Error:
   4.121 -   xen_vm_record_free(vm_rec);
   4.122 -   xen_utils_free_domain_resources(res);
   4.123 -   free(*resources);
   4.124 -   *resources = NULL;
   4.125 -   return 0;
   4.126 -}
   4.127 -
   4.128 -// ----------------------------------------------------------------------------
   4.129 -
   4.130 -/* Free/deallocate/cleanup the resources list after use. */
   4.131 -int Xen_ConsoleSettingData_freeResources(_RESOURCES * resources)
   4.132 -{
   4.133 -   if (resources != NULL) {
   4.134 -       if (resources->consoles != NULL)
   4.135 -          xen_console_set_free(resources->consoles);
   4.136 -       free(resources);
   4.137 -       resources = NULL;
   4.138 -   }
   4.139 -   
   4.140 -   return 1;
   4.141 -}
   4.142 -
   4.143 -// ----------------------------------------------------------------------------
   4.144 -
   4.145 -/* Iterator to get the next resource from the resources list. */
   4.146 -int Xen_ConsoleSettingData_getNextResource(xen_utils_session *session,
   4.147 -                                           _RESOURCES * resources,
   4.148 -                                           _RESOURCE ** resource)
   4.149 -{
   4.150 -   if (resources == NULL || resources->consoles == NULL)
   4.151 -      return 0;
   4.152 -
   4.153 -   /* Check if reached the end of the list of consoles. */
   4.154 -   if (resources->currentconsolenum == resources->consoles->size)
   4.155 -      return 0;
   4.156 -
   4.157 -   /* Get the current console record. */
   4.158 -   if (!xen_console_get_record(session->xen, resource, resources->consoles->contents[resources->currentconsolenum]))
   4.159 -      return 0;
   4.160 -   
   4.161 -   resources->currentconsolenum++;
   4.162 -   return 1;
   4.163 -}
   4.164 -
   4.165 -// ----------------------------------------------------------------------------
   4.166 -
   4.167 -/* Get the specific resource that matches the CMPI object path. */
   4.168 -int Xen_ConsoleSettingData_getResourceForObjectPath(xen_utils_session *session,
   4.169 -                                                    _RESOURCE ** resource,
   4.170 -                                                    const CMPIObjectPath * objectpath)
   4.171 -{
   4.172 -   char *instId;
   4.173 -   char uuid[MAX_SYSTEM_NAME_LEN];
   4.174 -   int ccode;
   4.175 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   4.176 -
   4.177 -   if (CMIsNullObject(objectpath)) return 0;
   4.178 -
   4.179 -   /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
   4.180 -   CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
   4.181 -   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
   4.182 -
   4.183 -   instId = CMGetCharPtr(iddata.value.string);
   4.184 -   if ((instId == NULL) || (*instId == '\0')) return 0;
   4.185 -
   4.186 -   /* Extract the console uuid from InstanceID property. */
   4.187 -   if (!_CMPIStrncpyDeviceNameFromID(uuid, instId, MAX_SYSTEM_NAME_LEN))
   4.188 -      return 0;
   4.189 -
   4.190 -   xen_console console;
   4.191 -   if (!xen_console_get_by_uuid(session->xen, &console, uuid))
   4.192 -      return 0;
   4.193 -
   4.194 -   ccode = xen_console_get_record(session->xen, resource, console);
   4.195 -   xen_console_free(console);
   4.196 -   return ccode;
   4.197 -}
   4.198 -
   4.199 -// ----------------------------------------------------------------------------
   4.200 -
   4.201 -/* Free/deallocate/cleanup the resource after use. */
   4.202 -int Xen_ConsoleSettingData_freeResource(_RESOURCE * resource)
   4.203 -{
   4.204 -   xen_console_record_free(resource);
   4.205 -   return 1;
   4.206 -}
   4.207 -
   4.208 -// ---------------------------------------------------------------------------- 
   4.209 -
   4.210 -/* Set the property values of a CMPI instance from a specific resource. */
   4.211 -int Xen_ConsoleSettingData_setInstanceFromResource(xen_utils_session *session,
   4.212 -                                                   _RESOURCE * resource,
   4.213 -                                                   const CMPIInstance * instance,
   4.214 -                                                   const CMPIBroker * broker)
   4.215 -{
   4.216 -   char buf[MAX_INSTANCEID_LEN];
   4.217 -   xen_vm_record *alloced_vm_rec = NULL;
   4.218 -   xen_vm_record *vm_rec;
   4.219 -   
   4.220 -   if (resource == NULL) return 0;
   4.221 -   if (CMIsNullObject(instance)) return 0;
   4.222 -
   4.223 -   xen_vm_record_opt *vm_rec_opt = resource->vm;
   4.224 -   if (vm_rec_opt->is_record) {
   4.225 -      vm_rec = vm_rec_opt->u.record;
   4.226 -   }
   4.227 -   else {
   4.228 -      if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) {
   4.229 -      /* Error description in session object! */
   4.230 -         return 0;
   4.231 -      }
   4.232 -      alloced_vm_rec = vm_rec;
   4.233 -   }
   4.234 -
   4.235 -   /* Set the CMPIInstance properties from the resource data. */
   4.236 -   snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec->name_label, resource->uuid);
   4.237 -   CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
   4.238 -   CMSetProperty(instance, "ElementName",(CMPIValue *)"Console", CMPI_chars);
   4.239 -
   4.240 -   int type = 24; /* 24 == Graphics Controller */
   4.241 -   CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
   4.242 -
   4.243 -   int consumerVisibility = 3; /* 3 == Virtualized */
   4.244 -   CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
   4.245 -
   4.246 -   unsigned long long consoles = 1;
   4.247 -   CMSetProperty(instance, "Reservation",(CMPIValue *)&consoles, CMPI_uint64);
   4.248 -   CMSetProperty(instance, "Limit",(CMPIValue *)&consoles, CMPI_uint64);
   4.249 -   CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Console Devices", CMPI_chars);
   4.250 -   CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&consoles, CMPI_uint64);
   4.251 -
   4.252 -   int alloctype = 1;
   4.253 -   CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   4.254 -   CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   4.255 -
   4.256 -   if (resource->location)
   4.257 -      CMSetProperty(instance, "URI", (CMPIValue *)resource->location, CMPI_chars);
   4.258 -
   4.259 -   int protocol = -1;
   4.260 -   if (resource->protocol == XEN_CONSOLE_PROTOCOL_VT100)
   4.261 -      protocol = 0; /* 0 == VT100 */
   4.262 -   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RFB)
   4.263 -      protocol = 1; /* 1 == VNC */
   4.264 -   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RDP)
   4.265 -      protocol = 2; /* 2 == SDL */
   4.266 -
   4.267 -   if (protocol != -1)
   4.268 -      CMSetProperty(instance, "Protocol",(CMPIValue *)&protocol, CMPI_uint16);
   4.269 -
   4.270 -   if (alloced_vm_rec)
   4.271 -      xen_vm_record_free(alloced_vm_rec);
   4.272 -
   4.273 -   return 1;
   4.274 -}
   4.275 -
   4.276 -// ----------------------------------------------------------------------------
   4.277 -
   4.278 -/* Delete the specified resource from the system. */
   4.279 -int Xen_ConsoleSettingData_deleteResource(_RESOURCES * resources,
   4.280 -                                          _RESOURCE * resource)
   4.281 -{
   4.282 -   /* Unsupported. */
   4.283 -   return -1;
   4.284 -}
   4.285 -
   4.286 -// ----------------------------------------------------------------------------
   4.287 -
   4.288 -/* Modify the specified resource using the property values of a CMPI instance. */
   4.289 -int Xen_ConsoleSettingData_setResourceFromInstance(_RESOURCE * resource,
   4.290 -                                                   const CMPIInstance * instance,
   4.291 -                                                   const CMPIBroker * broker)
   4.292 -{
   4.293 -   /* Unsupported. */
   4.294 -   return -1;
   4.295 -}
   4.296 -
   4.297 -// ----------------------------------------------------------------------------
   4.298 -
   4.299 -/* Create a new resource using the property values of a CMPI instance. */
   4.300 -int Xen_ConsoleSettingData_createResourceFromInstance(_RESOURCES * resources,
   4.301 -                                                      _RESOURCE ** resource,
   4.302 -                                                      const CMPIInstance * instance,
   4.303 -                                                      const CMPIBroker * broker)
   4.304 -{
   4.305 -   /* Unsupported. */
   4.306 -   return -1;
   4.307 -}
   4.308 -
     5.1 --- a/src/Xen_ConsoleSettingData_Resource.h	Thu Jul 19 18:04:38 2007 -0600
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,107 +0,0 @@
     5.4 -// Copyright (C) 2007 Novell, Inc.
     5.5 -//
     5.6 -//    This library is free software; you can redistribute it and/or
     5.7 -//    modify it under the terms of the GNU Lesser General Public
     5.8 -//    License as published by the Free Software Foundation; either
     5.9 -//    version 2.1 of the License, or (at your option) any later version.
    5.10 -//
    5.11 -//    This library is distributed in the hope that it will be useful,
    5.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.14 -//    Lesser General Public License for more details.
    5.15 -//
    5.16 -//    You should have received a copy of the GNU Lesser General Public
    5.17 -//    License along with this library; if not, write to the Free Software
    5.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.19 -// ============================================================================
    5.20 -// Authors:       Jim Fehlig <jfehlig@novell.com>
    5.21 -//
    5.22 -// Contributors:
    5.23 -//
    5.24 -// Description:
    5.25 -// ============================================================================
    5.26 -#if !defined(__XEN_CONSOLESETTINGDATA_RESOURCE_H__)
    5.27 -#define __XEN_CONSOLESETTINGDATA_RESOURCE_H__
    5.28 -
    5.29 -/* Include required libxen headers. */
    5.30 -#include <xen_common.h>
    5.31 -#include <xen_console.h>
    5.32 -
    5.33 -#include "xen_utils.h"
    5.34 -
    5.35 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.36 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES.
    5.37 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS
    5.38 -   LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC.
    5.39 -   THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN
    5.40 -   ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */
    5.41 -typedef struct {
    5.42 -   xen_console_set *consoles;
    5.43 -   unsigned int currentconsolenum;
    5.44 -} _RESOURCES;
    5.45 -
    5.46 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.47 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE.
    5.48 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH
    5.49 -   RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE
    5.50 -   PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE
    5.51 -   ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */
    5.52 -typedef xen_console_record  _RESOURCE;
    5.53 -
    5.54 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */
    5.55 -
    5.56 -/* Include the required CMPI data types. */
    5.57 -#include "cmpidt.h"
    5.58 -
    5.59 -// ----------------------------------------------------------------------------
    5.60 -// Generic resource access methods for CMPI providers.
    5.61 -// Return value:
    5.62 -//	-1 = Unsupported
    5.63 -//	 0 = Failed
    5.64 -//	 1 = OK
    5.65 -// ----------------------------------------------------------------------------
    5.66 -
    5.67 -/* Get a handle to the list of all system resources for this class. */
    5.68 -int Xen_ConsoleSettingData_getResources(xen_utils_session *session,
    5.69 -                                        _RESOURCES ** resources);
    5.70 -
    5.71 -/* Free/deallocate/cleanup the resources list after use. */
    5.72 -int Xen_ConsoleSettingData_freeResources(_RESOURCES * resources);
    5.73 -
    5.74 -/* Iterator to get the next resource from the resources list. */
    5.75 -int Xen_ConsoleSettingData_getNextResource(xen_utils_session *session,
    5.76 -                                           _RESOURCES * resources,
    5.77 -                                           _RESOURCE ** resource);
    5.78 -
    5.79 -/* Get the specific resource that matches the CMPI object path. */
    5.80 -int Xen_ConsoleSettingData_getResourceForObjectPath(xen_utils_session *session,
    5.81 -                                                    _RESOURCE ** resource,
    5.82 -                                                    const CMPIObjectPath * objectpath);
    5.83 -
    5.84 -/* Free/deallocate/cleanup a resource after use. */
    5.85 -int Xen_ConsoleSettingData_freeResource(_RESOURCE * resource);
    5.86 -
    5.87 -/* Set the property values of a CMPI instance from a specific resource. */
    5.88 -int Xen_ConsoleSettingData_setInstanceFromResource(xen_utils_session *session,
    5.89 -                                                   _RESOURCE * resource,
    5.90 -                                                   const CMPIInstance * instance,
    5.91 -                                                   const CMPIBroker * broker);
    5.92 -
    5.93 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS
    5.94 -
    5.95 -/* Delete the specified resource from the system. */
    5.96 -int Xen_ConsoleSettingData_deleteResource(_RESOURCES * resources,
    5.97 -                                          _RESOURCE * resource);
    5.98 -
    5.99 -/* Modify the specified resource using the property values of a CMPI instance. */
   5.100 -int Xen_ConsoleSettingData_setResourceFromInstance(_RESOURCE * resource,
   5.101 -                                                   const CMPIInstance * instance,
   5.102 -                                                   const CMPIBroker * broker);
   5.103 -
   5.104 -/* Create a new resource using the property values of a CMPI instance. */
   5.105 -int Xen_ConsoleSettingData_createResourceFromInstance(_RESOURCES * resources,
   5.106 -                                                      _RESOURCE ** resource,
   5.107 -                                                      const CMPIInstance * instance,
   5.108 -                                                      const CMPIBroker * broker);
   5.109 -
   5.110 -#endif /* __XEN_CONSOLESETTINGDATA_RESOURCE_H__ */
     6.1 --- a/src/xen_utils.c	Thu Jul 19 18:04:38 2007 -0600
     6.2 +++ b/src/xen_utils.c	Thu Jul 26 16:47:21 2007 -0600
     6.3 @@ -760,6 +760,46 @@ int xen_utils_add_to_string_string_map(c
     6.4  
     6.5  
     6.6  /*
     6.7 + * Flatten a Xen API string-string map.  The flattened map will be in form
     6.8 + * key0=value0,key1=value1,...,keyN=valueN
     6.9 + * Returns char array containing flattened map on success, NULL on failure.
    6.10 + * Caller is responsible for freeing memory.
    6.11 + */
    6.12 +char *xen_utils_flatten_string_string_map(xen_string_string_map *map)
    6.13 +{
    6.14 +   unsigned int i = 0;
    6.15 +   unsigned int size = 0;
    6.16 +   char *flat_map;
    6.17 +   
    6.18 +   if (map == NULL || map->size == 0)
    6.19 +      return NULL;
    6.20 +   
    6.21 +   /* Calculate size of buffer needed to hold flattened map. */
    6.22 +   do {
    6.23 +      size += strlen(map->contents[i].key);
    6.24 +      size += strlen(map->contents[i].val);
    6.25 +      size += 2; // for '=' and ','
    6.26 +      i++;
    6.27 +   } while (i < map->size);
    6.28 +   
    6.29 +   flat_map = (char *)calloc(1, size + 1);
    6.30 +   if (flat_map == NULL)
    6.31 +      return NULL;
    6.32 +   
    6.33 +   for (i = 0; i < map->size; i++) {
    6.34 +      strcat(flat_map, map->contents[i].key);
    6.35 +      strcat(flat_map, "=");
    6.36 +      strcat(flat_map, map->contents[i].val);
    6.37 +      if ((i + 1) == map->size)
    6.38 +         break;
    6.39 +      strcat(flat_map, ",");
    6.40 +   }
    6.41 +   
    6.42 +   return flat_map;
    6.43 +}
    6.44 +
    6.45 +
    6.46 +/*
    6.47   * Trace the error descriptions found in xen session object.
    6.48   * This routine uses _sblim_trace function in cmpitrace interface
    6.49   * for actual tracing.  Output is to a location specified in the
     7.1 --- a/src/xen_utils.h	Thu Jul 19 18:04:38 2007 -0600
     7.2 +++ b/src/xen_utils.h	Thu Jul 26 16:47:21 2007 -0600
     7.3 @@ -323,6 +323,15 @@ int xen_utils_add_to_string_string_map(c
     7.4  
     7.5  
     7.6  /*
     7.7 + * Flatten a Xen API string-string map.  The flattened map will be in form
     7.8 + * key0=value0,key1=value1,...,keyN=valueN
     7.9 + * Returns char array containing flattened map on success, NULL on failure.
    7.10 + * Caller is responsible for freeing memory.
    7.11 + */
    7.12 +char *xen_utils_flatten_string_string_map(xen_string_string_map *map);
    7.13 +
    7.14 +
    7.15 +/*
    7.16   * Trace the error descriptions found in xen session object.
    7.17   * This routine uses _sblim_trace function in cmpitrace interface
    7.18   * for actual tracing.  Output is to a location specified in the