Esempio n. 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;
}
Esempio n. 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;
}
Esempio n. 3
0
//------------------------------------------------------------------
// Detect our own profile no
//
// return codes:
//   -1: profile enumeration failed
//   -2: profile not found (profile creation necessary)
//   -3: CPU policy reading from our own profile failed
//   -4: new profile activation failed
//   >=0: profile no (success)
//------------------------------------------------------------------
int detectProfile()
{
  internalProfile = 0xffffffff;
  lastChecked = 0xffffffff;

  if( !EnumPwrSchemes(&powerSchemeCallback,0) )
    return -1;      // enumeration failed

  if( internalProfile == 0xffffffff )
    return -2;      // profile not found

  // read the current CPU policy from our profile
  if( !ReadProcessorPwrScheme(internalProfile,&mach) )
    return -3;      // CPU policy reading failed

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

  updateStates();

  return internalProfile;   // profile found, return profile no
}
Esempio n. 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;
}
Esempio n. 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;
}