From b48b6fb59846f27c607380b66bf31ff9b8eda758 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 14 Oct 2002 21:21:06 +0000 Subject: [PATCH] Added method CheckSanity() which checks whether the (pre-)registered apps are still alive and removes obsolete entries. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1518 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/registrar/TRoster.cpp | 39 +++++++++++++++++++++++++++++++ src/servers/registrar/TRoster.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/src/servers/registrar/TRoster.cpp b/src/servers/registrar/TRoster.cpp index 2e57215ad4..ea71218e51 100644 --- a/src/servers/registrar/TRoster.cpp +++ b/src/servers/registrar/TRoster.cpp @@ -61,6 +61,9 @@ pre-registered applications. */ +//! The maximal period of time an app may be early pre-registered (60 s). +const bigtime_t kMaximalEarlyPreRegistrationPeriod = 60000000LL; + // constructor /*! \brief Creates a new roster. @@ -732,6 +735,42 @@ TRoster::ActivateApp(RosterAppInfo *info) } } +// CheckSanity +/*! \brief Checks whether the (pre-)registered applications are still running. + + This is necessary, since killed applications don't unregister properly. +*/ +void +TRoster::CheckSanity() +{ + // not early (pre-)registered applications + AppInfoList obsoleteApps; + for (AppInfoList::Iterator it = fRegisteredApps.It(); it.IsValid(); ++it) { + team_info teamInfo; + if (get_team_info((*it)->team, &teamInfo) != B_OK) + obsoleteApps.AddInfo(*it); + } + // remove the apps + for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { + RemoveApp(*it); + delete *it; + } + // early pre-registered applications + obsoleteApps.MakeEmpty(); + bigtime_t timeLimit = system_time() - kMaximalEarlyPreRegistrationPeriod; + for (AppInfoList::Iterator it = fEarlyPreRegisteredApps.It(); + it.IsValid(); + ++it) { + if ((*it)->registration_time < timeLimit) + obsoleteApps.AddInfo(*it); + } + // remove the apps + for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { + fEarlyPreRegisteredApps.RemoveInfo(*it); + delete *it; + } +} + // _AppAdded /*! \brief Hook method invoked, when an application has been added. diff --git a/src/servers/registrar/TRoster.h b/src/servers/registrar/TRoster.h index cea0fb4394..973b98fe41 100644 --- a/src/servers/registrar/TRoster.h +++ b/src/servers/registrar/TRoster.h @@ -69,6 +69,8 @@ public: void RemoveApp(RosterAppInfo *info); void ActivateApp(RosterAppInfo *info); + void CheckSanity(); + private: // hook functions void _AppAdded(RosterAppInfo *info);