* Fixed typos, this also closes ticket #4026.
* Fixed many coding style issues. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StatusView.h"
|
#include "StatusView.h"
|
||||||
#include "CPUFrequencyView.h"
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -19,14 +20,16 @@
|
|||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include "CPUFrequencyView.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
||||||
|
|
||||||
|
|
||||||
#define MAX_FREQ_STRING "9999MHz"
|
#define MAX_FREQ_STRING "9999MHz"
|
||||||
|
|
||||||
// messages FrequencySwitcher
|
// messages FrequencySwitcher
|
||||||
const uint32 kMsgDynamicPolicyPuls = '&dpp';
|
const uint32 kMsgDynamicPolicyPulse = '&dpp';
|
||||||
|
|
||||||
// messages menu
|
// messages menu
|
||||||
const uint32 kMsgPolicyDynamic = 'pody';
|
const uint32 kMsgPolicyDynamic = 'pody';
|
||||||
@@ -48,7 +51,6 @@ FrequencySwitcher::FrequencySwitcher(CPUFreqDriverInterface* interface,
|
|||||||
fCurrentFrequency(NULL),
|
fCurrentFrequency(NULL),
|
||||||
fDynamicPolicyStarted(false)
|
fDynamicPolicyStarted(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +62,10 @@ FrequencySwitcher::~FrequencySwitcher()
|
|||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
FrequencySwitcher::Filter(BMessage *message, BHandler **target)
|
FrequencySwitcher::Filter(BMessage* message, BHandler** target)
|
||||||
{
|
{
|
||||||
filter_result result = B_DISPATCH_MESSAGE;
|
filter_result result = B_DISPATCH_MESSAGE;
|
||||||
if (message->what == kMsgDynamicPolicyPuls) {
|
if (message->what == kMsgDynamicPolicyPulse) {
|
||||||
_CalculateDynamicState();
|
_CalculateDynamicState();
|
||||||
result = B_SKIP_MESSAGE;
|
result = B_SKIP_MESSAGE;
|
||||||
}
|
}
|
||||||
@@ -84,8 +86,7 @@ FrequencySwitcher::SetMode(const freq_preferences& pref)
|
|||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
isDynamic = true;
|
isDynamic = true;
|
||||||
fSteppingThreshold = pref.stepping_threshold;
|
fSteppingThreshold = pref.stepping_threshold;
|
||||||
if (fMessageRunner && fIntegrationTime != pref.integration_time)
|
if (fMessageRunner && fIntegrationTime != pref.integration_time) {
|
||||||
{
|
|
||||||
fIntegrationTime = pref.integration_time;
|
fIntegrationTime = pref.integration_time;
|
||||||
fMessageRunner->SetInterval(fIntegrationTime);
|
fMessageRunner->SetInterval(fIntegrationTime);
|
||||||
}
|
}
|
||||||
@@ -128,13 +129,12 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
bigtime_t now = system_time();
|
bigtime_t now = system_time();
|
||||||
bigtime_t activeTime = sysInfo.cpu_infos[0].active_time;
|
bigtime_t activeTime = sysInfo.cpu_infos[0].active_time;
|
||||||
|
|
||||||
// if the dynamic mode is not started firt init the prev values
|
// if the dynamic mode is not started first init the prev values
|
||||||
if (!fDynamicPolicyStarted) {
|
if (!fDynamicPolicyStarted) {
|
||||||
fPrevActiveTime = activeTime;
|
fPrevActiveTime = activeTime;
|
||||||
fPrevTime = now;
|
fPrevTime = now;
|
||||||
fDynamicPolicyStarted = true;
|
fDynamicPolicyStarted = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
float usage = (float)(activeTime - fPrevActiveTime )
|
float usage = (float)(activeTime - fPrevActiveTime )
|
||||||
/ (now - fPrevTime);
|
/ (now - fPrevTime);
|
||||||
if (usage >= 1.0)
|
if (usage >= 1.0)
|
||||||
@@ -145,8 +145,7 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
float usageOfStep = ColorStepView::UsageOfStep(i, numberOfStates,
|
float usageOfStep = ColorStepView::UsageOfStep(i, numberOfStates,
|
||||||
fSteppingThreshold);
|
fSteppingThreshold);
|
||||||
|
|
||||||
if (usage < usageOfStep)
|
if (usage < usageOfStep) {
|
||||||
{
|
|
||||||
StateList* list = fDriverInterface->GetCpuFrequencyStates();
|
StateList* list = fDriverInterface->GetCpuFrequencyStates();
|
||||||
freq_info* newState = list->ItemAt(numberOfStates - 1 - i);
|
freq_info* newState = list->ItemAt(numberOfStates - 1 - i);
|
||||||
if (newState != fCurrentFrequency) {
|
if (newState != fCurrentFrequency) {
|
||||||
@@ -164,29 +163,27 @@ FrequencySwitcher::_CalculateDynamicState()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FrequencySwitcher::_StartDynamicPolicy(bool start,
|
FrequencySwitcher::_StartDynamicPolicy(bool start, const freq_preferences& pref)
|
||||||
const freq_preferences& pref)
|
|
||||||
{
|
{
|
||||||
if (start) {
|
if (start) {
|
||||||
if (!fMessageRunner) {
|
if (!fMessageRunner) {
|
||||||
fIntegrationTime = pref.integration_time;
|
fIntegrationTime = pref.integration_time;
|
||||||
fMessageRunner = new BMessageRunner(fTarget,
|
fMessageRunner = new BMessageRunner(fTarget,
|
||||||
new BMessage(kMsgDynamicPolicyPuls)
|
new BMessage(kMsgDynamicPolicyPulse), pref.integration_time, -1);
|
||||||
, pref.integration_time, -1);
|
|
||||||
fCurrentFrequency = fDriverInterface->GetCurrentFrequencyState();
|
fCurrentFrequency = fDriverInterface->GetCurrentFrequencyState();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (fMessageRunner) {
|
|
||||||
delete fMessageRunner;
|
delete fMessageRunner;
|
||||||
fMessageRunner = NULL;
|
fMessageRunner = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
||||||
PreferencesStorage<freq_preferences> * storage,
|
PreferencesStorage<freq_preferences>* storage,
|
||||||
CPUFreqDriverInterface* interface)
|
CPUFreqDriverInterface* interface)
|
||||||
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
|
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
@@ -197,7 +194,7 @@ FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
|||||||
new BMessage(kMsgPolicyDynamic));
|
new BMessage(kMsgPolicyDynamic));
|
||||||
fHighPerformance = new BMenuItem("High Performance",
|
fHighPerformance = new BMenuItem("High Performance",
|
||||||
new BMessage(kMsgPolicyPerformance));
|
new BMessage(kMsgPolicyPerformance));
|
||||||
fLowEnergie = new BMenuItem("Low Energie",
|
fLowEnergie = new BMenuItem("Low Energy",
|
||||||
new BMessage(kMsgPolicyLowEnergy));
|
new BMessage(kMsgPolicyLowEnergy));
|
||||||
|
|
||||||
menu->AddItem(fDynamicPerformance);
|
menu->AddItem(fDynamicPerformance);
|
||||||
@@ -242,15 +239,14 @@ FrequencyMenu::_SetL1MenuLabelFrom(BMenuItem* item)
|
|||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
FrequencyMenu::Filter(BMessage* msg, BHandler** target)
|
||||||
{
|
{
|
||||||
filter_result result = B_DISPATCH_MESSAGE;
|
filter_result result = B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
BMenuItem* item, *superItem, *markedItem;
|
BMenuItem* item, *superItem, *markedItem;
|
||||||
msg->FindPointer("source", (void**)&item);
|
msg->FindPointer("source", (void**)&item);
|
||||||
if (!item) {
|
if (!item)
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
bool safeChanges = false;
|
bool safeChanges = false;
|
||||||
freq_preferences* pref = fStorage->GetPreferences();
|
freq_preferences* pref = fStorage->GetPreferences();
|
||||||
@@ -307,8 +303,6 @@ FrequencyMenu::Filter(BMessage *msg, BHandler **target)
|
|||||||
void
|
void
|
||||||
FrequencyMenu::UpdateMenu()
|
FrequencyMenu::UpdateMenu()
|
||||||
{
|
{
|
||||||
BMenuItem* customItem, *markedItem, *superItem;
|
|
||||||
|
|
||||||
freq_preferences* pref = fStorage->GetPreferences();
|
freq_preferences* pref = fStorage->GetPreferences();
|
||||||
switch (pref->mode) {
|
switch (pref->mode) {
|
||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
@@ -324,20 +318,26 @@ FrequencyMenu::UpdateMenu()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
markedItem = fCustomStateMenu->FindMarked();
|
{
|
||||||
|
BMenuItem* markedItem = fCustomStateMenu->FindMarked();
|
||||||
if (markedItem)
|
if (markedItem)
|
||||||
markedItem->SetMarked(false);
|
markedItem->SetMarked(false);
|
||||||
customItem = fCustomStateMenu->ItemAt(pref->custom_stepping);
|
BMenuItem* customItem
|
||||||
|
= fCustomStateMenu->ItemAt(pref->custom_stepping);
|
||||||
if (customItem)
|
if (customItem)
|
||||||
customItem->SetMarked(true);
|
customItem->SetMarked(true);
|
||||||
superItem = fCustomStateMenu->Supermenu()->Superitem();
|
BMenuItem* superItem = fCustomStateMenu->Supermenu()->Superitem();
|
||||||
if (superItem && customItem)
|
if (superItem && customItem)
|
||||||
superItem->SetLabel(customItem->Label());
|
superItem->SetLabel(customItem->Label());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
StatusView::StatusView(BRect frame, bool inDeskbar,
|
StatusView::StatusView(BRect frame, bool inDeskbar,
|
||||||
PreferencesStorage<freq_preferences>* storage)
|
PreferencesStorage<freq_preferences>* storage)
|
||||||
: BView(frame, kDeskbarItemName, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
: BView(frame, kDeskbarItemName, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
@@ -359,8 +359,7 @@ StatusView::StatusView(BRect frame, bool inDeskbar,
|
|||||||
if (storage) {
|
if (storage) {
|
||||||
fOwningStorage = false;
|
fOwningStorage = false;
|
||||||
fStorage = storage;
|
fStorage = storage;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fOwningStorage = true;
|
fOwningStorage = true;
|
||||||
fStorage = new PreferencesStorage<freq_preferences>("CPUFrequency",
|
fStorage = new PreferencesStorage<freq_preferences>("CPUFrequency",
|
||||||
kDefaultPreferences);
|
kDefaultPreferences);
|
||||||
@@ -426,7 +425,7 @@ StatusView::_Quit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StatusView *
|
StatusView*
|
||||||
StatusView::Instantiate(BMessage* archive)
|
StatusView::Instantiate(BMessage* archive)
|
||||||
{
|
{
|
||||||
if (!validate_instantiation(archive, "StatusView"))
|
if (!validate_instantiation(archive, "StatusView"))
|
||||||
@@ -474,8 +473,7 @@ StatusView::AttachedToWindow()
|
|||||||
|
|
||||||
// perferences menu
|
// perferences menu
|
||||||
fPreferencesMenu = new BPopUpMenu(B_EMPTY_STRING, false, false);
|
fPreferencesMenu = new BPopUpMenu(B_EMPTY_STRING, false, false);
|
||||||
fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this,
|
fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this, fStorage,
|
||||||
fStorage,
|
|
||||||
&fDriverInterface);
|
&fDriverInterface);
|
||||||
|
|
||||||
fPreferencesMenu->SetFont(be_plain_font);
|
fPreferencesMenu->SetFont(be_plain_font);
|
||||||
@@ -626,10 +624,10 @@ StatusView::_Init()
|
|||||||
void
|
void
|
||||||
StatusView::_SetupNewFreqString()
|
StatusView::_SetupNewFreqString()
|
||||||
{
|
{
|
||||||
if (fCurrentFrequency)
|
if (fCurrentFrequency) {
|
||||||
fFreqString = ColorStepView::CreateFrequencyString(
|
fFreqString = ColorStepView::CreateFrequencyString(
|
||||||
fCurrentFrequency->frequency);
|
fCurrentFrequency->frequency);
|
||||||
else
|
} else
|
||||||
fFreqString = "? MHz";
|
fFreqString = "? MHz";
|
||||||
|
|
||||||
ResizeToPreferred();
|
ResizeToPreferred();
|
||||||
@@ -663,7 +661,10 @@ StatusView::_OpenPreferences()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" _EXPORT BView *
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" _EXPORT BView*
|
||||||
instantiate_deskbar_item(void)
|
instantiate_deskbar_item(void)
|
||||||
{
|
{
|
||||||
return new StatusView(BRect(0, 0, 15, 15), true, NULL);
|
return new StatusView(BRect(0, 0, 15, 15), true, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user