From e57acc3a990689adc3d230f877bb98ca979aeac0 Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Thu, 23 Jul 2015 15:03:56 +0200 Subject: [PATCH] BMediaRoster: Fix initialization and destruction * Improve consistency by adding a BMediaRosterEx destructor and using it for the specular functionality of ctor instead to use the father's class destructor. * Avoid double initialization of MediaInitializer that becomes MediaRosterUndertaker. * Remove superfluos call to BMediaRoster::Quit() in media_addon_server. --- headers/private/media/MediaRosterEx.h | 1 + src/kits/media/MediaRoster.cpp | 42 ++++++++++---------- src/servers/media_addon/MediaAddonServer.cpp | 3 -- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/headers/private/media/MediaRosterEx.h b/headers/private/media/MediaRosterEx.h index cbd76903b9..cb4f83730b 100644 --- a/headers/private/media/MediaRosterEx.h +++ b/headers/private/media/MediaRosterEx.h @@ -35,6 +35,7 @@ class BMediaRosterEx : public BMediaRoster { public: BMediaRosterEx(status_t* out_error); + virtual ~BMediaRosterEx(); status_t SaveNodeConfiguration(BMediaNode* node); status_t LoadNodeConfiguration(media_addon_id addonid, diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp index 7e3e72f025..fce1bcd7eb 100644 --- a/src/kits/media/MediaRoster.cpp +++ b/src/kits/media/MediaRoster.cpp @@ -75,14 +75,10 @@ namespace BPrivate { namespace media { -class MediaInitializer { +// This class is provided to ensure the BMediaRoster is quit. +class MediaRosterUndertaker { public: - MediaInitializer() - { - InitDataExchange(); - } - - ~MediaInitializer() + ~MediaRosterUndertaker() { if (BMediaRoster::CurrentRoster() != NULL) { BMediaRoster::CurrentRoster()->Lock(); @@ -98,7 +94,7 @@ public: using namespace BPrivate::media; -static MediaInitializer sInitializer; +static MediaRosterUndertaker sUndertaker; BMediaRosterEx::BMediaRosterEx(status_t* _error) @@ -125,6 +121,24 @@ BMediaRosterEx::BMediaRosterEx(status_t* _error) } +BMediaRosterEx::~BMediaRosterEx() +{ + CALLED(); + + delete gTimeSourceObjectManager; + delete gDormantNodeManager; + + // unregister this application with the media server + server_unregister_app_request request; + server_unregister_app_reply reply; + request.team = BPrivate::current_team(); + QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, + sizeof(reply)); + + BPrivate::SharedBufferList::Invalidate(); +} + + status_t BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node) { @@ -3348,18 +3362,6 @@ BMediaRoster::~BMediaRoster() { CALLED(); - delete gTimeSourceObjectManager; - delete gDormantNodeManager; - - // unregister this application with the media server - server_unregister_app_request request; - server_unregister_app_reply reply; - request.team = BPrivate::current_team(); - QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, - sizeof(reply)); - - BPrivate::SharedBufferList::Invalidate(); - // Unset the global instance pointer, the destructor is also called // if a client app calls Lock(); and Quit(); directly. sDefaultInstance = NULL; diff --git a/src/servers/media_addon/MediaAddonServer.cpp b/src/servers/media_addon/MediaAddonServer.cpp index 475add71c7..6201700c4c 100644 --- a/src/servers/media_addon/MediaAddonServer.cpp +++ b/src/servers/media_addon/MediaAddonServer.cpp @@ -338,9 +338,6 @@ MediaAddonServer::QuitRequested() for (iterator = fInfoMap.begin(); iterator != fInfoMap.end(); iterator++) _PutAddonIfPossible(iterator->second); - BMediaRoster::CurrentRoster()->Lock(); - BMediaRoster::CurrentRoster()->Quit(); - return true; }