[Haiku-commits] r31058 - haiku/trunk/src/preferences/cpufrequency

axeld at BerliOS axeld at mail.berlios.de
Mon Jun 15 12:51:30 CEST 2009


Author: axeld
Date: 2009-06-15 12:51:29 +0200 (Mon, 15 Jun 2009)
New Revision: 31058
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31058&view=rev

Modified:
   haiku/trunk/src/preferences/cpufrequency/StatusView.cpp
Log:
* Fixed typos, this also closes ticket #4026.
* Fixed many coding style issues.


Modified: haiku/trunk/src/preferences/cpufrequency/StatusView.cpp
===================================================================
--- haiku/trunk/src/preferences/cpufrequency/StatusView.cpp	2009-06-15 09:49:12 UTC (rev 31057)
+++ haiku/trunk/src/preferences/cpufrequency/StatusView.cpp	2009-06-15 10:51:29 UTC (rev 31058)
@@ -7,8 +7,9 @@
  */
 
 #include "StatusView.h"
-#include "CPUFrequencyView.h"
 
+#include <string.h>
+
 #include <Alert.h>
 #include <Application.h>
 #include <Deskbar.h>
@@ -19,14 +20,16 @@
 #include <Roster.h>
 #include <TextView.h>
 
-#include <string.h>
+#include "CPUFrequencyView.h"
 
+
 extern "C" _EXPORT BView *instantiate_deskbar_item(void);
 
+
 #define MAX_FREQ_STRING "9999MHz"
 
 // messages FrequencySwitcher
-const uint32 kMsgDynamicPolicyPuls = '&dpp';
+const uint32 kMsgDynamicPolicyPulse = '&dpp';
 
 // messages menu
 const uint32 kMsgPolicyDynamic = 'pody';
@@ -40,15 +43,14 @@
 
 
 FrequencySwitcher::FrequencySwitcher(CPUFreqDriverInterface* interface,
-										BHandler* target)
-	:	BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE),
-		fDriverInterface(interface),
-		fTarget(target),
-		fMessageRunner(NULL),
-		fCurrentFrequency(NULL),
-		fDynamicPolicyStarted(false)
+		BHandler* target)
+	: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE),
+	fDriverInterface(interface),
+	fTarget(target),
+	fMessageRunner(NULL),
+	fCurrentFrequency(NULL),
+	fDynamicPolicyStarted(false)
 {
-
 }
 
 
@@ -60,10 +62,10 @@
 
 
 filter_result
