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.
This commit is contained in:
Dario Casalinuovo 2015-07-23 15:03:56 +02:00
parent 6cd18b575c
commit e57acc3a99
3 changed files with 23 additions and 23 deletions

View File

@ -35,6 +35,7 @@ class BMediaRosterEx : public BMediaRoster
{ {
public: public:
BMediaRosterEx(status_t* out_error); BMediaRosterEx(status_t* out_error);
virtual ~BMediaRosterEx();
status_t SaveNodeConfiguration(BMediaNode* node); status_t SaveNodeConfiguration(BMediaNode* node);
status_t LoadNodeConfiguration(media_addon_id addonid, status_t LoadNodeConfiguration(media_addon_id addonid,

View File

@ -75,14 +75,10 @@ namespace BPrivate {
namespace media { namespace media {
class MediaInitializer { // This class is provided to ensure the BMediaRoster is quit.
class MediaRosterUndertaker {
public: public:
MediaInitializer() ~MediaRosterUndertaker()
{
InitDataExchange();
}
~MediaInitializer()
{ {
if (BMediaRoster::CurrentRoster() != NULL) { if (BMediaRoster::CurrentRoster() != NULL) {
BMediaRoster::CurrentRoster()->Lock(); BMediaRoster::CurrentRoster()->Lock();
@ -98,7 +94,7 @@ public:
using namespace BPrivate::media; using namespace BPrivate::media;
static MediaInitializer sInitializer; static MediaRosterUndertaker sUndertaker;
BMediaRosterEx::BMediaRosterEx(status_t* _error) 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 status_t
BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node) BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node)
{ {
@ -3348,18 +3362,6 @@ BMediaRoster::~BMediaRoster()
{ {
CALLED(); 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 // Unset the global instance pointer, the destructor is also called
// if a client app calls Lock(); and Quit(); directly. // if a client app calls Lock(); and Quit(); directly.
sDefaultInstance = NULL; sDefaultInstance = NULL;

View File

@ -338,9 +338,6 @@ MediaAddonServer::QuitRequested()
for (iterator = fInfoMap.begin(); iterator != fInfoMap.end(); iterator++) for (iterator = fInfoMap.begin(); iterator != fInfoMap.end(); iterator++)
_PutAddonIfPossible(iterator->second); _PutAddonIfPossible(iterator->second);
BMediaRoster::CurrentRoster()->Lock();
BMediaRoster::CurrentRoster()->Quit();
return true; return true;
} }