* Improved the disabled look (in case there is no battery -- apparently, the

ACPI interface needs some more work, as it currently uses
  BATTERY_CRITICAL_STATE to report that there is no battery...).
* Cleanup of many more of Clemens' coding style violations...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32256 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-11 17:49:27 +00:00
parent bd767f5a4e
commit 95ea1dab5a
7 changed files with 74 additions and 76 deletions
+11 -14
View File
@@ -5,10 +5,10 @@
* Authors:
* Clemens Zeidler, [email protected]
*/
#ifndef ACPI_DRIVER_INTERFACE_H
#define ACPI_DRIVER_INTERFACE_H
#include "DriverInterface.h"
#include <Locker.h>
@@ -17,13 +17,12 @@
const int8 kRateBufferSize = 10;
class RateBuffer
{
class RateBuffer {
public:
RateBuffer();
void AddRate(int32 rate);
int32 GetMeanRate();
private:
int32 fRateBuffer[kRateBufferSize];
int8 fPosition;
@@ -32,11 +31,10 @@ private:
};
class Battery
{
class Battery {
public:
Battery(int driverHandler);
~Battery();
~Battery();
status_t InitCheck();
@@ -49,19 +47,18 @@ public:
private:
void _Init();
int fDriverHandler;
status_t fInitStatus;
acpi_extended_battery_info fExtendedBatteryInfo;
RateBuffer fRateBuffer;
acpi_battery_info fCachedAcpiInfo;
};
class ACPIDriverInterface : public PowerStatusDriverInterface
{
class ACPIDriverInterface : public PowerStatusDriverInterface {
public:
virtual ~ACPIDriverInterface();
@@ -75,13 +72,13 @@ public:
protected:
// Read the battery info from the hardware.
virtual status_t _ReadBatteryInfo();
virtual void _WatchPowerStatus();
virtual status_t _FindDrivers(const char* path);
BObjectList<Battery> fDriverList;
BLocker fInterfaceLocker;
};
#endif
#endif // ACPI_DRIVER_INTERFACE_H
+6 -7
View File
@@ -5,31 +5,30 @@
* Authors:
* Clemens Zeidler, [email protected]
*/
#ifndef APM_DRIVER_INTERFACE_H
#define APM_DRIVER_INTERFACE_H
#include "DriverInterface.h"
class APMDriverInterface : public PowerStatusDriverInterface
{
class APMDriverInterface : public PowerStatusDriverInterface {
public:
virtual ~APMDriverInterface();
virtual status_t Connect();
virtual status_t GetBatteryInfo(battery_info* info, int32 index);
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
int32 index);
int32 index);
virtual int32 GetBatteryCount();
protected:
virtual void _WatchPowerStatus();
private:
private:
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
int fDevice;
#endif
};
#endif
#endif // APM_DRIVER_INTERFACE_H
+24 -30
View File
@@ -1,11 +1,12 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler, [email protected]
*/
#include "DriverInterface.h"
#include <Autolock.h>
@@ -14,7 +15,6 @@
Monitor::~Monitor()
{
}
@@ -39,8 +39,7 @@ Monitor::StopWatching(BHandler* target)
void
Monitor::Broadcast(uint32 message)
{
for (int i = 0; i < fWatcherList.CountItems(); i++)
{
for (int i = 0; i < fWatcherList.CountItems(); i++) {
BMessenger messenger(fWatcherList.ItemAt(i));
messenger.SendMessage(message);
}
@@ -50,9 +49,9 @@ Monitor::Broadcast(uint32 message)
PowerStatusDriverInterface::PowerStatusDriverInterface()
:
fIsWatching(0),
fThreadId(-1)
fThread(-1)
{
}
@@ -67,27 +66,25 @@ PowerStatusDriverInterface::StartWatching(BHandler* target)
{
BAutolock autolock(fListLocker);
status_t status = Monitor::StartWatching(target);
if (status != B_OK)
return status;
if (fThreadId > 0)
if (fThread > 0)
return B_OK;
fThreadId = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
B_LOW_PRIORITY, this);
if (fThreadId >= 0) {
atomic_set(&fIsWatching, 1);
status = resume_thread(fThreadId);
}
else
return fThreadId;
if (status != B_OK && fWatcherList.CountItems() == 0) {
fThread = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
B_LOW_PRIORITY, this);
if (fThread >= 0) {
atomic_set(&fIsWatching, 1);
status = resume_thread(fThread);
} else
return fThread;
if (status != B_OK && fWatcherList.CountItems() == 0)
atomic_set(&fIsWatching, 0);
}
return status;
}
@@ -95,17 +92,15 @@ status_t
PowerStatusDriverInterface::StopWatching(BHandler* target)
{
BAutolock autolock(fListLocker);
if (fThreadId < 0)
if (fThread < 0)
return B_BAD_VALUE;
status_t status;
if (fWatcherList.CountItems() == 1) {
atomic_set(&fIsWatching, 0);
status = wait_for_thread(fThreadId, &status);
fThreadId = -1;
wait_for_thread(fThread, NULL);
fThread = -1;
}
return Monitor::StopWatching(target);
}
@@ -122,9 +117,8 @@ void
PowerStatusDriverInterface::Disconnect()
{
atomic_set(&fIsWatching, 0);
status_t status;
wait_for_thread(fThreadId, &status);
fThreadId = -1;
wait_for_thread(fThread, NULL);
fThread = -1;
}
+13 -15
View File
@@ -1,14 +1,14 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler, [email protected]
*/
#ifndef DRIVER_INTERFACE_H
#define DRIVER_INTERFACE_H
#include <Handler.h>
#include <Locker.h>
#include <ObjectList.h>
@@ -16,13 +16,13 @@
#include "device/power_managment.h"
typedef BObjectList<BHandler> WatcherList;
const uint32 kMsgUpdate = 'updt';
struct battery_info
{
struct battery_info {
int8 state;
int32 capacity;
int32 full_capacity;
@@ -32,11 +32,10 @@ struct battery_info
/*! Handle a list of watcher and broadcast a messages to them. */
class Monitor
{
class Monitor {
public:
virtual ~Monitor();
virtual status_t StartWatching(BHandler* target);
virtual status_t StopWatching(BHandler* target);
@@ -44,12 +43,10 @@ public:
protected:
WatcherList fWatcherList;
};
class PowerStatusDriverInterface : public Monitor, public Referenceable
{
class PowerStatusDriverInterface : public Monitor, public Referenceable {
public:
PowerStatusDriverInterface();
~PowerStatusDriverInterface();
@@ -57,26 +54,27 @@ public:
virtual status_t StartWatching(BHandler* target);
virtual status_t StopWatching(BHandler* target);
virtual void Broadcast(uint32 message);
virtual status_t Connect() = 0;
virtual void Disconnect();
virtual status_t GetBatteryInfo(battery_info* status, int32 index) = 0;
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
int32 index) = 0;
virtual int32 GetBatteryCount() = 0;
protected:
virtual void _WatchPowerStatus() = 0;
vint32 fIsWatching;
private:
static int32 _ThreadWatchPowerFunction(void* data);
thread_id fThreadId;
thread_id fThread;
BLocker fListLocker;
};
#endif
#endif // DRIVER_INTERFACE_H
-1
View File
@@ -79,7 +79,6 @@ PowerStatus::ReadyToRun()
isInstalled = deskbar.HasItem(kDeskbarItemName);
}
isInstalled = true;
if (isDeskbarRunning && !isInstalled) {
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
+19 -9
View File
@@ -191,30 +191,27 @@ PowerStatusView::_DrawBattery(BRect rect)
rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));
int32 percent = fPercent;
if (percent > 100 || percent < 0)
if (percent > 100 || percent < 0 || !fHasBattery)
percent = 100;
if (percent > 0) {
rgb_color base;
if (fOnline) {
if (fHasBattery) {
if (percent <= 15)
base.set_to(180, 0, 0);
else
base.set_to(20, 180, 0);
} else {
base = HighColor();
percent = 100;
}
rect.InsetBy(gap, gap);
rect.right = rect.left + rect.Width() * percent / 100.0;
if (be_control_look != NULL)
if (be_control_look != NULL) {
be_control_look->DrawButtonBackground(this, rect, rect, base,
fOnline ? 0 : BControlLook::B_DISABLED);
//if (!)
else
fHasBattery ? 0 : BControlLook::B_DISABLED);
} else
FillRect(rect);
}
@@ -343,11 +340,15 @@ PowerStatusView::Update(bool force)
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
fTimeLeft = fBatteryInfo.time_left;
if (fBatteryInfo.state & BATTERY_CHARGING)
if ((fBatteryInfo.state & BATTERY_CHARGING) != 0)
fOnline = true;
else
fOnline = false;
// TODO: if critical really means that, its name should be changed...
fHasBattery = (fBatteryInfo.state & BATTERY_CRITICAL_STATE) == 0
&& fPercent >= 0;
if (fInDeskbar) {
// make sure the tray icon is large enough
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
@@ -358,6 +359,15 @@ PowerStatusView::Update(bool force)
if (text[0])
width += ceilf(StringWidth(text)) + 4;
} else {
char text[256];
if (fHasBattery) {
snprintf(text, sizeof(text), "%ld%%\n%ld:%02ld\n%s",
fPercent, fTimeLeft / 3600, (fTimeLeft / 60) % 60,
fOnline ? "charging" : "discharging");
} else
strcpy(text, "no battery");
SetToolTip(text);
}
if (width == 0) {
// make sure we're not going away completely
+1
View File
@@ -60,6 +60,7 @@ protected:
int32 fPercent;
time_t fTimeLeft;
bool fOnline;
bool fHasBattery;
BSize fPreferredSize;
};