[haiku-commits] haiku: hrev48633 - in src: apps/powerstatus add-ons/mail_daemon/inbound_protocols/imap

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 8 Jan 2015 15:37:23 +0100 (CET)

hrev48633 adds 6 changesets to branch 'master'
old head: f873c092c7164072b8a54e95c2f637cfc8829795
new head: 070e77cc591bbd58756040c4b5b67aae15cd9e99
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=070e77c+%5Ef873c09

----------------------------------------------------------------------------

4fe2002: IMAP: fixed GCC4 build.

6f04ad0: ACPI: increased acpi DPC thread priority.
  
  * Since the power status outages only happen on load, it's likely
    that we run some code too late (I haven't looked at the ACPI specs,
    though).
  * In any case, I now get wrong results much less often.

90169e6: PowerStatus: give the locker a name.
  
  * Plus minor cleanup.

b19e9d5: PowerStatus: improved API, minor fixes.
  
  * ioctl() does not return a status_t; fixed its usage.
  * Do not overwrite the cached battery info with bogus data (this is
    quite strict, though).
  * Improved DriverInterface API with a more "natural" argument order.
  * Simplified some code.

e889ce2: PowerStatus: fixed how the info is retrieved.
  
  * The state was usually 0 once there was more than one battery
    slot.
  * We now ignore missing batteries completely, instead of taking
    eventually bogus data into account.
  * Fixed how to determine fOnline, and fHasBattery, and when to ignore
    probes.
  * Made it more strict when to show the notification, ie. it's now only
    shown when actually discharging.
  * This fixes all spurious notifications for me.

070e77c: PowerStatus: added note battery color.
  
  * When the capacity drops below 30%, it now turns yellow.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

13 files changed, 175 insertions(+), 208 deletions(-)
.../kernel/bus_managers/acpi/BusManager.cpp      |   4 +-
.../inbound_protocols/imap/IMAPFolder.h          |   8 +-
.../inbound_protocols/imap/IMAPMailbox.h         |   6 +-
.../inbound_protocols/imap/IMAPProtocol.cpp      |   4 +-
src/apps/powerstatus/ACPIDriverInterface.cpp     | 113 ++++++++++---------
src/apps/powerstatus/ACPIDriverInterface.h       |  47 ++++----
src/apps/powerstatus/APMDriverInterface.cpp      |  71 ++----------
src/apps/powerstatus/APMDriverInterface.h        |  22 ++--
src/apps/powerstatus/DriverInterface.cpp         |   5 +-
src/apps/powerstatus/DriverInterface.h           |  48 ++++----
src/apps/powerstatus/ExtendedInfoWindow.cpp      |   8 +-
src/apps/powerstatus/PowerStatusView.cpp         |  43 ++++---
src/apps/powerstatus/PowerStatusView.h           |   4 +-

############################################################################

Commit:      4fe2002b472457c74c6ba59f4ceec5606df6a690
URL:         http://cgit.haiku-os.org/haiku/commit/?id=4fe2002
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 09:33:22 2015 UTC

IMAP: fixed GCC4 build.

----------------------------------------------------------------------------

diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h 
b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h
index 997b65c..f818cd8 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2012-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef IMAP_FOLDER_H
@@ -15,6 +15,7 @@
 #include <String.h>
 
 
+class BFile;
 class IMAPProtocol;
 
 
@@ -94,8 +95,13 @@ private:
                                                                        size_t& 
length);
 
 private:
+#if __GNUC__ >= 4
+       typedef __gnu_cxx::hash_map<uint32, uint32> UIDToFlagsMap;
+       typedef __gnu_cxx::hash_map<uint32, entry_ref> UIDToRefMap;
+#else
        typedef std::hash_map<uint32, uint32> UIDToFlagsMap;
        typedef std::hash_map<uint32, entry_ref> UIDToRefMap;
+#endif
 
                        IMAPProtocol&           fProtocol;
                        const entry_ref         fRef;
diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPMailbox.h 
b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPMailbox.h
index d1fa8ed..ada972e 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPMailbox.h
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPMailbox.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2013-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef IMAP_MAILBOX_H
@@ -53,7 +53,11 @@ protected:
                uint32  flags;
                uint32  size;
        };
+#if __GNUC__ >= 4
+       typedef __gnu_cxx::hash_map<uint32, MessageFlagsAndSize> 
MessageEntryMap;
+#else
        typedef std::hash_map<uint32, MessageFlagsAndSize> MessageEntryMap;
+#endif
 
                        IMAP::Protocol&         fProtocol;
                        BString                         fMailboxName;
diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp 
b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp
index 17ccf22..a93cbdf 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2013-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 
@@ -127,7 +127,7 @@ IMAPProtocol::MessageStored(IMAPFolder& folder, entry_ref& 
ref, BFile& stream,
        uint32 fetchFlags, BMessage& attributes)
 {
        if ((fetchFlags & (IMAP::kFetchHeader | IMAP::kFetchBody))
-                       == IMAP::kFetchHeader | IMAP::kFetchBody) {
+                       == (IMAP::kFetchHeader | IMAP::kFetchBody)) {
                ProcessMessageFetched(ref, stream, attributes);
        } else if ((fetchFlags & IMAP::kFetchHeader) != 0) {
                ProcessHeaderFetched(ref, stream, attributes);

############################################################################

Commit:      6f04ad0358fde871c86238cda5d9dc21d67ed40b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6f04ad0
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 09:34:01 2015 UTC

ACPI: increased acpi DPC thread priority.

* Since the power status outages only happen on load, it's likely
  that we run some code too late (I haven't looked at the ACPI specs,
  though).
* In any case, I now get wrong results much less often.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/bus_managers/acpi/BusManager.cpp 
b/src/add-ons/kernel/bus_managers/acpi/BusManager.cpp
index 79a4828..9e8d2b0 100644
--- a/src/add-ons/kernel/bus_managers/acpi/BusManager.cpp
+++ b/src/add-ons/kernel/bus_managers/acpi/BusManager.cpp
@@ -1,7 +1,7 @@
 /*
  * Copyright 2009, Vincent Duvert, vincent.duvert@xxxxxxx
  * Copyright 2009, Clemens Zeidler, haiku@xxxxxxxxxxxxxxxxxx
- * Copyright 2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2008-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Copyright 2006, Bryan Varner. All rights reserved.
  * Copyright 2005, Nathan Whitehorn. All rights reserved.
  *
@@ -203,7 +203,7 @@ acpi_std_ops(int32 op,...)
                        }
 
                        if (gDPC->new_dpc_queue(&gDPCHandle, "acpi_task",
-                                       B_NORMAL_PRIORITY) != B_OK) {
+                                       B_URGENT_DISPLAY_PRIORITY + 1) != B_OK) 
{
                                ERROR("failed to create os execution queue\n");
                                return B_ERROR;
                        }

############################################################################

Commit:      90169e6310ba20c6c41ee81347d27724c3cf7080
URL:         http://cgit.haiku-os.org/haiku/commit/?id=90169e6
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 09:42:58 2015 UTC

PowerStatus: give the locker a name.

* Plus minor cleanup.

----------------------------------------------------------------------------

diff --git a/src/apps/powerstatus/ACPIDriverInterface.cpp 
b/src/apps/powerstatus/ACPIDriverInterface.cpp
index 5fe3187..e66567c 100644
--- a/src/apps/powerstatus/ACPIDriverInterface.cpp
+++ b/src/apps/powerstatus/ACPIDriverInterface.cpp
@@ -17,13 +17,15 @@
 #include <Path.h>
 
 
+static const char* kDriverDir = "/dev/power";
+
+
 RateBuffer::RateBuffer()
        :
        fPosition(0),
        fSize(kRateBufferSize),
        fCurrentSize(0)
 {
-
 }
 
 
@@ -55,6 +57,9 @@ RateBuffer::GetMeanRate()
 }
 
 
+// #pragma mark -
+
+
 Battery::Battery(int driverHandler)
        :
        fDriverHandler(driverHandler)
@@ -148,6 +153,10 @@ ACPIDriverInterface::~ACPIDriverInterface()
        for (int i = 0; i < fDriverList.CountItems(); i++)
                delete fDriverList.ItemAt(i);
 
+ACPIDriverInterface::ACPIDriverInterface()
+       :
+       fInterfaceLocker("acpi interface")
+{
 }
 
 
diff --git a/src/apps/powerstatus/ACPIDriverInterface.h 
b/src/apps/powerstatus/ACPIDriverInterface.h
index 17285bc..ca28599 100644
--- a/src/apps/powerstatus/ACPIDriverInterface.h
+++ b/src/apps/powerstatus/ACPIDriverInterface.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -19,15 +19,15 @@ const int8 kRateBufferSize = 10;
 
 class RateBuffer {
 public:
-                                                       RateBuffer();
-       void                                    AddRate(int32 rate);
-       int32                                   GetMeanRate();
+                                                               RateBuffer();
+       void                                            AddRate(int32 rate);
+       int32                                           GetMeanRate();
 
 private:
-       int32                                   fRateBuffer[kRateBufferSize];
-       int8                                    fPosition;
-       int8                                    fSize;
-       int8                                    fCurrentSize;
+       int32                                           
fRateBuffer[kRateBufferSize];
+       int8                                            fPosition;
+       int8                                            fSize;
+       int8                                            fCurrentSize;
 };
 
 
@@ -47,7 +47,7 @@ public:
 private:
        void                                            _Init();
 
-
+private:
        int                                                     fDriverHandler;
        status_t                                        fInitStatus;
 
@@ -60,7 +60,8 @@ private:
 
 class ACPIDriverInterface : public PowerStatusDriverInterface {
 public:
-       virtual                                 ~ACPIDriverInterface();
+                                                               
ACPIDriverInterface();
+       virtual                                         ~ACPIDriverInterface();
 
        virtual status_t                Connect();
        virtual status_t                GetBatteryInfo(battery_info* info, 
int32 index);
diff --git a/src/apps/powerstatus/DriverInterface.cpp 
b/src/apps/powerstatus/DriverInterface.cpp
index c10cea9..2fab528 100644
--- a/src/apps/powerstatus/DriverInterface.cpp
+++ b/src/apps/powerstatus/DriverInterface.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -53,7 +53,8 @@ PowerStatusDriverInterface::PowerStatusDriverInterface()
        :
        fIsWatching(0),
        fWaitSem(-1),
-       fThread(-1)
+       fThread(-1),
+       fListLocker("driver list")
 {
 }
 

############################################################################

Commit:      b19e9d5b71831ec5df3f2b06632bfef3d0bdcab9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b19e9d5
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 14:22:32 2015 UTC

PowerStatus: improved API, minor fixes.

* ioctl() does not return a status_t; fixed its usage.
* Do not overwrite the cached battery info with bogus data (this is
  quite strict, though).
* Improved DriverInterface API with a more "natural" argument order.
* Simplified some code.

----------------------------------------------------------------------------

diff --git a/src/apps/powerstatus/ACPIDriverInterface.cpp 
b/src/apps/powerstatus/ACPIDriverInterface.cpp
index e66567c..58a2820 100644
--- a/src/apps/powerstatus/ACPIDriverInterface.cpp
+++ b/src/apps/powerstatus/ACPIDriverInterface.cpp
@@ -1,15 +1,18 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
  *             Clemens Zeidler, haiku@xxxxxxxxxxxxxxxxxx
  */
 
 
 #include "ACPIDriverInterface.h"
 
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <Autolock.h>
 #include <Directory.h>
@@ -82,15 +85,19 @@ Battery::InitCheck()
 
 
 status_t
-Battery::ReadBatteryInfo()
+Battery::UpdateBatteryInfo()
 {
-       status_t status;
-       status = ioctl(fDriverHandler, GET_BATTERY_INFO, &fCachedAcpiInfo,
-               sizeof(acpi_battery_info));
+       acpi_battery_info info;
+       if (ioctl(fDriverHandler, GET_BATTERY_INFO, &info,
+                       sizeof(acpi_battery_info)) != 0)
+               return errno;
 
-       if (status != B_OK)
-               return status;
+       if ((fExtendedBatteryInfo.last_full_charge > 0
+                       && info.capacity > 
fExtendedBatteryInfo.last_full_charge)
+               || info.capacity < 0)
+               return B_BAD_DATA;
 
+       fCachedInfo = info;
        return B_OK;
 }
 
@@ -98,15 +105,16 @@ Battery::ReadBatteryInfo()
 status_t
 Battery::GetBatteryInfoCached(battery_info* info)
 {
-       info->state = fCachedAcpiInfo.state;
-       info->current_rate = fCachedAcpiInfo.current_rate;
-       info->capacity = fCachedAcpiInfo.capacity;
+       info->state = fCachedInfo.state;
+       info->current_rate = fCachedInfo.current_rate;
+       info->capacity = fCachedInfo.capacity;
        info->full_capacity = fExtendedBatteryInfo.last_full_charge;
-       fRateBuffer.AddRate(fCachedAcpiInfo.current_rate);
-       if (fCachedAcpiInfo.current_rate > 0 && fRateBuffer.GetMeanRate() != 0)
-               info->time_left = 3600 * fCachedAcpiInfo.capacity
+
+       fRateBuffer.AddRate(fCachedInfo.current_rate);
+       if (fCachedInfo.current_rate > 0 && fRateBuffer.GetMeanRate() != 0) {
+               info->time_left = 3600 * fCachedInfo.capacity
                        / fRateBuffer.GetMeanRate();
-       else
+       } else
                info->time_left = -1;
 
        return B_OK;
@@ -116,11 +124,11 @@ Battery::GetBatteryInfoCached(battery_info* info)
 status_t
 Battery::GetExtendedBatteryInfo(acpi_extended_battery_info* info)
 {
-       status_t status;
-       status = ioctl(fDriverHandler, GET_EXTENDED_BATTERY_INFO, info,
-               sizeof(acpi_extended_battery_info));
+       if (ioctl(fDriverHandler, GET_EXTENDED_BATTERY_INFO, info,
+                       sizeof(acpi_extended_battery_info)) != 0)
+               return errno;
 
-       return status;
+       return B_OK;
 }
 
 
@@ -128,30 +136,21 @@ void
 Battery::_Init()
 {
        uint32 magicId = 0;
-       fInitStatus = ioctl(fDriverHandler, IDENTIFY_DEVICE, &magicId,
-               sizeof(uint32));
-       if (fInitStatus != B_OK)
-               return;
-
-       fInitStatus = ioctl(fDriverHandler, GET_EXTENDED_BATTERY_INFO,
-               &fExtendedBatteryInfo, sizeof(acpi_extended_battery_info));
-       if (fInitStatus != B_OK)
+       if (ioctl(fDriverHandler, IDENTIFY_DEVICE, &magicId, sizeof(uint32)) != 
0) {
+               fInitStatus = errno;
                return;
-
-       fInitStatus = ioctl(fDriverHandler, GET_BATTERY_INFO, &fCachedAcpiInfo,
-               sizeof(acpi_battery_info));
+       }
+       fInitStatus = GetExtendedBatteryInfo(&fExtendedBatteryInfo);
        if (fInitStatus != B_OK)
                return;
 
        printf("ACPI driver found\n");
-
+       UpdateBatteryInfo();
 }
 
 
-ACPIDriverInterface::~ACPIDriverInterface()
-{
-       for (int i = 0; i < fDriverList.CountItems(); i++)
-               delete fDriverList.ItemAt(i);
+// #pragma mark - ACPIDriverInterface
+
 
 ACPIDriverInterface::ACPIDriverInterface()
        :
@@ -160,42 +159,40 @@ ACPIDriverInterface::ACPIDriverInterface()
 }
 
 
-const char* kDriverDir = "/dev/power";
+ACPIDriverInterface::~ACPIDriverInterface()
+{
+       for (int i = 0; i < fDriverList.CountItems(); i++)
+               delete fDriverList.ItemAt(i);
+}
 
 
 status_t
 ACPIDriverInterface::Connect()
 {
-       printf("ACPI connect\n");
        return _FindDrivers(kDriverDir);
 }
 
 
 status_t
-ACPIDriverInterface::GetBatteryInfo(battery_info* info, int32 index)
+ACPIDriverInterface::GetBatteryInfo(int32 index, battery_info* info)
 {
        BAutolock autolock(fInterfaceLocker);
        if (index < 0 || index >= fDriverList.CountItems())
                return B_ERROR;
 
-       status_t status;
-       status = fDriverList.ItemAt(index)->GetBatteryInfoCached(info);
-       return status;
+       return fDriverList.ItemAt(index)->GetBatteryInfoCached(info);
 }
 
 
 status_t
-ACPIDriverInterface::GetExtendedBatteryInfo(acpi_extended_battery_info* info,
-       int32 index)
+ACPIDriverInterface::GetExtendedBatteryInfo(int32 index,
+       acpi_extended_battery_info* info)
 {
        BAutolock autolock(fInterfaceLocker);
        if (index < 0 || index >= fDriverList.CountItems())
                return B_ERROR;
 
-       status_t status;
-       status = fDriverList.ItemAt(index)->GetExtendedBatteryInfo(info);
-
-       return status;
+       return fDriverList.ItemAt(index)->GetExtendedBatteryInfo(info);
 }
 
 
@@ -207,10 +204,10 @@ ACPIDriverInterface::GetBatteryCount()
 
 
 status_t
-ACPIDriverInterface::_ReadBatteryInfo()
+ACPIDriverInterface::_UpdateBatteryInfo()
 {
        for (int i = 0; i < fDriverList.CountItems(); i++)
-               fDriverList.ItemAt(i)->ReadBatteryInfo();
+               fDriverList.ItemAt(i)->UpdateBatteryInfo();
 
        return B_OK;
 }
@@ -223,7 +220,7 @@ ACPIDriverInterface::_WatchPowerStatus()
                // every two seconds
 
        while (atomic_get(&fIsWatching) > 0) {
-               _ReadBatteryInfo();
+               _UpdateBatteryInfo();
                Broadcast(kMsgUpdate);
                acquire_sem_etc(fWaitSem, 1, B_RELATIVE_TIMEOUT, 
kUpdateInterval);
        }
@@ -245,21 +242,18 @@ ACPIDriverInterface::_FindDrivers(const char* dirpath)
                if (entry.IsDirectory()) {
                        if (_FindDrivers(path.Path()) == B_OK)
                                return B_OK;
-               }
-               else {
+               } else {
                        int32 handler = open(path.Path(), O_RDWR);
                        if (handler >= 0) {
                                printf("try %s\n", path.Path());
                                Battery* battery = new Battery(handler);
-                               if (battery->InitCheck() == B_OK) {
-                                       fDriverList.AddItem(battery);
+                               if (battery->InitCheck() == B_OK
+                                       && fDriverList.AddItem(battery)) {
                                        status = B_OK;
-                               }
-                               else
+                               } else
                                        delete battery;
                        }
                }
-
        }
        return status;
 }
diff --git a/src/apps/powerstatus/ACPIDriverInterface.h 
b/src/apps/powerstatus/ACPIDriverInterface.h
index ca28599..2390a65 100644
--- a/src/apps/powerstatus/ACPIDriverInterface.h
+++ b/src/apps/powerstatus/ACPIDriverInterface.h
@@ -39,7 +39,7 @@ public:
        status_t                                        InitCheck();
 
        // Read battery info and update the cache.
-       status_t                                        ReadBatteryInfo();
+       status_t                                        UpdateBatteryInfo();
        status_t                                        
GetBatteryInfoCached(battery_info* info);
        status_t                                        GetExtendedBatteryInfo(
                                                                        
acpi_extended_battery_info* info);
@@ -54,7 +54,7 @@ private:
        acpi_extended_battery_info      fExtendedBatteryInfo;
 
        RateBuffer                                      fRateBuffer;
-       acpi_battery_info                       fCachedAcpiInfo;
+       acpi_battery_info                       fCachedInfo;
 };
 
 