-FrequencySwitcher::Filter(BMessage *message, BHandler **target)
+FrequencySwitcher::Filter(BMessage* message, BHandler** target)
 {
 	filter_result result = B_DISPATCH_MESSAGE;
-	if (message->what == kMsgDynamicPolicyPuls) {
+	if (message->what == kMsgDynamicPolicyPulse) {
 		_CalculateDynamicState();
 		result = B_SKIP_MESSAGE;
 	}
@@ -79,32 +81,31 @@
 	freq_info* currentState = fDriverInterface->GetCurrentFrequencyState();
 	freq_info* state = NULL;
 	bool isDynamic = false;
-	
+
 	switch (pref.mode) {
 		case DYNAMIC:
 			isDynamic = true;
 			fSteppingThreshold = pref.stepping_threshold;
-			if (fMessageRunner && fIntegrationTime != pref.integration_time)
-			{
+			if (fMessageRunner && fIntegrationTime != pref.integration_time) {
 				fIntegrationTime = pref.integration_time;
 				fMessageRunner->SetInterval(fIntegrationTime);
 			}
 			if (!fDynamicPolicyStarted)
 				_StartDynamicPolicy(true, pref);
 			break;
-		
+
 		case PERFORMANCE:
 			state = list->ItemAt(int32(0));
 			if (state != currentState)
 				fDriverInterface->SetFrequencyState(state);
 			break;
-		
+
 		case LOW_ENERGIE:
 			state = list->ItemAt(stateCount - 1);
 			if (state != currentState)
 				fDriverInterface->SetFrequencyState(state);
 			break;
-		
+
 		case CUSTOM:
 			if (pref.custom_stepping < stateCount) {
 				state = list->ItemAt(pref.custom_stepping);
@@ -112,7 +113,7 @@
 			}
 			break;
 	}
-	
+
 	if (!isDynamic && fDynamicPolicyStarted) {
 		fDynamicPolicyStarted = false;
 		_StartDynamicPolicy(false, pref);
@@ -127,26 +128,24 @@
 	get_system_info(&sysInfo);
 	bigtime_t now = system_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) {
 		fPrevActiveTime = activeTime;
 		fPrevTime = now;
 		fDynamicPolicyStarted = true;
-	}
-	else {
+	} else {
 		float usage = (float)(activeTime - fPrevActiveTime )
 						/ (now - fPrevTime);
 		if (usage >= 1.0)
 			usage = 0.9999999;
-			
+
 		int32 numberOfStates = fDriverInterface->GetNumberOfFrequencyStates();
 		for (int i = 0; i < numberOfStates; i++) {
 			float usageOfStep = ColorStepView::UsageOfStep(i, numberOfStates,
-														fSteppingThreshold);
+				fSteppingThreshold);
 
-			if (usage < usageOfStep)
-			{
+			if (usage < usageOfStep) {
 				StateList* list = fDriverInterface->GetCpuFrequencyStates();
 				freq_info* newState = list->ItemAt(numberOfStates - 1 - i);
 				if (newState != fCurrentFrequency) {
@@ -154,7 +153,7 @@
 					fDriverInterface->SetFrequencyState(newState);
 					fCurrentFrequency = newState;
 				}
-				break;	
+				break;
 			}
 		}
 		fPrevActiveTime = activeTime;
@@ -164,48 +163,46 @@
 
 
 void
-FrequencySwitcher::_StartDynamicPolicy(bool start,
-										const freq_preferences& pref)
+FrequencySwitcher::_StartDynamicPolicy(bool start, const freq_preferences& pref)
 {
 	if (start) {
 		if (!fMessageRunner) {
 			fIntegrationTime = pref.integration_time;
 			fMessageRunner = new BMessageRunner(fTarget,
-											new BMessage(kMsgDynamicPolicyPuls)
-											, pref.integration_time, -1);
+				new BMessage(kMsgDynamicPolicyPulse), pref.integration_time, -1);
 			fCurrentFrequency = fDriverInterface->GetCurrentFrequencyState();
 		}
+	} else {
+		delete fMessageRunner;
+		fMessageRunner = NULL;
 	}
-	else {
-		if (fMessageRunner) {
-			delete fMessageRunner;
-			fMessageRunner = NULL;
-		}
-	}
 }
 
 
+//	#pragma mark -
+
+
 FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
-								PreferencesStorage<freq_preferences> * storage,
-								CPUFreqDriverInterface* interface)
-	:	BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
-		fTarget(target),
-		fStorage(storage),
-		fInterface(interface)
+		PreferencesStorage<freq_preferences>* storage,
+		CPUFreqDriverInterface* interface)
+	: BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE),
+	fTarget(target),
+	fStorage(storage),
+	fInterface(interface)
 {
 	fDynamicPerformance = new BMenuItem("Dynamic Performance",
-											new BMessage(kMsgPolicyDynamic));
+		new BMessage(kMsgPolicyDynamic));
 	fHighPerformance = new BMenuItem("High Performance",
-										new BMessage(kMsgPolicyPerformance));
-	fLowEnergie = new BMenuItem("Low Energie",
-									new BMessage(kMsgPolicyLowEnergy));
-	
+		new BMessage(kMsgPolicyPerformance));
+	fLowEnergie = new BMenuItem("Low Energy",
+		new BMessage(kMsgPolicyLowEnergy));
+
 	menu->AddItem(fDynamicPerformance);
 	menu->AddItem(fHighPerformance);
 	menu->AddItem(fLowEnergie);
-	
+
 	fCustomStateMenu = new BMenu("Set State");
-			
+
 	StateList* stateList = fInterface->GetCpuFrequencyStates();
 	for (int i = 0; i < stateList->CountItems(); i++) {
 		freq_info* info = stateList->ItemAt(i);
@@ -213,16 +210,16 @@
 		label << info->frequency;
 		label += " MHz";
 		fCustomStateMenu->AddItem(new BMenuItem(label.String(),
-										new BMessage(kMsgPolicySetState)));
+			new BMessage(kMsgPolicySetState)));
 	}
-	
+
 	menu->AddItem(fCustomStateMenu);
-	
+
 	// set the target of the items
 	fDynamicPerformance->SetTarget(fTarget);
 	fHighPerformance->SetTarget(fTarget);
 	fLowEnergie->SetTarget(fTarget);
