diff --git a/src/apps/powerstatus/DriverInterface.cpp b/src/apps/powerstatus/DriverInterface.cpp index 3d070c0140..6c9029d14c 100644 --- a/src/apps/powerstatus/DriverInterface.cpp +++ b/src/apps/powerstatus/DriverInterface.cpp @@ -21,7 +21,6 @@ Monitor::~Monitor() status_t Monitor::StartWatching(BHandler* target) { - BAutolock autolock(fListLocker); if (fWatcherList.HasItem(target)) return B_ERROR; @@ -33,7 +32,6 @@ Monitor::StartWatching(BHandler* target) status_t Monitor::StopWatching(BHandler* target) { - BAutolock autolock(fListLocker); return fWatcherList.RemoveItem(target); } @@ -57,15 +55,17 @@ PowerStatusDriverInterface::PowerStatusDriverInterface() } + PowerStatusDriverInterface::~PowerStatusDriverInterface() { - + } -#include + status_t PowerStatusDriverInterface::StartWatching(BHandler* target) { + BAutolock autolock(fListLocker); status_t status = Monitor::StartWatching(target); if (status != B_OK) @@ -73,8 +73,7 @@ PowerStatusDriverInterface::StartWatching(BHandler* target) if (fThreadId > 0) return B_OK; - - printf("spawn\n"); + fThreadId = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread", B_LOW_PRIORITY, this); if (fThreadId >= 0) { @@ -95,6 +94,7 @@ PowerStatusDriverInterface::StartWatching(BHandler* target) status_t PowerStatusDriverInterface::StopWatching(BHandler* target) { + BAutolock autolock(fListLocker); if (fThreadId < 0) return B_BAD_VALUE; @@ -110,6 +110,14 @@ PowerStatusDriverInterface::StopWatching(BHandler* target) } +void +PowerStatusDriverInterface::Broadcast(uint32 message) +{ + BAutolock autolock(fListLocker); + Monitor::Broadcast(message); +} + + void PowerStatusDriverInterface::Disconnect() { diff --git a/src/apps/powerstatus/DriverInterface.h b/src/apps/powerstatus/DriverInterface.h index da6e55785c..7040783abe 100644 --- a/src/apps/powerstatus/DriverInterface.h +++ b/src/apps/powerstatus/DriverInterface.h @@ -9,9 +9,10 @@ #ifndef DRIVER_INTERFACE_H #define DRIVER_INTERFACE_H +#include #include #include -#include +#include #include "device/power_managment.h" @@ -42,19 +43,20 @@ public: virtual void Broadcast(uint32 message); protected: - BLocker fListLocker; WatcherList fWatcherList; }; -class PowerStatusDriverInterface : public Monitor +class PowerStatusDriverInterface : public Monitor, public Referenceable { public: PowerStatusDriverInterface(); ~PowerStatusDriverInterface(); + 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(); @@ -73,6 +75,7 @@ private: static int32 _ThreadWatchPowerFunction(void* data); thread_id fThreadId; + BLocker fListLocker; }; diff --git a/src/apps/powerstatus/ExtendedInfoWindow.cpp b/src/apps/powerstatus/ExtendedInfoWindow.cpp index 923ccae82e..a5096bc2fa 100644 --- a/src/apps/powerstatus/ExtendedInfoWindow.cpp +++ b/src/apps/powerstatus/ExtendedInfoWindow.cpp @@ -338,6 +338,8 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) fDriverInterface(interface), fSelectedView(NULL) { + fDriverInterface->AcquireReference(); + BView *view = new BView(Bounds(), "view", B_FOLLOW_ALL, 0); view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(view); @@ -394,9 +396,10 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) ExtendedInfoWindow::~ExtendedInfoWindow() { - for (int i = 0; i < fBatteryViewList.CountItems(); i++) { + for (int i = 0; i < fBatteryViewList.CountItems(); i++) fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i)); - } + + fDriverInterface->ReleaseReference(); } diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 57bc3a9764..3a89a4ce11 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -400,12 +400,13 @@ PowerStatusReplicant::PowerStatusReplicant(BMessage* archive) PowerStatusReplicant::~PowerStatusReplicant() { - if (fMessengerExist) + if (fMessengerExist) { delete fExtWindowMessenger; + } fDriverInterface->StopWatching(this); fDriverInterface->Disconnect(); - delete fDriverInterface; + fDriverInterface->ReleaseReference(); }