Unregister SystemTimeSource when the media_addon_server quit, better error checking and explicit initialization/deletion for some attributes
Signed-off-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Jérôme Duval
parent
5a1e452ba2
commit
49f0011c1e
@@ -121,6 +121,7 @@ private:
|
|||||||
thread_id fControlThread;
|
thread_id fControlThread;
|
||||||
bool fStartup;
|
bool fStartup;
|
||||||
bool fStartupSound;
|
bool fStartupSound;
|
||||||
|
SystemTimeSource* fSystemTimeSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -203,8 +204,11 @@ MediaAddonServer::MonitorHandler::AddOnDisabled(const add_on_entry_info* info)
|
|||||||
MediaAddonServer::MediaAddonServer(const char* signature)
|
MediaAddonServer::MediaAddonServer(const char* signature)
|
||||||
:
|
:
|
||||||
BApplication(signature),
|
BApplication(signature),
|
||||||
|
fMonitorHandler(NULL),
|
||||||
|
fPulseRunner(NULL),
|
||||||
fStartup(true),
|
fStartup(true),
|
||||||
fStartupSound(true)
|
fStartupSound(true),
|
||||||
|
fSystemTimeSource(NULL)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
fMediaRoster = BMediaRoster::Roster();
|
fMediaRoster = BMediaRoster::Roster();
|
||||||
@@ -227,14 +231,15 @@ MediaAddonServer::~MediaAddonServer()
|
|||||||
for (; iterator != fFileMap.end(); iterator++)
|
for (; iterator != fFileMap.end(); iterator++)
|
||||||
gDormantNodeManager->UnregisterAddOn(iterator->second);
|
gDormantNodeManager->UnregisterAddOn(iterator->second);
|
||||||
|
|
||||||
// TODO: unregister system time source
|
delete fMonitorHandler;
|
||||||
|
delete fPulseRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaAddonServer::ReadyToRun()
|
MediaAddonServer::ReadyToRun()
|
||||||
{
|
{
|
||||||
if (!be_roster->IsRunning("application/x-vnd.Be.media-server")) {
|
if (!be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
|
||||||
// the media server is not running, let's quit
|
// the media server is not running, let's quit
|
||||||
fprintf(stderr, "The media_server is not running!\n");
|
fprintf(stderr, "The media_server is not running!\n");
|
||||||
Quit();
|
Quit();
|
||||||
@@ -249,17 +254,17 @@ MediaAddonServer::ReadyToRun()
|
|||||||
|
|
||||||
// The very first thing to do is to create the system time source,
|
// The very first thing to do is to create the system time source,
|
||||||
// register it with the server, and make it the default SYSTEM_TIME_SOURCE
|
// register it with the server, and make it the default SYSTEM_TIME_SOURCE
|
||||||
BMediaNode *timeSource = new SystemTimeSource;
|
fSystemTimeSource = new SystemTimeSource();
|
||||||
status_t result = fMediaRoster->RegisterNode(timeSource);
|
status_t result = fMediaRoster->RegisterNode(fSystemTimeSource);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
fprintf(stderr, "Can't register system time source : %s\n",
|
fprintf(stderr, "Can't register system time source : %s\n",
|
||||||
strerror(result));
|
strerror(result));
|
||||||
debugger("Can't register system time source");
|
debugger("Can't register system time source");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeSource->ID() != NODE_SYSTEM_TIMESOURCE_ID)
|
if (fSystemTimeSource->ID() != NODE_SYSTEM_TIMESOURCE_ID)
|
||||||
debugger("System time source got wrong node ID");
|
debugger("System time source got wrong node ID");
|
||||||
media_node node = timeSource->Node();
|
media_node node = fSystemTimeSource->Node();
|
||||||
result = MediaRosterEx(fMediaRoster)->SetNode(SYSTEM_TIME_SOURCE, &node);
|
result = MediaRosterEx(fMediaRoster)->SetNode(SYSTEM_TIME_SOURCE, &node);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
debugger("Can't setup system time source as default");
|
debugger("Can't setup system time source as default");
|
||||||
@@ -277,6 +282,10 @@ MediaAddonServer::ReadyToRun()
|
|||||||
// the monitor handler needs a pulse to check if add-ons are ready
|
// the monitor handler needs a pulse to check if add-ons are ready
|
||||||
fPulseRunner = new BMessageRunner(fMonitorHandler, &pulse, 1000000LL);
|
fPulseRunner = new BMessageRunner(fMonitorHandler, &pulse, 1000000LL);
|
||||||
|
|
||||||
|
result = fPulseRunner->InitCheck();
|
||||||
|
if (result != B_OK)
|
||||||
|
ERROR("Can't create the pulse runner");
|
||||||
|
|
||||||
fMonitorHandler->AddAddOnDirectories("media");
|
fMonitorHandler->AddAddOnDirectories("media");
|
||||||
|
|
||||||
#ifdef USER_ADDON_PATH
|
#ifdef USER_ADDON_PATH
|
||||||
@@ -313,6 +322,19 @@ MediaAddonServer::QuitRequested()
|
|||||||
for (iterator = fInfoMap.begin(); iterator != fInfoMap.end(); iterator++)
|
for (iterator = fInfoMap.begin(); iterator != fInfoMap.end(); iterator++)
|
||||||
_DestroyInstantiatedFlavors(iterator->second);
|
_DestroyInstantiatedFlavors(iterator->second);
|
||||||
|
|
||||||
|
// the System timesource should be removed before we quit the roster
|
||||||
|
if (fSystemTimeSource != NULL &&
|
||||||
|
be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
|
||||||
|
status_t result = fMediaRoster->UnregisterNode(fSystemTimeSource);
|
||||||
|
if (result != B_OK) {
|
||||||
|
fprintf(stderr, "Error removing the system time source : %s\n",
|
||||||
|
strerror(result));
|
||||||
|
ERROR("Can't remove the system time source");
|
||||||
|
}
|
||||||
|
fSystemTimeSource->Release();
|
||||||
|
fSystemTimeSource = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
BMediaRoster::CurrentRoster()->Lock();
|
BMediaRoster::CurrentRoster()->Lock();
|
||||||
BMediaRoster::CurrentRoster()->Quit();
|
BMediaRoster::CurrentRoster()->Quit();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user