-	
+
 	fCustomStateMenu->SetTargetForItems(fTarget);
 }
 
@@ -242,19 +239,18 @@
 
 
 filter_result
-FrequencyMenu::Filter(BMessage *msg, BHandler **target)
+FrequencyMenu::Filter(BMessage* msg, BHandler** target)
 {
 	filter_result result = B_DISPATCH_MESSAGE;
-	
+
 	BMenuItem* item, *superItem, *markedItem;
 	msg->FindPointer("source", (void**)&item);
-	if (!item) {
+	if (!item)
 		return result;
-	}
-		
+
 	bool safeChanges = false;
 	freq_preferences* pref = fStorage->GetPreferences();
-	
+
 	switch (msg->what) {
 		case kMsgPolicyDynamic:
 			pref->mode = DYNAMIC;
@@ -262,25 +258,25 @@
 			safeChanges = true;
 			msg->what = kUpdatedPreferences;
 			break;
-			
+
 		case kMsgPolicyPerformance:
 			pref->mode = PERFORMANCE;
 			_SetL1MenuLabelFrom(item);
 			safeChanges = true;
 			msg->what = kUpdatedPreferences;
 			break;
-			
+
 		case kMsgPolicyLowEnergy:
 			pref->mode = LOW_ENERGIE;
 			_SetL1MenuLabelFrom(item);
 			safeChanges = true;
 			msg->what = kUpdatedPreferences;
 			break;
-			
+
 		case kMsgPolicySetState:
 			pref->mode = CUSTOM;
 			pref->custom_stepping = item->Menu()->IndexOf(item);
-			
+
 			superItem = item->Menu()->Supermenu()->Superitem();
 			if (superItem)
 				superItem->SetLabel(item->Label());
@@ -291,15 +287,15 @@
 			if (markedItem)
 				markedItem->SetMarked(false);
 			item->SetMarked(true);
-			
+
 			safeChanges = true;
 			msg->what = kUpdatedPreferences;
 			break;
 	}
-	
+
 	if (safeChanges)
 		fStorage->SavePreferences();
-		
+
 	return result;
 }
 
@@ -307,39 +303,43 @@
 void
 FrequencyMenu::UpdateMenu()
 {
-	BMenuItem* customItem, *markedItem, *superItem;
-	
 	freq_preferences* pref = fStorage->GetPreferences();
 	switch (pref->mode) {
 		case DYNAMIC:
 			_SetL1MenuLabelFrom(fDynamicPerformance);
 			break;
-			
+
 		case PERFORMANCE:
 			_SetL1MenuLabelFrom(fHighPerformance);
 			break;
-		
+
 		case LOW_ENERGIE:
 			_SetL1MenuLabelFrom(fLowEnergie);
 			break;
-		
+
 		case CUSTOM:
-			markedItem = fCustomStateMenu->FindMarked();
+		{
+			BMenuItem* markedItem = fCustomStateMenu->FindMarked();
 			if (markedItem)
 				markedItem->SetMarked(false);
-			customItem = fCustomStateMenu->ItemAt(pref->custom_stepping);
+			BMenuItem* customItem
+				= fCustomStateMenu->ItemAt(pref->custom_stepping);
 			if (customItem)
 				customItem->SetMarked(true);
-			superItem = fCustomStateMenu->Supermenu()->Superitem();
+			BMenuItem* superItem = fCustomStateMenu->Supermenu()->Superitem();
 			if (superItem && customItem)
-				superItem->SetLabel(customItem->Label());	
-			break;	
+				superItem->SetLabel(customItem->Label());
+			break;
+		}
 	}
 }
 
 
+//	#pragma mark -
+
+
 StatusView::StatusView(BRect frame,	bool inDeskbar,
-						PreferencesStorage<freq_preferences>* storage)
+		PreferencesStorage<freq_preferences>* storage)
 	: BView(frame, kDeskbarItemName, B_FOLLOW_LEFT | B_FOLLOW_TOP,
 		B_WILL_DRAW | B_FRAME_EVENTS),
 	fInDeskbar(inDeskbar),
@@ -355,17 +355,16 @@
 			B_FOLLOW_NONE);
 		AddChild(fDragger);
 	}
-	
+
 	if (storage) {
 		fOwningStorage = false;
 		fStorage = storage;
-	}
-	else {
+	} else {
 		fOwningStorage = true;
 		fStorage = new PreferencesStorage<freq_preferences>("CPUFrequency",
-																kDefaultPreferences);
+			kDefaultPreferences);
 	}
