Refactored AddOnMonitor to allow an alternative constructor which does not
yet take the AddOnMonitorHandler (and also does not Run() the looper automatically). Added SetHandler() method which allows to set the handler afterward. Does not require updates in existing clients. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39740 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -25,11 +25,16 @@ class AddOnMonitor : public BLooper {
|
||||
private:
|
||||
typedef BLooper inherited;
|
||||
public:
|
||||
AddOnMonitor();
|
||||
// Does not automatically run the looper.
|
||||
AddOnMonitor(AddOnMonitorHandler* handler);
|
||||
// Automatically runs the looper.
|
||||
virtual ~AddOnMonitor();
|
||||
|
||||
virtual status_t InitCheck();
|
||||
|
||||
void SetHandler(AddOnMonitorHandler* handler);
|
||||
|
||||
private:
|
||||
status_t fInitCheck;
|
||||
BMessageRunner* fPulseRunner;
|
||||
|
||||
@@ -15,30 +15,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
AddOnMonitor::AddOnMonitor()
|
||||
:
|
||||
BLooper("AddOnMonitor"),
|
||||
fInitCheck(B_NO_INIT),
|
||||
fPulseRunner(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AddOnMonitor::AddOnMonitor(AddOnMonitorHandler* handler)
|
||||
:
|
||||
BLooper("AddOnMonitor"),
|
||||
fInitCheck(B_NO_INIT)
|
||||
fInitCheck(B_NO_INIT),
|
||||
fPulseRunner(NULL)
|
||||
{
|
||||
AddHandler(handler);
|
||||
SetPreferredHandler(handler);
|
||||
|
||||
status_t status;
|
||||
BMessenger messenger(handler, this, &status);
|
||||
if (status != B_OK) {
|
||||
fInitCheck = status;
|
||||
return;
|
||||
}
|
||||
|
||||
BMessage pulseMessage(B_PULSE);
|
||||
fPulseRunner = new BMessageRunner(messenger, &pulseMessage, 1000000);
|
||||
status = fPulseRunner->InitCheck();
|
||||
if (status != B_OK) {
|
||||
fInitCheck = status;
|
||||
fprintf(stderr, "AddOnMonitor() : bad status returned by "
|
||||
"fPulseRunner->InitCheck()\n");
|
||||
return;
|
||||
}
|
||||
SetHandler(handler);
|
||||
|
||||
thread_id id = Run();
|
||||
if (id < 0) {
|
||||
@@ -46,8 +38,6 @@ AddOnMonitor::AddOnMonitor(AddOnMonitorHandler* handler)
|
||||
fprintf(stderr, "AddOnMonitor() : bad id returned by Run()\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fInitCheck = B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,3 +52,42 @@ AddOnMonitor::InitCheck()
|
||||
{
|
||||
return fInitCheck;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddOnMonitor::SetHandler(AddOnMonitorHandler* handler)
|
||||
{
|
||||
if (handler == NULL)
|
||||
return;
|
||||
|
||||
AddHandler(handler);
|
||||
SetPreferredHandler(handler);
|
||||
|
||||
delete fPulseRunner;
|
||||
fPulseRunner = NULL;
|
||||
|
||||
status_t status;
|
||||
BMessenger messenger(handler, this, &status);
|
||||
if (status != B_OK) {
|
||||
fInitCheck = status;
|
||||
return;
|
||||
}
|
||||
|
||||
BMessage pulseMessage(B_PULSE);
|
||||
fPulseRunner = new(std::nothrow) BMessageRunner(messenger, &pulseMessage,
|
||||
1000000);
|
||||
if (fPulseRunner == NULL) {
|
||||
fInitCheck = B_NO_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
||||
status = fPulseRunner->InitCheck();
|
||||
if (status != B_OK) {
|
||||
fInitCheck = status;
|
||||
fprintf(stderr, "AddOnMonitor() : bad status returned by "
|
||||
"fPulseRunner->InitCheck()\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fInitCheck = B_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user