git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16430 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-02-16 17:37:36 +00:00
parent 8242ac7f2f
commit eb797182df
4 changed files with 327 additions and 339 deletions
+107 -128
View File
@@ -1,39 +1,19 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2006, Haiku.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Ingo Weinhold ([email protected])
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Roster.h
// Author: Ingo Weinhold ([email protected])
// Description: BRoster class lets you launch apps and keeps
// track of apps that are running.
// Global be_roster represents the default BRoster.
// app_info structure provides info for a running app.
//------------------------------------------------------------------------------
#ifndef _ROSTER_H #ifndef _ROSTER_H
#define _ROSTER_H #define _ROSTER_H
#include <Entry.h> #include <Entry.h>
#include <Messenger.h> #include <Messenger.h>
#include <OS.h> #include <OS.h>
// app_info
struct app_info { struct app_info {
app_info(); app_info();
~app_info(); ~app_info();
@@ -71,125 +51,124 @@ enum {
class BList; class BList;
// BRoster
class BRoster { class BRoster {
public: public:
BRoster(); BRoster();
~BRoster(); ~BRoster();
// running apps // running apps
bool IsRunning(const char *mimeSig) const; bool IsRunning(const char *mimeSig) const;
bool IsRunning(entry_ref *ref) const; bool IsRunning(entry_ref *ref) const;
team_id TeamFor(const char *mimeSig) const; team_id TeamFor(const char *mimeSig) const;
team_id TeamFor(entry_ref *ref) const; team_id TeamFor(entry_ref *ref) const;
void GetAppList(BList *teamIDList) const; void GetAppList(BList *teamIDList) const;
void GetAppList(const char *sig, BList *teamIDList) const; void GetAppList(const char *sig, BList *teamIDList) const;
// app infos // app infos
status_t GetAppInfo(const char *sig, app_info *info) const; status_t GetAppInfo(const char *sig, app_info *info) const;
status_t GetAppInfo(entry_ref *ref, app_info *info) const; status_t GetAppInfo(entry_ref *ref, app_info *info) const;
status_t GetRunningAppInfo(team_id team, app_info *info) const; status_t GetRunningAppInfo(team_id team, app_info *info) const;
status_t GetActiveAppInfo(app_info *info) const; status_t GetActiveAppInfo(app_info *info) const;
// find app // find app
status_t FindApp(const char *mimeType, entry_ref *app) const; status_t FindApp(const char *mimeType, entry_ref *app) const;
status_t FindApp(entry_ref *ref, entry_ref *app) const; status_t FindApp(entry_ref *ref, entry_ref *app) const;
// broadcast // broadcast
status_t Broadcast(BMessage *message) const; status_t Broadcast(BMessage *message) const;
status_t Broadcast(BMessage *message, BMessenger replyTo) const; status_t Broadcast(BMessage *message, BMessenger replyTo) const;
// watching // watching
status_t StartWatching(BMessenger target, status_t StartWatching(BMessenger target,
uint32 eventMask = B_REQUEST_LAUNCHED uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const;
| B_REQUEST_QUIT) const; status_t StopWatching(BMessenger target) const;
status_t StopWatching(BMessenger target) const;
status_t ActivateApp(team_id team) const; status_t ActivateApp(team_id team) const;
// launch app // launch app
status_t Launch(const char *mimeType, BMessage *initialMessage = 0, status_t Launch(const char *mimeType, BMessage *initialMessage = 0,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
status_t Launch(const char *mimeType, BList *messageList, status_t Launch(const char *mimeType, BList *messageList,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
status_t Launch(const char *mimeType, int argc, char **args, status_t Launch(const char *mimeType, int argc, char **args,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0, status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
status_t Launch(const entry_ref *ref, const BList *messageList, status_t Launch(const entry_ref *ref, const BList *messageList,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
status_t Launch(const entry_ref *ref, int argc, const char * const *args, status_t Launch(const entry_ref *ref, int argc, const char * const *args,
team_id *appTeam = 0) const; team_id *appTeam = 0) const;
// recent documents, folders, apps // recent documents, folders, apps
void GetRecentDocuments(BMessage *refList, int32 maxCount, void GetRecentDocuments(BMessage *refList, int32 maxCount,
const char *fileType = 0, const char *fileType = 0,
const char *appSig = 0) const; const char *appSig = 0) const;
void GetRecentDocuments(BMessage *refList, int32 maxCount, void GetRecentDocuments(BMessage *refList, int32 maxCount,
const char *fileTypes[], int32 fileTypesCount, const char *fileTypes[], int32 fileTypesCount,
const char *appSig = 0) const; const char *appSig = 0) const;
void GetRecentFolders(BMessage *refList, int32 maxCount, void GetRecentFolders(BMessage *refList, int32 maxCount,
const char *appSig = 0) const; const char *appSig = 0) const;
void GetRecentApps(BMessage *refList, int32 maxCount) const; void GetRecentApps(BMessage *refList, int32 maxCount) const;
void AddToRecentDocuments(const entry_ref *doc, void AddToRecentDocuments(const entry_ref *doc,
const char *appSig = 0) const; const char *appSig = 0) const;
void AddToRecentFolders(const entry_ref *folder, void AddToRecentFolders(const entry_ref *folder,
const char *appSig = 0) const; const char *appSig = 0) const;
// private/reserved stuff starts here // private/reserved stuff starts here
class Private; class Private;
private: private:
class ArgVector; class ArgVector;
friend class Private; friend class Private;
status_t ShutDown(bool reboot, bool confirm, bool synchronous); status_t _ShutDown(bool reboot, bool confirm, bool synchronous);
status_t AddApplication(const char *mimeSig, const entry_ref *ref, status_t _AddApplication(const char *mimeSig, const entry_ref *ref,
uint32 flags, team_id team, thread_id thread, uint32 flags, team_id team, thread_id thread,
port_id port, bool fullReg, uint32 *pToken, port_id port, bool fullReg, uint32 *pToken,
team_id *otherTeam) const; team_id *otherTeam) const;
status_t SetSignature(team_id team, const char *mimeSig) const; status_t _SetSignature(team_id team, const char *mimeSig) const;
void SetThread(team_id team, thread_id thread) const; void _SetThread(team_id team, thread_id thread) const;
status_t SetThreadAndTeam(uint32 entryToken, thread_id thread, status_t _SetThreadAndTeam(uint32 entryToken, thread_id thread,
team_id team) const; team_id team) const;
status_t CompleteRegistration(team_id team, thread_id thread, status_t _CompleteRegistration(team_id team, thread_id thread,
port_id port) const; port_id port) const;
bool IsAppPreRegistered(const entry_ref *ref, team_id team, bool _IsAppPreRegistered(const entry_ref *ref, team_id team,
app_info *info) const; app_info *info) const;
status_t RemovePreRegApp(uint32 entryToken) const; status_t _RemovePreRegApp(uint32 entryToken) const;
status_t RemoveApp(team_id team) const; status_t _RemoveApp(team_id team) const;
status_t xLaunchAppPrivate(const char *mimeType, const entry_ref *ref, status_t _LaunchApp(const char *mimeType, const entry_ref *ref,
const BList *messageList, int argc, const BList *messageList, int argc,
const char *const *args, const char *const *args,
team_id *appTeam) const; team_id *appTeam) const;
bool UpdateActiveApp(team_id team) const; bool _UpdateActiveApp(team_id team) const;
void SetAppFlags(team_id team, uint32 flags) const; void _SetAppFlags(team_id team, uint32 flags) const;
void DumpRoster() const; void _DumpRoster() const;
status_t resolve_app(const char *inType, entry_ref *ref, entry_ref *appRef, status_t _ResolveApp(const char *inType, entry_ref *ref, entry_ref *appRef,
char *appSig, uint32 *appFlags, char *appSig, uint32 *appFlags,
bool *wasDocument) const; bool *wasDocument) const;
status_t translate_ref(entry_ref *ref, BMimeType *appMeta, status_t _TranslateRef(entry_ref *ref, BMimeType *appMeta,
entry_ref *appRef, BFile *appFile, entry_ref *appRef, BFile *appFile,
bool *wasDocument) const; bool *wasDocument) const;
status_t translate_type(const char *mimeType, BMimeType *appMeta, status_t _TranslateType(const char *mimeType, BMimeType *appMeta,
entry_ref *appRef, BFile *appFile) const; entry_ref *appRef, BFile *appFile) const;
status_t sniff_file(const entry_ref *file, BNodeInfo *nodeInfo, status_t _SniffFile(const entry_ref *file, BNodeInfo *nodeInfo,
char *mimeType) const; char *mimeType) const;
status_t send_to_running(team_id team, int argc, const char *const *args, status_t _SendToRunning(team_id team, int argc, const char *const *args,
const BList *messageList, const entry_ref *ref, const BList *messageList, const entry_ref *ref,
bool readyToRun) const; bool readyToRun) const;
void InitMessengers(); void _InitMessengers();
void AddToRecentApps(const char *appSig) const; void _AddToRecentApps(const char *appSig) const;
void ClearRecentDocuments() const; void _ClearRecentDocuments() const;
void ClearRecentFolders() const; void _ClearRecentFolders() const;
void ClearRecentApps() const; void _ClearRecentApps() const;
void LoadRecentLists(const char *filename) const; void _LoadRecentLists(const char *filename) const;
void SaveRecentLists(const char *filename) const; void _SaveRecentLists(const char *filename) const;
BMessenger fMess; BMessenger fMessenger;
BMessenger fMimeMess; BMessenger fMimeMessenger;
uint32 _reserved[3]; uint32 _reserved[3];
}; };
// global BRoster instance // global BRoster instance
+52 -48
View File
@@ -1,76 +1,80 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2001-2006, Haiku.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Ingo Weinhold ([email protected])
*/
#ifndef _ROSTER_PRIVATE_H #ifndef _ROSTER_PRIVATE_H
#define _ROSTER_PRIVATE_H #define _ROSTER_PRIVATE_H
#include <Messenger.h> #include <Messenger.h>
#include <Roster.h> #include <Roster.h>
class BRoster::Private { class BRoster::Private {
public: public:
Private() : fRoster(const_cast<BRoster*>(be_roster)) {} Private() : fRoster(const_cast<BRoster*>(be_roster)) {}
Private(BRoster &roster) : fRoster(&roster) {} Private(BRoster &roster) : fRoster(&roster) {}
Private(BRoster *roster) : fRoster(roster) {} Private(BRoster *roster) : fRoster(roster) {}
void SetTo(BMessenger mainMessenger, BMessenger mimeMessenger); void SetTo(BMessenger mainMessenger, BMessenger mimeMessenger);
status_t SendTo(BMessage *message, BMessage *reply, bool mime); status_t SendTo(BMessage *message, BMessage *reply, bool mime);
bool IsMessengerValid(bool mime) const; bool IsMessengerValid(bool mime) const;
status_t ShutDown(bool reboot, bool confirm, bool synchronous) status_t ShutDown(bool reboot, bool confirm, bool synchronous)
{ return fRoster->ShutDown(reboot, confirm, synchronous); } { return fRoster->_ShutDown(reboot, confirm, synchronous); }
// needed by BApplication // needed by BApplication
status_t AddApplication(const char *mimeSig, const entry_ref *ref, status_t AddApplication(const char *mimeSig, const entry_ref *ref,
uint32 flags, team_id team, thread_id thread, uint32 flags, team_id team, thread_id thread,
port_id port, bool fullReg, uint32 *token, port_id port, bool fullReg, uint32 *token,
team_id *otherTeam) const team_id *otherTeam) const
{ return fRoster->AddApplication(mimeSig, ref, flags, team, thread, { return fRoster->_AddApplication(mimeSig, ref, flags, team, thread,
port, fullReg, token, otherTeam); } port, fullReg, token, otherTeam); }
status_t SetSignature(team_id team, const char *mimeSig) const status_t SetSignature(team_id team, const char *mimeSig) const
{ return fRoster->SetSignature(team, mimeSig); } { return fRoster->_SetSignature(team, mimeSig); }
status_t CompleteRegistration(team_id team, thread_id thread, status_t CompleteRegistration(team_id team, thread_id thread,
port_id port) const port_id port) const
{ return fRoster->CompleteRegistration(team, thread, port); } { return fRoster->_CompleteRegistration(team, thread, port); }
bool IsAppPreRegistered(const entry_ref *ref, team_id team, bool IsAppPreRegistered(const entry_ref *ref, team_id team,
app_info *info) const app_info *info) const
{ return fRoster->IsAppPreRegistered(ref, team, info); } { return fRoster->_IsAppPreRegistered(ref, team, info); }
status_t RemoveApp(team_id team) const status_t RemoveApp(team_id team) const
{ return fRoster->RemoveApp(team); } { return fRoster->_RemoveApp(team); }
// needed by GetRecentTester // needed by GetRecentTester
void AddToRecentApps(const char *appSig) const void AddToRecentApps(const char *appSig) const
{ fRoster->AddToRecentApps(appSig); } { fRoster->_AddToRecentApps(appSig); }
void ClearRecentDocuments() const void ClearRecentDocuments() const
{ fRoster->ClearRecentDocuments(); } { fRoster->_ClearRecentDocuments(); }
void ClearRecentFolders() const void ClearRecentFolders() const
{ fRoster->ClearRecentFolders(); } { fRoster->_ClearRecentFolders(); }
void ClearRecentApps() const void ClearRecentApps() const
{ fRoster->ClearRecentApps(); } { fRoster->_ClearRecentApps(); }
void LoadRecentLists(const char *file) const void LoadRecentLists(const char *file) const
{ fRoster->LoadRecentLists(file); } { fRoster->_LoadRecentLists(file); }
void SaveRecentLists(const char *file) const void SaveRecentLists(const char *file) const
{ fRoster->SaveRecentLists(file); } { fRoster->_SaveRecentLists(file); }
static void InitBeRoster(); static void InitBeRoster();
static void DeleteBeRoster(); static void DeleteBeRoster();
private: private:
BRoster *fRoster; BRoster *fRoster;
}; };
#endif // _ROSTER_PRIVATE_H #endif // _ROSTER_PRIVATE_H
+161 -156
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -223,10 +223,10 @@ BRoster::ArgVector::Unset()
BRoster::BRoster() BRoster::BRoster()
: :
fMess(), fMessenger(),
fMimeMess() fMimeMessenger()
{ {
InitMessengers(); _InitMessengers();
} }
@@ -328,7 +328,7 @@ BRoster::GetAppList(BList *teamIDList) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) { if (reply.what == B_REG_SUCCESS) {
@@ -368,7 +368,7 @@ BRoster::GetAppList(const char *sig, BList *teamIDList) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) { if (reply.what == B_REG_SUCCESS) {
@@ -403,7 +403,7 @@ BRoster::GetAppInfo(const char *sig, app_info *info) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) if (reply.what == B_REG_SUCCESS)
@@ -437,7 +437,7 @@ BRoster::GetAppInfo(entry_ref *ref, app_info *info) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) if (reply.what == B_REG_SUCCESS)
@@ -472,7 +472,7 @@ BRoster::GetRunningAppInfo(team_id team, app_info *info) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) if (reply.what == B_REG_SUCCESS)
@@ -501,7 +501,7 @@ BRoster::GetActiveAppInfo(app_info *info) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) if (reply.what == B_REG_SUCCESS)
@@ -544,7 +544,7 @@ BRoster::FindApp(const char *mimeType, entry_ref *app) const
{ {
status_t error = (mimeType && app ? B_OK : B_BAD_VALUE); status_t error = (mimeType && app ? B_OK : B_BAD_VALUE);
if (error == B_OK) if (error == B_OK)
error = resolve_app(mimeType, NULL, app, NULL, NULL, NULL); error = _ResolveApp(mimeType, NULL, app, NULL, NULL, NULL);
return error; return error;
} }
@@ -587,7 +587,7 @@ BRoster::FindApp(entry_ref *ref, entry_ref *app) const
status_t error = (ref && app ? B_OK : B_BAD_VALUE); status_t error = (ref && app ? B_OK : B_BAD_VALUE);
if (error == B_OK) { if (error == B_OK) {
entry_ref _ref(*ref); entry_ref _ref(*ref);
error = resolve_app(NULL, &_ref, app, NULL, NULL, NULL); error = _ResolveApp(NULL, &_ref, app, NULL, NULL, NULL);
} }
return error; return error;
} }
@@ -649,7 +649,7 @@ BRoster::Broadcast(BMessage *message, BMessenger replyTo) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -703,7 +703,7 @@ BRoster::StartWatching(BMessenger target, uint32 eventMask) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -729,7 +729,7 @@ BRoster::StopWatching(BMessenger target) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -842,17 +842,16 @@ BRoster::ActivateApp(team_id team) const
*/ */
status_t status_t
BRoster::Launch(const char *mimeType, BMessage *initialMessage, BRoster::Launch(const char *mimeType, BMessage *initialMessage,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (mimeType ? B_OK : B_BAD_VALUE); if (mimeType == NULL)
if (error == B_OK) { return B_BAD_VALUE;
BList messageList;
if (initialMessage) BList messageList;
messageList.AddItem(initialMessage); if (initialMessage)
error = xLaunchAppPrivate(mimeType, NULL, &messageList, 0, NULL, messageList.AddItem(initialMessage);
appTeam);
} return _LaunchApp(mimeType, NULL, &messageList, 0, NULL, appTeam);
return error;
} }
// Launch // Launch
@@ -886,14 +885,12 @@ BRoster::Launch(const char *mimeType, BMessage *initialMessage,
*/ */
status_t status_t
BRoster::Launch(const char *mimeType, BList *messageList, BRoster::Launch(const char *mimeType, BList *messageList,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (mimeType ? B_OK : B_BAD_VALUE); if (mimeType == NULL)
if (error == B_OK) { return B_BAD_VALUE;
error = xLaunchAppPrivate(mimeType, NULL, messageList, 0, NULL,
appTeam); return _LaunchApp(mimeType, NULL, messageList, 0, NULL, appTeam);
}
return error;
} }
// Launch // Launch
@@ -928,12 +925,12 @@ BRoster::Launch(const char *mimeType, BList *messageList,
*/ */
status_t status_t
BRoster::Launch(const char *mimeType, int argc, char **args, BRoster::Launch(const char *mimeType, int argc, char **args,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (mimeType ? B_OK : B_BAD_VALUE); if (mimeType == NULL)
if (error == B_OK) return B_BAD_VALUE;
error = xLaunchAppPrivate(mimeType, NULL, NULL, argc, args, appTeam);
return error; return _LaunchApp(mimeType, NULL, NULL, argc, args, appTeam);
} }
// Launch // Launch
@@ -977,16 +974,16 @@ BRoster::Launch(const char *mimeType, int argc, char **args,
*/ */
status_t status_t
BRoster::Launch(const entry_ref *ref, const BMessage *initialMessage, BRoster::Launch(const entry_ref *ref, const BMessage *initialMessage,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (ref ? B_OK : B_BAD_VALUE); if (ref == NULL)
if (error == B_OK) { return B_BAD_VALUE;
BList messageList;
if (initialMessage) BList messageList;
messageList.AddItem(const_cast<BMessage*>(initialMessage)); if (initialMessage)
error = xLaunchAppPrivate(NULL, ref, &messageList, 0, NULL, appTeam); messageList.AddItem(const_cast<BMessage*>(initialMessage));
}
return error; return _LaunchApp(NULL, ref, &messageList, 0, NULL, appTeam);
} }
// Launch // Launch
@@ -1027,12 +1024,12 @@ BRoster::Launch(const entry_ref *ref, const BMessage *initialMessage,
*/ */
status_t status_t
BRoster::Launch(const entry_ref *ref, const BList *messageList, BRoster::Launch(const entry_ref *ref, const BList *messageList,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (ref ? B_OK : B_BAD_VALUE); if (ref == NULL)
if (error == B_OK) return B_BAD_VALUE;
error = xLaunchAppPrivate(NULL, ref, messageList, 0, NULL, appTeam);
return error; return _LaunchApp(NULL, ref, messageList, 0, NULL, appTeam);
} }
// Launch // Launch
@@ -1079,10 +1076,10 @@ status_t
BRoster::Launch(const entry_ref *ref, int argc, const char * const *args, BRoster::Launch(const entry_ref *ref, int argc, const char * const *args,
team_id *appTeam) const team_id *appTeam) const
{ {
status_t error = (ref ? B_OK : B_BAD_VALUE); if (ref == NULL)
if (error == B_OK) return B_BAD_VALUE;
error = xLaunchAppPrivate(NULL, ref, NULL, argc, args, appTeam);
return error; return _LaunchApp(NULL, ref, NULL, argc, args, appTeam);
} }
@@ -1091,8 +1088,7 @@ BRoster::Launch(const entry_ref *ref, int argc, const char * const *args,
// GetRecentDocuments // GetRecentDocuments
void void
BRoster::GetRecentDocuments(BMessage *refList, int32 maxCount, BRoster::GetRecentDocuments(BMessage *refList, int32 maxCount,
const char *fileType, const char *fileType, const char *appSig) const
const char *appSig) const
{ {
if (!refList) if (!refList)
return; return;
@@ -1113,7 +1109,7 @@ BRoster::GetRecentDocuments(BMessage *refList, int32 maxCount,
err = msg.AddString("file type", fileType); err = msg.AddString("file type", fileType);
if (!err && appSig) if (!err && appSig)
err = msg.AddString("app sig", appSig); err = msg.AddString("app sig", appSig);
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1154,7 +1150,7 @@ BRoster::GetRecentDocuments(BMessage *refList, int32 maxCount,
} }
if (!err && appSig) if (!err && appSig)
err = msg.AddString("app sig", appSig); err = msg.AddString("app sig", appSig);
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1190,7 +1186,7 @@ BRoster::GetRecentFolders(BMessage *refList, int32 maxCount,
} }
if (!err && appSig) if (!err && appSig)
err = msg.AddString("app sig", appSig); err = msg.AddString("app sig", appSig);
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1223,7 +1219,7 @@ BRoster::GetRecentApps(BMessage *refList, int32 maxCount) const
msg.what = B_REG_GET_RECENT_APPS; msg.what = B_REG_GET_RECENT_APPS;
err = msg.AddInt32("max count", maxCount); err = msg.AddInt32("max count", maxCount);
} }
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1263,7 +1259,7 @@ BRoster::AddToRecentDocuments(const entry_ref *doc, const char *appSig) const
err = msg.AddRef("ref", doc); err = msg.AddRef("ref", doc);
if (!err) if (!err)
err = msg.AddString("app sig", (appSig ? appSig : callingAppSig)); err = msg.AddString("app sig", (appSig ? appSig : callingAppSig));
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1300,7 +1296,7 @@ BRoster::AddToRecentFolders(const entry_ref *folder, const char *appSig) const
err = msg.AddRef("ref", folder); err = msg.AddRef("ref", folder);
if (!err) if (!err)
err = msg.AddString("app sig", (appSig ? appSig : callingAppSig)); err = msg.AddString("app sig", (appSig ? appSig : callingAppSig));
fMess.SendMessage(&msg, &reply); fMessenger.SendMessage(&msg, &reply);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
@@ -1333,7 +1329,7 @@ BRoster::AddToRecentFolders(const entry_ref *folder, const char *appSig) const
- another error code in case something went wrong. - another error code in case something went wrong.
*/ */
status_t status_t
BRoster::ShutDown(bool reboot, bool confirm, bool synchronous) BRoster::_ShutDown(bool reboot, bool confirm, bool synchronous)
{ {
status_t error = B_OK; status_t error = B_OK;
@@ -1349,7 +1345,7 @@ BRoster::ShutDown(bool reboot, bool confirm, bool synchronous)
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
@@ -1402,10 +1398,10 @@ BRoster::ShutDown(bool reboot, bool confirm, bool synchronous)
is already registered. is already registered.
*/ */
status_t status_t
BRoster::AddApplication(const char *mimeSig, const entry_ref *ref, BRoster::_AddApplication(const char *mimeSig, const entry_ref *ref,
uint32 flags, team_id team, thread_id thread, uint32 flags, team_id team, thread_id thread,
port_id port, bool fullReg, uint32 *pToken, port_id port, bool fullReg, uint32 *pToken,
team_id *otherTeam) const team_id *otherTeam) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1427,7 +1423,7 @@ BRoster::AddApplication(const char *mimeSig, const entry_ref *ref,
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK) { if (error == B_OK) {
if (reply.what == B_REG_SUCCESS) { if (reply.what == B_REG_SUCCESS) {
@@ -1462,7 +1458,7 @@ BRoster::AddApplication(const char *mimeSig, const entry_ref *ref,
registered application. registered application.
*/ */
status_t status_t
BRoster::SetSignature(team_id team, const char *mimeSig) const BRoster::_SetSignature(team_id team, const char *mimeSig) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1474,7 +1470,7 @@ BRoster::SetSignature(team_id team, const char *mimeSig) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -1486,7 +1482,7 @@ BRoster::SetSignature(team_id team, const char *mimeSig) const
\todo Really needed? \todo Really needed?
*/ */
void void
BRoster::SetThread(team_id team, thread_id thread) const BRoster::_SetThread(team_id team, thread_id thread) const
{ {
} }
@@ -1507,8 +1503,8 @@ BRoster::SetThread(team_id team, thread_id thread) const
pre-registered application. pre-registered application.
*/ */
status_t status_t
BRoster::SetThreadAndTeam(uint32 entryToken, thread_id thread, BRoster::_SetThreadAndTeam(uint32 entryToken, thread_id thread,
team_id team) const team_id team) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1522,7 +1518,7 @@ BRoster::SetThreadAndTeam(uint32 entryToken, thread_id thread,
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -1545,8 +1541,8 @@ BRoster::SetThreadAndTeam(uint32 entryToken, thread_id thread,
application or the identified application is already fully registered. application or the identified application is already fully registered.
*/ */
status_t status_t
BRoster::CompleteRegistration(team_id team, thread_id thread, BRoster::_CompleteRegistration(team_id team, thread_id thread,
port_id port) const port_id port) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1560,7 +1556,7 @@ BRoster::CompleteRegistration(team_id team, thread_id thread,
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -1580,8 +1576,8 @@ BRoster::CompleteRegistration(team_id team, thread_id thread,
\return \c true, if the application is pre-registered, \c false if not. \return \c true, if the application is pre-registered, \c false if not.
*/ */
bool bool
BRoster::IsAppPreRegistered(const entry_ref *ref, team_id team, BRoster::_IsAppPreRegistered(const entry_ref *ref, team_id team,
app_info *info) const app_info *info) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1593,7 +1589,8 @@ BRoster::IsAppPreRegistered(const entry_ref *ref, team_id team,
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
bool isPreRegistered = false; bool isPreRegistered = false;
if (error == B_OK) { if (error == B_OK) {
@@ -1623,7 +1620,7 @@ BRoster::IsAppPreRegistered(const entry_ref *ref, team_id team,
pre-registered application. pre-registered application.
*/ */
status_t status_t
BRoster::RemovePreRegApp(uint32 entryToken) const BRoster::_RemovePreRegApp(uint32 entryToken) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1633,7 +1630,7 @@ BRoster::RemovePreRegApp(uint32 entryToken) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
@@ -1654,7 +1651,7 @@ BRoster::RemovePreRegApp(uint32 entryToken) const
(pre-)registered application. (pre-)registered application.
*/ */
status_t status_t
BRoster::RemoveApp(team_id team) const BRoster::_RemoveApp(team_id team) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -1664,14 +1661,14 @@ BRoster::RemoveApp(team_id team) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS) if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error); reply.FindInt32("error", &error);
return error; return error;
} }
// xLaunchAppPrivate // _LaunchApp
/*! \brief Launches the application associated with the supplied MIME type or /*! \brief Launches the application associated with the supplied MIME type or
the entry referred to by the supplied entry_ref. the entry referred to by the supplied entry_ref.
@@ -1726,11 +1723,11 @@ BRoster::RemoveApp(team_id team) const
- other error codes - other error codes
*/ */
status_t status_t
BRoster::xLaunchAppPrivate(const char *mimeType, const entry_ref *ref, BRoster::_LaunchApp(const char *mimeType, const entry_ref *ref,
const BList *messageList, int argc, const BList *messageList, int argc,
const char *const *args, team_id *appTeam) const const char *const *args, team_id *appTeam) const
{ {
DBG(OUT("BRoster::xLaunchAppPrivate()")); DBG(OUT("BRoster::xLaunchAppPrivate()"));
status_t error = (mimeType || ref ? B_OK : B_BAD_VALUE); status_t error = (mimeType || ref ? B_OK : B_BAD_VALUE);
// use a mutable copy of the document entry_ref // use a mutable copy of the document entry_ref
entry_ref _docRef; entry_ref _docRef;
@@ -1745,17 +1742,17 @@ DBG(OUT("BRoster::xLaunchAppPrivate()"));
uint32 appFlags = B_REG_DEFAULT_APP_FLAGS; uint32 appFlags = B_REG_DEFAULT_APP_FLAGS;
bool wasDocument = true; bool wasDocument = true;
if (error == B_OK) { if (error == B_OK) {
error = resolve_app(mimeType, docRef, &appRef, signature, &appFlags, error = _ResolveApp(mimeType, docRef, &appRef, signature, &appFlags,
&wasDocument); &wasDocument);
} }
DBG(OUT(" find app: %s (%lx)\n", strerror(error), error)); DBG(OUT(" find app: %s (%lx)\n", strerror(error), error));
// build an argument vector // build an argument vector
ArgVector argVector; ArgVector argVector;
if (error == B_OK) { if (error == B_OK) {
error = argVector.Init(argc, args, &appRef, error = argVector.Init(argc, args, &appRef,
(wasDocument ? docRef : NULL)); (wasDocument ? docRef : NULL));
} }
DBG(OUT(" build argv: %s (%lx)\n", strerror(error), error)); DBG(OUT(" build argv: %s (%lx)\n", strerror(error), error));
// pre-register the app // pre-register the app
app_info appInfo; app_info appInfo;
bool alreadyRunning = false; bool alreadyRunning = false;
@@ -1763,10 +1760,10 @@ DBG(OUT(" build argv: %s (%lx)\n", strerror(error), error));
team_id otherTeam = -1; team_id otherTeam = -1;
uint32 otherAppFlags = B_REG_DEFAULT_APP_FLAGS; uint32 otherAppFlags = B_REG_DEFAULT_APP_FLAGS;
if (error == B_OK && !alreadyRunning) { if (error == B_OK && !alreadyRunning) {
error = AddApplication(signature, &appRef, appFlags, -1, -1, -1, false, error = _AddApplication(signature, &appRef, appFlags, -1, -1, -1, false,
&appToken, &otherTeam); &appToken, &otherTeam);
if (error == B_ALREADY_RUNNING) { if (error == B_ALREADY_RUNNING) {
DBG(OUT(" already running\n")); DBG(OUT(" already running\n"));
alreadyRunning = true; alreadyRunning = true;
error = B_OK; error = B_OK;
// get the app flags for the running application // get the app flags for the running application
@@ -1774,16 +1771,16 @@ DBG(OUT(" already running\n"));
otherAppFlags = appInfo.flags; otherAppFlags = appInfo.flags;
} }
} }
DBG(OUT(" pre-register: %s (%lx)\n", strerror(error), error)); DBG(OUT(" pre-register: %s (%lx)\n", strerror(error), error));
// launch the app // launch the app
team_id team = -1; team_id team = -1;
if (error == B_OK && !alreadyRunning) { if (error == B_OK && !alreadyRunning) {
DBG(OUT(" token: %lu\n", appToken)); DBG(OUT(" token: %lu\n", appToken));
// load the app image // load the app image
thread_id appThread = load_image(argVector.Count(), thread_id appThread = load_image(argVector.Count(),
const_cast<const char**>( const_cast<const char**>(argVector.Args()),
argVector.Args()), const_cast<const char**>(environ));
const_cast<const char**>(environ));
// get the app team // get the app team
if (appThread >= 0) { if (appThread >= 0) {
thread_info threadInfo; thread_info threadInfo;
@@ -1794,22 +1791,26 @@ DBG(OUT(" token: %lu\n", appToken));
error = B_LAUNCH_FAILED_EXECUTABLE; error = B_LAUNCH_FAILED_EXECUTABLE;
} else } else
error = appThread; error = appThread;
DBG(OUT(" load image: %s (%lx)\n", strerror(error), error));
DBG(OUT(" load image: %s (%lx)\n", strerror(error), error));
// finish the registration // finish the registration
if (error == B_OK) if (error == B_OK)
error = SetThreadAndTeam(appToken, appThread, team); error = _SetThreadAndTeam(appToken, appThread, team);
DBG(OUT(" set thread and team: %s (%lx)\n", strerror(error), error));
DBG(OUT(" set thread and team: %s (%lx)\n", strerror(error), error));
// resume the launched team // resume the launched team
if (error == B_OK) if (error == B_OK)
error = resume_thread(appThread); error = resume_thread(appThread);
DBG(OUT(" resume thread: %s (%lx)\n", strerror(error), error));
DBG(OUT(" resume thread: %s (%lx)\n", strerror(error), error));
// on error: kill the launched team and unregister the app // on error: kill the launched team and unregister the app
if (error != B_OK) { if (error != B_OK) {
if (appThread >= 0) if (appThread >= 0)
kill_thread(appThread); kill_thread(appThread);
RemovePreRegApp(appToken); _RemovePreRegApp(appToken);
} }
} }
// send "on launch" messages // send "on launch" messages
if (error == B_OK) { if (error == B_OK) {
// the messages go to the launched team or to the already running one // the messages go to the launched team or to the already running one
@@ -1825,32 +1826,35 @@ DBG(OUT(" resume thread: %s (%lx)\n", strerror(error), error));
const entry_ref *_ref = (argvOnly || !wasDocument const entry_ref *_ref = (argvOnly || !wasDocument
|| argVector.Count() > 1 ? NULL : docRef); || argVector.Count() > 1 ? NULL : docRef);
if (!(argvOnly && alreadyRunning)) { if (!(argvOnly && alreadyRunning)) {
send_to_running(targetTeam, argVector.Count(), argVector.Args(), _SendToRunning(targetTeam, argVector.Count(), argVector.Args(),
_messageList, _ref, !alreadyRunning); _messageList, _ref, !alreadyRunning);
} }
} }
// set return values // set return values
if (error == B_OK && alreadyRunning) if (error == B_OK && alreadyRunning)
error = B_ALREADY_RUNNING; error = B_ALREADY_RUNNING;
if (appTeam) if (appTeam)
*appTeam = (error == B_OK ? team : -1); *appTeam = (error == B_OK ? team : -1);
DBG(OUT("BRoster::xLaunchAppPrivate() done: %s (%lx)\n", strerror(error), error));
DBG(OUT("BRoster::_LaunchApp() done: %s (%lx)\n",
strerror(error), error));
return error; return error;
} }
// SetAppFlags // SetAppFlags
void void
BRoster::SetAppFlags(team_id team, uint32 flags) const BRoster::_SetAppFlags(team_id team, uint32 flags) const
{ {
} }
// DumpRoster // DumpRoster
void void
BRoster::DumpRoster() const BRoster::_DumpRoster() const
{ {
} }
// resolve_app // _ResolveApp
/*! \brief Finds an application associated with a MIME type or a file. /*! \brief Finds an application associated with a MIME type or a file.
It does also supply the caller with some more information about the It does also supply the caller with some more information about the
@@ -1889,9 +1893,9 @@ BRoster::DumpRoster() const
- \see FindApp() for other error codes. - \see FindApp() for other error codes.
*/ */
status_t status_t
BRoster::resolve_app(const char *inType, entry_ref *ref, BRoster::_ResolveApp(const char *inType, entry_ref *ref,
entry_ref *appRef, char *appSig, uint32 *appFlags, entry_ref *appRef, char *appSig, uint32 *appFlags,
bool *wasDocument) const bool *wasDocument) const
{ {
status_t error = (inType || ref ? B_OK : B_BAD_VALUE); status_t error = (inType || ref ? B_OK : B_BAD_VALUE);
if (error == B_OK && inType && strlen(inType) >= B_MIME_TYPE_LENGTH) if (error == B_OK && inType && strlen(inType) >= B_MIME_TYPE_LENGTH)
@@ -1902,9 +1906,9 @@ BRoster::resolve_app(const char *inType, entry_ref *ref,
entry_ref _appRef; entry_ref _appRef;
if (error == B_OK) { if (error == B_OK) {
if (inType) if (inType)
error = translate_type(inType, &appMeta, &_appRef, &appFile); error = _TranslateType(inType, &appMeta, &_appRef, &appFile);
else { else {
error = translate_ref(ref, &appMeta, &_appRef, &appFile, error = _TranslateRef(ref, &appMeta, &_appRef, &appFile,
wasDocument); wasDocument);
} }
} }
@@ -1957,7 +1961,7 @@ BRoster::resolve_app(const char *inType, entry_ref *ref,
return error; return error;
} }
// translate_ref // _TranslateRef
/*! \brief Finds an application associated with a file. /*! \brief Finds an application associated with a file.
\a appMeta is left unmodified, if the file is executable, but has no \a appMeta is left unmodified, if the file is executable, but has no
@@ -1984,9 +1988,9 @@ BRoster::resolve_app(const char *inType, entry_ref *ref,
- \see FindApp() for other error codes. - \see FindApp() for other error codes.
*/ */
status_t status_t
BRoster::translate_ref(entry_ref *ref, BMimeType *appMeta, BRoster::_TranslateRef(entry_ref *ref, BMimeType *appMeta,
entry_ref *appRef, BFile *appFile, entry_ref *appRef, BFile *appFile,
bool *wasDocument) const bool *wasDocument) const
{ {
status_t error = (ref && appMeta && appRef && appFile ? B_OK status_t error = (ref && appMeta && appRef && appFile ? B_OK
: B_BAD_VALUE); : B_BAD_VALUE);
@@ -2039,20 +2043,20 @@ BRoster::translate_ref(entry_ref *ref, BMimeType *appMeta,
error = nodeInfo.SetTo(&node); error = nodeInfo.SetTo(&node);
char preferredApp[B_MIME_TYPE_LENGTH]; char preferredApp[B_MIME_TYPE_LENGTH];
if (error == B_OK) { if (error == B_OK) {
// if the file has a preferred app, let translate_type() find // if the file has a preferred app, let _TranslateType() find
// it for us // it for us
if (nodeInfo.GetPreferredApp(preferredApp) == B_OK) { if (nodeInfo.GetPreferredApp(preferredApp) == B_OK) {
error = translate_type(preferredApp, appMeta, appRef, error = _TranslateType(preferredApp, appMeta, appRef,
appFile); appFile);
} else { } else {
// no preferred app -- we need to get the file's type // no preferred app -- we need to get the file's type
char fileType[B_MIME_TYPE_LENGTH]; char fileType[B_MIME_TYPE_LENGTH];
// get the type from the file, or guess a type // get the type from the file, or guess a type
if (nodeInfo.GetType(fileType) != B_OK) if (nodeInfo.GetType(fileType) != B_OK)
error = sniff_file(ref, &nodeInfo, fileType); error = _SniffFile(ref, &nodeInfo, fileType);
// now let translate_type() do the actual work // now let _TranslateType() do the actual work
if (error == B_OK) { if (error == B_OK) {
error = translate_type(fileType, appMeta, appRef, error = _TranslateType(fileType, appMeta, appRef,
appFile); appFile);
} }
} }
@@ -2064,7 +2068,7 @@ BRoster::translate_ref(entry_ref *ref, BMimeType *appMeta,
return error; return error;
} }
// translate_type // _TranslateType
/*! \brief Finds an application associated with a MIME type. /*! \brief Finds an application associated with a MIME type.
\see FindApp() for how the application is searched. \see FindApp() for how the application is searched.
@@ -2082,8 +2086,8 @@ BRoster::translate_ref(entry_ref *ref, BMimeType *appMeta,
- \see FindApp() for other error codes. - \see FindApp() for other error codes.
*/ */
status_t status_t
BRoster::translate_type(const char *mimeType, BMimeType *appMeta, BRoster::_TranslateType(const char *mimeType, BMimeType *appMeta,
entry_ref *appRef, BFile *appFile) const entry_ref *appRef, BFile *appFile) const
{ {
status_t error = (mimeType && appMeta && appRef && appFile status_t error = (mimeType && appMeta && appRef && appFile
&& strlen(mimeType) < B_MIME_TYPE_LENGTH ? B_OK && strlen(mimeType) < B_MIME_TYPE_LENGTH ? B_OK
@@ -2135,7 +2139,7 @@ BRoster::translate_type(const char *mimeType, BMimeType *appMeta,
return error; return error;
} }
// sniff_file // _SniffFile
/*! \brief Sniffs the MIME type for a file. /*! \brief Sniffs the MIME type for a file.
Also updates the file's MIME info, if possible. Also updates the file's MIME info, if possible.
@@ -2151,8 +2155,8 @@ BRoster::translate_type(const char *mimeType, BMimeType *appMeta,
- other errors - other errors
*/ */
status_t status_t
BRoster::sniff_file(const entry_ref *file, BNodeInfo *nodeInfo, BRoster::_SniffFile(const entry_ref *file, BNodeInfo *nodeInfo,
char *mimeType) const char *mimeType) const
{ {
status_t error = (file && nodeInfo && mimeType ? B_OK : B_BAD_VALUE); status_t error = (file && nodeInfo && mimeType ? B_OK : B_BAD_VALUE);
if (error == B_OK) { if (error == B_OK) {
@@ -2171,7 +2175,7 @@ BRoster::sniff_file(const entry_ref *file, BNodeInfo *nodeInfo,
return error; return error;
} }
// send_to_running // _SendToRunning
/*! \brief Sends messages to a running team. /*! \brief Sends messages to a running team.
In particular those messages are \c B_ARGV_RECEIVED, \c B_REFS_RECEIVED, In particular those messages are \c B_ARGV_RECEIVED, \c B_REFS_RECEIVED,
@@ -2200,9 +2204,9 @@ BRoster::sniff_file(const entry_ref *file, BNodeInfo *nodeInfo,
- an error code otherwise - an error code otherwise
*/ */
status_t status_t
BRoster::send_to_running(team_id team, int argc, const char *const *args, BRoster::_SendToRunning(team_id team, int argc, const char *const *args,
const BList *messageList, const entry_ref *ref, const BList *messageList, const entry_ref *ref,
bool readyToRun) const bool readyToRun) const
{ {
status_t error = B_OK; status_t error = B_OK;
// Construct a messenger to the app: We can't use the public constructor, // Construct a messenger to the app: We can't use the public constructor,
@@ -2243,7 +2247,7 @@ BRoster::send_to_running(team_id team, int argc, const char *const *args,
void void
BRoster::InitMessengers() BRoster::_InitMessengers()
{ {
DBG(OUT("BRoster::InitMessengers()\n")); DBG(OUT("BRoster::InitMessengers()\n"));
@@ -2253,15 +2257,16 @@ BRoster::InitMessengers()
if (rosterPort >= 0 && get_port_info(rosterPort, &info) == B_OK) { if (rosterPort >= 0 && get_port_info(rosterPort, &info) == B_OK) {
DBG(OUT(" found roster port\n")); DBG(OUT(" found roster port\n"));
// ask for the MIME messenger // ask for the MIME messenger
BMessenger::Private(fMess).SetTo(info.team, rosterPort, B_PREFERRED_TOKEN); BMessenger::Private(fMessenger).SetTo(info.team, rosterPort,
B_PREFERRED_TOKEN);
BMessage reply; BMessage reply;
status_t error = fMess.SendMessage(B_REG_GET_MIME_MESSENGER, &reply); status_t error = fMessenger.SendMessage(B_REG_GET_MIME_MESSENGER, &reply);
if (error == B_OK && reply.what == B_REG_SUCCESS) { if (error == B_OK && reply.what == B_REG_SUCCESS) {
DBG(OUT(" got reply from roster\n")); DBG(OUT(" got reply from roster\n"));
reply.FindMessenger("messenger", &fMimeMess); reply.FindMessenger("messenger", &fMimeMessenger);
} else { } else {
DBG(OUT(" no (useful) reply from roster: error: %lx: %s\n", error, DBG(OUT(" no (useful) reply from roster: error: %lx: %s\n", error,
strerror(error))); strerror(error)));
if (error == B_OK) if (error == B_OK)
DBG(reply.PrintToStream()); DBG(reply.PrintToStream());
} }
@@ -2274,7 +2279,7 @@ BRoster::InitMessengers()
given signature to the front of the recent apps list. given signature to the front of the recent apps list.
*/ */
void void
BRoster::AddToRecentApps(const char *appSig) const BRoster::_AddToRecentApps(const char *appSig) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -2284,7 +2289,7 @@ BRoster::AddToRecentApps(const char *appSig) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
status_t result; status_t result;
if (error == B_OK) if (error == B_OK)
@@ -2301,33 +2306,33 @@ BRoster::AddToRecentApps(const char *appSig) const
documents list. documents list.
*/ */
void void
BRoster::ClearRecentDocuments() const BRoster::_ClearRecentDocuments() const
{ {
BMessage request(B_REG_CLEAR_RECENT_DOCUMENTS); BMessage request(B_REG_CLEAR_RECENT_DOCUMENTS);
BMessage reply; BMessage reply;
fMess.SendMessage(&request, &reply); fMessenger.SendMessage(&request, &reply);
} }
/*! \brief Sends a request to the roster to clear the recent /*! \brief Sends a request to the roster to clear the recent
documents list. documents list.
*/ */
void void
BRoster::ClearRecentFolders() const BRoster::_ClearRecentFolders() const
{ {
BMessage request(B_REG_CLEAR_RECENT_FOLDERS); BMessage request(B_REG_CLEAR_RECENT_FOLDERS);
BMessage reply; BMessage reply;
fMess.SendMessage(&request, &reply); fMessenger.SendMessage(&request, &reply);
} }
/*! \brief Sends a request to the roster to clear the recent /*! \brief Sends a request to the roster to clear the recent
documents list. documents list.
*/ */
void void
BRoster::ClearRecentApps() const BRoster::_ClearRecentApps() const
{ {
BMessage request(B_REG_CLEAR_RECENT_APPS); BMessage request(B_REG_CLEAR_RECENT_APPS);
BMessage reply; BMessage reply;
fMess.SendMessage(&request, &reply); fMessenger.SendMessage(&request, &reply);
} }
// LoadRecentLists // LoadRecentLists
@@ -2339,7 +2344,7 @@ BRoster::ClearRecentApps() const
\param filename The name of the file to load from \param filename The name of the file to load from
*/ */
void void
BRoster::LoadRecentLists(const char *filename) const BRoster::_LoadRecentLists(const char *filename) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -2349,7 +2354,7 @@ BRoster::LoadRecentLists(const char *filename) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
status_t result; status_t result;
if (error == B_OK) if (error == B_OK)
@@ -2369,7 +2374,7 @@ BRoster::LoadRecentLists(const char *filename) const
\param filename The name of the file to save to \param filename The name of the file to save to
*/ */
void void
BRoster::SaveRecentLists(const char *filename) const BRoster::_SaveRecentLists(const char *filename) const
{ {
status_t error = B_OK; status_t error = B_OK;
// compose the request message // compose the request message
@@ -2379,7 +2384,7 @@ BRoster::SaveRecentLists(const char *filename) const
// send the request // send the request
BMessage reply; BMessage reply;
if (error == B_OK) if (error == B_OK)
error = fMess.SendMessage(&request, &reply); error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply // evaluate the reply
status_t result; status_t result;
if (error == B_OK) if (error == B_OK)
+7 -7
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -28,8 +28,8 @@ void
BRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger) BRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger)
{ {
if (fRoster) { if (fRoster) {
fRoster->fMess = mainMessenger; fRoster->fMessenger = mainMessenger;
fRoster->fMimeMess = mimeMessenger; fRoster->fMimeMessenger = mimeMessenger;
} }
} }
@@ -59,9 +59,9 @@ BRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
error = B_NO_INIT; error = B_NO_INIT;
if (error == B_OK) { if (error == B_OK) {
if (mime) if (mime)
error = fRoster->fMimeMess.SendMessage(message, reply); error = fRoster->fMimeMessenger.SendMessage(message, reply);
else else
error = fRoster->fMess.SendMessage(message, reply); error = fRoster->fMessenger.SendMessage(message, reply);
} }
return error; return error;
} }
@@ -79,8 +79,8 @@ BRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
bool bool
BRoster::Private::IsMessengerValid(bool mime) const BRoster::Private::IsMessengerValid(bool mime) const
{ {
return (fRoster && (mime ? fRoster->fMimeMess.IsValid() return (fRoster && (mime ? fRoster->fMimeMessenger.IsValid()
: fRoster->fMess.IsValid())); : fRoster->fMessenger.IsValid()));
} }
// InitBeRoster // InitBeRoster