@@ -63,23 +63,23 @@ public:
                                                                
ACPIDriverInterface();
        virtual                                         ~ACPIDriverInterface();
 
-       virtual status_t                Connect();
-       virtual status_t                GetBatteryInfo(battery_info* info, 
int32 index);
-       virtual status_t                GetExtendedBatteryInfo(
-                                                               
acpi_extended_battery_info* info, int32 index);
+       virtual status_t                        Connect();
+       virtual status_t                        GetBatteryInfo(int32 index, 
battery_info* info);
+       virtual status_t                        GetExtendedBatteryInfo(int32 
index,
+                                                                       
acpi_extended_battery_info* info);
 
-       virtual int32                   GetBatteryCount();
+       virtual int32                           GetBatteryCount();
 
 protected:
        // Read the battery info from the hardware.
-       virtual status_t                _ReadBatteryInfo();
-
-       virtual void                    _WatchPowerStatus();
-       virtual status_t                _FindDrivers(const char* dirpath);
+       virtual status_t                        _UpdateBatteryInfo();
 
-       BObjectList<Battery>    fDriverList;
+       virtual void                            _WatchPowerStatus();
+       virtual status_t                        _FindDrivers(const char* 
dirpath);
 
-       BLocker                                 fInterfaceLocker;
+private:
+       BLocker                                         fInterfaceLocker;
+       BObjectList<Battery>            fDriverList;
 };
 
 #endif // ACPI_DRIVER_INTERFACE_H
diff --git a/src/apps/powerstatus/APMDriverInterface.cpp 
b/src/apps/powerstatus/APMDriverInterface.cpp
index f1b8943..4a05050 100644
--- a/src/apps/powerstatus/APMDriverInterface.cpp
+++ b/src/apps/powerstatus/APMDriverInterface.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -9,43 +9,23 @@
 
 #include "APMDriverInterface.h"
 
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
-#      include <arch/x86/apm_defs.h>
-#      include <generic_syscall_defs.h>
-#      include <syscalls.h>
-       // temporary, as long as there is no real power state API
-#endif
+#include <arch/x86/apm_defs.h>
+#include <generic_syscall_defs.h>
+#include <syscalls.h>
 
 
 const bigtime_t kUpdateInterval = 2000000;
                // every two seconds
 
 
-#ifndef HAIKU_TARGET_PLATFORM_HAIKU
-// definitions for the APM driver available for BeOS
-enum {
-       APM_CONTROL = B_DEVICE_OP_CODES_END + 1,
-       APM_DUMP_POWER_STATUS,
-       APM_BIOS_CALL,
-       APM_SET_SAFETY
-};
-
-#define BIOS_APM_GET_POWER_STATUS 0x530a
-#endif
-
-
 APMDriverInterface::~APMDriverInterface()
 {
-#ifndef HAIKU_TARGET_PLATFORM_HAIKU
-       close(fDevice);
-#endif
 }
 
 
 status_t
 APMDriverInterface::Connect()
 {
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
        uint32 version = 0;
        status_t status = _kern_generic_syscall(APM_SYSCALLS, B_SYSCALL_INFO,
                &version, sizeof(version));
@@ -56,28 +36,17 @@ APMDriverInterface::Connect()
        }
 
        return status;
