Пример #1
0
//------------------------------------------------------------------
// create new profile from current one
//
// return codes:
//   -1: active profile detection failed
//   -2: reading active profile policy failed
//   -3: writing our own profile failed
//   -4: reading active cpu policy failed
//   -5: writing our own cpu policy failed
//   -6: new profile activation failed
//   0: profile creation successful
//------------------------------------------------------------------
int createProfile()
{
  // get the # of the currently active profile
  UINT activeProfile;
  if( !GetActivePwrScheme(&activeProfile) )
    return -1;  

  // read the profile policy settings
  if( !ReadPwrScheme(activeProfile,&toBeCopied) )
    return -2;

  // copy this to the one we use later
  internalPolicy = toBeCopied;

  // create the # of our own profile
  lastChecked++;

  // disable throttling in this new profile
  internalPolicy.user.ForcedThrottleAc = 100;
  internalPolicy.user.ForcedThrottleDc = 100;

  // write our own profile policy settings to the registry
  if( !WritePwrScheme(&lastChecked,L"Speedswitch Control",L"\0\0",&internalPolicy) )
    return -3;

  // this is our profile #
  internalProfile = lastChecked;

  // read the CPU policy from the active profile
  if( !ReadProcessorPwrScheme(activeProfile,&mach) )
    return -4;

  // use this CPU policy for our own profile
  if( !WriteProcessorPwrScheme(internalProfile,&mach) )
    return -5;

  if( !SetActivePwrScheme(internalProfile,NULL,NULL) )
    return -6;

  updateStates();

  return 0;
}
Пример #2
0
//------------------------------------------------------------------
// write changed power policies
//
// return codes:
//   -1: power policy writing failure
//   -2: cpu policy writing failure
//   0: success
//------------------------------------------------------------------
int writePolicies( BOOL power, BOOL cpu )
{
  if( power && !WritePwrScheme(&internalProfile,L"Speedswitch Control",L"\0\0",&internalPolicy) )
  {
    ReadPwrScheme( internalProfile, &internalPolicy );
    return -1;
  }

  if( cpu && !WriteProcessorPwrScheme(internalProfile,&mach) )
  {
    ReadProcessorPwrScheme( internalProfile, &mach );

    if( power )
      SetActivePwrScheme( internalProfile, NULL, NULL );

    return -2;
  }

  SetActivePwrScheme( internalProfile, NULL, NULL );
  return 0;
}
Пример #3
0
//------------------------------------------------------------------
// set current ac/dc throttle and activate that
//------------------------------------------------------------------
BOOL setState( BOOL ac, BYTE policy )
{
  checkProfile( 1 );

  if( ac )
  {
    acThrottle = policy;
    mach.ProcessorPolicyAc.DynamicThrottle = policy;
  }
  else
  {
    dcThrottle = policy;
    mach.ProcessorPolicyDc.DynamicThrottle = policy;
  }

  if( !WriteProcessorPwrScheme(internalProfile,&mach) )
    return FALSE;

  if( !SetActivePwrScheme(internalProfile,NULL,NULL) )
    return FALSE;  

  return TRUE;
}
Пример #4
0
BOOL PowerSchemes::ApplyPowerSchemeXP(UINT & uiID)
{
	BOOL bResult = FALSE;
	if(GetActivePwrScheme(&uiID))
	{
		//printf("GetActivePwrScheme OK\n");

		//PROCESSOR_POWER_POLICY  ppp; 
		MACHINE_PROCESSOR_POWER_POLICY  mppp;
		/*
		ReadProcessorPwrScheme is available for use in the operating systems specified in the Requirements section. 
		Requirements: Windows XP [desktop apps only] | Windows Server 2003 [desktop apps only]  
		*/
		if(ReadProcessorPwrScheme(uiID, &mppp))
		{
			printf("ReadProcessorPwrScheme OK\n");

			mppp.ProcessorPolicyAc.Policy[0].AllowPromotion = 1; // C1
			mppp.ProcessorPolicyAc.Policy[1].AllowPromotion = 1; // C2
			mppp.ProcessorPolicyAc.Policy[2].AllowPromotion = 1; // C3
			if (WriteProcessorPwrScheme(uiID, &mppp))
				SetActivePwrScheme(uiID, 0, 0);

			bResult = TRUE;
		}
		else
		{
			//printf("ReadProcessorPwrScheme FAIL\n");
			bResult = FALSE;
		}
	}
	else {
		printf("GetActivePwrScheme FAIL\n"); 
		bResult = FALSE;;
	} 
	return bResult;
}
Пример #5
0
//------------------------------------------------------------------
// check power scheme integrity
//
// check: 0=no consistency check
//        1=check power scheme only
//        2=check processor scheme only
//        3=check both power and processor scheme
//------------------------------------------------------------------
BOOL checkProfile( int check )
{
  log( _T("Checking power scheme integrity ...") );
  
  CString err;
  err.LoadStringW( IDS_MAINERR2 );

  POWER_POLICY policyTemp;
  MACHINE_PROCESSOR_POWER_POLICY machTemp;
  static TCHAR msg[1024];   // für diverse Fehlertexte
  BOOL forceActivate = FALSE;

  if( !ReadPwrScheme(internalProfile,&policyTemp) )
  {
    log( _T("Recreating power scheme ...") );
    UINT x = internalProfile;

    if( !WritePwrScheme(&x,L"Speedswitch Control",L"\0\0",&internalPolicy) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW1 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }

    forceActivate = TRUE;
  }
  else if( check&1 )
  {
    if( !comparePowerProfile(policyTemp,internalPolicy) )
    {
      log( _T("Restoring power scheme data ...") );
      UINT x = internalProfile;

      if( !WritePwrScheme(&x,L"Speedswitch Control",L"\0\0",&internalPolicy) )
      {
        CString s1;
        s1.LoadStringW( IDS_SW2 );
        wsprintf( msg, s1, GetLastError() );
        MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
        return FALSE;
      }

      forceActivate = TRUE;
    }
  }

  if( !ReadProcessorPwrScheme(internalProfile,&machTemp) )
  {
    log( _T("Recreating processor scheme ...") );
    if( !WriteProcessorPwrScheme(internalProfile,&mach) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW3 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }   

    forceActivate = TRUE;
  }
  else if( check&2 )
  {
    if( !compareCPUScheme(machTemp,mach) )
    {
      log( _T("Restoring processor scheme data ...") );
      if( !WriteProcessorPwrScheme(internalProfile,&mach) )
      {
        CString s1;
        s1.LoadStringW( IDS_SW4 );
        wsprintf( msg, s1, GetLastError() );
        MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
        return FALSE;
      }  

      forceActivate = TRUE;
    }
  }

  UINT profile;

  if( !GetActivePwrScheme(&profile) )
  {
    CString s1;
    s1.LoadStringW( IDS_SW5 );
    wsprintf( msg, s1, GetLastError() );
    MessageBox( NULL, msg, err, MB_OK|MB_ICONEXCLAMATION );
    return FALSE;
  }

  if( forceActivate || profile!=internalProfile )
  {
    log( _T("Reactivating power scheme (%d, %d) ..."), profile, internalProfile );
    if( !SetActivePwrScheme(internalProfile,NULL,NULL) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW6 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }
  }

  return TRUE;
}