[haiku-commits] haiku: hrev49990 - in src: servers/media kits/media

  • From: b.vitruvio@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 6 Jan 2016 22:47:06 +0100 (CET)

hrev49990 adds 1 changeset to branch 'master'
old head: 1d11475790d26d2c0e3cda3f3e8ad12218cb72b6
new head: ec02769a58bb58b4bb20394d6f8107a3c53de15f
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=ec02769a58bb+%5E1d11475790d2

----------------------------------------------------------------------------

ec02769a58bb: media_server: Replace ping/pong with notifications

                                [ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev49990
Commit:      ec02769a58bb58b4bb20394d6f8107a3c53de15f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ec02769a58bb
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Wed Jan  6 21:37:35 2016 UTC

----------------------------------------------------------------------------

4 files changed, 21 insertions(+), 96 deletions(-)
src/kits/media/MediaRoster.cpp     |  9 -----
src/servers/media/AppManager.cpp   | 67 ----------------------------------
src/servers/media/AppManager.h     |  6 ---
src/servers/media/media_server.cpp | 35 +++++++++++-------

----------------------------------------------------------------------------

diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 95b37e6..61d8509 100644
--- a/src/kits/media/MediaRoster.cpp
+++ b/src/kits/media/MediaRoster.cpp
@@ -3385,15 +3385,6 @@ void
 BMediaRoster::MessageReceived(BMessage* message)
 {
        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:
                {
                        RosterNotification notification;
diff --git a/src/servers/media/AppManager.cpp b/src/servers/media/AppManager.cpp
index e998f7c..761ddef 100644
--- a/src/servers/media/AppManager.cpp
+++ b/src/servers/media/AppManager.cpp
@@ -50,17 +50,11 @@ AppManager::AppManager()
        :
        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()
 {
-       delete_sem(fQuit);
-       wait_for_thread(fBigBrother, NULL);
 }
 
 
@@ -167,64 +161,3 @@ AppManager::_CleanupTeam(team_id team)
        gBufferManager->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);
-}
diff --git a/src/servers/media/AppManager.h b/src/servers/media/AppManager.h
index 1f865a4..0bc57fb 100644
--- a/src/servers/media/AppManager.h
+++ b/src/servers/media/AppManager.h
@@ -30,17 +30,11 @@ public:
 
 private:
                        void                            _CleanupTeam(team_id 
team);
-                       void                            _TeamDied(team_id team);
-
-       static  status_t                        _BigBrotherEntry(void* self);
-                       void                            _BigBrother();
 
 private:
                        typedef std::map<team_id, BMessenger> AppMap;
 
                        AppMap                          fMap;
-                       thread_id                       fBigBrother;
-                       sem_id                          fQuit;
 };
 
 
diff --git a/src/servers/media/media_server.cpp 
b/src/servers/media/media_server.cpp
index 241c114..f4d7dd6 100644
--- a/src/servers/media/media_server.cpp
+++ b/src/servers/media/media_server.cpp
@@ -43,7 +43,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 
2002, 2003 "
 #include <Roster.h>
 #include <MediaDefs.h>
 #include <MediaFormats.h>
-#include <MediaRoster.h>
 #include <Messenger.h>
 
 #include <syscalls.h>
@@ -114,15 +113,13 @@ ServerApp::ServerApp()
                this);
        resume_thread(fControlThread);
 
-       BMediaRoster* roster = BMediaRoster::Roster();
-       if (roster->StartWatching(BMessenger(this, this),
-                       B_MEDIA_SERVER_QUIT) != B_OK) {
-               TRACE("ServerApp: can't watch for B_MEDIA_SERVER_QUIT");
+       if (be_roster->StartWatching(BMessenger(this, this),
+                       B_REQUEST_QUIT) != B_OK) {
+               TRACE("ServerApp: Can't find the registrar.");
        }
 }
 
 
-
 ServerApp::~ServerApp()
 {
        TRACE("ServerApp::~ServerApp()\n");
@@ -130,17 +127,14 @@ ServerApp::~ServerApp()
        delete_port(fControlPort);
        wait_for_thread(fControlThread, NULL);
 
+       if (be_roster->StopWatching(BMessenger(this, this)) != B_OK)
+               TRACE("ServerApp: Can't unregister roster notifications.");
+
        delete gNotificationManager;
        delete gBufferManager;
        delete gAppManager;
        delete gNodeManager;
        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);
                        break;
 
-               case B_MEDIA_SERVER_QUIT:
-                       gNodeManager->CleanupDormantFlavorInfos();
+               case B_SOME_APP_QUIT:
+               {
+                       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;
+               }
 
                default:
                        BApplication::MessageReceived(msg);


Other related posts: