#include "Linux_PowerManagementService.h" #include "power.h" #include "globals.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) { 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) { 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) { 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) { 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) { KSetStatus2(_cb, status, ERR_INVALID_PARAMETER, "PowerState argument is missing"); 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")