Aside from I locked the wrong (base) class. The problem was more that the driver interface was deleted to early.
Using a Referenceable seems to fix it now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31992 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3fccf0679f
commit
0814569216
@ -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 <stdio.h>
|
||||
|
||||
status_t
|
||||
PowerStatusDriverInterface::StartWatching(BHandler* target)
|
||||
{
|
||||
BAutolock autolock(fListLocker);
|
||||
status_t status = Monitor::StartWatching(target);
|
||||
|
||||
if (status != B_OK)
|
||||
@ -74,7 +74,6 @@ 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()
|
||||
{
|
||||
|
@ -9,9 +9,10 @@
|
||||
#ifndef DRIVER_INTERFACE_H
|
||||
#define DRIVER_INTERFACE_H
|
||||
|
||||
#include <Handler.h>
|
||||
#include <Locker.h>
|
||||
#include <ObjectList.h>
|
||||
#include <Handler.h>
|
||||
#include <Referenceable.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user