os-cmpi-xen

changeset 85:75019e01e546

Added provider for Xen_ConsoleSettingData class.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Wed Feb 21 15:46:34 2007 -0700 (2007-02-21)
parents e8137fd93139
children ff99c4398c16
files ChangeLog Makefile.am schema/Xen_Console.mof schema/Xen_ConsoleSettingData.mof schema/Xen_ConsoleSettingData.registration src/Makefile.am src/Xen_ConsoleSettingData.c src/Xen_ConsoleSettingData_Resource.c src/Xen_ConsoleSettingData_Resource.h src/Xen_Console_Resource.c
line diff
     1.1 --- a/ChangeLog	Wed Feb 21 12:26:23 2007 -0700
     1.2 +++ b/ChangeLog	Wed Feb 21 15:46:34 2007 -0700
     1.3 @@ -1,3 +1,14 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Wed Feb 21 15:45:06 MST 2007 - jfehlig@novell.com
     1.6 +
     1.7 +        - Added Xen_ConsoleSettingData provider
     1.8 +
     1.9 +-------------------------------------------------------------------
    1.10 +Wed Feb 20 17:15:06 MST 2007 - jfehlig@novell.com
    1.11 +
    1.12 +        - Added Xen_Console and Xen_ComputerSystemConsole
    1.13 +          providers.  -- Raj Subrahmanian
    1.14 +
    1.15  -------------------------------------------------------------------
    1.16  Mon Feb 12 15:30:12 MST 2007 - jfehlig@novell.com
    1.17  
     2.1 --- a/Makefile.am	Wed Feb 21 12:26:23 2007 -0700
     2.2 +++ b/Makefile.am	Wed Feb 21 15:46:34 2007 -0700
     2.3 @@ -106,6 +106,7 @@ XEN_MOFS = \
     2.4  	schema/Xen_DiskSettingData.mof \
     2.5  	schema/Xen_DiskSettingsDefineState.mof \
     2.6  	schema/Xen_DiskElementSettingData.mof \
     2.7 +	schema/Xen_ConsoleSettingData.mof \
     2.8  	schema/Xen_MemoryPool.mof \
     2.9  	schema/Xen_HostedMemoryPool.mof \
    2.10  	schema/Xen_MemoryPoolComponent.mof \
    2.11 @@ -168,6 +169,7 @@ XEN_REGS = \
    2.12  	schema/Xen_DiskSettingData.registration \
    2.13  	schema/Xen_DiskSettingsDefineState.registration \
    2.14  	schema/Xen_DiskElementSettingData.registration \
    2.15 +	schema/Xen_ConsoleSettingData.registration \
    2.16  	schema/Xen_MemoryPool.registration \
    2.17  	schema/Xen_HostedMemoryPool.registration \
    2.18  	schema/Xen_MemoryPoolComponent.registration \
     3.1 --- a/schema/Xen_Console.mof	Wed Feb 21 12:26:23 2007 -0700
     3.2 +++ b/schema/Xen_Console.mof	Wed Feb 21 15:46:34 2007 -0700
     3.3 @@ -8,9 +8,13 @@
     3.4          "a console attached to a Xen domain.")]
     3.5  class Xen_Console : CIM_LogicalDevice
     3.6  {
     3.7 -	[Description ("URI for this console")]
     3.8 -	string URI;
     3.9 -	[Description ("Console Protocol")]
    3.10 -	string Protocol;
    3.11 +   [Description ("URI for the console service")]
    3.12 +   string URI;
    3.13 +
    3.14 +   [Description ("Protocol used for the console"),
    3.15 +   ValueMap { "0", "1",  "2", ".." },
    3.16 +   Values { "VT100", "Remote Framebuffer (VNC)", "Remote Desktop (SDL)",
    3.17 +      "Vendor Reserved"}]
    3.18 +   uint16 Protocol;
    3.19  };
    3.20  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/schema/Xen_ConsoleSettingData.mof	Wed Feb 21 15:46:34 2007 -0700
     4.3 @@ -0,0 +1,26 @@
     4.4 +// Copyright (c) 2007 Novell, Inc. All rights reserved.
     4.5 +
     4.6 +// ==================================================================
     4.7 +// Xen_ConsoleSettingData
     4.8 +// ==================================================================
     4.9 +[Provider ("cmpi:Xen_ConsoleSettingData"),
    4.10 + Description (
    4.11 +        "A class derived from CIM_ResourceAllocationSettingData to "
    4.12 +	"represent the Xen_Console settings of a virtualized console "
    4.13 +	"in a Xen domain.")]
    4.14 +class Xen_ConsoleSettingData : CIM_ResourceAllocationSettingData
    4.15 +{
    4.16 +   [Description ("URI for the console service")]
    4.17 +   string URI;
    4.18 +
    4.19 +   [Description ("Protocol used for the console"),
    4.20 +   ValueMap { "0", "1",  "2", ".." },
    4.21 +   Values { "VT100", "Remote Framebuffer (VNC)", "Remote Desktop (SDL)",
    4.22 +      "Vendor Reserved"}]
    4.23 +   uint16 Protocol;
    4.24 +
    4.25 +   [Description ("Additional configuration information for the "
    4.26 +      "console device.")]
    4.27 +   string ConsoleConfigInfo;
    4.28 +
    4.29 +};
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/schema/Xen_ConsoleSettingData.registration	Wed Feb 21 15:46:34 2007 -0700
     5.3 @@ -0,0 +1,2 @@
     5.4 +# Classname Namespace ProviderName ProviderModule ProviderTypes ...
     5.5 +Xen_ConsoleSettingData root/cimv2 Xen_ConsoleSettingData Xen_ConsoleSettingData instance 
     6.1 --- a/src/Makefile.am	Wed Feb 21 12:26:23 2007 -0700
     6.2 +++ b/src/Makefile.am	Wed Feb 21 15:46:34 2007 -0700
     6.3 @@ -59,6 +59,7 @@ noinst_HEADERS = \
     6.4  	Xen_MemorySettingData_Resource.h \
     6.5  	Xen_NetworkPortSettingData_Resource.h \
     6.6  	Xen_DiskSettingData_Resource.h \
     6.7 +	Xen_ConsoleSettingData_Resource.h \
     6.8  	Xen_MemoryPool_Resource.h \
     6.9  	Xen_ProcessorPool_Resource.h \
    6.10  	Xen_ProcessorCapabilitiesSettingData_Resource.h \
    6.11 @@ -111,6 +112,7 @@ provider_LTLIBRARIES = \
    6.12  	libXen_DiskSettingData.la \
    6.13  	libXen_DiskSettingsDefineState.la \
    6.14  	libXen_DiskElementSettingData.la \
    6.15 +	libXen_ConsoleSettingData.la \
    6.16  	libXen_MemoryPool.la \
    6.17  	libXen_HostedMemoryPool.la \
    6.18  	libXen_MemoryPoolComponent.la \
    6.19 @@ -309,6 +311,11 @@ libXen_DiskElementSettingData_la_CFLAGS 
    6.20  libXen_DiskElementSettingData_la_LIBADD = libXen_ProviderCommon.la
    6.21  libXen_DiskElementSettingData_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@
    6.22  
    6.23 +libXen_ConsoleSettingData_la_SOURCES = Xen_ConsoleSettingData.c Xen_ConsoleSettingData_Resource.c
    6.24 +libXen_ConsoleSettingData_la_CFLAGS = -I../ @LIBXEN_CFLAGS@
    6.25 +libXen_ConsoleSettingData_la_LIBADD = libXen_ProviderCommon.la
    6.26 +libXen_ConsoleSettingData_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@
    6.27 +
    6.28  libXen_MemoryPool_la_SOURCES = Xen_MemoryPool.c Xen_MemoryPool_Resource.c
    6.29  libXen_MemoryPool_la_CFLAGS = -I../
    6.30  libXen_MemoryPool_la_LIBADD = libXen_ProviderCommon.la -lxenstore
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/Xen_ConsoleSettingData.c	Wed Feb 21 15:46:34 2007 -0700
     7.3 @@ -0,0 +1,645 @@
     7.4 +// Copyright (C) 2007 Novell, Inc.
     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:       Jim Fehlig <jfehlig@novell.com>
    7.21 +// Contributors:  
    7.22 +// Description:   This file implements the WBEM operations for Xen console
    7.23 +//                setting data.
    7.24 +// ============================================================================
    7.25 +
    7.26 +/* Include the required CMPI data types, function headers, and macros */
    7.27 +#include "cmpidt.h"
    7.28 +#include "cmpift.h"
    7.29 +#include "cmpimacs.h"
    7.30 +
    7.31 +/* Include utility functions */
    7.32 +#include "cmpiutil.h"
    7.33 +
    7.34 +/* Include _SBLIM_TRACE() logging support */
    7.35 +#include "cmpitrace.h"
    7.36 +
    7.37 +/* Include Xen utilities */
    7.38 +#include "xen_utils.h"
    7.39 +
    7.40 +/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    7.41 +#include "Xen_ConsoleSettingData_Resource.h"
    7.42 +
    7.43 +
    7.44 +// ----------------------------------------------------------------------------
    7.45 +// COMMON GLOBAL VARIABLES
    7.46 +// ----------------------------------------------------------------------------
    7.47 +
    7.48 +/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    7.49 +static const CMPIBroker *_BROKER;
    7.50 +
    7.51 +/* Xen session object.  Initialize when the provider is loaded, close when
    7.52 + * provider unloaded. */
    7.53 +static xen_utils_session *session = NULL;
    7.54 +
    7.55 +
    7.56 +// ============================================================================
    7.57 +// CMPI INSTANCE PROVIDER FUNCTION TABLE
    7.58 +// ============================================================================
    7.59 +
    7.60 +// ----------------------------------------------------------------------------
    7.61 +// Info for the class supported by the instance provider
    7.62 +// ----------------------------------------------------------------------------
    7.63 +
    7.64 +/* Name of the class implemented by this instance provider. */
    7.65 +/*** CUSTOMIZE FOR EACH PROVIDER ***/
    7.66 +static char * _CLASSNAME = "Xen_ConsoleSettingData";
    7.67 +
    7.68 +/* NULL terminated list of key properties of this class. */
    7.69 +/*** CUSTOMIZE FOR EACH PROVIDER ***/
    7.70 +const static char * _KEYNAMES[] = {"InstanceID", NULL};
    7.71 +                                   
    7.72 +// ----------------------------------------------------------------------------
    7.73 +// Cleanup()
    7.74 +// Perform any necessary cleanup immediately before this provider is unloaded.
    7.75 +// ----------------------------------------------------------------------------
    7.76 +static CMPIStatus Cleanup(
    7.77 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
    7.78 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
    7.79 +        CMPIBoolean terminating)   /* [in] True if MB is terminating */
    7.80 +{
    7.81 +   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
    7.82 +
    7.83 +   _SBLIM_ENTER("Cleanup");
    7.84 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
    7.85 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
    7.86 +
    7.87 +   if (session) {
    7.88 +      xen_utils_xen_close(session);
    7.89 +      session = NULL;
    7.90 +   }
    7.91 +   _SBLIM_RETURNSTATUS(status);
    7.92 +}
    7.93 +
    7.94 +// ----------------------------------------------------------------------------
    7.95 +// EnumInstanceNames()
    7.96 +// Return a list of all the instances names (return their object paths only).
    7.97 +// ----------------------------------------------------------------------------
    7.98 +static CMPIStatus EnumInstanceNames(
    7.99 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.100 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.101 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.102 +		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   7.103 +{
   7.104 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.105 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.106 +   _RESOURCE * resource;			/* Handle to each system resource. */
   7.107 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.108 +   int found = 0;				/* Found any instances? */
   7.109 +  
   7.110 +   _SBLIM_ENTER("EnumInstanceNames");
   7.111 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.112 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.113 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.114 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.115 +
   7.116 +   if (!xen_utils_validate_session(&session)) {
   7.117 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.118 +      goto exit;
   7.119 +   }
   7.120 +
   7.121 +   /* Get a handle to the list of system resources. */
   7.122 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.123 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.124 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.125 +      goto exit;
   7.126 +   }
   7.127 +
   7.128 +   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   7.129 +   while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
   7.130 +      /* Create a new CMPIInstance to store this resource. */
   7.131 +      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   7.132 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   7.133 +         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   7.134 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   7.135 +         goto exit;
   7.136 +      }
   7.137 +
   7.138 +      /* Set the instance property values from the resource data. */
   7.139 +      if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   7.140 +         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   7.141 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   7.142 +         goto exit;
   7.143 +      }
   7.144 +
   7.145 +      /* Free the resource data. */
   7.146 +      if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.147 +         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.148 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.149 +         goto exit;
   7.150 +      }
   7.151 +
   7.152 +      /* Return the CMPIObjectPath for this instance. */
   7.153 +      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   7.154 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   7.155 +         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   7.156 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   7.157 +         goto exit;
   7.158 +      }
   7.159 +      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   7.160 +     
   7.161 +      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   7.162 +      CMReturnObjectPath(results, objectpath);
   7.163 +      found++;
   7.164 +   }
   7.165 +
   7.166 +   _SBLIM_TRACE(2,("--- %d object paths found", found));
   7.167 +   CMReturnDone(results);
   7.168 +
   7.169 +exit:
   7.170 +   /* Free the list of system resources. */
   7.171 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.172 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.173 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.174 +   }
   7.175 +  
   7.176 +   _SBLIM_RETURNSTATUS(status);
   7.177 +}
   7.178 +
   7.179 +// ----------------------------------------------------------------------------
   7.180 +// EnumInstances()
   7.181 +// Return a list of all the instances (return all the instance data).
   7.182 +// ----------------------------------------------------------------------------
   7.183 +static CMPIStatus EnumInstances(
   7.184 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.185 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.186 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.187 +		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   7.188 +		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   7.189 +{
   7.190 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.191 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.192 +   _RESOURCE * resource;			/* Handle to each system resource. */
   7.193 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.194 +   int found = 0;				/* Found any resource instances? */
   7.195 +
   7.196 +   _SBLIM_ENTER("EnumInstances");
   7.197 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.198 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.199 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.200 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.201 +
   7.202 +   if (!xen_utils_validate_session(&session)) {
   7.203 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.204 +      goto exit;
   7.205 +   }
   7.206 +
   7.207 +   /* Get a handle to the list of system resources. */
   7.208 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.209 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.210 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.211 +      goto exit;
   7.212 +   }
   7.213 +
   7.214 +   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   7.215 +   while (Xen_ConsoleSettingData_getNextResource(session, resources, &resource)) {
   7.216 +      /* Create a new CMPIInstance to store this resource. */
   7.217 +      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   7.218 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   7.219 +         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   7.220 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   7.221 +         goto exit;
   7.222 +      }
   7.223 +
   7.224 +      /* Setup a filter to only return the desired properties. */
   7.225 +      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   7.226 +      if (status.rc != CMPI_RC_OK) {
   7.227 +         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   7.228 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   7.229 +         goto exit;
   7.230 +      }
   7.231 +
   7.232 +      /* Set the instance property values from the resource data. */
   7.233 +      if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   7.234 +         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   7.235 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   7.236 +         goto exit;
   7.237 +      }
   7.238 +
   7.239 +      /* Free the resource data. */
   7.240 +      if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.241 +         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.242 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.243 +         goto exit;
   7.244 +      }
   7.245 +
   7.246 +      /* Return the CMPIInstance for this instance. */
   7.247 +      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   7.248 +      CMReturnInstance(results, instance);
   7.249 +      found++;
   7.250 +   }
   7.251 +
   7.252 +   _SBLIM_TRACE(2,("--- %d instances found", found));
   7.253 +   CMReturnDone(results);
   7.254 +
   7.255 +exit:
   7.256 +   /* Free the list of system resources. */
   7.257 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.258 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.259 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.260 +   }
   7.261 +
   7.262 +   _SBLIM_RETURNSTATUS(status);
   7.263 +}
   7.264 +
   7.265 +// ----------------------------------------------------------------------------
   7.266 +// GetInstance()
   7.267 +// Return the instance data for the specified instance only.
   7.268 +// ----------------------------------------------------------------------------
   7.269 +static CMPIStatus GetInstance(
   7.270 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.271 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.272 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.273 +		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   7.274 +		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   7.275 +{
   7.276 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.277 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.278 +   _RESOURCE * resource;			/* Handle to the system resource. */
   7.279 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.280 +   int found = 0;				/* Found the target instance? */
   7.281 +
   7.282 +   _SBLIM_ENTER("GetInstance");
   7.283 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.284 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.285 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.286 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.287 +
   7.288 +   if (!xen_utils_validate_session(&session)) {
   7.289 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.290 +      goto exit;
   7.291 +   }
   7.292 +
   7.293 +   /* Get a handle to the list of system resources. */
   7.294 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.295 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.296 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.297 +      goto exit;
   7.298 +   }
   7.299 +
   7.300 +   /* Get the target resource. */
   7.301 +   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   7.302 +   if (!found || (resource == NULL)) {
   7.303 +      _SBLIM_TRACE(1,("--- Target instance not found"));
   7.304 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   7.305 +      goto exit;
   7.306 +   }
   7.307 +
   7.308 +   /* Create a new CMPIInstance to store this resource. */
   7.309 +   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   7.310 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   7.311 +      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   7.312 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   7.313 +      goto exit;
   7.314 +   }
   7.315 +
   7.316 +   /* Setup a filter to only return the desired properties. */
   7.317 +   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   7.318 +   if (status.rc != CMPI_RC_OK) {
   7.319 +      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   7.320 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   7.321 +      goto exit;
   7.322 +   }
   7.323 +
   7.324 +   /* Set the instance property values from the resource data. */
   7.325 +   if (!Xen_ConsoleSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   7.326 +      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   7.327 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   7.328 +      goto exit;
   7.329 +   }
   7.330 +
   7.331 +   /* Free the resource data. */
   7.332 +   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.333 +      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.334 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.335 +      goto exit;
   7.336 +   }
   7.337 +
   7.338 +   /* Return the CMPIInstance for this instance. */
   7.339 +   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   7.340 +   CMReturnInstance(results, instance);
   7.341 +
   7.342 +   _SBLIM_TRACE(2,("--- instance found"));
   7.343 +   CMReturnDone(results);
   7.344 +
   7.345 +exit:
   7.346 +   /* Free the list of system resources. */
   7.347 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.348 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.349 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.350 +   }
   7.351 +
   7.352 +   _SBLIM_RETURNSTATUS(status);
   7.353 +}
   7.354 +
   7.355 +// ----------------------------------------------------------------------------
   7.356 +// SetInstance()
   7.357 +// Save modified instance data for the specified instance.
   7.358 +// ----------------------------------------------------------------------------
   7.359 +static CMPIStatus SetInstance(
   7.360 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.361 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.362 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.363 +		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   7.364 +		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   7.365 +        const char **properties)
   7.366 +{
   7.367 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.368 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.369 +   _RESOURCE * resource;	       		/* Handle to the system resource. */
   7.370 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.371 +   int found = 0;				/* Found the target instance? */
   7.372 +
   7.373 +   _SBLIM_ENTER("SetInstance");
   7.374 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.375 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.376 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.377 +   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   7.378 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.379 +
   7.380 +   if (!xen_utils_validate_session(&session)) {
   7.381 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.382 +      goto exit;
   7.383 +   }
   7.384 +
   7.385 +   /* Get a handle to the list of system resources. */
   7.386 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.387 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.388 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.389 +      goto exit;
   7.390 +   }
   7.391 +
   7.392 +   /* Get the target resource. */
   7.393 +   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   7.394 +   if (!found || (resource == NULL)) {
   7.395 +      _SBLIM_TRACE(1,("--- Target instance not found"));
   7.396 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   7.397 +      goto exit;
   7.398 +   }
   7.399 +
   7.400 +   _SBLIM_TRACE(2,("--- instance found", found));
   7.401 +
   7.402 +   /* Update the target resource data with the new instance property values. */
   7.403 +   int rc = Xen_ConsoleSettingData_setResourceFromInstance(resource, newinstance, _BROKER);
   7.404 +
   7.405 +   /* Free the resource data. */
   7.406 +   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.407 +      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.408 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.409 +      goto exit;
   7.410 +   }
   7.411 +
   7.412 +   if (rc != 1) {
   7.413 +      if (rc == -1) {
   7.414 +         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   7.415 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   7.416 +      } else {
   7.417 +         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   7.418 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   7.419 +      }
   7.420 +      goto exit;
   7.421 +   }
   7.422 +
   7.423 +exit:
   7.424 +   /* Free the list of system resources. */
   7.425 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.426 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.427 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.428 +   }
   7.429 +
   7.430 +   _SBLIM_RETURNSTATUS(status);
   7.431 +}
   7.432 +
   7.433 +// ----------------------------------------------------------------------------
   7.434 +// CreateInstance()
   7.435 +// Create a new instance from the specified instance data.
   7.436 +// ----------------------------------------------------------------------------
   7.437 +static CMPIStatus CreateInstance(
   7.438 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.439 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.440 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.441 +		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   7.442 +		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   7.443 +{
   7.444 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.445 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.446 +   _RESOURCE * resource;			/* Handle to the system resource. */
   7.447 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.448 +   int found = 0;				/* Found the target instance? */
   7.449 +
   7.450 +   _SBLIM_ENTER("CreateInstance");
   7.451 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.452 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.453 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.454 +   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   7.455 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.456 +
   7.457 +   if (!xen_utils_validate_session(&session)) {
   7.458 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.459 +      goto exit;
   7.460 +   }
   7.461 +
   7.462 +   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   7.463 +   reference = CMGetObjectPath(newinstance, NULL);
   7.464 +
   7.465 +   /* Get a handle to the list of system resources. */
   7.466 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.467 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.468 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.469 +      goto exit;
   7.470 +   }
   7.471 +
   7.472 +   /* Get the target resource. */
   7.473 +   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   7.474 +
   7.475 +   /* Free the resource data. */
   7.476 +   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.477 +      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.478 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.479 +      goto exit;
   7.480 +   }
   7.481 +
   7.482 +   if (found) {
   7.483 +      _SBLIM_TRACE(1,("--- Target instance already exists"));
   7.484 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   7.485 +      goto exit;
   7.486 +   }
   7.487 +
   7.488 +   /* Create a new resource with the new instance property values. */
   7.489 +   int rc = Xen_ConsoleSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   7.490 +   if (rc != 1) {
   7.491 +      if (rc == -1) {
   7.492 +         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   7.493 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   7.494 +      } else {
   7.495 +         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   7.496 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   7.497 +      }
   7.498 +      goto exit;
   7.499 +   }
   7.500 +
   7.501 +   /* Return the object path for the newly created instance. */
   7.502 +   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   7.503 +   CMSetNameSpace(objectpath, namespace);
   7.504 +   CMReturnObjectPath(results, objectpath);
   7.505 +   CMReturnDone(results);
   7.506 +
   7.507 +exit:
   7.508 +   /* Free the list of system resources. */
   7.509 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.510 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.511 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.512 +   }
   7.513 +
   7.514 +   _SBLIM_RETURNSTATUS(status);
   7.515 +}
   7.516 +
   7.517 +// ----------------------------------------------------------------------------
   7.518 +// DeleteInstance()
   7.519 +// Delete or remove the specified instance from the system.
   7.520 +// ----------------------------------------------------------------------------
   7.521 +static CMPIStatus DeleteInstance(
   7.522 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.523 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.524 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.525 +		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   7.526 +{
   7.527 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   7.528 +   _RESOURCES * resources;			/* Handle to the list of system resources. */
   7.529 +   _RESOURCE * resource;		/* Handle to the system resource. */
   7.530 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.531 +   int found = 0;				/* Found the target instance? */
   7.532 +
   7.533 +   _SBLIM_ENTER("DeleteInstance");
   7.534 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.535 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.536 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.537 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.538 +
   7.539 +   if (!xen_utils_validate_session(&session)) {
   7.540 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   7.541 +      goto exit;
   7.542 +   }
   7.543 +
   7.544 +   /* Get a handle to the list of system resources. */
   7.545 +   if (!Xen_ConsoleSettingData_getResources(session, &resources)) {
   7.546 +      _SBLIM_TRACE(1,("--- _getResources() failed"));
   7.547 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   7.548 +      goto exit;
   7.549 +   }
   7.550 +
   7.551 +   /* Get the target resource. */
   7.552 +   found = Xen_ConsoleSettingData_getResourceForObjectPath(session, &resource, reference);
   7.553 +   if (!found || (resource == NULL)) {
   7.554 +      _SBLIM_TRACE(1,("--- Target instance not found"));
   7.555 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   7.556 +      goto exit;
   7.557 +   }
   7.558 +
   7.559 +   _SBLIM_TRACE(2,("--- instance found", found));
   7.560 +
   7.561 +   /* Delete the target resource. */
   7.562 +   int rc = Xen_ConsoleSettingData_deleteResource(resources, resource);
   7.563 +
   7.564 +   /* Free the resource data. */
   7.565 +   if (!Xen_ConsoleSettingData_freeResource(resource)) {
   7.566 +      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   7.567 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   7.568 +      goto exit;
   7.569 +   }
   7.570 +
   7.571 +   if (rc != 1) {
   7.572 +      if (rc == -1) {
   7.573 +         _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
   7.574 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   7.575 +      } else {
   7.576 +         _SBLIM_TRACE(1,("--- _deleteResource() failed"));
   7.577 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
   7.578 +      }
   7.579 +      goto exit;
   7.580 +   }
   7.581 +
   7.582 +exit:
   7.583 +   /* Free the list of system resources. */
   7.584 +   if (!Xen_ConsoleSettingData_freeResources(resources)) {
   7.585 +      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   7.586 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   7.587 +   }
   7.588 +
   7.589 +   _SBLIM_RETURNSTATUS(status);
   7.590 +}
   7.591 +
   7.592 +
   7.593 +// ----------------------------------------------------------------------------
   7.594 +// ExecQuery()
   7.595 +// Return a list of all the instances that satisfy the specified query filter.
   7.596 +// ----------------------------------------------------------------------------
   7.597 +static CMPIStatus ExecQuery(
   7.598 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.599 +		const CMPIContext * context,		/* [in] Additional context info, if any. */
   7.600 +		const CMPIResult * results,		/* [out] Results of this operation. */
   7.601 +		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   7.602 +		const char * language,		/* [in] Name of the query language. */
   7.603 +		const char * query)			/* [in] Text of the query written in the query language. */
   7.604 +{
   7.605 +   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   7.606 +   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   7.607 +
   7.608 +   _SBLIM_ENTER("ExecQuery");
   7.609 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.610 +   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.611 +   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   7.612 +   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   7.613 +   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   7.614 +   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   7.615 +
   7.616 +   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   7.617 +   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   7.618 +
   7.619 +   CMReturnDone(results);
   7.620 +
   7.621 +exit:
   7.622 +   _SBLIM_RETURNSTATUS(status);
   7.623 +}
   7.624 +
   7.625 +// ----------------------------------------------------------------------------
   7.626 +// Initialize()
   7.627 +// Perform any necessary initialization immediately after this provider is
   7.628 +// first loaded.
   7.629 +// ----------------------------------------------------------------------------
   7.630 +static void Initialize(
   7.631 +		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   7.632 +		const CMPIContext * context)		/* [in] Additional context info, if any. */
   7.633 +{
   7.634 +   _SBLIM_ENTER("Initialize");
   7.635 +   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   7.636 +   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   7.637 +
   7.638 +   /* Initialized Xen session object. */
   7.639 +   if (session == NULL)
   7.640 +      xen_utils_xen_init(&session);
   7.641 +   
   7.642 +   _SBLIM_RETURN();
   7.643 +}
   7.644 +
   7.645 +// ============================================================================
   7.646 +// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
   7.647 +// ============================================================================
   7.648 +CMInstanceMIStub( , Xen_ConsoleSettingData, _BROKER, Initialize(&mi, ctx));
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/Xen_ConsoleSettingData_Resource.c	Wed Feb 21 15:46:34 2007 -0700
     8.3 @@ -0,0 +1,305 @@
     8.4 +// Copyright (C) 2007 Novell, Inc
     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:       Jim Fehlig <jfehlig@novell.com>
    8.21 +//
    8.22 +// Contributors:
    8.23 +//
    8.24 +// Description:
    8.25 +// ============================================================================
    8.26 +
    8.27 +#include <stdlib.h>
    8.28 +#include <string.h>
    8.29 +#include <assert.h>
    8.30 +
    8.31 +#include <xen_common.h>
    8.32 +#include <xen_vm.h>
    8.33 +#include <xen_console.h>
    8.34 +
    8.35 +#include "Xen_ConsoleSettingData_Resource.h"
    8.36 +
    8.37 +/* Include the required CMPI data types, function headers, and macros. */
    8.38 +#include "cmpidt.h"
    8.39 +#include "cmpift.h"
    8.40 +#include "cmpimacs.h"
    8.41 +
    8.42 +#include "xen_utils.h"
    8.43 +#include "provider_common.h"
    8.44 +
    8.45 +/* Include _SBLIM_TRACE() logging support */
    8.46 +#include "cmpitrace.h"
    8.47 +
    8.48 +// ----------------------------------------------------------------------------
    8.49 +
    8.50 +static int concat_console_lists(xen_console_set **target, xen_console_set *source)
    8.51 +{
    8.52 +
    8.53 +   int total_size;
    8.54 +   int i, j;
    8.55 +   
    8.56 +   /* Nothing to concatenate if source is empty */
    8.57 +   if (source == NULL || source->size == 0)
    8.58 +      return 1;
    8.59 +   
    8.60 +   /* If targe is empty, assign source to target */
    8.61 +   if (*target == NULL) {
    8.62 +      *target = source;
    8.63 +      return 1;
    8.64 +   }
    8.65 +   
    8.66 +   /* realloc memory and append source to target */
    8.67 +   total_size = (*target)->size + source->size;
    8.68 +   *target = realloc(*target, sizeof(xen_console_set) + (total_size * sizeof(xen_console)));
    8.69 +   if (*target == NULL)
    8.70 +      return 0;
    8.71 +   
    8.72 +   for (j = (*target)->size, i = 0; i < source->size; i++) {
    8.73 +      (*target)->contents[j + i] = source->contents[i];
    8.74 +      source->contents[i] = NULL;
    8.75 +   }
    8.76 +   (*target)->size = total_size;
    8.77 +   
    8.78 +   /* Free source list - it has been copied to target */
    8.79 +   xen_console_set_free(source);
    8.80 +   return 1;
    8.81 +}
    8.82 +
    8.83 +
    8.84 +/* Get a handle to the list of all system resources for this class. */
    8.85 +int Xen_ConsoleSettingData_getResources(xen_utils_session *session,
    8.86 +                                        _RESOURCES ** resources)
    8.87 +{
    8.88 +   xen_domain_resources *res;
    8.89 +   xen_console_set *all_consoles = NULL;
    8.90 +   xen_vm_record *vm_rec = NULL;
    8.91 +   
    8.92 +   /* malloc a new handle for the resources list. */
    8.93 +   *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    8.94 +   if (*resources == NULL)
    8.95 +      return 0;
    8.96 +
    8.97 +   /* Get a list of domain resources. */
    8.98 +   if (!xen_utils_get_domain_resources(session, &res)) {
    8.99 +      *resources = NULL;
   8.100 +      return 0;
   8.101 +   }
   8.102 +
   8.103 +   /* Create list of console resources from consoles found in each domain. */
   8.104 +   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   8.105 +      xen_console_set *console_set;
   8.106 +      if (!xen_vm_get_consoles(session->xen, &console_set, vm_rec->handle))
   8.107 +         goto Error;
   8.108 +      
   8.109 +      if (!concat_console_lists(&all_consoles, console_set))
   8.110 +         goto Error;
   8.111 +      
   8.112 +      xen_vm_record_free(vm_rec);
   8.113 +   }
   8.114 +   
   8.115 +   (*resources)->consoles = all_consoles;
   8.116 +   (*resources)->currentconsolenum = 0;
   8.117 +   
   8.118 +   return 1;
   8.119 +   
   8.120 + Error:
   8.121 +   xen_vm_record_free(vm_rec);
   8.122 +   xen_utils_free_domain_resources(res);
   8.123 +   free(*resources);
   8.124 +   *resources = NULL;
   8.125 +   return 0;
   8.126 +}
   8.127 +
   8.128 +// ----------------------------------------------------------------------------
   8.129 +
   8.130 +/* Free/deallocate/cleanup the resources list after use. */
   8.131 +int Xen_ConsoleSettingData_freeResources(_RESOURCES * resources)
   8.132 +{
   8.133 +   if (resources != NULL) {
   8.134 +       if (resources->consoles != NULL)
   8.135 +          xen_console_set_free(resources->consoles);
   8.136 +       free(resources);
   8.137 +       resources = NULL;
   8.138 +   }
   8.139 +   
   8.140 +   return 1;
   8.141 +}
   8.142 +
   8.143 +// ----------------------------------------------------------------------------
   8.144 +
   8.145 +/* Iterator to get the next resource from the resources list. */
   8.146 +int Xen_ConsoleSettingData_getNextResource(xen_utils_session *session,
   8.147 +                                           _RESOURCES * resources,
   8.148 +                                           _RESOURCE ** resource)
   8.149 +{
   8.150 +   if (resources == NULL || resources->consoles == NULL)
   8.151 +      return 0;
   8.152 +
   8.153 +   /* Check if reached the end of the list of consoles. */
   8.154 +   if (resources->currentconsolenum == resources->consoles->size)
   8.155 +      return 0;
   8.156 +
   8.157 +   /* Get the current console record. */
   8.158 +   if (!xen_console_get_record(session->xen, resource, resources->consoles->contents[resources->currentconsolenum]))
   8.159 +      return 0;
   8.160 +   
   8.161 +   resources->currentconsolenum++;
   8.162 +   return 1;
   8.163 +}
   8.164 +
   8.165 +// ----------------------------------------------------------------------------
   8.166 +
   8.167 +/* Get the specific resource that matches the CMPI object path. */
   8.168 +int Xen_ConsoleSettingData_getResourceForObjectPath(xen_utils_session *session,
   8.169 +                                                    _RESOURCE ** resource,
   8.170 +                                                    const CMPIObjectPath * objectpath)
   8.171 +{
   8.172 +   char *instId;
   8.173 +   char uuid[MAX_SYSTEM_NAME_LEN];
   8.174 +   int ccode;
   8.175 +   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   8.176 +
   8.177 +   if (CMIsNullObject(objectpath)) return 0;
   8.178 +
   8.179 +   /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
   8.180 +   CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
   8.181 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
   8.182 +
   8.183 +   instId = CMGetCharPtr(iddata.value.string);
   8.184 +   if ((instId == NULL) || (*instId == '\0')) return 0;
   8.185 +
   8.186 +   /* Extract the console uuid from InstanceID property. */
   8.187 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, instId, MAX_SYSTEM_NAME_LEN))
   8.188 +      return 0;
   8.189 +
   8.190 +   xen_console console;
   8.191 +   if (!xen_console_get_by_uuid(session->xen, &console, uuid))
   8.192 +      return 0;
   8.193 +
   8.194 +   ccode = xen_console_get_record(session->xen, resource, console);
   8.195 +   xen_console_free(console);
   8.196 +   return ccode;
   8.197 +}
   8.198 +
   8.199 +// ----------------------------------------------------------------------------
   8.200 +
   8.201 +/* Free/deallocate/cleanup the resource after use. */
   8.202 +int Xen_ConsoleSettingData_freeResource(_RESOURCE * resource)
   8.203 +{
   8.204 +   xen_console_record_free(resource);
   8.205 +   return 1;
   8.206 +}
   8.207 +
   8.208 +// ---------------------------------------------------------------------------- 
   8.209 +
   8.210 +/* Set the property values of a CMPI instance from a specific resource. */
   8.211 +int Xen_ConsoleSettingData_setInstanceFromResource(xen_utils_session *session,
   8.212 +                                                   _RESOURCE * resource,
   8.213 +                                                   const CMPIInstance * instance,
   8.214 +                                                   const CMPIBroker * broker)
   8.215 +{
   8.216 +   char buf[MAX_INSTANCEID_LEN];
   8.217 +   xen_vm_record *alloced_vm_rec = NULL;
   8.218 +   xen_vm_record *vm_rec;
   8.219 +   
   8.220 +   if (resource == NULL) return 0;
   8.221 +   if (CMIsNullObject(instance)) return 0;
   8.222 +
   8.223 +   xen_vm_record_opt *vm_rec_opt = resource->vm;
   8.224 +   if (vm_rec_opt->is_record) {
   8.225 +      vm_rec = vm_rec_opt->u.record;
   8.226 +   }
   8.227 +   else {
   8.228 +      if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) {
   8.229 +      /* Error description in session object! */
   8.230 +         return 0;
   8.231 +      }
   8.232 +      alloced_vm_rec = vm_rec;
   8.233 +   }
   8.234 +
   8.235 +   /* Set the CMPIInstance properties from the resource data. */
   8.236 +   snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec->name_label, resource->uuid);
   8.237 +   CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
   8.238 +   CMSetProperty(instance, "ElementName",(CMPIValue *)"Console", CMPI_chars);
   8.239 +
   8.240 +   int type = 24; /* 24 == Graphics Controller */
   8.241 +   CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
   8.242 +
   8.243 +   int consumerVisibility = 3; /* 3 == Virtualized */
   8.244 +   CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
   8.245 +
   8.246 +   unsigned long long consoles = 1;
   8.247 +   CMSetProperty(instance, "Reservation",(CMPIValue *)&consoles, CMPI_uint64);
   8.248 +   CMSetProperty(instance, "Limit",(CMPIValue *)&consoles, CMPI_uint64);
   8.249 +   CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Console Devices", CMPI_chars);
   8.250 +   CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&consoles, CMPI_uint64);
   8.251 +
   8.252 +   int alloctype = 1;
   8.253 +   CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   8.254 +   CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
   8.255 +
   8.256 +   if (resource->uri)
   8.257 +      CMSetProperty(instance, "URI", (CMPIValue *)resource->uri, CMPI_chars);
   8.258 +
   8.259 +   int protocol = -1;
   8.260 +   if (resource->protocol == XEN_CONSOLE_PROTOCOL_VT100)
   8.261 +      protocol = 0; /* 0 == VT100 */
   8.262 +   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RFB)
   8.263 +      protocol = 1; /* 1 == VNC */
   8.264 +   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RDP)
   8.265 +      protocol = 2; /* 2 == SDL */
   8.266 +
   8.267 +   if (protocol != -1)
   8.268 +      CMSetProperty(instance, "Protocol",(CMPIValue *)&protocol, CMPI_uint16);
   8.269 +
   8.270 +   if (alloced_vm_rec)
   8.271 +      xen_vm_record_free(alloced_vm_rec);
   8.272 +
   8.273 +   return 1;
   8.274 +}
   8.275 +
   8.276 +// ----------------------------------------------------------------------------
   8.277 +
   8.278 +/* Delete the specified resource from the system. */
   8.279 +int Xen_ConsoleSettingData_deleteResource(_RESOURCES * resources,
   8.280 +                                          _RESOURCE * resource)
   8.281 +{
   8.282 +   /* Unsupported. */
   8.283 +   return -1;
   8.284 +}
   8.285 +
   8.286 +// ----------------------------------------------------------------------------
   8.287 +
   8.288 +/* Modify the specified resource using the property values of a CMPI instance. */
   8.289 +int Xen_ConsoleSettingData_setResourceFromInstance(_RESOURCE * resource,
   8.290 +                                                   const CMPIInstance * instance,
   8.291 +                                                   const CMPIBroker * broker)
   8.292 +{
   8.293 +   /* Unsupported. */
   8.294 +   return -1;
   8.295 +}
   8.296 +
   8.297 +// ----------------------------------------------------------------------------
   8.298 +
   8.299 +/* Create a new resource using the property values of a CMPI instance. */
   8.300 +int Xen_ConsoleSettingData_createResourceFromInstance(_RESOURCES * resources,
   8.301 +                                                      _RESOURCE ** resource,
   8.302 +                                                      const CMPIInstance * instance,
   8.303 +                                                      const CMPIBroker * broker)
   8.304 +{
   8.305 +   /* Unsupported. */
   8.306 +   return -1;
   8.307 +}
   8.308 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/Xen_ConsoleSettingData_Resource.h	Wed Feb 21 15:46:34 2007 -0700
     9.3 @@ -0,0 +1,107 @@
     9.4 +// Copyright (C) 2007 Novell, Inc.
     9.5 +//
     9.6 +//    This library is free software; you can redistribute it and/or
     9.7 +//    modify it under the terms of the GNU Lesser General Public
     9.8 +//    License as published by the Free Software Foundation; either
     9.9 +//    version 2.1 of the License, or (at your option) any later version.
    9.10 +//
    9.11 +//    This library is distributed in the hope that it will be useful,
    9.12 +//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.13 +//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.14 +//    Lesser General Public License for more details.
    9.15 +//
    9.16 +//    You should have received a copy of the GNU Lesser General Public
    9.17 +//    License along with this library; if not, write to the Free Software
    9.18 +//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.19 +// ============================================================================
    9.20 +// Authors:       Jim Fehlig <jfehlig@novell.com>
    9.21 +//
    9.22 +// Contributors:
    9.23 +//
    9.24 +// Description:
    9.25 +// ============================================================================
    9.26 +#if !defined(__XEN_CONSOLESETTINGDATA_RESOURCE_H__)
    9.27 +#define __XEN_CONSOLESETTINGDATA_RESOURCE_H__
    9.28 +
    9.29 +/* Include required libxen headers. */
    9.30 +#include <xen_common.h>
    9.31 +#include <xen_console.h>
    9.32 +
    9.33 +#include "xen_utils.h"
    9.34 +
    9.35 +/*** CUSTOMIZE FOR EACH PROVIDER ***/
    9.36 +/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES.
    9.37 +   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS
    9.38 +   LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC.
    9.39 +   THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN
    9.40 +   ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */
    9.41 +typedef struct {
    9.42 +   xen_console_set *consoles;
    9.43 +   unsigned int currentconsolenum;
    9.44 +} _RESOURCES;
    9.45 +
    9.46 +/*** CUSTOMIZE FOR EACH PROVIDER ***/
    9.47 +/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE.
    9.48 +   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH
    9.49 +   RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE
    9.50 +   PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE
    9.51 +   ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */
    9.52 +typedef xen_console_record  _RESOURCE;
    9.53 +
    9.54 +/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */
    9.55 +
    9.56 +/* Include the required CMPI data types. */
    9.57 +#include "cmpidt.h"
    9.58 +
    9.59 +// ----------------------------------------------------------------------------
    9.60 +// Generic resource access methods for CMPI providers.
    9.61 +// Return value:
    9.62 +//	-1 = Unsupported
    9.63 +//	 0 = Failed
    9.64 +//	 1 = OK
    9.65 +// ----------------------------------------------------------------------------
    9.66 +
    9.67 +/* Get a handle to the list of all system resources for this class. */
    9.68 +int Xen_ConsoleSettingData_getResources(xen_utils_session *session,
    9.69 +                                        _RESOURCES ** resources);
    9.70 +
    9.71 +/* Free/deallocate/cleanup the resources list after use. */
    9.72 +int Xen_ConsoleSettingData_freeResources(_RESOURCES * resources);
    9.73 +
    9.74 +/* Iterator to get the next resource from the resources list. */
    9.75 +int Xen_ConsoleSettingData_getNextResource(xen_utils_session *session,
    9.76 +                                           _RESOURCES * resources,
    9.77 +                                           _RESOURCE ** resource);
    9.78 +
    9.79 +/* Get the specific resource that matches the CMPI object path. */
    9.80 +int Xen_ConsoleSettingData_getResourceForObjectPath(xen_utils_session *session,
    9.81 +                                                    _RESOURCE ** resource,
    9.82 +                                                    const CMPIObjectPath * objectpath);
    9.83 +
    9.84 +/* Free/deallocate/cleanup a resource after use. */
    9.85 +int Xen_ConsoleSettingData_freeResource(_RESOURCE * resource);
    9.86 +
    9.87 +/* Set the property values of a CMPI instance from a specific resource. */
    9.88 +int Xen_ConsoleSettingData_setInstanceFromResource(xen_utils_session *session,
    9.89 +                                                   _RESOURCE * resource,
    9.90 +                                                   const CMPIInstance * instance,
    9.91 +                                                   const CMPIBroker * broker);
    9.92 +
    9.93 +// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS
    9.94 +
    9.95 +/* Delete the specified resource from the system. */
    9.96 +int Xen_ConsoleSettingData_deleteResource(_RESOURCES * resources,
    9.97 +                                          _RESOURCE * resource);
    9.98 +
    9.99 +/* Modify the specified resource using the property values of a CMPI instance. */
   9.100 +int Xen_ConsoleSettingData_setResourceFromInstance(_RESOURCE * resource,
   9.101 +                                                   const CMPIInstance * instance,
   9.102 +                                                   const CMPIBroker * broker);
   9.103 +
   9.104 +/* Create a new resource using the property values of a CMPI instance. */
   9.105 +int Xen_ConsoleSettingData_createResourceFromInstance(_RESOURCES * resources,
   9.106 +                                                      _RESOURCE ** resource,
   9.107 +                                                      const CMPIInstance * instance,
   9.108 +                                                      const CMPIBroker * broker);
   9.109 +
   9.110 +#endif /* __XEN_CONSOLESETTINGDATA_RESOURCE_H__ */
    10.1 --- a/src/Xen_Console_Resource.c	Wed Feb 21 12:26:23 2007 -0700
    10.2 +++ b/src/Xen_Console_Resource.c	Wed Feb 21 15:46:34 2007 -0700
    10.3 @@ -244,17 +244,16 @@ int Xen_Console_setInstanceFromResource(
    10.4     if (resource->uri)
    10.5        CMSetProperty(instance, "URI", (CMPIValue *)resource->uri, CMPI_chars);
    10.6  
    10.7 -   switch (resource->protocol) {
    10.8 -      case XEN_CONSOLE_PROTOCOL_VT100:
    10.9 -         CMSetProperty(instance, "Protocol",(CMPIValue *)"VT100", CMPI_chars);
   10.10 -         break;
   10.11 -      case XEN_CONSOLE_PROTOCOL_RFB:
   10.12 -         CMSetProperty(instance, "Protocol",(CMPIValue *)"Remote Framebuffer (VNC)", CMPI_chars);
   10.13 -         break;
   10.14 -      case XEN_CONSOLE_PROTOCOL_RDP:
   10.15 -         CMSetProperty(instance, "Protocol",(CMPIValue *)"Remote Desktop (SDL)", CMPI_chars);
   10.16 -         break;
   10.17 -   }
   10.18 +   int protocol = -1;
   10.19 +   if (resource->protocol == XEN_CONSOLE_PROTOCOL_VT100)
   10.20 +      protocol = 0; /* 0 == VT100 */
   10.21 +   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RFB)
   10.22 +      protocol = 1; /* 1 == VNC */
   10.23 +   else if (resource->protocol == XEN_CONSOLE_PROTOCOL_RDP)
   10.24 +      protocol = 2; /* 2 == SDL */
   10.25 +
   10.26 +   if (protocol != -1)
   10.27 +      CMSetProperty(instance, "Protocol",(CMPIValue *)&protocol, CMPI_uint16);
   10.28  
   10.29     if (alloced_vm_rec)
   10.30        xen_vm_record_free(alloced_vm_rec);