-	
+
 	_Init();
 }
 
@@ -383,7 +382,7 @@
 
 	fOwningStorage = true;
 	fStorage = new PreferencesStorage<freq_preferences>(kPreferencesFileName,
-															kDefaultPreferences);
+		kDefaultPreferences);
 	_Init();
 }
 
@@ -426,7 +425,7 @@
 }
 
 
-StatusView *
+StatusView*
 StatusView::Instantiate(BMessage* archive)
 {
 	if (!validate_instantiation(archive, "StatusView"))
@@ -459,30 +458,29 @@
 		SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
 
 	SetLowColor(ViewColor());
-	
+
 	// watching if the driver change the frequency
 	fDriverInterface.StartWatching(this);
 
 	// monitor preferences file
 	fPrefFileWatcher = new PrefFileWatcher<freq_preferences>(fStorage, this);
 	AddFilter(fPrefFileWatcher);
-	
+
 	// FrequencySwitcher
 	fFrequencySwitcher = new FrequencySwitcher(&fDriverInterface, this);
 	fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
 	AddFilter(fFrequencySwitcher);
-	
+
 	// perferences menu
 	fPreferencesMenu = new BPopUpMenu(B_EMPTY_STRING, false, false);
-	fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this,
-													fStorage,
-													&fDriverInterface);
-	
+	fPreferencesMenuFilter = new FrequencyMenu(fPreferencesMenu, this, fStorage,
+		&fDriverInterface);
+
 	fPreferencesMenu->SetFont(be_plain_font);
 
 	fPreferencesMenu->AddSeparatorItem();
 	fOpenPrefItem = new BMenuItem("Open Speedstep Preferences" B_UTF8_ELLIPSIS,
-									new BMessage(kMsgOpenSSPreferences));
+		new BMessage(kMsgOpenSSPreferences));
 	fPreferencesMenu->AddItem(fOpenPrefItem);
 	fOpenPrefItem->SetTarget(this);
 
@@ -492,7 +490,7 @@
 		fQuitItem->SetTarget(this);
 	}
 	AddFilter(fPreferencesMenuFilter);
-	
+
 	fPreferencesMenuFilter->UpdateMenu();
 }
 
@@ -501,7 +499,7 @@
 StatusView::DetachedFromWindow()
 {
 	fDriverInterface.StopWatching();
-	
+
 	if (RemoveFilter(fPrefFileWatcher))
 		delete fPrefFileWatcher;
 	if (RemoveFilter(fFrequencySwitcher))
@@ -525,16 +523,16 @@
 			_SetupNewFreqString();
 			Invalidate();
 			break;
-		
+
 		case kUpdatedPreferences:
 			fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
 			fPreferencesMenuFilter->UpdateMenu();
 			break;
-		
+
 		case B_ABOUT_REQUESTED:
 			_AboutRequested();
 			break;
-				
+
 		case B_QUIT_REQUESTED:
 			_Quit();
 			break;
@@ -558,9 +556,9 @@
 	font_height fontHeight;
 	GetFontHeight(&fontHeight);
 	float height = fontHeight.ascent + fontHeight.descent;
-	
+
 	MovePenTo(0, height);
-	
+
 	DrawString(fFreqString.String());
 }
 
@@ -612,13 +610,13 @@
 	fFrequencySwitcher->SetMode(*(fStorage->GetPreferences()));
 }
 
-			
+
 void
 StatusView::_Init()
 {
 	fShowPopUpMenu = true;
 	fCurrentFrequency = fDriverInterface.GetCurrentFrequencyState();
-	
+
 	_SetupNewFreqString();
 }
 
@@ -626,10 +624,10 @@
 void
 StatusView::_SetupNewFreqString()
 {
-	if (fCurrentFrequency)
+	if (fCurrentFrequency) {
 		fFreqString = ColorStepView::CreateFrequencyString(
 			fCurrentFrequency->frequency);
-	else 
+	} else
 		fFreqString = "? MHz";
 
 	ResizeToPreferred();
@@ -663,7 +661,10 @@
 }
 
 
-extern "C" _EXPORT BView *
+//	#pragma mark -
+
+
+extern "C" _EXPORT BView*
 instantiate_deskbar_item(void)
 {
 	return new StatusView(BRect(0, 0, 15, 15), true, NULL);




More information about the Haiku-commits mailing list