-
-#else
-       fDevice = open("/dev/misc/apm", O_RDONLY);
-       if (fDevice < 0) {
-               return B_ERROR;
-       }
-
-       return B_OK;
-#endif
 }
 
 
 status_t
-APMDriverInterface::GetBatteryInfo(battery_info* info, int32 index)
+APMDriverInterface::GetBatteryInfo(int32 index, battery_info* info)
 {
        if (index != 0)
                return B_BAD_VALUE;
 
        info->current_rate = -1;
 
-#ifdef HAIKU_TARGET_PLATFORM_HAIKU
-       // TODO: retrieve data from APM kernel interface
        apm_battery_info apmInfo;
        status_t status = _kern_generic_syscall(APM_SYSCALLS, 
APM_GET_BATTERY_INFO,
                &apmInfo, sizeof(apm_battery_info));
@@ -89,37 +58,14 @@ APMDriverInterface::GetBatteryInfo(battery_info* info, 
int32 index)
        }
 
        return status;
-#else
-       if (fDevice < 0)
-               return B_ERROR;
-
-       uint16 regs[6] = {0, 0, 0, 0, 0, 0};
-       regs[0] = BIOS_APM_GET_POWER_STATUS;
-       regs[1] = 0x1;
-       if (ioctl(fDevice, APM_BIOS_CALL, regs) == 0) {
-               bool online = (regs[1] >> 8) != 0 && (regs[1] >> 8) != 2;
-               info->state = online ? BATTERY_CHARGING : BATTERY_DISCHARGING;
-               info->capacity = regs[2] & 255;
-               if (info->capacity > 100)
-                       info->capacity = -1;
-               info->full_capacity = 100;
-               info->time_left = info->capacity >= 0 ? regs[3] : -1;
-               if (info->time_left > 0xffff)
-                       info->time_left = -1;
-               else if (info->time_left & 0x8000)
-                       info->time_left = (info->time_left & 0x7fff) * 60;
-       }
-
-       return B_OK;
-#endif
 }
 
 
 status_t
