summaryrefslogtreecommitdiffstats
path: root/src/power
diff options
context:
space:
mode:
authorRadek Novacek <rnovacek@redhat.com>2012-07-23 12:41:11 +0200
committerRadek Novacek <rnovacek@redhat.com>2012-07-23 12:41:11 +0200
commit7bc4421f26954c2acd817c690cbbde03a4391878 (patch)
tree85bd87c085bab9fe8bf8c62ee8e41f95d283e977 /src/power
parent8061ba1c48f6b8448a458d1919cd6520e2e4a658 (diff)
downloadopenlmi-providers-7bc4421f26954c2acd817c690cbbde03a4391878.tar.gz
openlmi-providers-7bc4421f26954c2acd817c690cbbde03a4391878.tar.xz
openlmi-providers-7bc4421f26954c2acd817c690cbbde03a4391878.zip
Move all providers to src/ directory
Diffstat (limited to 'src/power')
-rw-r--r--src/power/CMakeLists.txt19
-rw-r--r--src/power/Linux_PowerManagement.mof58
-rwxr-xr-xsrc/power/provider-register.sh755
-rwxr-xr-xsrc/power/sblim_cmpi_power_test.py52
-rw-r--r--src/power/src/CMakeLists.txt70
-rw-r--r--src/power/src/Linux_AssociatedPowerManagementServiceProvider.c294
-rw-r--r--src/power/src/Linux_ConcreteJobProvider.c206
-rw-r--r--src/power/src/Linux_ElementCapabilitiesProvider.c225
-rw-r--r--src/power/src/Linux_HostedServiceProvider.c258
-rw-r--r--src/power/src/Linux_PowerManagementCapabilitiesProvider.c162
-rw-r--r--src/power/src/Linux_PowerManagementServiceProvider.c278
-rw-r--r--src/power/src/globals.c24
-rw-r--r--src/power/src/globals.h7
-rw-r--r--src/power/src/power.c517
-rw-r--r--src/power/src/power.h56
-rw-r--r--src/power/src/trace.c29
-rw-r--r--src/power/src/trace.h4
17 files changed, 3014 insertions, 0 deletions
diff --git a/src/power/CMakeLists.txt b/src/power/CMakeLists.txt
new file mode 100644
index 0000000..72087b7
--- /dev/null
+++ b/src/power/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+cmake_minimum_required (VERSION 2.6)
+
+set(CMAKE_C_FLAGS "-std=c99 -Wall -pedantic -g")
+
+add_subdirectory(src)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set(LIB_SUFFIX "")
+else(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ SET(LIB_SUFFIX 64)
+endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/Linux_PowerManagement.registration DESTINATION share/sblim-cmpi-power/)
+install(FILES Linux_PowerManagement.mof DESTINATION share/sblim-cmpi-power/)
+install(FILES provider-register.sh DESTINATION share/sblim-cmpi-power/)
+
+add_custom_target(register
+ ${CMAKE_CURRENT_SOURCE_DIR}/provider-register.sh -m ${CMAKE_CURRENT_SOURCE_DIR}/Linux_PowerManagement.mof -r ${CMAKE_CURRENT_BINARY_DIR}/src/Linux_PowerManagement.registration)
diff --git a/src/power/Linux_PowerManagement.mof b/src/power/Linux_PowerManagement.mof
new file mode 100644
index 0000000..21dfa38
--- /dev/null
+++ b/src/power/Linux_PowerManagement.mof
@@ -0,0 +1,58 @@
+[ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_PowerManagementService: CIM_PowerManagementService
+{
+};
+
+[ Association,
+ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_AssociatedPowerManagementService: CIM_AssociatedPowerManagementService
+{
+ [ Override ("ServiceProvided"),
+ Max ( 1 ),
+ Description ( "The Service that is available." )]
+ Linux_PowerManagementService REF ServiceProvided;
+
+ [ Override ("UserOfService"),
+ Description ( "The ManagedElement that can use the Service." )]
+ Linux_ComputerSystem REF UserOfService;
+};
+
+[ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_PowerManagementCapabilities: CIM_PowerManagementCapabilities
+{
+};
+
+[ Association,
+ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_HostedService: CIM_HostedService
+{
+ [ Override ("Antecedent"),
+ Min ( 1 ),
+ Max ( 1 ),
+ Description ( "The hosting System." )]
+ Linux_ComputerSystem REF Antecedent;
+
+ [ Override ( "Dependent" ),
+ Weak,
+ Description ( "The Service hosted on the System." )]
+ Linux_PowerManagementService REF Dependent;
+};
+
+[ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_ConcreteJob: CIM_ConcreteJob
+{
+};
+
+[ Provider("cmpi:cmpiLinux_PowerManagement") ]
+class Linux_ElementCapabilities: CIM_ElementCapabilities
+{
+ [ Key,
+ Min ( 1 ),
+ Description ( "The managed element." )]
+ Linux_PowerManagementService REF ManagedElement;
+
+ [ Key,
+ Description ( "The Capabilities object associated with the element." )]
+ Linux_PowerManagementCapabilities REF Capabilities;
+};
+
diff --git a/src/power/provider-register.sh b/src/power/provider-register.sh
new file mode 100755
index 0000000..b156427
--- /dev/null
+++ b/src/power/provider-register.sh
@@ -0,0 +1,755 @@
+#!/bin/sh
+# $Id: provider-register.sh,v 1.9 2009/05/23 02:52:50 tyreld Exp $
+# ==================================================================
+# (C) Copyright IBM Corp. 2002, 2009, 2009
+#
+# THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
+# ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
+# CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
+#
+# You can obtain a current copy of the Eclipse Public License from
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
+# Contributors:
+# Description: Script to install class definitions (MOFs) and
+# registration data for a variety of supported CIMOMs
+# ==================================================================
+
+pegasus_repository()
+{
+ for p in $PEGASUS_HOME /var/lib/Pegasus /var/lib/pegasus \
+ /usr/local/var/lib/pegasus /var/local/lib/pegasus /var/opt/tog-pegasus
+ do
+ if test -d $p/repository
+ then
+ echo $p/$1
+ return 0
+ fi
+ done
+ return 1
+}
+
+pegasus_path()
+{
+ for p in $PEGASUS_HOME/bin /usr/bin /usr/sbin /usr/local/bin \
+ /usr/local/sbin /opt/tog-pegasus/bin /opt/tog-pegasus/sbin
+ do
+ if test -x $p/$1
+ then
+ echo $p/$1
+ return 0
+ fi
+ done
+ return 1
+}
+
+pegasus_transform()
+{
+ OUTFILE=$1
+ shift
+ regfiles=$*
+ PROVIDERMODULES=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
+ if test x"$PROVIDERMODULES" = x
+ then
+ echo Failed to read registration files >&2
+ return 1
+ fi
+ PROVIDERS=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 3-4 | sort | uniq`
+
+# produce ProviderModules
+ echo > $OUTFILE
+ chatter "Processing provider modules:" $PROVIDERMODULES
+ for pm in $PROVIDERMODULES
+ do
+ cat >> $OUTFILE <<EOFPM
+instance of PG_ProviderModule
+{
+ Name = "$pm";
+ Location = "$pm";
+ Vendor = "SBLIM";
+ Version = "2.0.0";
+ InterfaceType = "CMPI";
+ InterfaceVersion = "2.0.0";
+};
+
+EOFPM
+ done
+
+# produce Providers
+ set -- $PROVIDERS
+ while test x$1 != x
+ do
+ cat >> $OUTFILE <<EOFP
+instance of PG_Provider
+{
+ Name = "$1";
+ ProviderModuleName = "$2";
+};
+
+EOFP
+ shift 2
+ done
+
+#produce Capabilities
+ let serial=0
+ for rf in $regfiles
+ do
+ cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
+ do
+ let serial=serial+1
+ numcap=
+ for cap in $CAPS
+ do
+ case $cap in
+ instance)
+ if test x$numcap = x
+ then numcap=2
+ else numcap="$numcap, 2"
+ fi;;
+ association)
+ if test x$numcap = x
+ then numcap=3
+ else numcap="$numcap, 3"
+ fi;;
+ indication)
+ if test x$numcap = x
+ then numcap=4
+ else numcap="$numcap, 4"
+ fi;;
+ method)
+ if test x$numcap = x
+ then numcap=5
+ else numcap="$numcap, 5"
+ fi;;
+ **) echo unknown provider type $cap >&2
+ return 1;;
+ esac
+ done
+ cat >> $OUTFILE <<EOFC
+instance of PG_ProviderCapabilities
+{
+ ProviderModuleName = "$PROVIDERMODULE";
+ ProviderName = "$PROVIDERNAME";
+ ClassName = "$CLASSNAME";
+ ProviderType = { $numcap };
+ Namespaces = {"$NAMESPACE"};
+ SupportedProperties = NULL;
+ SupportedMethods = NULL;
+ CapabilityID = "$CLASSNAME-$serial";
+};
+
+EOFC
+ done
+ done
+}
+
+pegasus_install()
+{
+ if ps -C cimserver > /dev/null 2>&1
+ then
+ CIMMOF=`pegasus_path cimmof`
+ if test $? != 0
+ then
+ echo "Error: cimmof not found" >&2
+ return 1
+ fi
+ state=active
+ else
+ CIMMOF=`pegasus_path cimmofl`
+ if test $? != 0
+ then
+ echo "Error: cimmofl not found" >&2
+ return 1
+ fi
+ PEGASUSREPOSITORY=`pegasus_repository`
+ if test $? != 0
+ then
+ echo "Error: pegasus repository not found" >&2
+ return 1
+ fi
+ CIMMOF="$CIMMOF -R $PEGASUSREPOSITORY"
+ state=inactive
+ fi
+
+ mofpath=
+ mymofs=
+ myregs=
+ mofmode=1
+ namespace=$1
+ shift
+
+ while test x$1 != x
+ do
+ if test $1 = ":"
+ then
+ mofmode=0
+ shift
+ continue
+ fi
+ if test $mofmode = 1
+ then
+ if test x$mofpath = x
+ then
+ mofpath=`dirname $1`
+ fi
+ mymofs="$mymofs $1"
+ else
+ myregs="$myregs $1"
+ fi
+ shift
+ done
+
+ for _TEMPDIR in /var/tmp /tmp
+ do
+ if test -w $_TEMPDIR
+ then
+ _REGFILENAME=$_TEMPDIR/$$.mof
+ break
+ fi
+ done
+
+
+ trap "rm -f $_REGFILENAME" EXIT
+
+ if pegasus_transform $_REGFILENAME $myregs
+ then
+ chatter Registering providers with $state cimserver
+ $CIMMOF -uc -I $mofpath -n $namespace $mymofs &&
+ $CIMMOF -uc -n root/PG_Interop $_REGFILENAME
+ else
+ echo "Failed to build pegasus registration MOF." >&2
+ return 1
+ fi
+}
+
+pegasus_uninstall()
+{
+ mymofs=
+ myregs=
+ mofmode=1
+ namespace=$1
+ shift
+
+ while test x$1 != x
+ do
+ if test $1 = ":"
+ then
+ mofmode=0
+ shift
+ continue
+ fi
+ if test $mofmode = 1
+ then
+ mymofs="$mymofs $1"
+ else
+ myregs="$myregs $1"
+ fi
+ shift
+ done
+
+ if ps -C cimserver > /dev/null 2>&1
+ then
+ PROVIDERMODULES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
+ if test x"$PROVIDERMODULES" = x
+ then
+ echo Failed to read registration files >&2
+ return 1
+ fi
+ CIMPROVIDER=`pegasus_path cimprovider`
+ if test $? != 0
+ then
+ echo "Error: cimprovider not found" >&2
+ return 1
+ fi
+ for pm in $PROVIDERMODULES
+ do
+ chatter "Remove provider module" $pm
+ $CIMPROVIDER -d -m $pm > /dev/null &&
+ $CIMPROVIDER -r -m $pm > /dev/null
+ done
+ WBEMEXEC=`pegasus_path wbemexec`
+ if test $? != 0
+ then
+ echo "Error: wbemexec not found" >&2
+ return 1
+ fi
+ CLASSES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 1 | grep -v '^CIM_'`
+
+ for _TEMPDIR in /var/tmp /tmp
+ do
+ if test -w $_TEMPDIR
+ then
+ _DELETE_NAME=$TEMPDIR/delete-class.mof
+ break
+ fi
+ done
+
+ trap "rm -f $_DELETE_NAME" EXIT
+
+ for cls in $CLASSES
+ do
+ chatter Delete CIM Class $cls
+ cat > $_DELETE_NAME <<EOFA
+<?xml version="1.0" encoding="utf-8" ?>
+<CIM CIMVERSION="2.0" DTDVERSION="2.0">
+ <MESSAGE ID="4711" PROTOCOLVERSION="1.0">
+ <SIMPLEREQ>
+ <IMETHODCALL NAME="DeleteClass">
+ <LOCALNAMESPACEPATH>
+EOFA
+ for ns in `echo $namespace | sed 's?/? ?'g`
+ do
+ cat >> $_DELETE_NAME <<EOFX
+ <NAMESPACE NAME="$ns"></NAMESPACE>
+EOFX
+ done
+ cat >> $_DELETE_NAME <<EOFE
+ </LOCALNAMESPACEPATH>
+ <IPARAMVALUE NAME="ClassName">
+ <CLASSNAME NAME="$cls"/>
+ </IPARAMVALUE>
+ </IMETHODCALL>
+ </SIMPLEREQ>
+ </MESSAGE>
+</CIM>
+EOFE
+ $WBEMEXEC > /dev/null $_DELETE_NAME
+ done
+ else
+ echo "Sorry, cimserver must be running to deregister the providers." >&2
+ return 1
+ fi
+}
+
+sfcb_transform()
+{
+ OUTFILE=$1
+ shift
+ regfiles=$*
+
+#produce sfcb registraion
+ for rf in $regfiles
+ do
+ cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
+ do
+ chatter "Registering class" $CLASSNAME
+ cat >> $OUTFILE <<EOFC
+[$CLASSNAME]
+ provider: $PROVIDERNAME
+ location: $PROVIDERMODULE
+ type: $CAPS
+ namespace: $NAMESPACE
+#
+EOFC
+ done
+ done
+}
+
+sfcb_rebuild()
+{
+ if ps -C sfcbd > /dev/null 2>&1
+ then
+ # sfcb is running -- need to restart
+ for INITSCRIPT in /etc/init.d/sfcb /usr/local/etc/init.d/sfcb none
+ do
+ if test -x $INITSCRIPT
+ then
+ break;
+ fi
+ done
+ chatter "Shutting down sfcb."
+ if test $INITSCRIPT = none
+ then
+ killall sfcbd
+ else
+ $INITSCRIPT stop
+ fi
+ t=0
+ while ps -C sfcbd > /dev/null 2>&1
+ do
+ sleep 1
+ t=`expr $t + 1`
+ if test $t -gt 10
+ then
+ echo "Timed out waiting for sfcb shutdown..." >&2
+ echo "Please stop sfcb manually and rebuild the repository using sfcbrepos." >&2
+ return 1
+ fi
+ done
+ chatter "Rebuilding repository."
+ sfcbrepos -f $endian
+ if test $? != 0
+ then
+ echo "Repository rebuild failed." >&2
+ return 1
+ fi
+
+ if test $INITSCRIPT = none
+ then
+ echo "No init script found - you need to start sfcbd manually." >&2
+ return 1
+ else
+ chatter "Restarting sfcb."
+ $INITSCRIPT start
+ fi
+ else
+ # Not running - rebuild repository
+ chatter "Rebuilding repository."
+ sfcbrepos -f $endian
+ fi
+}
+
+sfcb_install()
+{
+ mymofs=
+ myregs=
+ mofmode=1
+ namespace=$1
+ shift
+
+ while test x$1 != x
+ do
+ if test $1 = ":"
+ then
+ mofmode=0
+ shift
+ baseregname=`basename $1 .registration`
+ continue
+ fi
+ if test $mofmode = 1
+ then
+ mymofs="$mymofs $1"
+ else
+ myregs="$myregs $1"
+ fi
+ shift
+ done
+
+ for _TEMPDIR in /var/tmp /tmp
+ do
+ if test -w $_TEMPDIR
+ then
+ _REGFILENAME=$_TEMPDIR/$baseregname.reg
+ break
+ fi
+ done
+
+ trap "rm -f $_REGFILENAME" EXIT
+
+ if sfcb_transform $_REGFILENAME $myregs
+ then
+ chatter "Staging provider registration."
+ sfcbstage -n $namespace -r $_REGFILENAME $mymofs
+ if test $? != 0
+ then
+ echo "Failed to stage provider registration." >&2
+ return 1
+ fi
+ sfcb_rebuild
+ else
+ echo "Failed to build sfcb registration file." >&2
+ return 1
+ fi
+}
+
+sfcb_uninstall()
+{
+ mymofs=
+ namespace=$1
+ shift
+
+ while test x$1 != x
+ do
+ if test $1 = ":"
+ then
+ shift
+ baseregname=`basename $1 .registration`
+ break
+ fi
+ mymofs="$mymofs `basename $1`"
+ shift
+ done
+
+ # "Unstage" MOFs and the registration file
+ chatter "Unstaging provider registrations."
+ sfcbunstage -n $namespace -r $baseregname.reg $mymofs
+
+ # Rebuild repository
+ sfcb_rebuild
+}
+
+openwbem_transform()
+{
+ OUTFILE=$1
+ shift
+ moffiles=$*
+
+ if rm -f $OUTFILE
+ then
+ for _f in $moffiles
+ do
+ sed "s/Provider *( *\"cmpi:/Provider(\"cmpi::/g" < $_f >> $OUTFILE
+ done
+ fi
+}
+
+openwbem_repository()
+{
+ for p in /var/lib/openwbem /usr/local/var/openwbem
+ do
+ if test -f $p/schema.dat
+ then
+ echo $p
+ return 0
+ fi
+ done
+ return 1
+}
+
+openwbem_install()
+{
+ CIMMOF=`which owmofc 2> /dev/null`
+ if test $? != 0
+ then
+ echo "Error: cimmof not found" >&2
+ return 1
+ fi
+
+ if ps -C owcimomd > /dev/null 2>&1
+ then
+ state=active
+ else
+ CIMMOF="$CIMMOF -d `openwbem_repository`"
+ if test $? != 0
+ then
+ echo "Error: OpenWBEM repository not found" >&2
+ return 1
+ fi
+ state=inactive
+ fi
+
+ for _TEMPDIR in /var/tmp /tmp
+ do
+ if test -w $_TEMPDIR
+ then
+ _REGFILENAME=$_TEMPDIR/$$.mof
+ break
+ fi
+ done
+
+ trap "rm -f $_REGFILENAME" EXIT
+
+ if openwbem_transform $_REGFILENAME $*
+ then
+ chatter Registering providers with $state owcimomd
+ $CIMMOF $_REGFILENAME > /dev/null
+ else
+ echo "Failed to build OpenWBEM registration MOF." >&2
+ return 1
+ fi
+}
+
+openwbem_uninstall()
+{
+ CIMMOF=`which owmofc 2> /dev/null`
+ if test $? != 0
+ then
+ echo "Error: cimmof not found" >&2
+ return 1
+ fi
+
+ if ps -C owcimomd > /dev/null 2>&1
+ then
+ state=active
+ else
+ CIMMOF="$CIMMOF -d `openwbem_repository`"
+ if test $? != 0
+ then
+ echo "Error: OpenWBEM repository not found" >&2
+ return 1
+ fi
+ state=inactive
+ fi
+
+ for _TEMPDIR in /var/tmp /tmp
+ do
+ if test -w $_TEMPDIR
+ then
+ _REGFILENAME=$_TEMPDIR/$$.mof
+ break
+ fi
+ done
+
+ trap "rm -f $_REGFILENAME" EXIT
+
+ if openwbem_transform $_REGFILENAME $*
+ then
+ chatter Deregistering providers with $state owcimomd
+ $CIMMOF -r $_REGFILENAME > /dev/null
+ else
+ echo "Failed to build OpenWBEM registration MOF." >&2
+ return 1
+ fi
+}
+
+cim_server()
+{
+ for exname in sfcbd cimserver owcimomd
+ do
+ if pegasus_path $exname > /dev/null
+ then
+ case $exname in
+ sfcbd) echo sfcb; return 0;;
+ cimserver) echo pegasus; return 0;;
+ owcimomd) echo openwbem; return 0;;
+ esac
+ break;
+ fi
+ done
+ echo unknown
+ return 1
+}
+
+usage()
+{
+ echo "usage: $0 [-h] [-v] [-d] [-t <cimserver>] [-n <namespace>] -r regfile ... -m mof ..."
+}
+
+chatter()
+{
+ if test x$verbose != x
+ then
+ echo $*
+ fi
+}
+
+gb_getopt()
+{
+ rmode=0
+ mmode=0
+ options=
+ moffiles=
+ registrations=
+ while [ -n "$1" ]
+ do
+ case $1 in
+ -r) mmode=0;
+ rmode=1;
+ shift;;
+ -m) mmode=1;
+ rmode=0;
+ shift;;
+ -*) mmode=0;
+ rmode=0;
+ options="$options $1";
+ shift;;
+ **) if [ $mmode = 1 ]
+ then moffiles="$moffiles $1"
+ elif [ $rmode = 1 ]
+ then registrations="$registrations -r $1"
+ else options="$options $1";
+ fi;
+ shift;;
+ esac
+ done
+ echo $options $registrations $moffiles
+}
+
+prepargs=`gb_getopt $*`
+args=`getopt dvhX:t:r:n: $prepargs`
+rc=$?
+
+if [ $rc = 127 ]
+then
+ echo "warning: getopt not found ...continue without syntax check"
+ args=$prepargs
+elif [ $rc != 0 ]
+then
+ usage $0
+ exit 1
+fi
+
+namespace="root/cimv2"
+
+set -- $args
+
+while [ -n "$1" ]
+do
+ case $1 in
+ -h) help=1;
+ shift;
+ break;;
+ -v) verbose=1;
+ shift;;
+ -X) endian="-X $2";
+ shift 2;;
+ -d) deregister=1;
+ shift;;
+ -t) cimserver=$2;
+ shift 2;;
+ -n) namespace=$2;
+ shift 2;;
+ -r) regs="$regs $2";
+ shift 2;;
+ --) shift;
+ break;;
+ **) break;;
+ esac
+done
+
+mofs=$*
+
+if [ "$help" = "1" ]
+then
+ usage
+ echo -e "\t-h display help message"
+ echo -e "\t-v verbose mode"
+ echo -e "\t-d deregister provider and uninstall schema"
+ echo -e "\t-t specify cimserver type (pegasus|sfcb|openwbem|sniacimom)"
+ echo -e "\t-r specify registration files"
+ echo -e "\t-m specify schema mof files"
+ echo -e "\t-X create repository for alternate platform (sfcb only at the moment)."
+ echo -e "\t-n target namespace definition (default: root/cimv2)."
+ echo
+ echo Use this command to install schema mofs and register providers.
+ echo CIM Server Type is required as well as at least one registration file and one mof.
+ exit 0
+fi
+
+if test x"$mofs" = x || test x"$regs" = x
+then
+ usage $0
+ exit 1
+fi
+
+if test x$cimserver = x
+then
+ cimserver=`cim_server`
+ if test $? = 0
+ then
+ chatter "Autoselected CIM server type:" $cimserver
+ else
+ echo "CIM server type could not be determined, specify with -t." >&2
+ exit 1
+ fi
+fi
+
+if test x$deregister = x
+then
+ case $cimserver in
+ pegasus) pegasus_install $namespace $mofs ":" $regs;;
+ sfcb) sfcb_install $namespace $mofs ":" $regs;;
+ openwbem) openwbem_install $mofs ;;
+ sniacimom) echo sniacimom not yet supported && exit 1 ;;
+ **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
+ esac
+else
+ case $cimserver in
+ pegasus) pegasus_uninstall $namespace $mofs ":" $regs;;
+ sfcb) sfcb_uninstall $namespace $mofs ":" $regs;;
+ openwbem) openwbem_uninstall $mofs ;;
+ sniacimom) echo sniacimom not yet supported && exit 1 ;;
+ **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
+ esac
+fi
diff --git a/src/power/sblim_cmpi_power_test.py b/src/power/sblim_cmpi_power_test.py
new file mode 100755
index 0000000..f67fd87
--- /dev/null
+++ b/src/power/sblim_cmpi_power_test.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+import sys
+import pywbem
+
+if len(sys.argv) < 4:
+ print """Usage: %s <address> <state> [username] [password]
+ Connect to CIM server at address and change the power state of the machine.
+
+Available states:
+ 4 - sleep
+ 5 - force reboot
+ 7 - hibernate
+ 8 - force poweroff
+ 12 - poweroff
+ 15 - reboot
+
+Example: %s https://127.0.0.1"5989 4 root redhat""" % (sys.argv[0], sys.argv[0])
+ sys.exit(1)
+
+url = sys.argv[1]
+try:
+ state = int(sys.argv[2])
+except ValueError:
+ print >>sys.stderr, "Unknown state: %s" % sys.argv[2]
+ sys.exit(4)
+
+username = None
+password = None
+if len(sys.argv) > 3:
+ username = sys.argv[3]
+if len(sys.argv) > 4:
+ password = sys.argv[4]
+
+cliconn = pywbem.WBEMConnection(url, (username, password))
+
+computerSystems = cliconn.ExecQuery('WQL', 'select * from Linux_ComputerSystem')
+
+if len(computerSystems) == 0:
+ print >>sys.stderr, "No usable Linux_ComputerSystem instance found."
+ sys.exit(2)
+
+if len(computerSystems) > 1:
+ print >>sys.stderr, "More than one Linux_ComputerSystem instance found, don't know which to use."
+ sys.exit(3)
+
+print cliconn.InvokeMethod("RequestPowerStateChange", "Linux_PowerManagementService",
+ ManagedElement=computerSystems[0].path,
+ TimeoutPeriod=pywbem.datetime.now(),
+ PowerState=pywbem.Uint16(state),
+ Time=pywbem.datetime.now()
+ )
diff --git a/src/power/src/CMakeLists.txt b/src/power/src/CMakeLists.txt
new file mode 100644
index 0000000..c9d0f40
--- /dev/null
+++ b/src/power/src/CMakeLists.txt
@@ -0,0 +1,70 @@
+
+find_package(PkgConfig)
+
+# Read CIM classes out of MOF file
+execute_process(COMMAND sed -e "/class/ !D" -e "s/class \\(.*\\):.*/\\1/g"
+ INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../Linux_PowerManagement.mof
+ OUTPUT_VARIABLE CIM_CLASSES
+)
+
+# And fill list with them
+string(REGEX MATCHALL "[a-zA-Z_-]+" CIM_CLASSES ${CIM_CLASSES})
+
+# Get headers and sources names from the list of CIM classes
+set(CIM_HEADERS "")
+set(CIM_PROVIDERS "")
+foreach(CLASS ${CIM_CLASSES})
+ set(CIM_HEADERS ${CIM_HEADERS} ${CLASS}.h)
+ set(PROVIDER ${CLASS}Provider.c)
+ set(CIM_PROVIDERS ${CIM_PROVIDERS} ${PROVIDER})
+endforeach(CLASS ${CIM_CLASSES})
+
+# Add library
+add_library(cmpiLinux_PowerManagement SHARED
+ power.c
+ trace.c
+ globals.c
+ ${CIM_PROVIDERS}
+ ${CIM_HEADERS}
+)
+
+# Link konkret library
+target_link_libraries(cmpiLinux_PowerManagement "-lkonkret")
+include_directories(/usr/include/cmpi ${CMAKE_CURRENT_BINARY_DIR})
+
+# Check if we have upower and link it
+pkg_check_modules(upower upower-glib)
+if (${upower_FOUND})
+ add_definitions(-DHAS_UPOWER)
+ target_link_libraries(cmpiLinux_PowerManagement ${upower_LIBRARIES})
+ include_directories(${upower_INCLUDE_DIRS})
+endif (${upower_FOUND})
+
+# Check if we have systemctl
+find_program(systemctl NAMES systemctl)
+if (${systemctl_FOUND})
+ add_definitions(-DHAS_SYSTEMCTL)
+endif (${systemctl_FOUND})
+
+find_program(konkret NAMES konkret)
+find_program(konkretreg NAMES konkretreg)
+
+# Generate headers for CIM classes
+add_custom_command(OUTPUT ${CIM_HEADERS}
+ COMMAND KONKRET_SCHEMA_DIR=/usr/share/mof/cim-current
+ ${konkret}
+ -m /usr/share/sblim-cmpi-base/Linux_Base.mof
+ -m ${CMAKE_CURRENT_SOURCE_DIR}/../Linux_PowerManagement.mof
+ ${CIM_CLASSES}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../Linux_PowerManagement.mof
+ COMMENT "Generating headers from .mof file"
+ )
+
+add_custom_command(TARGET cmpiLinux_PowerManagement
+ POST_BUILD
+ COMMAND ${konkretreg} -r libcmpiLinux_PowerManagement.so > Linux_PowerManagement.registration
+ COMMENT "Generating .reg file from library"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ )
+
+install(TARGETS cmpiLinux_PowerManagement DESTINATION lib${LIB_SUFFIX}/cmpi)
diff --git a/src/power/src/Linux_AssociatedPowerManagementServiceProvider.c b/src/power/src/Linux_AssociatedPowerManagementServiceProvider.c
new file mode 100644
index 0000000..7d61d83
--- /dev/null
+++ b/src/power/src/Linux_AssociatedPowerManagementServiceProvider.c
@@ -0,0 +1,294 @@
+
+#include "Linux_AssociatedPowerManagementService.h"
+#include "Linux_PowerManagementService.h"
+#include "Linux_ComputerSystem.h"
+
+#include "power.h"
+
+#include "trace.h"
+#include "globals.h"
+
+static const CMPIBroker* _cb;
+
+static void Linux_AssociatedPowerManagementServiceInitialize(CMPIInstanceMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static void Linux_AssociatedPowerManagementServiceAssociationInitialize(CMPIAssociationMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceCleanup\n");
+
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceEnumInstanceNames\n");
+
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceEnumInstances\n");
+
+ const char *ns = KNameSpace(cop);
+
+ Linux_AssociatedPowerManagementService w;
+ Linux_AssociatedPowerManagementService_Init(&w, _cb, ns);
+
+ Linux_ComputerSystemRef computerSystemRef;
+ Linux_ComputerSystemRef_Init(&computerSystemRef, _cb, ns);
+ Linux_ComputerSystemRef_Set_Name(&computerSystemRef, get_system_name());
+ Linux_ComputerSystemRef_Set_CreationClassName(&computerSystemRef, "Linux_ComputerSystem");
+ Linux_AssociatedPowerManagementService_Set_UserOfService(&w, &computerSystemRef);
+
+ Linux_PowerManagementServiceRef powerManagementServiceRef;
+ Linux_PowerManagementServiceRef_Init(&powerManagementServiceRef, _cb, ns);
+ Linux_PowerManagementServiceRef_Set_Name(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_SystemName(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_CreationClassName(&powerManagementServiceRef, "Linux_PowerManagementService");
+ Linux_PowerManagementServiceRef_Set_SystemCreationClassName(&powerManagementServiceRef, "Linux_ComputerSystem");
+ Linux_AssociatedPowerManagementService_Set_ServiceProvided(&w, &powerManagementServiceRef);
+
+ int count;
+ unsigned short *list = power_available_requested_power_states(mi->hdl, &count);
+ Linux_AssociatedPowerManagementService_Init_AvailableRequestedPowerStates(&w, count);
+ for (int i = 0; i < count; i++) {
+ Linux_AssociatedPowerManagementService_Set_AvailableRequestedPowerStates(&w, i, list[i]);
+ }
+
+ Linux_AssociatedPowerManagementService_Set_TransitioningToPowerState(&w, power_transitioning_to_power_state(mi->hdl));
+ Linux_AssociatedPowerManagementService_Set_PowerState(&w, 2);
+ Linux_AssociatedPowerManagementService_Set_RequestedPowerState(&w, power_requested_power_state(mi->hdl));
+
+ KReturnInstance(cr, w);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceGetInstance\n");
+
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char**properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceAssociationCleanup(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceAssociators(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole,
+ const char** properties)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceAssociators\n"
+ "\tassocClass: %s\n"
+ "\tresultClass: %s\n"
+ "\trole: %s\n"
+ "\tresultRole: %s\n", assocClass, resultClass, role, resultRole);
+
+ if (!assocClass) {
+ assocClass = "Linux_AssociatedPowerManagementService";
+ }
+
+ return KDefaultAssociators(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_AssociatedPowerManagementService_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole,
+ properties);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceAssociatorNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceAssociatorNames\n"
+ "\tassocClass: %s\n"
+ "\tresultClass: %s\n"
+ "\trole: %s\n"
+ "\tresultRole: %s\n", assocClass, resultClass, role, resultRole);
+
+ if (!assocClass) {
+ assocClass = "Linux_AssociatedPowerManagementService";
+ }
+
+ return KDefaultAssociatorNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_AssociatedPowerManagementService_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceReferences(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role,
+ const char** properties)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceReferences\n"
+ "\tassocClass: %s\n"
+ "\trole: %s\n", assocClass, role);
+
+ if (!assocClass) {
+ assocClass = "Linux_AssociatedPowerManagementService";
+ }
+
+ return KDefaultReferences(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_AssociatedPowerManagementService_ClassName,
+ assocClass,
+ role,
+ properties);
+}
+
+static CMPIStatus Linux_AssociatedPowerManagementServiceReferenceNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role)
+{
+ TRACE(1, "Linux_AssociatedPowerManagementServiceReferenceNames(assocClass: %s, role: %s)\n", assocClass, role);
+
+ if (!assocClass) {
+ assocClass = "Linux_AssociatedPowerManagementService";
+ }
+
+ return KDefaultReferenceNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_AssociatedPowerManagementService_ClassName,
+ assocClass,
+ role);
+}
+
+CMInstanceMIStub(
+ Linux_AssociatedPowerManagementService,
+ Linux_AssociatedPowerManagementService,
+ _cb,
+ Linux_AssociatedPowerManagementServiceInitialize(&mi))
+
+CMAssociationMIStub(
+ Linux_AssociatedPowerManagementService,
+ Linux_AssociatedPowerManagementService,
+ _cb,
+ Linux_AssociatedPowerManagementServiceAssociationInitialize(&mi))
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_AssociatedPowerManagementService",
+ "Linux_AssociatedPowerManagementService",
+ "instance association")
diff --git a/src/power/src/Linux_ConcreteJobProvider.c b/src/power/src/Linux_ConcreteJobProvider.c
new file mode 100644
index 0000000..361d045
--- /dev/null
+++ b/src/power/src/Linux_ConcreteJobProvider.c
@@ -0,0 +1,206 @@
+#include <konkret/konkret.h>
+#include <stdint.h>
+#include "Linux_ConcreteJob.h"
+
+static const CMPIBroker* _cb = NULL;
+
+#include "power.h"
+#include "trace.h"
+
+static void Linux_ConcreteJobInitializeInstance(CMPIInstanceMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static void Linux_ConcreteJobInitializeMethod(CMPIMethodMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static CMPIStatus Linux_ConcreteJobCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ if (power_get_jobs(mi->hdl) != NULL) {
+ // We have jobs running -> do not unload
+ CMReturn(CMPI_RC_DO_NOT_UNLOAD);
+ }
+ power_unref(mi->hdl);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ConcreteJobEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_ConcreteJobEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ CMPIStatus status;
+ const char *ns = KNameSpace(cop);
+
+ TRACE(1, "Linux_ConcreteJobEnumInstances");
+ PowerStateChangeJob *powerStateChangeJob;
+ GList *plist = power_get_jobs(mi->hdl);
+
+ while (plist) {
+ powerStateChangeJob = plist->data;
+ Linux_ConcreteJob concreteJob;
+ Linux_ConcreteJob_Init(&concreteJob, _cb, ns);
+ Linux_ConcreteJob_Set_InstanceID(&concreteJob, "Linux_PowerStateChange_ConcreteJob:123"); // TODO: unique ID
+ Linux_ConcreteJob_Set_JobState(&concreteJob, job_state(powerStateChangeJob));
+ Linux_ConcreteJob_Set_TimeOfLastStateChange(&concreteJob, CMNewDateTimeFromBinary(_cb, ((uint64_t) job_timeOfLastChange(powerStateChangeJob)) * 1000000, 0, &status));
+ //Linux_ConcreteJob_Set_
+ KReturnInstance(cr, concreteJob);
+ plist = g_list_next(plist);
+ }
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ConcreteJobGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_ConcreteJobCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ConcreteJobModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ConcreteJobDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ConcreteJobExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ Linux_ConcreteJob,
+ Linux_ConcreteJob,
+ _cb,
+ Linux_ConcreteJobInitializeInstance(&mi))
+
+static CMPIStatus Linux_ConcreteJobMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ power_unref(mi->hdl);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ConcreteJobInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return Linux_ConcreteJob_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ Linux_ConcreteJob,
+ Linux_ConcreteJob,
+ _cb,
+ Linux_ConcreteJobInitializeMethod(&mi))
+
+KUint32 Linux_ConcreteJob_KillJob(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_ConcreteJobRef* self,
+ const KBoolean* DeleteOnKill,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 Linux_ConcreteJob_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_ConcreteJobRef* self,
+ const KUint16* RequestedState,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 Linux_ConcreteJob_GetError(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_ConcreteJobRef* self,
+ KString* Error,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_ConcreteJob",
+ "Linux_ConcreteJob",
+ "instance method")
diff --git a/src/power/src/Linux_ElementCapabilitiesProvider.c b/src/power/src/Linux_ElementCapabilitiesProvider.c
new file mode 100644
index 0000000..62c42e6
--- /dev/null
+++ b/src/power/src/Linux_ElementCapabilitiesProvider.c
@@ -0,0 +1,225 @@
+#include <konkret/konkret.h>
+#include "Linux_ElementCapabilities.h"
+#include <Linux_ComputerSystem.h>
+#include "globals.h"
+
+static const CMPIBroker* _cb;
+
+static void Linux_ElementCapabilitiesInitialize()
+{
+}
+
+static CMPIStatus Linux_ElementCapabilitiesCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ const char *ns = KNameSpace(cop);
+
+ Linux_ElementCapabilities w;
+ Linux_ElementCapabilities_Init(&w, _cb, ns);
+
+ Linux_PowerManagementServiceRef powerManagementServiceRef;
+ Linux_PowerManagementServiceRef_Init(&powerManagementServiceRef, _cb, ns);
+ Linux_PowerManagementServiceRef_Set_Name(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_SystemName(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_CreationClassName(&powerManagementServiceRef, "Linux_PowerManagementService");
+ Linux_PowerManagementServiceRef_Set_SystemCreationClassName(&powerManagementServiceRef, "Linux_ComputerSystem");
+
+ Linux_ElementCapabilities_Set_ManagedElement(&w, &powerManagementServiceRef);
+
+ Linux_PowerManagementCapabilitiesRef powerManagementCapabilitiesRef;
+ Linux_PowerManagementCapabilitiesRef_Init(&powerManagementCapabilitiesRef, _cb, ns);
+ Linux_PowerManagementCapabilitiesRef_Set_InstanceID(&powerManagementCapabilitiesRef, "RedHat:PowerManagementCapabilities");
+
+ Linux_ElementCapabilities_Set_Capabilities(&w, &powerManagementCapabilitiesRef);
+
+ KReturnInstance(cr, w);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char**properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesAssociationCleanup(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesAssociators(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole,
+ const char** properties)
+{
+ return KDefaultAssociators(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_ElementCapabilities_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole,
+ properties);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesAssociatorNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole)
+{
+ return KDefaultAssociatorNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_ElementCapabilities_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesReferences(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role,
+ const char** properties)
+{
+ return KDefaultReferences(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_ElementCapabilities_ClassName,
+ assocClass,
+ role,
+ properties);
+}
+
+static CMPIStatus Linux_ElementCapabilitiesReferenceNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role)
+{
+ return KDefaultReferenceNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_ElementCapabilities_ClassName,
+ assocClass,
+ role);
+}
+
+CMInstanceMIStub(
+ Linux_ElementCapabilities,
+ Linux_ElementCapabilities,
+ _cb,
+ Linux_ElementCapabilitiesInitialize())
+
+CMAssociationMIStub(
+ Linux_ElementCapabilities,
+ Linux_ElementCapabilities,
+ _cb,
+ Linux_ElementCapabilitiesInitialize())
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_ElementCapabilities",
+ "Linux_ElementCapabilities",
+ "instance association")
diff --git a/src/power/src/Linux_HostedServiceProvider.c b/src/power/src/Linux_HostedServiceProvider.c
new file mode 100644
index 0000000..4f6c7ac
--- /dev/null
+++ b/src/power/src/Linux_HostedServiceProvider.c
@@ -0,0 +1,258 @@
+
+#include <cmpimacs.h>
+#include <konkret/konkret.h>
+#include "Linux_HostedService.h"
+#include "Linux_ComputerSystem.h"
+
+#include "globals.h"
+#include "trace.h"
+
+static const CMPIBroker* _cb;
+
+static void Linux_HostedServiceInitialize()
+{
+}
+
+static CMPIStatus Linux_HostedServiceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_HostedServiceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_HostedServiceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ const char *ns = KNameSpace(cop);
+
+ Linux_HostedService w;
+ Linux_HostedService_Init(&w, _cb, ns);
+
+ /*
+ * TODO: Find instance dynamically based on Name property
+ */
+ /*
+ CMPIObjectPath *computerSystemOP = CMNewObjectPath(_cb, ns, "CIM_ComputerSystem", &rc);
+ CMPIEnumeration *en = CBEnumInstanceNames(_cb, cc, computerSystemOP, &rc);
+ while (CMHasNext(en, &rc)) {
+ data = CMGetNext(en, &rc);
+ if (data.type != CMPI_ref) {
+ TRACE(1, "Not a reference\n");
+ continue;
+ }
+ fprintf(stderr, "object: %s\n", CMGetCharsPtr(CMObjectPathToString(data.value.ref, &rc), &rc));
+
+ name = data.value.ref->ft->getKey(data.value.ref, "Name", &rc);
+ if (name.type != CMPI_string) {
+ fprintf(stderr, "Non-string name %d\n", name.type);
+ continue;
+ }
+ if (rc.rc != CMPI_RC_OK) return rc;
+
+ fprintf(stderr, "Name: %s\n", CMGetCharsPtr(name.value.string, &rc));
+ if (strcmp(CMGetCharsPtr(name.value.string, &rc), get_system_name()) == 0) {
+ TRACE(1, "Found\n");
+ CIM_ComputerSystemRef_InitFromObjectPath(&computerSystemRef, _cb, data.value.ref);
+ break;
+ }
+ }
+ */
+
+ Linux_ComputerSystemRef computerSystemRef;
+ Linux_ComputerSystemRef_Init(&computerSystemRef, _cb, ns);
+ Linux_ComputerSystemRef_Set_Name(&computerSystemRef, get_system_name());
+ Linux_ComputerSystemRef_Set_CreationClassName(&computerSystemRef, "Linux_ComputerSystem");
+ Linux_HostedService_Set_Antecedent(&w, &computerSystemRef);
+
+ Linux_PowerManagementServiceRef powerManagementServiceRef;
+ Linux_PowerManagementServiceRef_Init(&powerManagementServiceRef, _cb, ns);
+ Linux_PowerManagementServiceRef_Set_Name(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_SystemName(&powerManagementServiceRef, get_system_name());
+ Linux_PowerManagementServiceRef_Set_CreationClassName(&powerManagementServiceRef, "Linux_PowerManagementService");
+ Linux_PowerManagementServiceRef_Set_SystemCreationClassName(&powerManagementServiceRef, "Linux_ComputerSystem");
+ Linux_HostedService_Set_Dependent(&w, &powerManagementServiceRef);
+
+ KReturnInstance(cr, w);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_HostedServiceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_HostedServiceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_HostedServiceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char**properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_HostedServiceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_HostedServiceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_HostedServiceAssociationCleanup(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_HostedServiceAssociators(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole,
+ const char** properties)
+{
+ return KDefaultAssociators(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_HostedService_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole,
+ properties);
+}
+
+static CMPIStatus Linux_HostedServiceAssociatorNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole)
+{
+ return KDefaultAssociatorNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_HostedService_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole);
+}
+
+static CMPIStatus Linux_HostedServiceReferences(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role,
+ const char** properties)
+{
+ return KDefaultReferences(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_HostedService_ClassName,
+ assocClass,
+ role,
+ properties);
+}
+
+static CMPIStatus Linux_HostedServiceReferenceNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role)
+{
+ return KDefaultReferenceNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ Linux_HostedService_ClassName,
+ assocClass,
+ role);
+}
+
+CMInstanceMIStub(
+ Linux_HostedService,
+ Linux_HostedService,
+ _cb,
+ Linux_HostedServiceInitialize())
+
+CMAssociationMIStub(
+ Linux_HostedService,
+ Linux_HostedService,
+ _cb,
+ Linux_HostedServiceInitialize())
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_HostedService",
+ "Linux_HostedService",
+ "instance association")
diff --git a/src/power/src/Linux_PowerManagementCapabilitiesProvider.c b/src/power/src/Linux_PowerManagementCapabilitiesProvider.c
new file mode 100644
index 0000000..bb74e34
--- /dev/null
+++ b/src/power/src/Linux_PowerManagementCapabilitiesProvider.c
@@ -0,0 +1,162 @@
+#include <konkret/konkret.h>
+#include "Linux_PowerManagementCapabilities.h"
+
+#include "power.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void Linux_PowerManagementCapabilitiesInitialize(CMPIInstanceMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static void Linux_PowerManagementCapabilitiesInitializeMethod(CMPIMethodMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ const char *ns = KNameSpace(cop);
+
+ Linux_PowerManagementCapabilities w;
+ Linux_PowerManagementCapabilities_Init(&w, _cb, ns);
+ // TODO: make it unique
+ Linux_PowerManagementCapabilities_Set_InstanceID(&w, "Linux:PowerManagementCapabilities");
+ Linux_PowerManagementCapabilities_Set_ElementName(&w, "Linux:PowerManagementCapabilities");
+ Linux_PowerManagementCapabilities_Set_Caption(&w, "Linux:PowerManagementCapabilities");
+
+ int count;
+ unsigned short *list = power_available_requested_power_states(mi->hdl, &count);
+ Linux_PowerManagementCapabilities_Init_PowerStatesSupported(&w, count);
+ for (int i = 0; i < count; i++) {
+ Linux_PowerManagementCapabilities_Set_PowerStatesSupported(&w, i, list[i]);
+ }
+
+ // TODO: get this list dynamically from PowerStatesSupported (see SMASH)
+ Linux_PowerManagementCapabilities_Init_PowerChangeCapabilities(&w, 3);
+ Linux_PowerManagementCapabilities_Set_PowerChangeCapabilities(&w, 0, Linux_PowerManagementCapabilities_PowerChangeCapabilities_Power_State_Settable);
+ Linux_PowerManagementCapabilities_Set_PowerChangeCapabilities(&w, 1, Linux_PowerManagementCapabilities_PowerChangeCapabilities_Power_Cycling_Supported);
+ Linux_PowerManagementCapabilities_Set_PowerChangeCapabilities(&w, 2, Linux_PowerManagementCapabilities_PowerChangeCapabilities_Graceful_Shutdown_Supported);
+ KReturnInstance(cr, w);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ Linux_PowerManagementCapabilities,
+ Linux_PowerManagementCapabilities,
+ _cb,
+ Linux_PowerManagementCapabilitiesInitialize(&mi))
+
+static CMPIStatus Linux_PowerManagementCapabilitiesMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementCapabilitiesInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return Linux_PowerManagementCapabilities_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ Linux_PowerManagementCapabilities,
+ Linux_PowerManagementCapabilities,
+ _cb,
+ Linux_PowerManagementCapabilitiesInitializeMethod(&mi))
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_PowerManagementCapabilities",
+ "Linux_PowerManagementCapabilities",
+ "instance method")
diff --git a/src/power/src/Linux_PowerManagementServiceProvider.c b/src/power/src/Linux_PowerManagementServiceProvider.c
new file mode 100644
index 0000000..8ce3f6c
--- /dev/null
+++ b/src/power/src/Linux_PowerManagementServiceProvider.c
@@ -0,0 +1,278 @@
+
+#include "Linux_PowerManagementService.h"
+
+#include "power.h"
+#include "globals.h"
+#include "trace.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void Linux_PowerManagementServiceInitialize(CMPIInstanceMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+static void Linux_PowerManagementServiceMethodInitialize(CMPIMethodMI *mi)
+{
+ mi->hdl = power_ref(_cb);
+}
+
+
+static CMPIStatus Linux_PowerManagementServiceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ TRACE(1, "Linux_PowerManagementServiceCleanup\n");
+
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementServiceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ TRACE(1, "Linux_PowerManagementServiceEnumInstanceNames\n");
+
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus Linux_PowerManagementServiceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ TRACE(1, "Linux_PowerManagementServiceEnumInstances\n");
+
+ Linux_PowerManagementService w;
+
+ Linux_PowerManagementService_Init(&w, _cb, KNameSpace(cop));
+ Linux_PowerManagementService_Set_CreationClassName(&w, "Linux_PowerManagementService");
+ Linux_PowerManagementService_Set_Name(&w, get_system_name());
+ Linux_PowerManagementService_Set_SystemCreationClassName(&w, "Linux_ComputerSystem");
+ Linux_PowerManagementService_Set_SystemName(&w, get_system_name());
+
+ /* EnabledState is an integer enumeration that indicates the enabled
+ * and disabled states of an element. It can also indicate the transitions
+ * between these requested states.
+ */
+ Linux_PowerManagementService_Set_EnabledState(&w, Linux_PowerManagementService_EnabledDefault_Enabled);
+
+
+ /* RequestedState is an integer enumeration that indicates the last
+ * requested or desired state for the element, irrespective of the mechanism
+ * through which it was requested. The actual state of the element is
+ * represented by EnabledState. This property is provided to compare the
+ * last requested and current enabled or disabled states.
+ */
+ Linux_PowerManagementService_Set_RequestedState(&w, Linux_PowerManagementService_RequestedState_No_Change);
+
+ Linux_PowerManagementService_Init_AvailableRequestedStates(&w, 2);
+ Linux_PowerManagementService_Set_AvailableRequestedStates(&w, 0, 2); // Enabled
+ Linux_PowerManagementService_Set_AvailableRequestedStates(&w, 1, 3); // Disabled
+
+
+ Linux_PowerManagementService_Print(&w, stderr);
+
+ KReturnInstance(cr, w);
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementServiceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus Linux_PowerManagementServiceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementServiceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementServiceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus Linux_PowerManagementServiceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ Linux_PowerManagementService,
+ Linux_PowerManagementService,
+ _cb,
+ Linux_PowerManagementServiceInitialize(&mi))
+
+static CMPIStatus Linux_PowerManagementServiceMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ power_unref(mi->hdl);
+ mi->hdl = NULL;
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus Linux_PowerManagementServiceInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return Linux_PowerManagementService_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ Linux_PowerManagementService,
+ Linux_PowerManagementService,
+ _cb,
+ Linux_PowerManagementServiceMethodInitialize(&mi))
+
+KUint32 Linux_PowerManagementService_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_PowerManagementServiceRef* self,
+ const KUint16* RequestedState,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+
+}
+
+KUint32 Linux_PowerManagementService_StartService(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_PowerManagementServiceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 Linux_PowerManagementService_StopService(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_PowerManagementServiceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 Linux_PowerManagementService_SetPowerState(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_PowerManagementServiceRef* self,
+ const KUint16* PowerState,
+ const KRef* ManagedElement,
+ const KDateTime* Time,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 Linux_PowerManagementService_RequestPowerStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const Linux_PowerManagementServiceRef* self,
+ const KUint16* PowerState,
+ const KRef* ManagedElement,
+ const KDateTime* Time,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ TRACE(1, "Linux_PowerManagementService_RequestPowerStateChange\n");
+ KUint32 result = KUINT32_INIT;
+
+ if (Time->exists && Time->null && TimeoutPeriod->exists && TimeoutPeriod->null) {
+ /* SMASH says: The TimeoutPeriod and Time parameters shall not be
+ * supported for the same invocation of the RequestPowerStateChange( )
+ * method. When the TimeoutPeriod and Time parameters are specified
+ * for the same method invocation, the method shall return a value of 2.
+ */
+ KUint32_Set(&result, 2);
+ return result;
+ }
+
+ // Time argument is not handled because we don't support powering on systems
+
+ if (!PowerState->exists || PowerState->null) {
+ TRACE(1, "wrong PowerState\n");
+ KSetStatus(status, ERR_INVALID_PARAMETER);
+ return result;
+ }
+ power_request_power_state(mi->hdl, PowerState->value);
+
+ KSetStatus(status, OK);
+ KUint32_Set(&result, 4096);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "Linux_PowerManagementService",
+ "Linux_PowerManagementService",
+ "instance method")
diff --git a/src/power/src/globals.c b/src/power/src/globals.c
new file mode 100644
index 0000000..2ba5075
--- /dev/null
+++ b/src/power/src/globals.c
@@ -0,0 +1,24 @@
+
+#include "globals.h"
+
+#define _XOPEN_SOURCE 500
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "trace.h"
+
+static char *_hostname = NULL;
+
+const char *get_system_name()
+{
+ if (_hostname == NULL) {
+ _hostname = malloc(256 * sizeof(char));
+ if (gethostname(_hostname, 255) == -1) {
+ TRACE(4, "get_hostname(): gethostname returned -1");
+ free(_hostname);
+ _hostname = NULL;
+ }
+ }
+ // TODO: try to get full qualified hostname
+ return _hostname;
+}
diff --git a/src/power/src/globals.h b/src/power/src/globals.h
new file mode 100644
index 0000000..adec07e
--- /dev/null
+++ b/src/power/src/globals.h
@@ -0,0 +1,7 @@
+
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+const char *get_system_name();
+
+#endif \ No newline at end of file
diff --git a/src/power/src/power.c b/src/power/src/power.c
new file mode 100644
index 0000000..751ab22
--- /dev/null
+++ b/src/power/src/power.c
@@ -0,0 +1,517 @@
+#include "power.h"
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include <glib.h>
+
+#include "Linux_AssociatedPowerManagementService.h"
+#include "Linux_ConcreteJob.h"
+
+#ifdef HAS_UPOWER
+#include <upower.h>
+#endif
+
+struct _Power {
+ unsigned int instances;
+ unsigned short requestedPowerState;
+ unsigned short transitioningToPowerState;
+ const CMPIBroker *broker;
+ CMPI_MUTEX_TYPE mutex;
+ GList *jobs; // list of PowerStateChangeJob
+#ifdef HAS_UPOWER
+ UpClient *up;
+#endif
+};
+
+#define MUTEX_LOCK(power) power->broker->xft->lockMutex(power->mutex)
+#define MUTEX_UNLOCK(power) power->broker->xft->unlockMutex(power->mutex)
+
+struct _PowerStateChangeJob {
+ const CMPIBroker *broker;
+ Power *power;
+ unsigned short requestedPowerState;
+ unsigned short jobState;
+ int timeOfLastChange;
+ int timeBeforeRemoval;
+ int cancelled;
+ int superseded; // There is another job that overrides this job
+ char *error;
+ CMPI_THREAD_TYPE thread;
+ CMPI_MUTEX_TYPE mutex;
+};
+
+Power *_power = NULL;
+
+
+// This is just for debugging purposes, remove later
+#include <execinfo.h>
+#include <signal.h>
+void print_backtrace(int signal)
+{
+ fprintf(stderr, "BackTrace\n");
+ void *buffer[32];
+ int count = backtrace(buffer, 32);
+ fprintf(stderr, "Size: %d\n", count);
+ backtrace_symbols_fd(buffer, count, stderr->_fileno);
+ fprintf(stderr, "Segfault detected, process id: %d. Entering infinite loop.\n", getpid());
+ volatile int end = 0;
+ while (!end) {
+ sleep(1);
+ }
+}
+
+Power *power_new(const CMPIBroker *_cb)
+{
+ signal(SIGSEGV, print_backtrace);
+ fprintf(stderr, "BackTrace handler registered\n");
+
+ Power *power = malloc(sizeof(Power));
+ power->broker = _cb;
+ power->instances = 0;
+ power->requestedPowerState = Linux_AssociatedPowerManagementService_RequestedPowerState_Unknown;
+ power->transitioningToPowerState = Linux_AssociatedPowerManagementService_TransitioningToPowerState_No_Change;
+ power->mutex = _cb->xft->newMutex(0);
+ power->jobs = NULL;
+#ifdef HAS_UPOWER
+ g_type_init();
+ power->up = up_client_new();
+#endif
+ return power;
+}
+
+void power_destroy(Power *power)
+{
+#ifdef HAS_UPOWER
+ free(power->up);
+#endif
+}
+
+Power *power_ref(const CMPIBroker *_cb)
+{
+ if (_power == NULL) {
+ _power = power_new(_cb);
+ }
+ MUTEX_LOCK(_power);
+ _power->instances++;
+ MUTEX_UNLOCK(_power);
+ return _power;
+}
+
+void power_unref(Power *power)
+{
+ MUTEX_LOCK(power);
+ power->instances--;
+ MUTEX_UNLOCK(power);
+ if (power->instances == 0) {
+ power_destroy(power);
+ power = NULL;
+ _power = NULL;
+ }
+}
+
+unsigned short power_requested_power_state(Power *power)
+{
+ return power->requestedPowerState;
+}
+
+unsigned short power_transitioning_to_power_state(Power *power)
+{
+ return power->transitioningToPowerState;
+}
+
+void *state_change_thread(void *data)
+{
+ PowerStateChangeJob *powerStateChangeJob = data;
+ MUTEX_LOCK(powerStateChangeJob);
+ powerStateChangeJob->jobState = Linux_ConcreteJob_JobState_Running;
+ powerStateChangeJob->timeOfLastChange = time(NULL);
+ MUTEX_UNLOCK(powerStateChangeJob);
+
+
+ // Check if the job was cancelled
+ if (powerStateChangeJob->cancelled) {
+ MUTEX_LOCK(powerStateChangeJob);
+ powerStateChangeJob->jobState = Linux_ConcreteJob_JobState_Terminated;
+ powerStateChangeJob->timeOfLastChange = time(NULL);
+ MUTEX_UNLOCK(powerStateChangeJob);
+
+ if (!powerStateChangeJob->superseded) {
+ // There is no job that replaced this job
+ MUTEX_LOCK(powerStateChangeJob->power);
+ powerStateChangeJob->power->transitioningToPowerState = Linux_AssociatedPowerManagementService_TransitioningToPowerState_No_Change;
+ MUTEX_UNLOCK(powerStateChangeJob->power);
+ }
+
+ fprintf(stderr, "state_change_thread cancelled\n");
+ return NULL;
+ }
+
+ // Execute the job
+#ifdef HAS_UPOWER
+ GError *error = NULL;
+#endif
+
+ int succeeded = 0;
+ switch (powerStateChangeJob->requestedPowerState) {
+ case Linux_AssociatedPowerManagementService_PowerState_Sleep__Deep:
+ // Sleep
+#ifdef HAS_UPOWER
+ succeeded = up_client_suspend_sync(powerStateChangeJob->power->up, NULL, &error);
+#else
+ succeeded = system("pm-suspend") == 0;
+#endif
+ break;
+ case Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft:
+ // Reboot (without shutting down programs)
+#ifdef HAS_SYSTEMCTL
+ succeeded = system("systemctl --force reboot &") == 0;
+#else
+ succeeded = system("reboot --force &") == 0;
+#endif
+ break;
+ case Linux_AssociatedPowerManagementService_PowerState_Hibernate_Off___Soft:
+ // Hibernate
+#ifdef HAS_UPOWER
+ succeeded = up_client_hibernate_sync(powerStateChangeJob->power->up, NULL, &error);
+#else
+ succeeded = system("pm-hibernate") == 0;
+#endif
+ break;
+ case Linux_AssociatedPowerManagementService_PowerState_Off___Soft:
+ // Poweroff (without shutting down programs)
+#ifdef HAS_SYSTEMCTL
+ succeeded = system("systemctl --force poweroff &") == 0;
+#else
+ succeeded = system("shutdown --halt now &") == 0;
+#endif
+ break;
+ case Linux_AssociatedPowerManagementService_PowerState_Off___Soft_Graceful:
+ // Poweroff (shut down programs first)
+#ifdef HAS_SYSTEMCTL
+ succeeded = system("systemctl poweroff &") == 0;
+#else
+ succeeded = system("shutdown --poweroff now &") == 0;
+#endif
+ break;
+ case Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft_Graceful:
+ // Reboot (shut down programs first)
+#ifdef HAS_SYSTEMCTL
+ succeeded = system("systemctl reboot &") == 0;
+#else
+ succeeded = system("shutdown --reboot now &") == 0;
+#endif
+ break;
+ }
+
+ MUTEX_LOCK(powerStateChangeJob->power);
+ powerStateChangeJob->power->transitioningToPowerState = Linux_AssociatedPowerManagementService_TransitioningToPowerState_No_Change;
+ MUTEX_UNLOCK(powerStateChangeJob->power);
+
+ MUTEX_LOCK(powerStateChangeJob);
+ if (succeeded) {
+ powerStateChangeJob->jobState = Linux_ConcreteJob_JobState_Completed;
+ } else {
+ powerStateChangeJob->jobState = Linux_ConcreteJob_JobState_Exception;
+#ifdef HAS_UPOWER
+ if (error != NULL) {
+ powerStateChangeJob->error = error->message;
+ }
+#endif
+ }
+ powerStateChangeJob->timeOfLastChange = time(NULL);
+ MUTEX_UNLOCK(powerStateChangeJob);
+
+ fprintf(stderr, "state_change_thread finished\n");
+ return NULL;
+}
+
+int power_request_power_state(Power *power, unsigned short state)
+{
+ int rc = CMPI_RC_OK;
+
+ int count, found = 0;
+ unsigned short *states = power_available_requested_power_states(power, &count);
+ for (int i = 0; i < count; ++i) {
+ if (states[i] == state) {
+ found = 1;
+ break;
+ }
+ }
+ free(states);
+ if (!found) {
+ fprintf(stderr, "Invalid state: %d\n", state);
+ return CMPI_RC_ERR_INVALID_PARAMETER;
+ }
+
+ PowerStateChangeJob *powerStateChangeJob = malloc(sizeof(PowerStateChangeJob));
+ powerStateChangeJob->broker = power->broker;
+ powerStateChangeJob->power = power;
+ powerStateChangeJob->mutex = power->broker->xft->newMutex(0);
+ powerStateChangeJob->requestedPowerState = state;
+ powerStateChangeJob->jobState = Linux_ConcreteJob_JobState_New;
+ powerStateChangeJob->cancelled = 0;
+ powerStateChangeJob->superseded = 0;
+ powerStateChangeJob->timeOfLastChange = time(NULL);
+ powerStateChangeJob->timeBeforeRemoval = 300;
+ powerStateChangeJob->error = NULL;
+
+ MUTEX_LOCK(power);
+ power->requestedPowerState = state;
+ power->transitioningToPowerState = state;
+
+ PowerStateChangeJob *job;
+ GList *plist = power->jobs;
+ while (plist) {
+ job = plist->data;
+ MUTEX_LOCK(job);
+ if (job->jobState != Linux_ConcreteJob_JobState_Suspended &&
+ job->jobState != Linux_ConcreteJob_JobState_Killed &&
+ job->jobState != Linux_ConcreteJob_JobState_Terminated) {
+
+ job->cancelled = 1;
+ job->superseded = 1;
+ job->jobState = Linux_ConcreteJob_JobState_Shutting_Down;
+ job->timeOfLastChange = time(NULL);
+ }
+ MUTEX_UNLOCK(job);
+ plist = g_list_next(plist);
+ }
+ powerStateChangeJob->thread = power->broker->xft->newThread(state_change_thread, powerStateChangeJob, 1);
+ power->jobs = g_list_append(power->jobs, powerStateChangeJob);
+ MUTEX_UNLOCK(power);
+ fprintf(stderr, "State change thread started\n");
+
+ return rc;
+}
+
+unsigned short *power_available_requested_power_states(Power *power, int *count)
+{
+ unsigned short *list = malloc(17 * sizeof(unsigned short));
+ int i = 0;
+
+ /* 1 Other
+ * Linux_AssociatedPowerManagementService_PowerState_Other
+ */
+
+ /* 2 On
+ * corresponding to ACPI state G0 or S0 or D0.
+ *
+ * Bring system to full On from any state (Sleep, Hibernate, Off)
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_On
+ */
+ // not supported
+
+ /* 3 Sleep - Light
+ * corresponding to ACPI state G1, S1/S2, or D1.
+ *
+ * Standby
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Sleep___Light
+ */
+ // not supported
+
+ /* 4 Sleep - Deep
+ * corresponding to ACPI state G1, S3, or D2.
+ *
+ * Suspend
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Sleep__Deep
+ */
+ // Sleep
+#ifdef HAS_UPOWER
+ if (up_client_get_can_suspend(power->up)) {
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Sleep__Deep;
+ }
+#else
+ if (system("pm-is-supported --suspend") == 0) {
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Sleep__Deep;
+ }
+#endif
+
+ /* 5 Power Cycle (Off - Soft)
+ * corresponding to ACPI state G2, S5, or D3, but where the managed
+ * element is set to return to power state "On" at a pre-determined time.
+ *
+ * Reset system without removing power
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft
+ */
+ // Reboot (without shutting down programs)
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft;
+
+ /* 6 Off - Hard
+ * corresponding to ACPI state G3, S5, or D3.
+ *
+ * Power Off performed through mechanical means like unplugging
+ * power cable or UPS On
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Off___Hard
+ */
+
+ /* 7 Hibernate (Off - Soft)
+ * corresponding to ACPI state S4, where the state of the managed element
+ * is preserved and will be recovered upon powering on.
+ *
+ * System context and OS image written to non-volatile storage;
+ * system and devices powered off
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Hibernate_Off___Soft
+ */
+ // Hibernate
+#ifdef HAS_UPOWER
+ if (up_client_get_can_hibernate(power->up)) {
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Hibernate_Off___Soft;
+ }
+#else
+ if (system("pm-is-supported --hibernate") == 0) {
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Hibernate_Off___Soft;
+ }
+#endif
+
+ /* 8 Off - Soft
+ * corresponding to ACPI state G2, S5, or D3.
+ *
+ * System power off but auxiliary or flea power may be available
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Off___Soft
+ */
+ // Poweroff (without shutting down programs)
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Off___Soft;
+
+ /* 9 Power Cycle (Off-Hard)
+ * corresponds to the managed element reaching the ACPI state G3
+ * followed by ACPI state S0.
+ *
+ * Equivalent to Off–Hard followed by On
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off_Hard
+ */
+ // not implemented
+
+ /* 10 Master Bus Reset
+ * corresponds to the system reaching ACPI state S5 followed by ACPI
+ * state S0. This is used to represent system master bus reset.
+ *
+ * Hardware reset
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Master_Bus_Reset
+ */
+ // not implemented
+
+ /* 11 Diagnostic Interrupt (NMI)
+ * corresponding to the system reaching ACPI state S5 followed by ACPI
+ * state S0. This is used to represent system non-maskable interrupt.
+ *
+ * Hardware reset
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Diagnostic_Interrupt_NMI
+ */
+ // not implemented
+
+ /* 12 Off - Soft Graceful
+ * equivalent to Off Soft but preceded by a request to the managed element
+ * to perform an orderly shutdown.
+ *
+ * System power off but auxiliary or flea power may be available but preceded
+ * by a request to the managed element to perform an orderly shutdown.
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Off___Soft_Graceful
+ */
+ // Poweroff (shut down programs first)
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Off___Soft_Graceful;
+
+ /* 13 Off - Hard Graceful
+ * equivalent to Off Hard but preceded by a request to the managed element
+ * to perform an orderly shutdown.
+ *
+ * Power Off performed through mechanical means like unplugging power cable
+ * or UPS On but preceded by a request to the managed element to perform
+ * an orderly shutdown.
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Off___Hard_Graceful
+ */
+ // not implemented
+
+ /* 14 Master Bus Rest Graceful
+ * equivalent to Master Bus Reset but preceded by a request to the managed
+ * element to perform an orderly shutdown.
+ *
+ * Hardware reset but preceded by a request to the managed element
+ * to perform an orderly shutdown.
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Master_Bus_Reset_Graceful
+ */
+ // not implemented
+
+ /* 15 Power Cycle (Off - Soft Graceful)
+ * equivalent to Power Cycle (Off - Soft) but preceded by a request
+ * to the managed element to perform an orderly shutdown.
+ *
+ * Reset system without removing power but preceded by a request
+ * to the managed element to perform an orderly shutdown.
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft_Graceful
+ */
+ // Reboot (shut down programs first)
+ list[i++] = Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Soft_Graceful;
+
+ /* 16 Power Cycle (Off - Hard Graceful)
+ * equivalent to Power Cycle (Off - Hard) but preceded by a request
+ * to the managed element to perform an orderly shutdown.
+ *
+ * Equivalent to Off–Hard followed by On but preceded by a request
+ * to the managed element to perform an orderly shutdown.
+ *
+ * Linux_AssociatedPowerManagementService_PowerState_Power_Cycle_Off___Hard_Graceful
+ */
+ // not implemented
+
+ *count = i;
+ return list;
+}
+
+void job_free(PowerStateChangeJob *job)
+{
+ job->broker->xft->destroyMutex(job->mutex);
+}
+
+GList *power_get_jobs(Power *power)
+{
+ PowerStateChangeJob *powerStateChangeJob;
+ GList *plist = power->jobs;
+ while (plist) {
+ powerStateChangeJob = plist->data;
+ MUTEX_LOCK(powerStateChangeJob);
+ if ((powerStateChangeJob->jobState == Linux_ConcreteJob_JobState_Completed ||
+ powerStateChangeJob->jobState == Linux_ConcreteJob_JobState_Killed ||
+ powerStateChangeJob->jobState == Linux_ConcreteJob_JobState_Terminated) &&
+ time(NULL) - powerStateChangeJob->timeOfLastChange > powerStateChangeJob->timeBeforeRemoval) {
+
+ MUTEX_LOCK(power);
+ power->jobs = g_list_remove_link(power->jobs, plist);
+ MUTEX_UNLOCK(power);
+ job_free(powerStateChangeJob);
+ }
+ MUTEX_UNLOCK(powerStateChangeJob);
+ plist = g_list_next(plist);
+ }
+ return power->jobs;
+}
+
+unsigned short job_state(PowerStateChangeJob *state)
+{
+ return state->jobState;
+}
+
+int job_timeOfLastChange(PowerStateChangeJob *state)
+{
+ return state->timeOfLastChange;
+}
+
+int job_timeBeforeRemoval(PowerStateChangeJob *state)
+{
+ return state->timeBeforeRemoval;
+}
+
diff --git a/src/power/src/power.h b/src/power/src/power.h
new file mode 100644
index 0000000..8f1f0bc
--- /dev/null
+++ b/src/power/src/power.h
@@ -0,0 +1,56 @@
+#ifndef POWER_H
+#define POWER_H
+
+#include <glib.h>
+
+typedef struct _Power Power;
+typedef struct _CMPIBroker CMPIBroker;
+typedef struct _PowerStateChangeJob PowerStateChangeJob;
+
+/**
+ * Get reference to global power object
+ * \note Don't forget to call power_unref
+ */
+Power *power_ref(const CMPIBroker *_cb);
+
+/**
+ * Decrement reference counter for power struct
+ */
+void power_unref(Power *power);
+
+/**
+ * Get list of available requested power states
+ *
+ * \param power Pointer to power struct, obtained by power_ref
+ * \param count Number of states returned
+ * \return list of power states
+ */
+unsigned short *power_available_requested_power_states(Power *power, int *count);
+
+/**
+ * Get requested power state
+ *
+ * \param power Pointer to power struct, obtained by power_ref
+ * \return current requested power state
+ */
+unsigned short power_requested_power_state(Power *power);
+
+/**
+ * Request change power state to \p state
+ *
+ * \param power Pointer to power struct, obtained by power_ref
+ * \param state Requested power state
+ * \return CMPI return code
+ */
+int power_request_power_state(Power *power, unsigned short state);
+
+GList *power_get_jobs(Power *power);
+
+unsigned short power_transitioning_to_power_state(Power *power);
+
+
+unsigned short job_state(PowerStateChangeJob *state);
+int job_timeOfLastChange(PowerStateChangeJob *state);
+int job_timeBeforeRemoval(PowerStateChangeJob *state);
+
+#endif // POWER_H
diff --git a/src/power/src/trace.c b/src/power/src/trace.c
new file mode 100644
index 0000000..1f23a6a
--- /dev/null
+++ b/src/power/src/trace.c
@@ -0,0 +1,29 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+static FILE *_trace_file = NULL;
+
+void _trace(int level, const char *file, int line, const char *format, ...)
+{
+ // TODO; level
+ if (_trace_file == NULL) {
+ char *filename = getenv("SBLIM_TRACE_FILE");
+ if (filename != NULL) {
+ _trace_file = fopen(filename, "a");
+ if (_trace_file == NULL) {
+ _trace_file = stderr;
+ }
+ } else {
+ _trace_file = stderr;
+ }
+ }
+
+ va_list args;
+ va_start(args, format);
+ fprintf(_trace_file, "%s:%d\t", file, line);
+ vfprintf(_trace_file, format, args);
+ fprintf(_trace_file, "\n");
+ va_end(args);
+}
diff --git a/src/power/src/trace.h b/src/power/src/trace.h
new file mode 100644
index 0000000..65118d4
--- /dev/null
+++ b/src/power/src/trace.h
@@ -0,0 +1,4 @@
+
+#define TRACE(level, ...) _trace(level, __FILE__, __LINE__, __VA_ARGS__)
+
+void _trace(int level, const char *file, int line, const char *format, ...);