Improved BMessenger::InitData() a bit: Now only one roster call is done, when a signature but no team ID is given.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@676 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2002-08-09 23:31:40 +00:00
parent e840a8d122
commit 9e9f5a1ad3
+17 -17
View File
@@ -32,6 +32,7 @@
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
#include <string.h>
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h> #include <Application.h>
@@ -585,28 +586,27 @@ void
BMessenger::InitData(const char *signature, team_id team, status_t *result) BMessenger::InitData(const char *signature, team_id team, status_t *result)
{ {
status_t error = B_OK; status_t error = B_OK;
// if no team ID is given, get one using the signature // get an app_info
app_info info;
if (team < 0) { if (team < 0) {
// no team ID given
if (signature) { if (signature) {
team = be_roster->TeamFor(signature); error = be_roster->GetAppInfo(signature, &info);
if (team < 0) { team = info.team;
error = team; // B_ERROR means that no application with the given signature
// B_ERROR means that no application with the given signature // is running. But we are supposed to return B_BAD_VALUE.
// is running. But we are supposed to return B_BAD_VALUE. if (error == B_ERROR)
if (error == B_ERROR) error = B_BAD_VALUE;
error = B_BAD_VALUE;
}
} else } else
error = B_BAD_TYPE; error = B_BAD_TYPE;
} } else {
// get the app_info of the team // a team ID is given
app_info info;
if (error == B_OK)
error = be_roster->GetRunningAppInfo(team, &info); error = be_roster->GetRunningAppInfo(team, &info);
// check, whether the signature is correct // Compare the returned signature with the supplied one.
if (error == B_OK && signature && strcmp(signature, info.signature) != 0) if (error == B_OK && signature && strcmp(signature, info.signature))
error = B_MISMATCHED_VALUES; error = B_MISMATCHED_VALUES;
// check whether it the app flags say B_ARGV_ONLY }
// check whether the app flags say B_ARGV_ONLY
if (error == B_OK && (info.flags & B_ARGV_ONLY)) { if (error == B_OK && (info.flags & B_ARGV_ONLY)) {
error = B_BAD_TYPE; error = B_BAD_TYPE;
// Set the team ID nevertheless -- that's what Be's implementation // Set the team ID nevertheless -- that's what Be's implementation