media_server: Replace ping/pong with notifications
This commit is contained in:
@@ -3385,15 +3385,6 @@ void
|
|||||||
BMediaRoster::MessageReceived(BMessage* message)
|
BMediaRoster::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case 'PING':
|
|
||||||
{
|
|
||||||
// media_server plays ping-pong with the BMediaRosters
|
|
||||||
// to detect dead teams. Normal communication uses ports.
|
|
||||||
static BMessage pong('PONG');
|
|
||||||
message->SendReply(&pong, static_cast<BHandler *>(NULL), 2000000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MEDIA_ROSTER_REQUEST_NOTIFICATIONS:
|
case MEDIA_ROSTER_REQUEST_NOTIFICATIONS:
|
||||||
{
|
{
|
||||||
RosterNotification notification;
|
RosterNotification notification;
|
||||||
|
|||||||
@@ -50,17 +50,11 @@ AppManager::AppManager()
|
|||||||
:
|
:
|
||||||
BLocker("media app manager")
|
BLocker("media app manager")
|
||||||
{
|
{
|
||||||
fQuit = create_sem(0, "big brother waits");
|
|
||||||
fBigBrother = spawn_thread(_BigBrotherEntry, "big brother is watching you",
|
|
||||||
B_NORMAL_PRIORITY, this);
|
|
||||||
resume_thread(fBigBrother);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AppManager::~AppManager()
|
AppManager::~AppManager()
|
||||||
{
|
{
|
||||||
delete_sem(fQuit);
|
|
||||||
wait_for_thread(fBigBrother, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,64 +161,3 @@ AppManager::_CleanupTeam(team_id team)
|
|||||||
gBufferManager->CleanupTeam(team);
|
gBufferManager->CleanupTeam(team);
|
||||||
gNotificationManager->CleanupTeam(team);
|
gNotificationManager->CleanupTeam(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AppManager::_TeamDied(team_id team)
|
|
||||||
{
|
|
||||||
UnregisterTeam(team);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
AppManager::_BigBrotherEntry(void* self)
|
|
||||||
{
|
|
||||||
static_cast<AppManager*>(self)->_BigBrother();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! The BigBrother thread send ping messages to the BMediaRoster of
|
|
||||||
all currently running teams. If the reply times out or is wrong,
|
|
||||||
the team cleanup function _TeamDied() will be called.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
AppManager::_BigBrother()
|
|
||||||
{
|
|
||||||
status_t status = B_TIMED_OUT;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (!Lock())
|
|
||||||
break;
|
|
||||||
|
|
||||||
bool startOver = false;
|
|
||||||
AppMap::iterator iterator = fMap.begin();
|
|
||||||
for (; iterator != fMap.end(); iterator++) {
|
|
||||||
// No need to send the alive message
|
|
||||||
// if the team died.
|
|
||||||
if (iterator->second.IsValid() == true) {
|
|
||||||
BMessage ping('PING');
|
|
||||||
BMessage reply;
|
|
||||||
reply.what = 0;
|
|
||||||
status = iterator->second.SendMessage(&ping, &reply, 5000000,
|
|
||||||
2000000);
|
|
||||||
if (status != B_OK || reply.what != 'PONG') {
|
|
||||||
startOver = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
startOver = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startOver == true) {
|
|
||||||
Unlock();
|
|
||||||
_TeamDied(iterator->first);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Unlock();
|
|
||||||
status = acquire_sem_etc(fQuit, 1, B_RELATIVE_TIMEOUT, 2000000);
|
|
||||||
} while (status == B_TIMED_OUT || status == B_INTERRUPTED);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,17 +30,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _CleanupTeam(team_id team);
|
void _CleanupTeam(team_id team);
|
||||||
void _TeamDied(team_id team);
|
|
||||||
|
|
||||||
static status_t _BigBrotherEntry(void* self);
|
|
||||||
void _BigBrother();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<team_id, BMessenger> AppMap;
|
typedef std::map<team_id, BMessenger> AppMap;
|
||||||
|
|
||||||
AppMap fMap;
|
AppMap fMap;
|
||||||
thread_id fBigBrother;
|
|
||||||
sem_id fQuit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 "
|
|||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <MediaDefs.h>
|
#include <MediaDefs.h>
|
||||||
#include <MediaFormats.h>
|
#include <MediaFormats.h>
|
||||||
#include <MediaRoster.h>
|
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
@@ -114,15 +113,13 @@ ServerApp::ServerApp()
|
|||||||
this);
|
this);
|
||||||
resume_thread(fControlThread);
|
resume_thread(fControlThread);
|
||||||
|
|
||||||
BMediaRoster* roster = BMediaRoster::Roster();
|
if (be_roster->StartWatching(BMessenger(this, this),
|
||||||
if (roster->StartWatching(BMessenger(this, this),
|
B_REQUEST_QUIT) != B_OK) {
|
||||||
B_MEDIA_SERVER_QUIT) != B_OK) {
|
TRACE("ServerApp: Can't find the registrar.");
|
||||||
TRACE("ServerApp: can't watch for B_MEDIA_SERVER_QUIT");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ServerApp::~ServerApp()
|
ServerApp::~ServerApp()
|
||||||
{
|
{
|
||||||
TRACE("ServerApp::~ServerApp()\n");
|
TRACE("ServerApp::~ServerApp()\n");
|
||||||
@@ -130,17 +127,14 @@ ServerApp::~ServerApp()
|
|||||||
delete_port(fControlPort);
|
delete_port(fControlPort);
|
||||||
wait_for_thread(fControlThread, NULL);
|
wait_for_thread(fControlThread, NULL);
|
||||||
|
|
||||||
|
if (be_roster->StopWatching(BMessenger(this, this)) != B_OK)
|
||||||
|
TRACE("ServerApp: Can't unregister roster notifications.");
|
||||||
|
|
||||||
delete gNotificationManager;
|
delete gNotificationManager;
|
||||||
delete gBufferManager;
|
delete gBufferManager;
|
||||||
delete gAppManager;
|
delete gAppManager;
|
||||||
delete gNodeManager;
|
delete gNodeManager;
|
||||||
delete gMediaFilesManager;
|
delete gMediaFilesManager;
|
||||||
|
|
||||||
BMediaRoster* roster = BMediaRoster::CurrentRoster();
|
|
||||||
if (roster->StopWatching(BMessenger(this, this),
|
|
||||||
B_MEDIA_SERVER_QUIT) != B_OK) {
|
|
||||||
TRACE("ServerApp: can't unwatch for B_MEDIA_SERVER_QUIT");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -944,9 +938,22 @@ ServerApp::MessageReceived(BMessage* msg)
|
|||||||
gMediaFilesManager->HandleAddSystemBeepEvent(msg);
|
gMediaFilesManager->HandleAddSystemBeepEvent(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_MEDIA_SERVER_QUIT:
|
case B_SOME_APP_QUIT:
|
||||||
gNodeManager->CleanupDormantFlavorInfos();
|
{
|
||||||
|
BString mimeSig;
|
||||||
|
if (msg->FindString("be:signature", &mimeSig) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (mimeSig == B_MEDIA_ADDON_SERVER_SIGNATURE)
|
||||||
|
gNodeManager->CleanupDormantFlavorInfos();
|
||||||
|
|
||||||
|
team_id id;
|
||||||
|
if (msg->FindInt32("team", &id) == B_OK
|
||||||
|
&& gAppManager->HasTeam(id)) {
|
||||||
|
gAppManager->UnregisterTeam(id);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(msg);
|
BApplication::MessageReceived(msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user