* _IsSystemApp() did not work anymore with the new directory hierarchy. It will

now check for the complete path instead of just the prefix. This fixes bug
  #3862.
* Made TRoster.h self contained.
* Style cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30788 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-05-18 09:10:58 +00:00
parent 49fb9a2eab
commit c8e7c8ef86
2 changed files with 310 additions and 297 deletions
+123 -117
View File
@@ -7,8 +7,14 @@
applications. applications.
*/ */
#include "TRoster.h"
#include <new> #include <new>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <Application.h> #include <Application.h>
#include <AppMisc.h> #include <AppMisc.h>
#include <AutoDeleter.h> #include <AutoDeleter.h>
@@ -18,14 +24,9 @@
#include <MessagePrivate.h> #include <MessagePrivate.h>
#include <MessengerPrivate.h> #include <MessengerPrivate.h>
#include <Path.h> #include <Path.h>
#include <Roster.h> // for B_BACKGROUND_APP
#include <ServerProtocol.h> #include <ServerProtocol.h>
#include <storage_support.h> #include <storage_support.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "AppInfoListMessagingTargetSet.h" #include "AppInfoListMessagingTargetSet.h"
#include "Debug.h" #include "Debug.h"
#include "EventMaskWatcher.h" #include "EventMaskWatcher.h"
@@ -33,17 +34,12 @@
#include "RegistrarDefs.h" #include "RegistrarDefs.h"
#include "RosterAppInfo.h" #include "RosterAppInfo.h"
#include "RosterSettingsCharStream.h" #include "RosterSettingsCharStream.h"
#include "TRoster.h"
using std::nothrow; using std::nothrow;
using namespace BPrivate; using namespace BPrivate;
static bool larger_index(const recent_entry *entry1, const recent_entry *entry2); /*! \class TRoster
/*!
\class TRoster
\brief Implements the application roster. \brief Implements the application roster.
This class handles the BRoster requests. For each kind a hook method is This class handles the BRoster requests. For each kind a hook method is
@@ -70,20 +66,20 @@ static bool larger_index(const recent_entry *entry1, const recent_entry *entry2)
//! The maximal period of time an app may be early pre-registered (60 s). //! The maximal period of time an app may be early pre-registered (60 s).
const bigtime_t kMaximalEarlyPreRegistrationPeriod = 60000000LL; const bigtime_t kMaximalEarlyPreRegistrationPeriod = 60000000LL;
//! Applications living in this tree are considered "vital system apps". //! Applications living in these directory are considered "system apps".
static const char *const kVitalSystemAppPathPrefix // TODO: move those into a common shared system header
= "/boot/system/servers"; static const char* const kSystemAppPath = "/boot/system";
static const char* const kSystemServerPath = "/boot/system/servers";
// #pragma mark - Private local functions
//! Applications living in this tree are considered "system apps".
static const char *const kSystemAppPathPrefix = "/boot/system";
// get_default_roster_settings_file
/*! \brief Returns the path to the default roster settings. /*! \brief Returns the path to the default roster settings.
\param path BPath to be set to the roster settings path. \param path BPath to be set to the roster settings path.
\return the settings path as C string (\code path.Path() \endcode). \return the settings path as C string (\code path.Path() \endcode).
*/ */
static static const char*
const char *
get_default_roster_settings_file(BPath& path) get_default_roster_settings_file(BPath& path)
{ {
// get the path of the settings dir and append the subpath of our file // get the path of the settings dir and append the subpath of our file
@@ -99,7 +95,27 @@ get_default_roster_settings_file(BPath &path)
return path.Path(); return path.Path();
} }
// constructor
/*! \brief Returns true if entry1's index is larger than entry2's index.
Also returns true if either entry is \c NULL.
Used for sorting the recent entry lists loaded from disk into the
proper order.
*/
bool
larger_index(const recent_entry* entry1, const recent_entry* entry2)
{
if (entry1 && entry2)
return entry1->index > entry2->index;
return true;
}
// #pragma mark -
/*! \brief Creates a new roster. /*! \brief Creates a new roster.
The object is completely initialized and ready to handle requests. The object is completely initialized and ready to handle requests.
@@ -122,14 +138,14 @@ TRoster::TRoster()
_LoadRosterSettings(); _LoadRosterSettings();
} }
// destructor
/*! \brief Frees all resources associated with this object. /*! \brief Frees all resources associated with this object.
*/ */
TRoster::~TRoster() TRoster::~TRoster()
{ {
} }
// HandleAddApplication
/*! \brief Handles an AddApplication() request. /*! \brief Handles an AddApplication() request.
\param request The request message \param request The request message
*/ */
@@ -163,6 +179,7 @@ TRoster::HandleAddApplication(BMessage *request)
port = -1; port = -1;
if (request->FindBool("full_registration", &fullReg) != B_OK) if (request->FindBool("full_registration", &fullReg) != B_OK)
fullReg = false; fullReg = false;
PRINT(("team: %ld, signature: %s\n", team, signature)); PRINT(("team: %ld, signature: %s\n", team, signature));
PRINT(("full registration: %d\n", fullReg)); PRINT(("full registration: %d\n", fullReg));
@@ -233,7 +250,8 @@ PRINT(("ref: %ld, %lld, %s\n", ref.device, ref.directory, ref.name));
// add it to the right list // add it to the right list
bool addingSuccess = false; bool addingSuccess = false;
if (team >= 0) { if (team >= 0) {
PRINT(("added ref: %ld, %lld, %s\n", info->ref.device, info->ref.directory, info->ref.name)); PRINT(("added ref: %ld, %lld, %s\n", info->ref.device,
info->ref.directory, info->ref.name));
addingSuccess = (AddApp(info) == B_OK); addingSuccess = (AddApp(info) == B_OK);
if (addingSuccess && fullReg) if (addingSuccess && fullReg)
_AppAdded(info); _AppAdded(info);
@@ -258,7 +276,6 @@ PRINT(("added to early pre-regs, token: %lu\n", token));
fRecentApps.Add(signature, flags); fRecentApps.Add(signature, flags);
else else
fRecentApps.Add(&ref, flags); fRecentApps.Add(&ref, flags);
// fRecentApps.Print();
BMessage reply(B_REG_SUCCESS); BMessage reply(B_REG_SUCCESS);
// The token is valid only when no team ID has been supplied. // The token is valid only when no team ID has been supplied.
@@ -278,7 +295,7 @@ PRINT(("added to early pre-regs, token: %lu\n", token));
FUNCTION_END(); FUNCTION_END();
} }
// HandleCompleteRegistration
/*! \brief Handles a CompleteRegistration() request. /*! \brief Handles a CompleteRegistration() request.
\param request The request message \param request The request message
*/ */
@@ -342,7 +359,7 @@ TRoster::HandleCompleteRegistration(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleIsAppRegistered
/*! \brief Handles an IsAppRegistered() request. /*! \brief Handles an IsAppRegistered() request.
\param request The request message \param request The request message
*/ */
@@ -411,7 +428,7 @@ TRoster::HandleIsAppRegistered(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleRemovePreRegApp
/*! \brief Handles a RemovePreRegApp() request. /*! \brief Handles a RemovePreRegApp() request.
\param request The request message \param request The request message
*/ */
@@ -449,7 +466,7 @@ TRoster::HandleRemovePreRegApp(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleRemoveApp
/*! \brief Handles a RemoveApp() request. /*! \brief Handles a RemoveApp() request.
\param request The request message \param request The request message
*/ */
@@ -465,7 +482,9 @@ TRoster::HandleRemoveApp(BMessage *request)
team_id team; team_id team;
if (request->FindInt32("team", &team) != B_OK) if (request->FindInt32("team", &team) != B_OK)
team = -1; team = -1;
PRINT(("team: %ld\n", team)); PRINT(("team: %ld\n", team));
// remove the app // remove the app
if (error == B_OK) { if (error == B_OK) {
if (RosterAppInfo* info = fRegisteredApps.InfoFor(team)) { if (RosterAppInfo* info = fRegisteredApps.InfoFor(team)) {
@@ -487,7 +506,7 @@ PRINT(("team: %ld\n", team));
FUNCTION_END(); FUNCTION_END();
} }
// HandleSetThreadAndTeam
/*! \brief Handles a SetThreadAndTeam() request. /*! \brief Handles a SetThreadAndTeam() request.
\param request The request message \param request The request message
*/ */
@@ -499,6 +518,7 @@ TRoster::HandleSetThreadAndTeam(BMessage *request)
BAutolock _(fLock); BAutolock _(fLock);
status_t error = B_OK; status_t error = B_OK;
// get the parameters // get the parameters
team_id team; team_id team;
thread_id thread; thread_id thread;
@@ -509,11 +529,14 @@ TRoster::HandleSetThreadAndTeam(BMessage *request)
thread = -1; thread = -1;
if (request->FindInt32("token", (int32*)&token) != B_OK) if (request->FindInt32("token", (int32*)&token) != B_OK)
SET_ERROR(error, B_BAD_VALUE); SET_ERROR(error, B_BAD_VALUE);
// check the parameters // check the parameters
// team // team
if (error == B_OK && team < 0) if (error == B_OK && team < 0)
SET_ERROR(error, B_BAD_VALUE); SET_ERROR(error, B_BAD_VALUE);
PRINT(("team: %ld, thread: %ld, token: %lu\n", team, thread, token)); PRINT(("team: %ld, thread: %ld, token: %lu\n", team, thread, token));
// update the app_info // update the app_info
if (error == B_OK) { if (error == B_OK) {
RosterAppInfo* info = fEarlyPreRegisteredApps.InfoForToken(token); RosterAppInfo* info = fEarlyPreRegisteredApps.InfoForToken(token);
@@ -575,7 +598,7 @@ PRINT(("team: %ld, thread: %ld, token: %lu\n", team, thread, token));
FUNCTION_END(); FUNCTION_END();
} }
// HandleSetSignature
/*! \brief Handles a SetSignature() request. /*! \brief Handles a SetSignature() request.
\param request The request message \param request The request message
*/ */
@@ -614,7 +637,7 @@ TRoster::HandleSetSignature(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleGetAppInfo
/*! \brief Handles a Get{Running,Active,}AppInfo() request. /*! \brief Handles a Get{Running,Active,}AppInfo() request.
\param request The request message \param request The request message
*/ */
@@ -639,12 +662,14 @@ TRoster::HandleGetAppInfo(BMessage *request)
hasRef = false; hasRef = false;
if (request->FindString("signature", &signature) != B_OK) if (request->FindString("signature", &signature) != B_OK)
hasSignature = false; hasSignature = false;
if (hasTeam) if (hasTeam)
PRINT(("team: %ld\n", team)); PRINT(("team: %ld\n", team));
if (hasRef) if (hasRef)
PRINT(("ref: %ld, %lld, %s\n", ref.device, ref.directory, ref.name)); PRINT(("ref: %ld, %lld, %s\n", ref.device, ref.directory, ref.name));
if (hasSignature) if (hasSignature)
PRINT(("signature: %s\n", signature)); PRINT(("signature: %s\n", signature));
// get the info // get the info
RosterAppInfo* info = NULL; RosterAppInfo* info = NULL;
if (error == B_OK) { if (error == B_OK) {
@@ -683,7 +708,7 @@ PRINT(("signature: %s\n", signature));
FUNCTION_END(); FUNCTION_END();
} }
// HandleGetAppList
/*! \brief Handles a GetAppList() request. /*! \brief Handles a GetAppList() request.
\param request The request message \param request The request message
*/ */
@@ -765,7 +790,7 @@ TRoster::HandleUpdateActiveApp(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleBroadcast
/*! \brief Handles a Broadcast() request. /*! \brief Handles a Broadcast() request.
\param request The request message \param request The request message
*/ */
@@ -834,7 +859,7 @@ TRoster::HandleBroadcast(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleStartWatching
/*! \brief Handles a StartWatching() request. /*! \brief Handles a StartWatching() request.
\param request The request message \param request The request message
*/ */
@@ -877,7 +902,7 @@ TRoster::HandleStartWatching(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleStopWatching
/*! \brief Handles a StopWatching() request. /*! \brief Handles a StopWatching() request.
\param request The request message \param request The request message
*/ */
@@ -911,7 +936,7 @@ TRoster::HandleStopWatching(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleGetRecentDocuments
/*! \brief Handles a GetRecentDocuments() request. /*! \brief Handles a GetRecentDocuments() request.
\param request The request message \param request The request message
*/ */
@@ -927,7 +952,7 @@ TRoster::HandleGetRecentDocuments(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleGetRecentFolders
/*! \brief Handles a GetRecentFolders() request. /*! \brief Handles a GetRecentFolders() request.
\param request The request message \param request The request message
*/ */
@@ -943,7 +968,7 @@ TRoster::HandleGetRecentFolders(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleGetRecentApps
/*! \brief Handles a GetRecentApps() request. /*! \brief Handles a GetRecentApps() request.
\param request The request message \param request The request message
*/ */
@@ -971,7 +996,7 @@ TRoster::HandleGetRecentApps(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleAddToRecentDocuments
/*! \brief Handles an AddToRecentDocuments() request. /*! \brief Handles an AddToRecentDocuments() request.
\param request The request message \param request The request message
*/ */
@@ -1002,7 +1027,7 @@ TRoster::HandleAddToRecentDocuments(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleAddToRecentFolders
/*! \brief Handles an AddToRecentFolders() request. /*! \brief Handles an AddToRecentFolders() request.
\param request The request message \param request The request message
*/ */
@@ -1033,7 +1058,7 @@ TRoster::HandleAddToRecentFolders(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleAddToRecentApps
/*! \brief Handles an AddToRecentApps() request. /*! \brief Handles an AddToRecentApps() request.
\param request The request message \param request The request message
*/ */
@@ -1061,6 +1086,7 @@ TRoster::HandleAddToRecentApps(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
void void
TRoster::HandleLoadRecentLists(BMessage* request) TRoster::HandleLoadRecentLists(BMessage* request)
{ {
@@ -1085,6 +1111,7 @@ TRoster::HandleLoadRecentLists(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
void void
TRoster::HandleSaveRecentLists(BMessage* request) TRoster::HandleSaveRecentLists(BMessage* request)
{ {
@@ -1109,7 +1136,7 @@ TRoster::HandleSaveRecentLists(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// ClearRecentDocuments
/*! \brief Clears the current list of recent documents /*! \brief Clears the current list of recent documents
*/ */
void void
@@ -1120,7 +1147,7 @@ TRoster::ClearRecentDocuments()
fRecentDocuments.Clear(); fRecentDocuments.Clear();
} }
// ClearRecentFolders
/*! \brief Clears the current list of recent folders /*! \brief Clears the current list of recent folders
*/ */
void void
@@ -1131,7 +1158,7 @@ TRoster::ClearRecentFolders()
fRecentFolders.Clear(); fRecentFolders.Clear();
} }
// ClearRecentApps
/*! \brief Clears the current list of recent apps /*! \brief Clears the current list of recent apps
*/ */
void void
@@ -1142,7 +1169,7 @@ TRoster::ClearRecentApps()
fRecentApps.Clear(); fRecentApps.Clear();
} }
// Init
/*! \brief Initializes the roster. /*! \brief Initializes the roster.
Currently only adds the registrar to the roster. Currently only adds the registrar to the roster.
@@ -1176,8 +1203,7 @@ TRoster::Init()
if (error == B_OK) { if (error == B_OK) {
info->Init(be_app->Thread(), be_app->Team(), info->Init(be_app->Thread(), be_app->Team(),
BMessenger::Private(be_app_messenger).Port(), BMessenger::Private(be_app_messenger).Port(),
B_EXCLUSIVE_LAUNCH | B_BACKGROUND_APP, &ref, B_EXCLUSIVE_LAUNCH | B_BACKGROUND_APP, &ref, kRegistrarSignature);
kRegistrarSignature);
info->state = APP_STATE_REGISTERED; info->state = APP_STATE_REGISTERED;
info->registration_time = system_time(); info->registration_time = system_time();
error = AddApp(info); error = AddApp(info);
@@ -1190,7 +1216,7 @@ TRoster::Init()
return error; return error;
} }
// AddApp
/*! \brief Add the supplied app info to the list of (pre-)registered apps. /*! \brief Add the supplied app info to the list of (pre-)registered apps.
\param info The app info to be added \param info The app info to be added
@@ -1208,7 +1234,7 @@ TRoster::AddApp(RosterAppInfo *info)
return error; return error;
} }
// RemoveApp
/*! \brief Removes the supplied app info from the list of (pre-)registered /*! \brief Removes the supplied app info from the list of (pre-)registered
apps. apps.
@@ -1258,7 +1284,7 @@ TRoster::UpdateActiveApp(RosterAppInfo *info)
} }
} }
// CheckSanity
/*! \brief Checks whether the (pre-)registered applications are still running. /*! \brief Checks whether the (pre-)registered applications are still running.
This is necessary, since killed applications don't unregister properly. This is necessary, since killed applications don't unregister properly.
@@ -1301,7 +1327,7 @@ TRoster::CheckSanity()
// don't delete infos a second time // don't delete infos a second time
} }
// SetShuttingDown
/*! \brief Tells the roster whether a shutdown process is in progess at the /*! \brief Tells the roster whether a shutdown process is in progess at the
moment. moment.
@@ -1319,7 +1345,7 @@ TRoster::SetShuttingDown(bool shuttingDown)
fShuttingDown = shuttingDown; fShuttingDown = shuttingDown;
} }
// GetShutdownApps
/*! \brief Returns lists of applications to be asked to quit on shutdown. /*! \brief Returns lists of applications to be asked to quit on shutdown.
\param userApps List of RosterAppInfos identifying the user applications. \param userApps List of RosterAppInfos identifying the user applications.
@@ -1410,7 +1436,7 @@ TRoster::GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
return error; return error;
} }
// AddWatcher
status_t status_t
TRoster::AddWatcher(Watcher* watcher) TRoster::AddWatcher(Watcher* watcher)
{ {
@@ -1426,7 +1452,6 @@ TRoster::AddWatcher(Watcher *watcher)
} }
// RemoveWatcher
void void
TRoster::RemoveWatcher(Watcher* watcher) TRoster::RemoveWatcher(Watcher* watcher)
{ {
@@ -1437,7 +1462,6 @@ TRoster::RemoveWatcher(Watcher *watcher)
} }
// _AppAdded
/*! \brief Hook method invoked, when an application has been fully registered. /*! \brief Hook method invoked, when an application has been fully registered.
\param info The RosterAppInfo of the added application. \param info The RosterAppInfo of the added application.
*/ */
@@ -1451,8 +1475,9 @@ TRoster::_AppAdded(RosterAppInfo *info)
fWatchingService.NotifyWatchers(&message, &filter); fWatchingService.NotifyWatchers(&message, &filter);
} }
// _AppRemoved
/*! \brief Hook method invoked, when a fully registered application has been removed. /*! \brief Hook method invoked, when a fully registered application has been
removed.
\param info The RosterAppInfo of the removed application. \param info The RosterAppInfo of the removed application.
*/ */
void void
@@ -1471,15 +1496,14 @@ TRoster::_AppRemoved(RosterAppInfo *info)
} }
} }
// _AppActivated
/*! \brief Hook method invoked, when an application has been activated. /*! \brief Hook method invoked, when an application has been activated.
\param info The RosterAppInfo of the activated application. \param info The RosterAppInfo of the activated application.
*/ */
void void
TRoster::_AppActivated(RosterAppInfo* info) TRoster::_AppActivated(RosterAppInfo* info)
{ {
if (info) { if (info != NULL && info->state == APP_STATE_REGISTERED) {
if (info->state == APP_STATE_REGISTERED) {
// send B_APP_ACTIVATED to the app // send B_APP_ACTIVATED to the app
BMessenger messenger; BMessenger messenger;
BMessenger::Private messengerPrivate(messenger); BMessenger::Private messengerPrivate(messenger);
@@ -1496,17 +1520,15 @@ TRoster::_AppActivated(RosterAppInfo *info)
fWatchingService.NotifyWatchers(&watcherMessage, &filter); fWatchingService.NotifyWatchers(&watcherMessage, &filter);
} }
} }
}
// _AppDeactivated
/*! \brief Hook method invoked, when an application has been deactivated. /*! \brief Hook method invoked, when an application has been deactivated.
\param info The RosterAppInfo of the deactivated application. \param info The RosterAppInfo of the deactivated application.
*/ */
void void
TRoster::_AppDeactivated(RosterAppInfo* info) TRoster::_AppDeactivated(RosterAppInfo* info)
{ {
if (info) { if (info != NULL && info->state == APP_STATE_REGISTERED) {
if (info->state == APP_STATE_REGISTERED) {
// send B_APP_ACTIVATED to the app // send B_APP_ACTIVATED to the app
BMessenger messenger; BMessenger messenger;
BMessenger::Private messengerPrivate(messenger); BMessenger::Private messengerPrivate(messenger);
@@ -1517,9 +1539,8 @@ TRoster::_AppDeactivated(RosterAppInfo *info)
MessageDeliverer::Default()->DeliverMessage(&message, messenger); MessageDeliverer::Default()->DeliverMessage(&message, messenger);
} }
} }
}
// _AddMessageAppInfo
/*! \brief Adds an app_info to a message. /*! \brief Adds an app_info to a message.
The info is added as a flat_app_info to a field "app_info" with the type The info is added as a flat_app_info to a field "app_info" with the type
@@ -1536,17 +1557,19 @@ TRoster::_AddMessageAppInfo(BMessage *message, const app_info *info)
// pointer. Therefore we flatten the info. // pointer. Therefore we flatten the info.
flat_app_info flatInfo; flat_app_info flatInfo;
flatInfo.info = *info; flatInfo.info = *info;
// set the ref name to NULL and copy it into the flat structure // set the ref name to NULL and copy it into the flat structure
flatInfo.info.ref.name = NULL; flatInfo.info.ref.name = NULL;
flatInfo.ref_name[0] = '\0'; flatInfo.ref_name[0] = '\0';
if (info->ref.name) if (info->ref.name)
strcpy(flatInfo.ref_name, info->ref.name); strcpy(flatInfo.ref_name, info->ref.name);
// add the flat info // add the flat info
return message->AddData("app_info", B_REG_APP_INFO_TYPE, &flatInfo, return message->AddData("app_info", B_REG_APP_INFO_TYPE, &flatInfo,
sizeof(flat_app_info)); sizeof(flat_app_info));
} }
// _AddMessageWatchingInfo
/*! \brief Adds application monitoring related fields to a message. /*! \brief Adds application monitoring related fields to a message.
\param message The message. \param message The message.
\param info The app_info of the concerned application. \param info The app_info of the concerned application.
@@ -1569,7 +1592,7 @@ TRoster::_AddMessageWatchingInfo(BMessage *message, const app_info *info)
return error; return error;
} }
// _NextToken
/*! \brief Returns the next available token. /*! \brief Returns the next available token.
\return The token. \return The token.
*/ */
@@ -1579,7 +1602,7 @@ TRoster::_NextToken()
return ++fLastToken; return ++fLastToken;
} }
// _AddIARRequest
/*! \brief Adds an IsAppRegistered() request to the given map. /*! \brief Adds an IsAppRegistered() request to the given map.
If something goes wrong, the method deletes the request. If something goes wrong, the method deletes the request.
@@ -1607,7 +1630,7 @@ TRoster::_AddIARRequest(IARRequestMap& map, int32 key, BMessage* request)
requests->AddMessage(request); requests->AddMessage(request);
} }
// _ReplyToIARRequests
/*! \brief Invokes _ReplyToIARRequest() for all messages in the given /*! \brief Invokes _ReplyToIARRequest() for all messages in the given
message queue. message queue.
@@ -1616,8 +1639,7 @@ TRoster::_AddIARRequest(IARRequestMap& map, int32 key, BMessage* request)
(may be \c NULL) (may be \c NULL)
*/ */
void void
TRoster::_ReplyToIARRequests(BMessageQueue *requests, TRoster::_ReplyToIARRequests(BMessageQueue* requests, const RosterAppInfo* info)
const RosterAppInfo *info)
{ {
while (BMessage* request = requests->NextMessage()) { while (BMessage* request = requests->NextMessage()) {
_ReplyToIARRequest(request, info); _ReplyToIARRequest(request, info);
@@ -1625,7 +1647,7 @@ TRoster::_ReplyToIARRequests(BMessageQueue *requests,
} }
} }
// _ReplyToIARRequest
/*! \brief Sends a reply message to an IsAppRegistered() request. /*! \brief Sends a reply message to an IsAppRegistered() request.
The message to be sent is a simple \c B_REG_SUCCESS message containing The message to be sent is a simple \c B_REG_SUCCESS message containing
@@ -1663,7 +1685,7 @@ PRINT(("_ReplyToIARRequest(): pre-registered: %d\n", preRegistered));
request->SendReply(&reply); request->SendReply(&reply);
} }
// _HandleGetRecentEntries
/*! \brief Handles requests for both GetRecentDocuments() and /*! \brief Handles requests for both GetRecentDocuments() and
GetRecentFolders(). GetRecentFolders().
*/ */
@@ -1686,7 +1708,8 @@ TRoster::_HandleGetRecentEntries(BMessage *request)
// Look for optional file type(s) // Look for optional file type(s)
if (!error) { if (!error) {
type_code typeFound; type_code typeFound;
status_t typeError = request->GetInfo("file type", &typeFound, &fileTypesCount); status_t typeError = request->GetInfo("file type", &typeFound,
&fileTypesCount);
if (!typeError) if (!typeError)
typeError = typeFound == B_STRING_TYPE ? B_OK : B_BAD_TYPE; typeError = typeFound == B_STRING_TYPE ? B_OK : B_BAD_TYPE;
if (!typeError) { if (!typeError) {
@@ -1780,16 +1803,14 @@ bool
TRoster::_IsSystemApp(RosterAppInfo* info) const TRoster::_IsSystemApp(RosterAppInfo* info) const
{ {
BPath path; BPath path;
status_t error = path.SetTo(&info->ref); if (path.SetTo(&info->ref) != B_OK || path.GetParent(&path) != B_OK)
if (error != B_OK)
return false; return false;
int len = strlen(path.Path()); return !strcmp(path.Path(), kSystemAppPath)
int prefixLen = strlen(kSystemAppPathPrefix); || !strcmp(path.Path(), kSystemServerPath);
return (len > prefixLen
&& strncmp(path.Path(), kSystemAppPathPrefix, prefixLen) == 0);
} }
status_t status_t
TRoster::_LoadRosterSettings(const char* path) TRoster::_LoadRosterSettings(const char* path)
{ {
@@ -1859,7 +1880,7 @@ TRoster::_LoadRosterSettings(const char *path)
case etFolder: case etFolder:
{ {
// For curing laziness // For curing laziness
std::list<recent_entry*> *list = (type == etDoc) std::list<recent_entry*>* list = type == etDoc
? &fRecentDocuments.fEntryList ? &fRecentDocuments.fEntryList
: &fRecentFolders.fEntryList; : &fRecentFolders.fEntryList;
@@ -1890,7 +1911,8 @@ TRoster::_LoadRosterSettings(const char *path)
} }
recent_entry* entry = NULL; recent_entry* entry = NULL;
if (!streamError) { if (!streamError) {
entry = new(nothrow) recent_entry(&ref, app, index); entry = new(nothrow) recent_entry(&ref, app,
index);
streamError = entry ? B_OK : B_NO_MEMORY; streamError = entry ? B_OK : B_NO_MEMORY;
} }
if (!streamError) { if (!streamError) {
@@ -1949,18 +1971,20 @@ TRoster::_LoadRosterSettings(const char *path)
fRecentApps.Print(); fRecentApps.Print();
printf("----------------------------------------------------------------------\n"); printf("----------------------------------------------------------------------\n");
} }
if (error) if (error) {
D(PRINT(("WARNING: TRoster::_LoadRosterSettings(): error loading roster settings " D(PRINT(("WARNING: TRoster::_LoadRosterSettings(): error loading roster "
"from '%s', 0x%lx\n", settingsPath, error))); "settings from '%s', 0x%lx\n", settingsPath, error)));
}
return error; return error;
} }
status_t status_t
TRoster::_SaveRosterSettings(const char* path) TRoster::_SaveRosterSettings(const char* path)
{ {
BPath _path; BPath _path;
const char* settingsPath const char* settingsPath
= path ? path : get_default_roster_settings_file(_path); = path != NULL ? path : get_default_roster_settings_file(_path);
status_t error; status_t error;
FILE* file; FILE* file;
@@ -1970,40 +1994,22 @@ TRoster::_SaveRosterSettings(const char *path)
if (!error) { if (!error) {
status_t saveError; status_t saveError;
saveError = fRecentDocuments.Save(file, "Recent documents", "RecentDoc"); saveError = fRecentDocuments.Save(file, "Recent documents", "RecentDoc");
if (saveError) if (saveError) {
D(PRINT(("TRoster::_SaveRosterSettings(): recent documents save failed " D(PRINT(("TRoster::_SaveRosterSettings(): recent documents save "
"with error 0x%lx\n", saveError))); "failed with error 0x%lx\n", saveError)));
}
saveError = fRecentFolders.Save(file, "Recent folders", "RecentFolder"); saveError = fRecentFolders.Save(file, "Recent folders", "RecentFolder");
if (saveError) if (saveError) {
D(PRINT(("TRoster::_SaveRosterSettings(): recent folders save failed " D(PRINT(("TRoster::_SaveRosterSettings(): recent folders save "
"with error 0x%lx\n", saveError))); "failed with error 0x%lx\n", saveError)));
}
saveError = fRecentApps.Save(file); saveError = fRecentApps.Save(file);
if (saveError) if (saveError) {
D(PRINT(("TRoster::_SaveRosterSettings(): recent folders save failed " D(PRINT(("TRoster::_SaveRosterSettings(): recent folders save "
"with error 0x%lx\n", saveError))); "failed with error 0x%lx\n", saveError)));
}
fclose(file); fclose(file);
} }
return error; return error;
} }
// #pragma mark - Private local functions
/*! \brief Returns true if entry1's index is larger than entry2's index.
Also returns true if either entry is \c NULL.
Used for sorting the recent entry lists loaded from disk into the
proper order.
*/
bool
larger_index(const recent_entry *entry1, const recent_entry *entry2)
{
if (entry1 && entry2)
return entry1->index > entry2->index;
else
return true;
}
+13 -6
View File
@@ -13,6 +13,7 @@
#include <Locker.h> #include <Locker.h>
#include <MessageQueue.h> #include <MessageQueue.h>
#include <Roster.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <hash_set> #include <hash_set>
@@ -70,8 +71,10 @@ public:
void CheckSanity(); void CheckSanity();
void SetShuttingDown(bool shuttingDown); void SetShuttingDown(bool shuttingDown);
status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps, status_t GetShutdownApps(AppInfoList& userApps,
AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps); AppInfoList& systemApps,
AppInfoList& backgroundApps,
hash_set<team_id>& vitalSystemApps);
status_t AddWatcher(Watcher* watcher); status_t AddWatcher(Watcher* watcher);
void RemoveWatcher(Watcher* watcher); void RemoveWatcher(Watcher* watcher);
@@ -84,19 +87,23 @@ private:
void _AppDeactivated(RosterAppInfo* info); void _AppDeactivated(RosterAppInfo* info);
// helper functions // helper functions
static status_t _AddMessageAppInfo(BMessage* message, const app_info* info); static status_t _AddMessageAppInfo(BMessage* message,
const app_info* info);
static status_t _AddMessageWatchingInfo(BMessage* message, static status_t _AddMessageWatchingInfo(BMessage* message,
const app_info* info); const app_info* info);
uint32 _NextToken(); uint32 _NextToken();
void _AddIARRequest(IARRequestMap& map, int32 key, BMessage* request); void _AddIARRequest(IARRequestMap& map, int32 key,
BMessage* request);
void _ReplyToIARRequests(BMessageQueue* requests, void _ReplyToIARRequests(BMessageQueue* requests,
const RosterAppInfo* info); const RosterAppInfo* info);
void _ReplyToIARRequest(BMessage* request, const RosterAppInfo* info); void _ReplyToIARRequest(BMessage* request,
const RosterAppInfo* info);
void _HandleGetRecentEntries(BMessage* request); void _HandleGetRecentEntries(BMessage* request);
void _ValidateRunning(const entry_ref& ref, const char* signature); void _ValidateRunning(const entry_ref& ref,
const char* signature);
bool _IsSystemApp(RosterAppInfo* info) const; bool _IsSystemApp(RosterAppInfo* info) const;
status_t _LoadRosterSettings(const char* path = NULL); status_t _LoadRosterSettings(const char* path = NULL);