-APMDriverInterface::GetExtendedBatteryInfo(acpi_extended_battery_info* info,
-       int32 index)
+APMDriverInterface::GetExtendedBatteryInfo(int32 index,
+       acpi_extended_battery_info* info)
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
@@ -138,4 +84,3 @@ APMDriverInterface::_WatchPowerStatus()
                acquire_sem_etc(fWaitSem, 1, B_RELATIVE_TIMEOUT, 
kUpdateInterval);
        }
 }
-
diff --git a/src/apps/powerstatus/APMDriverInterface.h 
b/src/apps/powerstatus/APMDriverInterface.h
index dc50bb1..fa5488f 100644
--- a/src/apps/powerstatus/APMDriverInterface.h
+++ b/src/apps/powerstatus/APMDriverInterface.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -14,21 +14,17 @@
 
 class APMDriverInterface : public PowerStatusDriverInterface {
 public:
-       virtual                         ~APMDriverInterface();
+       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);
-       virtual int32           GetBatteryCount();
+       virtual status_t                        Connect();
+       virtual status_t                        GetBatteryInfo(int32 index, 
battery_info* info);
+       virtual status_t                        GetExtendedBatteryInfo(int32 
index,
+                                                                       
acpi_extended_battery_info* info);
+       virtual int32                           GetBatteryCount();
 
 protected:
-       virtual void            _WatchPowerStatus();
-
-private:
-#ifndef HAIKU_TARGET_PLATFORM_HAIKU
-       int                                     fDevice;
-#endif
+       virtual void                            _WatchPowerStatus();
 };
 
+
 #endif // APM_DRIVER_INTERFACE_H
diff --git a/src/apps/powerstatus/DriverInterface.h 
b/src/apps/powerstatus/DriverInterface.h
index fd196bc..683c967 100644
--- a/src/apps/powerstatus/DriverInterface.h
+++ b/src/apps/powerstatus/DriverInterface.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -34,47 +34,49 @@ struct battery_info {
 /*! Handle a list of watcher and broadcast a messages to them. */
 class Monitor {
 public:
-       virtual                         ~Monitor();
+       virtual                                         ~Monitor();
 
-       virtual status_t        StartWatching(BHandler* target);
-       virtual status_t        StopWatching(BHandler* target);
+       virtual status_t                        StartWatching(BHandler* target);
+       virtual status_t                        StopWatching(BHandler* target);
 
-       virtual void            Broadcast(uint32 message);
+       virtual void                            Broadcast(uint32 message);
 
 protected:
-       WatcherList                     fWatcherList;
+       WatcherList                                     fWatcherList;
 };
 
 
 class PowerStatusDriverInterface : public Monitor, public BReferenceable {
 public:
-                                               PowerStatusDriverInterface();
-                                               ~PowerStatusDriverInterface();
+                                                               
PowerStatusDriverInterface();
+                                                               
~PowerStatusDriverInterface();
 
-       virtual status_t        StartWatching(BHandler* target);
-       virtual status_t        StopWatching(BHandler* target);
-       virtual void            Broadcast(uint32 message);
+       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                        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 status_t                        GetBatteryInfo(int32 index,
+                                                                       
battery_info* status) = 0;
+       virtual status_t                        GetExtendedBatteryInfo(int32 
index,
+                                                                       
acpi_extended_battery_info* info) = 0;
 
-       virtual int32           GetBatteryCount() = 0;
+       virtual int32                           GetBatteryCount() = 0;
 
 protected:
-       virtual void            _WatchPowerStatus() = 0;
+       virtual void                            _WatchPowerStatus() = 0;
 
-       int32                           fIsWatching;
-       sem_id                          fWaitSem;
+protected:
+       int32                                           fIsWatching;
+       sem_id                                          fWaitSem;
 
 private:
-       static int32            _ThreadWatchPowerFunction(void* data);
+       static int32                            _ThreadWatchPowerFunction(void* 
data);
 
-       thread_id                       fThread;
-       BLocker                         fListLocker;
+       thread_id                                       fThread;
+       BLocker                                         fListLocker;
 };
 
 
diff --git a/src/apps/powerstatus/ExtendedInfoWindow.cpp 
b/src/apps/powerstatus/ExtendedInfoWindow.cpp
index da80bd9..35f9ec6 100644
--- a/src/apps/powerstatus/ExtendedInfoWindow.cpp
+++ b/src/apps/powerstatus/ExtendedInfoWindow.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -324,7 +324,7 @@ ExtPowerStatusView::Update(bool force)
                return;
 
        acpi_extended_battery_info extInfo;
-       fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryID);
+       fDriverInterface->GetExtendedBatteryInfo(fBatteryID, &extInfo);
 
        fBatteryInfoView->Update(fBatteryInfo, extInfo);
        fBatteryInfoView->Invalidate();
