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:
Dario Casalinuovo
2015-11-28 16:35:03 +01:00
parent 893e3de866
commit 05962bb1e1
3 changed files with 61 additions and 3 deletions
+42
View File
@@ -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
{