Add a way to register loopers for quit
* BApplication can now take the job to quit a BLooper at the application quit. It's rejecting requests from windows too. * BMediaRoster is using now this service in conjunction with the MediaRosterUndertaker. * The BeBook specify that we should have a valid BApplication before to instantiate the BMediaRoster. While in theory we should add a debugger call when this situation happens, in pratice this might lead to more problems. For example libraries might use the media_kit and create a BApplication object, but they aren't applications, this is a design problem. So I decided to replace it with a TRACE call for the moment.
This commit is contained in:
@@ -85,6 +85,11 @@ public:
|
||||
BHandler* handler);
|
||||
void SetPulseRate(bigtime_t rate);
|
||||
|
||||
// Register a BLooper to be quit before the BApplication
|
||||
// object is destroyed.
|
||||
status_t RegisterLooper(BLooper* looper);
|
||||
status_t UnregisterLooper(BLooper* looper);
|
||||
|
||||
// More scripting
|
||||
virtual status_t GetSupportedSuites(BMessage* data);
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ BMessenger be_app_messenger;
|
||||
|
||||
pthread_once_t sAppResourcesInitOnce = PTHREAD_ONCE_INIT;
|
||||
BResources* BApplication::sAppResources = NULL;
|
||||
BObjectList<BLooper> sOnQuitLooperList;
|
||||
|
||||
|
||||
enum {
|
||||
@@ -306,6 +307,13 @@ BApplication::~BApplication()
|
||||
// tell all loopers(usually windows) to quit. Also, wait for them.
|
||||
_QuitAllWindows(true);
|
||||
|
||||
// quit registered loopers
|
||||
for (int32 i = 0; i < sOnQuitLooperList.CountItems(); i++) {
|
||||
BLooper* looper = sOnQuitLooperList.ItemAt(i);
|
||||
if (looper->Lock())
|
||||
looper->Quit();
|
||||
}
|
||||
|
||||
// unregister from the roster
|
||||
BRoster::Private().RemoveApp(Team());
|
||||
|
||||
@@ -960,6 +968,40 @@ BApplication::LooperAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BApplication::RegisterLooper(BLooper* looper)
|
||||
{
|
||||
BWindow* window = dynamic_cast<BWindow*>(looper);
|
||||
if (window != NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (sOnQuitLooperList.HasItem(looper))
|
||||
return B_ERROR;
|
||||
|
||||
if (sOnQuitLooperList.AddItem(looper) != true)
|
||||
return B_ERROR;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BApplication::UnregisterLooper(BLooper* looper)
|
||||
{
|
||||
BWindow* window = dynamic_cast<BWindow*>(looper);
|
||||
if (window != NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (!sOnQuitLooperList.HasItem(looper))
|
||||
return B_ERROR;
|
||||
|
||||
if (sOnQuitLooperList.RemoveItem(looper) != true)
|
||||
return B_ERROR;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BApplication::IsLaunching() const
|
||||
{
|
||||
|
||||
@@ -42,8 +42,7 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
|
||||
|
||||
#include <MediaRoster.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Autolock.h>
|
||||
#include <BufferConsumer.h>
|
||||
#include <BufferProducer.h>
|
||||
@@ -58,8 +57,9 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
|
||||
#include <String.h>
|
||||
#include <TimeSource.h>
|
||||
|
||||
#include <AppMisc.h>
|
||||
#include <new>
|
||||
|
||||
#include <AppMisc.h>
|
||||
#include <DataExchange.h>
|
||||
#include <debug.h>
|
||||
#include <DormantNodeManager.h>
|
||||
@@ -82,6 +82,7 @@ struct RosterNotification {
|
||||
int32 what;
|
||||
};
|
||||
|
||||
|
||||
static bool sServerIsUp = false;
|
||||
static List<RosterNotification> sNotificationList;
|
||||
static BLocker sInitLocker("BMediaRoster::Roster locker");
|
||||
@@ -94,6 +95,10 @@ public:
|
||||
BAutolock _(sInitLocker);
|
||||
if (BMediaRoster::CurrentRoster() != NULL
|
||||
&& BMediaRoster::CurrentRoster()->Lock()) {
|
||||
|
||||
if (be_app != NULL)
|
||||
be_app->UnregisterLooper(BMediaRoster::CurrentRoster());
|
||||
|
||||
BMediaRoster::CurrentRoster()->Quit();
|
||||
}
|
||||
}
|
||||
@@ -2221,6 +2226,9 @@ BMediaRoster::Roster(status_t* out_error)
|
||||
{
|
||||
BAutolock lock(sInitLocker);
|
||||
|
||||
if (be_app == NULL)
|
||||
TRACE("Warning! You should have a valid BApplication.");
|
||||
|
||||
if (!lock.IsLocked())
|
||||
return NULL;
|
||||
|
||||
@@ -2240,8 +2248,11 @@ BMediaRoster::Roster(status_t* out_error)
|
||||
}
|
||||
if (out_error)
|
||||
*out_error = err;
|
||||
} else if (be_app != NULL) {
|
||||
be_app->RegisterLooper(sDefaultInstance);
|
||||
}
|
||||
}
|
||||
|
||||
return sDefaultInstance;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user