@@ -338,8 +338,8 @@ 
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
        :
        BWindow(BRect(100, 150, 500, 500), B_TRANSLATE("Extended battery info"),
                B_TITLED_WINDOW,
-               B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT |
-               B_ASYNCHRONOUS_CONTROLS),
+               B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT
+                       | B_ASYNCHRONOUS_CONTROLS),
        fDriverInterface(interface),
        fSelectedView(NULL)
 {
diff --git a/src/apps/powerstatus/PowerStatusView.cpp 
b/src/apps/powerstatus/PowerStatusView.cpp
index 7c209e3..216bf78 100644
--- a/src/apps/powerstatus/PowerStatusView.cpp
+++ b/src/apps/powerstatus/PowerStatusView.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2014, Haiku, Inc. All Rights Reserved.
+ * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -62,7 +62,8 @@ const int32 kLowBatteryPercentage = 15;
 
 PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
        BRect frame, int32 resizingMode,  int batteryID, bool inDeskbar)
-       : BView(frame, kDeskbarItemName, resizingMode,
+       :
+       BView(frame, kDeskbarItemName, resizingMode,
                B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
        fDriverInterface(interface),
        fBatteryID(batteryID),
@@ -464,11 +465,11 @@ void
 PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
 {
        if (batteryID >= 0) {
-               fDriverInterface->GetBatteryInfo(batteryInfo, batteryID);
+               fDriverInterface->GetBatteryInfo(batteryID, batteryInfo);
        } else {
                for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
                        battery_info info;
-                       fDriverInterface->GetBatteryInfo(&info, i);
+                       fDriverInterface->GetBatteryInfo(i, &info);
 
                        if (i == 0)
                                *batteryInfo = info;

############################################################################

Commit:      e889ce25192fe68ce2415018895bf53150bccdb2
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e889ce2
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 14:27:29 2015 UTC

PowerStatus: fixed how the info is retrieved.

* The state was usually 0 once there was more than one battery
  slot.
* We now ignore missing batteries completely, instead of taking
  eventually bogus data into account.
* Fixed how to determine fOnline, and fHasBattery, and when to ignore
  probes.
* Made it more strict when to show the notification, ie. it's now only
  shown when actually discharging.
* This fixes all spurious notifications for me.

----------------------------------------------------------------------------

diff --git a/src/apps/powerstatus/PowerStatusView.cpp 
b/src/apps/powerstatus/PowerStatusView.cpp
index 216bf78..bb56612 100644
--- a/src/apps/powerstatus/PowerStatusView.cpp
+++ b/src/apps/powerstatus/PowerStatusView.cpp
@@ -106,7 +106,7 @@ PowerStatusView::_Init()
        fShowTime = false;
        fShowStatusIcon = true;
 
-       fPercent = -1;
+       fPercent = 100;
        fOnline = true;
        fTimeLeft = 0;
 }
@@ -338,13 +338,12 @@ PowerStatusView::Update(bool force)
        bool wasOnline = fOnline;
        bool hadBattery = fHasBattery;
 
-       _GetBatteryInfo(&fBatteryInfo, fBatteryID);
-
-       fHasBattery = (fBatteryInfo.state & BATTERY_CRITICAL_STATE) == 0;
+       _GetBatteryInfo(fBatteryID, &fBatteryInfo);
+       fHasBattery = fBatteryInfo.full_capacity > 0;
 
        if (fBatteryInfo.full_capacity > 0 && fHasBattery) {
                fPercent = (100 * fBatteryInfo.capacity) / 
fBatteryInfo.full_capacity;
-               fOnline = (fBatteryInfo.state & BATTERY_CHARGING) != 0;
+               fOnline = (fBatteryInfo.state & BATTERY_DISCHARGING) == 0;
                fTimeLeft = fBatteryInfo.time_left;
        } else {
                fPercent = 0;
@@ -352,7 +351,7 @@ PowerStatusView::Update(bool force)
                fTimeLeft = -1;
        }
 
-       if (fOnline && (fPercent <= 0 || fPercent > 100)) {
+       if (fHasBattery && (fPercent <= 0 || fPercent > 100)) {
                // Just ignore this probe -- it obviously returned invalid 
values
                fPercent = previousPercent;
                fTimeLeft = previousTimeLeft;
@@ -417,9 +416,8 @@ PowerStatusView::Update(bool force)
                Invalidate();
        }
 
-       if ((hadBattery && !fHasBattery)
-               || (previousPercent > kLowBatteryPercentage
-                       && fPercent <= kLowBatteryPercentage)) {
+       if (!fOnline && fHasBattery && previousPercent > kLowBatteryPercentage
+                       && fPercent <= kLowBatteryPercentage) {
                _NotifyLowBattery();
        }
 }
@@ -462,19 +460,26 @@ PowerStatusView::ToMessage(BMessage* archive) const
 
 
 void
-PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
+PowerStatusView::_GetBatteryInfo(int batteryID, battery_info* batteryInfo)
 {
        if (batteryID >= 0) {
                fDriverInterface->GetBatteryInfo(batteryID, batteryInfo);
        } else {
+               bool first = true;
+               memset(batteryInfo, 0, sizeof(battery_info));
+
                for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
                        battery_info info;
                        fDriverInterface->GetBatteryInfo(i, &info);
 
-                       if (i == 0)
+                       if (info.full_capacity <= 0)
+                               continue;
+
+                       if (first) {
                                *batteryInfo = info;
-                       else {
-                               batteryInfo->state &= info.state;
+                               first = false;
+                       } else {
+                               batteryInfo->state |= info.state;
                                batteryInfo->capacity += info.capacity;
                                batteryInfo->full_capacity += 
info.full_capacity;
                                batteryInfo->time_left += info.time_left;
diff --git a/src/apps/powerstatus/PowerStatusView.h 
b/src/apps/powerstatus/PowerStatusView.h
index 2dfd2c6..ca0d62e 100644
--- a/src/apps/powerstatus/PowerStatusView.h
+++ b/src/apps/powerstatus/PowerStatusView.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2014, Haiku, Inc. All Rights Reserved.
+ * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -45,7 +45,7 @@ protected:
                        status_t                ToMessage(BMessage* message) 
const;
 
 private:
-                       void                    _GetBatteryInfo(battery_info* 
info, int batteryID);
+                       void                    _GetBatteryInfo(int batteryID, 
battery_info* info);
                        void                    _Init();
                        void                    _SetLabel(char* buffer, size_t 
bufferLength);
                        void                    _DrawBattery(BRect rect);

############################################################################

Revision:    hrev48633
Commit:      070e77cc591bbd58756040c4b5b67aae15cd9e99
URL:         http://cgit.haiku-os.org/haiku/commit/?id=070e77c
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Jan  8 14:35:44 2015 UTC

PowerStatus: added note battery color.

* When the capacity drops below 30%, it now turns yellow.

----------------------------------------------------------------------------

diff --git a/src/apps/powerstatus/PowerStatusView.cpp 
b/src/apps/powerstatus/PowerStatusView.cpp
index bb56612..3b9d26c 100644
--- a/src/apps/powerstatus/PowerStatusView.cpp
+++ b/src/apps/powerstatus/PowerStatusView.cpp
@@ -58,6 +58,7 @@ const uint32 kMinIconWidth = 16;
 const uint32 kMinIconHeight = 16;
 
 const int32 kLowBatteryPercentage = 15;
+const int32 kNoteBatteryPercentage = 30;
 
 
 PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
@@ -206,6 +207,8 @@ PowerStatusView::_DrawBattery(BRect rect)
                if (fHasBattery) {
                        if (percent <= kLowBatteryPercentage)
                                base.set_to(180, 0, 0);
+                       else if (percent <= kNoteBatteryPercentage)
+                               base.set_to(200, 140, 0);
                        else
                                base.set_to(20, 180, 0);
 


Other related posts:

  • » [haiku-commits] haiku: hrev48633 - in src: apps/powerstatus add-ons/mail_daemon/inbound_protocols/imap - axeld