Created
September 16, 2012 22:27
-
-
Save j0sh/3734635 to your computer and use it in GitHub Desktop.
RTMPD -- Enqueue applications for delete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit b7839ea0070ed299f25d36293dd66579f95e109f | |
| Author: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Sun Sep 16 12:34:50 2012 -0700 | |
| -- Allow enqueuing applications for delete. | |
| diff --git a/sources/crtmpserver/src/crtmpserver.cpp b/sources/crtmpserver/src/crtmpserver.cpp | |
| index 8ef98f4..fc74972 100644 | |
| --- a/sources/crtmpserver/src/crtmpserver.cpp | |
| +++ b/sources/crtmpserver/src/crtmpserver.cpp | |
| @@ -272,6 +272,7 @@ void Run() { | |
| INFO("GO! GO! GO! (%u)", (uint32_t) getpid()); | |
| while (IOHandlerManager::Pulse()) { | |
| ClientApplicationManager::RunTasks(); | |
| + ClientApplicationManager::CleanupDeadApplications(); | |
| IOHandlerManager::DeleteDeadHandlers(); | |
| ProtocolManager::CleanupDeadProtocols(); | |
| } | |
| diff --git a/sources/thelib/include/application/baseclientapplication.h b/sources/thelib/include/application/baseclientapplication.h | |
| index fc0b293..9247b35 100644 | |
| --- a/sources/thelib/include/application/baseclientapplication.h | |
| +++ b/sources/thelib/include/application/baseclientapplication.h | |
| @@ -50,6 +50,7 @@ private: | |
| #ifdef HAS_VOD_MANAGER | |
| BaseVODManager *_pVODManager; | |
| #endif /* HAS_VOD_MANAGER */ | |
| + bool _isEnqueuedForShutdown; | |
| protected: | |
| Variant _configuration; | |
| bool _isDefault; | |
| @@ -177,6 +178,10 @@ public: | |
| */ | |
| static void Shutdown(BaseClientApplication *pApplication); | |
| + bool IsEnqueuedForShutdown(); | |
| + | |
| + void EnqueueForShutdown(); | |
| + | |
| string GetStreamNameByAlias(string &streamName, bool remove = true); | |
| void SetStreamAlias(string &streamName, string &streamAlias); | |
| void RemoveStreamAlias(string &streamAlias); | |
| diff --git a/sources/thelib/include/application/clientapplicationmanager.h b/sources/thelib/include/application/clientapplicationmanager.h | |
| index 312c164..56a81bd 100644 | |
| --- a/sources/thelib/include/application/clientapplicationmanager.h | |
| +++ b/sources/thelib/include/application/clientapplicationmanager.h | |
| @@ -36,6 +36,7 @@ private: | |
| static map<string, BaseClientApplication *> _applicationsByName; | |
| static BaseClientApplication *_pDefaultApplication; | |
| static vector<uint32_t> _tasks; | |
| + static map<uint32_t, BaseClientApplication*> _deadApplications; | |
| public: | |
| /*! | |
| @brief Deletes applications registered to the base client application | |
| @@ -77,6 +78,16 @@ public: | |
| static void RegisterTask(BaseClientApplication*); | |
| static void RunTasks(); | |
| + | |
| + /*! | |
| + @brief Enqueues an application for shutdown. | |
| + */ | |
| + static void EnqueueForShutdown(BaseClientApplication*); | |
| + | |
| + /*! | |
| + @brief Shuts down dead applications. | |
| + */ | |
| + static uint32_t CleanupDeadApplications(); | |
| }; | |
| diff --git a/sources/thelib/src/application/baseclientapplication.cpp b/sources/thelib/src/application/baseclientapplication.cpp | |
| index ce6be37..d6f9da8 100644 | |
| --- a/sources/thelib/src/application/baseclientapplication.cpp | |
| +++ b/sources/thelib/src/application/baseclientapplication.cpp | |
| @@ -560,3 +560,16 @@ string BaseClientApplication::GetServiceInfo(IOHandler *pIOHandler) { | |
| void BaseClientApplication::Task() | |
| { | |
| } | |
| + | |
| +bool BaseClientApplication::IsEnqueuedForShutdown() | |
| +{ | |
| + return _isEnqueuedForShutdown; | |
| +} | |
| + | |
| +void BaseClientApplication::EnqueueForShutdown() | |
| +{ | |
| + if (!_isEnqueuedForShutdown) { | |
| + ClientApplicationManager::EnqueueForShutdown(this); | |
| + _isEnqueuedForShutdown = true; | |
| + } | |
| +} | |
| diff --git a/sources/thelib/src/application/clientapplicationmanager.cpp b/sources/thelib/src/application/clientapplicationmanager.cpp | |
| index 5dbb536..dc3973a 100644 | |
| --- a/sources/thelib/src/application/clientapplicationmanager.cpp | |
| +++ b/sources/thelib/src/application/clientapplicationmanager.cpp | |
| @@ -25,6 +25,7 @@ map<uint32_t, BaseClientApplication *> ClientApplicationManager::_applicationsBy | |
| map<string, BaseClientApplication *> ClientApplicationManager::_applicationsByName; | |
| BaseClientApplication *ClientApplicationManager::_pDefaultApplication = NULL; | |
| vector<uint32_t> ClientApplicationManager::_tasks; | |
| +map<uint32_t, BaseClientApplication*> ClientApplicationManager::_deadApplications; | |
| void ClientApplicationManager::Shutdown() { | |
| @@ -126,3 +127,24 @@ void ClientApplicationManager::RunTasks() | |
| app->Task(); | |
| } | |
| } | |
| + | |
| +void ClientApplicationManager::EnqueueForShutdown(BaseClientApplication *app) | |
| +{ | |
| + if (!MAP_HAS1(_deadApplications, app->GetId())) { | |
| + INFO("Enqueue applicaton %s for shutdown", STR(app->GetName())); | |
| + _deadApplications[app->GetId()] = app; | |
| + } | |
| +} | |
| + | |
| +uint32_t ClientApplicationManager::CleanupDeadApplications() | |
| +{ | |
| + uint32_t result = 0; | |
| + while (_deadApplications.size() > 0) { | |
| + BaseClientApplication *app = MAP_VAL(_deadApplications.begin()); | |
| + MAP_ERASE1(_deadApplications, app->GetId()); | |
| + BaseClientApplication::Shutdown(app); // app is freed here | |
| + app = NULL; | |
| + result++; | |
| + } | |
| + return result; | |
| +} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment