The BRoster class lets you launch apps and keeps track of apps that are running. More...
Public Member Functions | |
BRoster () | |
Creates a new BRoster and sets up the connection to the roster service. | |
~BRoster () | |
Does nothing. | |
Querying | |
bool | IsRunning (const char *signature) const |
Returns whether or not an application with the supplied signature is currently running. | |
bool | IsRunning (entry_ref *ref) const |
Returns whether or not an application ran from an executable referred to by the supplied entry_ref is currently running. | |
team_id | TeamFor (const char *signature) const |
Returns the team ID of a currently running application with the supplied signature. | |
team_id | TeamFor (entry_ref *ref) const |
Returns the team ID of a currently running application executing the executable referred to by the supplied entry_ref. | |
void | GetAppList (BList *teamIDList) const |
Returns a list of all currently running applications. | |
void | GetAppList (const char *signature, BList *teamIDList) const |
Returns a list of all currently running applications with the specified signature. | |
status_t | GetAppInfo (const char *signature, app_info *info) const |
Returns the app_info of a currently running application with the supplied signature. | |
status_t | GetAppInfo (entry_ref *ref, app_info *info) const |
Returns the app_info of a currently running application executing the executable referred to by the supplied entry_ref. | |
status_t | GetRunningAppInfo (team_id team, app_info *info) const |
Returns the app_info of a currently running application identified by the supplied team ID. | |
status_t | GetActiveAppInfo (app_info *info) const |
Returns the app_info of a currently active application. | |
status_t | FindApp (const char *mimeType, entry_ref *app) const |
Finds an application associated with a MIME type. | |
status_t | FindApp (entry_ref *ref, entry_ref *app) const |
Finds an application associated with a file. | |
Launching, Activating, and Broadcasting | |
status_t | Broadcast (BMessage *message) const |
Sends a message to all running applications. | |
status_t | Broadcast (BMessage *message, BMessenger replyTo) const |
Sends a message to all running applications. | |
status_t | StartWatching (BMessenger target, uint32 eventMask=B_REQUEST_LAUNCHED|B_REQUEST_QUIT) const |
Adds a new roster application monitor. | |
status_t | StopWatching (BMessenger target) const |
Removes a roster application monitor added with StartWatching(). | |
status_t | ActivateApp (team_id team) const |
Activates the application identified by the supplied team ID. | |
status_t | Launch (const char *mimeType, BMessage *initialMessage=NULL, team_id *_appTeam=NULL) const |
Launches the application associated with the supplied MIME type. | |
status_t | Launch (const char *mimeType, BList *messageList, team_id *_appTeam=NULL) const |
Launches the application associated with the supplied MIME type. | |
status_t | Launch (const char *mimeType, int argc, const char *const *args, team_id *_appTeam=NULL) const |
Launches the application associated with the supplied MIME type. | |
status_t | Launch (const entry_ref *ref, const BMessage *initialMessage=NULL, team_id *_appTeam=NULL) const |
Launches the application associated with the entry referred to by the supplied entry_ref. | |
status_t | Launch (const entry_ref *ref, const BList *messageList, team_id *_appTeam=NULL) const |
Launches the application associated with the entry referred to by the supplied entry_ref. | |
status_t | Launch (const entry_ref *ref, int argc, const char *const *args, team_id *_appTeam=NULL) const |
Launches the application associated with the entry referred to by the supplied entry_ref. | |
Recent Information | |
void | GetRecentDocuments (BMessage *refList, int32 maxCount, const char *fileType=NULL, const char *signature=NULL) const |
Returns a list of the most recently used documents. | |
void | GetRecentDocuments (BMessage *refList, int32 maxCount, const char *fileTypes[], int32 fileTypesCount, const char *signature=NULL) const |
Returns a list of the most recently used documents. | |
void | GetRecentFolders (BMessage *refList, int32 maxCount, const char *signature=NULL) const |
Returns a list of recently accessed folders. | |
void | GetRecentApps (BMessage *refList, int32 maxCount) const |
Returns a list of the most recently launched applications. | |
void | AddToRecentDocuments (const entry_ref *document, const char *signature=NULL) const |
Adds the document to the list of recent documents. | |
void | AddToRecentFolders (const entry_ref *folder, const char *signature=NULL) const |
Adds folder to the list of recent folders. | |
The BRoster class lets you launch apps and keeps track of apps that are running.
The global be_roster object represents the default BRoster, while the app_info structure provides info for a running app.
BRoster::BRoster | ( | ) |
BRoster::~BRoster | ( | ) |
Does nothing.
status_t BRoster::ActivateApp | ( | team_id | team | ) | const |
Activates the application identified by the supplied team ID.
team | The app's team ID |
B_OK | Everything went fine. |
B_BAD_TEAM_ID | team does not identify a running application. |
void BRoster::AddToRecentDocuments | ( | const entry_ref * | document, |
const char * | signature = NULL |
||
) | const |
Adds the document to the list of recent documents.
document | The document to add. |
signature | To record that a specific application used the document. |
Adds folder to the list of recent folders.
folder | The folder to add. |
signature | To record that a specific application used the folder. |
Sends a message to all running applications.
The methods doesn't broadcast the message itself, but it asks the roster to do so. It immediatly returns after sending the request. The return value only tells about whether the request has successfully been sent.
The message is sent asynchronously. Replies to it go to the application. (be_app_messenger
).
message | The message to be broadcast. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL message. |
status_t BRoster::Broadcast | ( | BMessage * | message, |
BMessenger | replyTo | ||
) | const |
Sends a message to all running applications.
The methods doesn't broadcast the message itself, but it asks the roster to do so. It immediatly returns after sending the request. The return value only tells about whether the request has successfully been sent.
The message is sent asynchronously. Replies to it go to the specified target (replyTo).
message | The message to be broadcast. |
replyTo | Reply target for the message. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL message. |
Finds an application associated with a MIME type.
The method gets the signature of the supplied type's preferred application and the signature of the super type's preferred application. It will also get all supporting applications for the type and super type and build a list of candiate handlers. In the case that a preferred handler is configured for the sub-type, other supporting apps will be inserted in the candidate list before the super-type preferred and supporting handlers, since it is assumed that the super type handlers are not well suited for the sub-type. The following resolving algorithm is performed on each signature of the resulting list: The MIME database is asked which executable is associated with the signature. If the database doesn't have a reference to an exectuable, the boot volume is queried for a file with the signature. If more than one file has been found, the one with the greatest version is picked, or if no file has a version info, the one with the most recent modification date. The first application from the signature list which can be successfully resolved by this algorithm is returned. Contrary to BeOS behavior, this means that if the preferred application of the provided MIME type cannot be resolved, or if it does not have a preferred application associated, the method will return other applications with direct support for the MIME type before it resorts to the preferred application or supporting applications of the super type.
mimeType | The MIME type for which an application shall be found. |
app | A pointer to a pre-allocated entry_ref to be filled with a reference to the found application's executable. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType or app. |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated and no other supporting applications could be identified. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type was not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's only supporting application was in the trash. |
Finds an application associated with a file.
The method first checks, if the file has a preferred application associated with it (see BNodeInfo::GetPreferredApp()) and if so, tries to find the executable the same way FindApp(const char*, entry_ref*) does. If not, it gets the MIME type of the file and searches an application for it exactly like the first FindApp() method.
The type of the file is defined in a file attribute (BNodeInfo::GetType()), but if it is not set yet, the method tries to guess it via BMimeType::GuessMimeType().
As a special case the file may have execute permission. Then preferred application and type are ignored and an entry_ref to the file itself is returned.
ref | An entry_ref referring to the file for which an application shall be found. |
app | A pointer to a pre-allocated entry_ref to be filled with a reference to the found application's executable. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType or app. |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type was not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
Returns the app_info of a currently active application.
info | A pointer to a pre-allocated app_info structure to be filled in by this method. |
B_OK | Everything went fine. |
B_BAD_VALUE | info was NULL . |
B_ERROR | No application was currently active. |
info | A pointer to a pre-allocated app_info structure to be filled in by this method. |
B_OK | Everything went fine. |
B_BAD_VALUE | info was NULL . |
B_ERROR | No application was currently active. |
Returns the app_info of a currently running application with the supplied signature.
signature | The application signature. |
info | A pointer to a pre-allocated app_info structure to be filled by this method. |
B_OK | Everything went fine. |
B_BAD_VALUE | sig is NULL . |
B_ERROR | No application with the supplied signature is currently running. |
Returns the app_info of a currently running application executing the executable referred to by the supplied entry_ref.
ref | The app's entry_ref |
info | A pointer to a pre-allocated app_info structure to be filled in by this method. |
B_OK | Everything went fine. |
B_BAD_VALUE | ref is NULL . |
B_ERROR | No application executing the file referred to by ref was currently running. |
void BRoster::GetAppList | ( | BList * | teamIDList | ) | const |
Returns a list of all currently running applications.
The supplied list is not emptied before adding the team IDs of the running applications. The list elements are team_id's, not pointers.
teamIDList | A pointer to a pre-allocated BList to be filled with the team IDs. |
void BRoster::GetAppList | ( | const char * | signature, |
BList * | teamIDList | ||
) | const |
Returns a list of all currently running applications with the specified signature.
The supplied list is not emptied before adding the team IDs of the running applications. The list elements are team_id's, not pointers. If sig is NULL
or invalid, no team IDs are added to the list.
signature | The application signature. |
teamIDList | A pointer to a pre-allocated BList to be filled with the team IDs. |
Returns a list of the most recently launched applications.
refList | Filled out with information about recently used apps. |
maxCount | The maximum number of apps to get information on. |
void BRoster::GetRecentDocuments | ( | BMessage * | refList, |
int32 | maxCount, | ||
const char * | fileType = NULL , |
||
const char * | signature = NULL |
||
) | const |
Returns a list of the most recently used documents.
refList | Filled out with information about recently used documents. |
maxCount | The maximum number of documents to get information on. |
fileType | Filter documents by MIME-type string. |
signature | Get info only on documents that were used by a specific application. |
void BRoster::GetRecentDocuments | ( | BMessage * | refList, |
int32 | maxCount, | ||
const char * | fileTypes[], | ||
int32 | fileTypesCount, | ||
const char * | signature = NULL |
||
) | const |
Returns a list of the most recently used documents.
refList | Filled out with information about recently used documents. |
maxCount | The maximum number of documents to get information on. |
fileTypes | Filter documents by and array of MIME-type string. |
fileTypesCount | The number of MIME-types in fileType. |
signature | Get info only on documents that were used by a specific application. |
void BRoster::GetRecentFolders | ( | BMessage * | refList, |
int32 | maxCount, | ||
const char * | signature = NULL |
||
) | const |
Returns a list of recently accessed folders.
refList | Filled out with information about recently used folders. |
maxCount | The maximum number of folders to get information on. |
signature | Get info only on folders that were used by a specific application. |
Returns the app_info of a currently running application identified by the supplied team ID.
team | The app's team ID. |
info | A pointer to a pre-allocated app_info structure to be filled in by this method. |
B_OK | Everything went fine. |
B_BAD_VALUE | info was NULL . |
B_BAD_TEAM_ID | team did not identify a running application. |
bool BRoster::IsRunning | ( | const char * | signature | ) | const |
Returns whether or not an application with the supplied signature is currently running.
signature | The app signature. |
true
, if the supplied signature is not NULL
and an application with this signature is running, false
otherwise.bool BRoster::IsRunning | ( | entry_ref * | ref | ) | const |
status_t BRoster::Launch | ( | const char * | mimeType, |
BList * | messageList, | ||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the supplied MIME type.
The application to be started is searched the same way FindApp() does it.
messageList contains messages to be sent to the application "on launch", i.e. before ReadyToRun() is invoked on the BApplication object. The caller retains ownership of the supplied BList and the contained BMessages. In case the method fails with B_ALREADY_RUNNING
the messages are delivered to the already running instance.
mimeType | MIME type for which the application shall be launched. |
messageList | Optional list of messages to be sent to the application "on launch". May be NULL . |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
status_t BRoster::Launch | ( | const char * | mimeType, |
BMessage * | initialMessage = NULL , |
||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the supplied MIME type.
The application to be started is searched the same way FindApp() does it.
initialMessage is a message to be sent to the application "on launch", i.e. before ReadyToRun() is invoked on the BApplication object. The caller retains ownership of the supplied BMessage. In case the method fails with B_ALREADY_RUNNING
the message is delivered to the already running instance.
mimeType | MIME type for which the application shall be launched. |
initialMessage | Optional message to be sent to the application "on launch". May be NULL . |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
B_ALREADY_RUNNING | The application's app flags specify |
B_SINGLE_LAUNCH | or B_EXCLUSIVE_LAUNCH and the application (the very same (single) or at least one with the same signature (exclusive)) is already running. |
status_t BRoster::Launch | ( | const char * | mimeType, |
int | argc, | ||
const char *const * | args, | ||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the supplied MIME type.
The application to be started is searched the same way FindApp() does it.
The supplied argc and args are (if containing at least one argument) put into a B_ARGV_RECEIVED
message and sent to the launched application "on launch". The caller retains ownership of the supplied args. In case the method fails with B_ALREADY_RUNNING
the message is delivered to the already running instance.
mimeType | MIME type for which the application shall be launched. |
argc | Specifies the number of elements in args. |
args | An array of C-strings to be sent as B_ARGV_RECEIVED messaged to the launched application. |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
status_t BRoster::Launch | ( | const entry_ref * | ref, |
const BList * | messageList, | ||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the entry referred to by the supplied entry_ref.
The application to be started is searched the same way FindApp() does it.
If ref does refer to an application executable, that application is launched. Otherwise the respective application is searched and launched, and ref is sent to it in a B_REFS_RECEIVED
message.
messageList contains messages to be sent to the application "on launch", i.e. before ReadyToRun() is invoked on the BApplication object. The caller retains ownership of the supplied BList and the contained BMessages. In case the method fails with B_ALREADY_RUNNING
the messages are delivered to the already running instance. The same applies to the B_REFS_RECEIVED
message.
ref | entry_ref referring to the file for which an application shall be launched. |
messageList | Optional list of messages to be sent to the application "on launch". May be NULL . |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
status_t BRoster::Launch | ( | const entry_ref * | ref, |
const BMessage * | initialMessage = NULL , |
||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the entry referred to by the supplied entry_ref.
The application to be started is searched the same way FindApp() does it.
If ref does refer to an application executable, that application is launched. Otherwise the respective application is searched and launched, and ref is sent to it in a B_REFS_RECEIVED
message.
initialMessage is a message to be sent to the application "on launch", i.e. before ReadyToRun() is invoked on the BApplication object. The caller retains ownership of the supplied BMessage. In case the method fails with B_ALREADY_RUNNING
the message is delivered to the already running instance. The same applies to the B_REFS_RECEIVED
message.
ref | entry_ref referring to the file for which an application shall be launched. |
initialMessage | Optional message to be sent to the application "on launch". May be NULL . |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
B_ALREADY_RUNNING | The application's app flags specify B_SINGLE_LAUNCH or B_EXCLUSIVE_LAUNCH and the application (the very same (single) or at least one with the same signature (exclusive)) was already running. |
status_t BRoster::Launch | ( | const entry_ref * | ref, |
int | argc, | ||
const char *const * | args, | ||
team_id * | appTeam = NULL |
||
) | const |
Launches the application associated with the entry referred to by the supplied entry_ref.
The application to be started is searched the same way FindApp() does it.
If ref does refer to an application executable, that application is launched. Otherwise the respective application is searched and launched, and ref is sent to it in a B_REFS_RECEIVED
message, unless other arguments are passed via argc and args – then the entry_ref is converted into a path (C-string) and added to the argument vector.
The supplied argc and args are (if containing at least one argument) put into a B_ARGV_RECEIVED
message and sent to the launched application "on launch". The caller retains ownership of the supplied args. In case the method fails with B_ALREADY_RUNNING
the message is delivered to the already running instance. The same applies to the B_REFS_RECEIVED
message, if no arguments are supplied via argc and args.
ref | entry_ref referring to the file for which an application shall be launched. |
argc | Specifies the number of elements in args. |
args | An array of C-strings to be sent as B_ARGV_RECEIVED messaged to the launched application. |
appTeam | Pointer to a pre-allocated team_id variable to be set to the team ID of the launched application. |
B_OK | Everything went fine. |
B_BAD_VALUE | NULL mimeType |
B_LAUNCH_FAILED_NO_PREFERRED_APP | Neither with the supplied type nor with its supertype (if the supplied isn't a supertype itself) a preferred application is associated. |
B_LAUNCH_FAILED_APP_NOT_FOUND | The supplied type is not installed or its preferred application could not be found. |
B_LAUNCH_FAILED_APP_IN_TRASH | The supplied type's preferred application was in the trash. |
B_LAUNCH_FAILED_EXECUTABLE | The found application was not executable. |
status_t BRoster::StartWatching | ( | BMessenger | target, |
uint32 | eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT |
||
) | const |
Adds a new roster application monitor.
After StartWatching() event messages will be sent to the supplied target according to the specified flags until a respective StopWatching() call.
eventMask must be a bitwise OR of one or more of the following flags:
B_REQUEST_LAUNCHED:
A B_SOME_APP_LAUNCHED
is sent, whenever an application has been launched.B_REQUEST_QUIT:
A B_SOME_APP_QUIT
is sent, whenever an application has quit.B_REQUEST_ACTIVATED:
A B_SOME_APP_ACTIVATED
is sent, whenever an application has been activated.All event messages contain the following fields supplying more information about the concerned application:
"be:signature"
, B_STRING_TYPE:
The signature of the application."be:team"
, B_INT32_TYPE:
The team ID of the application (team_id
)."be:thread"
, B_INT32_TYPE:
The ID of the application's main thread (thread_id
)."be:flags"
, B_INT32_TYPE:
The application flags (uint32
)."be:ref"
, B_REF_TYPE:
An entry_ref referring to the application's executable.A second call to StartWatching() with the same target simply sets the new eventMask. The messages won't be sent twice to the target.
target | The target the event messages shall be sent to. |
eventMask | Specifies the events the caller is interested in. |
B_OK
if everything went fine or an error code, if some error occurred.status_t BRoster::StopWatching | ( | BMessenger | target | ) | const |
Removes a roster application monitor added with StartWatching().
target | The target that shall not longer receive any event messages. |
B_OK | Everything went fine. |
B_BAD_VALUE | No application monitor has been associated with the specified target before. |
team_id BRoster::TeamFor | ( | const char * | signature | ) | const |
Returns the team ID of a currently running application with the supplied signature.
signature | The app signature. |
B_BAD_VALUE | signature is NULL . |
B_ERROR | No application with the supplied signature is currently running. |
team_id BRoster::TeamFor | ( | entry_ref * | ref | ) | const |
Returns the team ID of a currently running application executing the executable referred to by the supplied entry_ref.
ref | The app's entry_ref |
B_BAD_VALUE | ref is NULL . |
B_ERROR | No application executing the file referred to by ref is currently running. |