* Implemented BRoster::ActivateApp().

* Added the respective case statement in AppServer::DispatchMessage().
  The code that actually activates the app is still missing.
* Removed the remnants of the old way of notifying the registrar about
  what app got activated (the activated client window did that).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13820 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2005-07-24 21:10:33 +00:00
parent f3b3bb4ebd
commit 18b5424c5f
6 changed files with 96 additions and 44 deletions

View File

@ -30,6 +30,7 @@ enum {
AS_CREATE_APP,
AS_DELETE_APP,
AS_QUIT_APP,
AS_ACTIVATE_APP,
AS_SET_SERVER_PORT,

View File

@ -305,6 +305,7 @@ static const char *kASCodeNames[] = {
"AS_CREATE_APP",
"AS_DELETE_APP",
"AS_QUIT_APP",
"AS_ACTIVATE_APP",
"AS_SET_SERVER_PORT",
"AS_CREATE_WINDOW",
"AS_DELETE_WINDOW",

View File

@ -47,10 +47,12 @@
#include <NodeInfo.h>
#include <OS.h>
#include <Path.h>
#include <PortLink.h>
#include <Query.h>
#include <RegistrarDefs.h>
#include <Roster.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h>
#include <Volume.h>
using namespace std;
@ -756,7 +758,53 @@ BRoster::StopWatching(BMessenger target) const
status_t
BRoster::ActivateApp(team_id team) const
{
return B_ERROR; // not implemented
// get the app server port
port_id port = find_port(SERVER_PORT_NAME);
if (port < B_OK)
return port;
// create a reply port
struct ReplyPort {
ReplyPort()
: port(create_port(1, "activate app reply"))
{
}
~ReplyPort()
{
if (port >= 0)
delete_port(port);
}
port_id port;
} replyPort;
if (replyPort.port < 0)
return replyPort.port;
BPrivate::PortLink link(port, replyPort.port);
// prepare the message
status_t error = link.StartMessage(AS_ACTIVATE_APP);
if (error != B_OK)
return error;
error = link.Attach(replyPort.port);
if (error != B_OK)
return error;
error = link.Attach(team);
if (error != B_OK)
return error;
// send it
int32 code;
error = link.FlushWithReply(code);
if (error != B_OK)
return error;
return code;
}
// Launch
@ -1790,36 +1838,6 @@ DBG(OUT("BRoster::xLaunchAppPrivate() done: %s (%lx)\n", strerror(error), error)
return error;
}
// UpdateActiveApp
/*! \brief Tells the registrar that a certain team is active now.
It doesn't matter, if the application is already active. In that case,
the registrar does nothing. Otherwise, the previously active application
is notified, that it is no longer active now, the now active application
is notified, that it is active now, and all watchers are notified, too.
\param team The app's team ID.
\return \c true, if everything went fine, \c false, if an error occured
(the team ID is unknown or an communication error occured).
*/
bool
BRoster::UpdateActiveApp(team_id team) const
{
status_t error = (team >= 0 ? (status_t)B_OK : (status_t)B_BAD_TEAM_ID);
// compose the request message
BMessage request(B_REG_ACTIVATE_APP);
if (error == B_OK)
error = request.AddInt32("team", team);
// send the request
BMessage reply;
if (error == B_OK)
error = fMess.SendMessage(&request, &reply);
// evaluate the reply
if (error == B_OK && reply.what != B_REG_SUCCESS)
reply.FindInt32("error", &error);
return (error == B_OK);
}
// SetAppFlags
void
BRoster::SetAppFlags(team_id team, uint32 flags) const

View File

@ -2400,11 +2400,6 @@ BWindow::setFocus(BView *focusView, bool notifyInputServer)
void
BWindow::handleActivation(bool active)
{
if (active) {
// TODO: talk to Ingo to make BWindow a friend for BRoster
// be_roster->UpdateActiveApp( be_app->Team() );
}
WindowActivated(active);
// recursively call hook function 'WindowActivated(bool)'

View File

@ -607,6 +607,38 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
break;
}
case AS_ACTIVATE_APP:
{
// Someone is requesting to activation of a certain app.
// Attached data:
// 1) port_id reply port
// 2) team_id team
status_t error = B_OK;
// get the parameters
port_id replyPort;
team_id team;
if (msg.Read(&replyPort) < B_OK
|| msg.Read(&team) < B_OK) {
error = B_ERROR;
}
// activate one of the app's windows.
if (error == B_OK) {
// TODO: ...
error = B_BAD_TEAM_ID;
}
// send the reply
BPrivate::PortLink replyLink(replyPort);
replyLink.StartMessage(error);
replyLink.Flush();
break;
}
default:
STRACE(("Server::MainLoop received unexpected code %ld (offset %ld)\n",
code, code - SERVER_TRUE));

View File

@ -703,10 +703,12 @@ TRoster::HandleActivateApp(BMessage *request)
BAutolock _(fLock);
status_t error = B_OK;
// get the parameters
team_id team;
if (request->FindInt32("team", &team) != B_OK)
error = B_BAD_VALUE;
// activate the app
if (error == B_OK) {
if (RosterAppInfo *info = fRegisteredApps.InfoFor(team))
@ -714,14 +716,17 @@ TRoster::HandleActivateApp(BMessage *request)
else
error = B_BAD_TEAM_ID;
}
// reply to the request
if (error == B_OK) {
BMessage reply(B_REG_SUCCESS);
request->SendReply(&reply);
} else {
BMessage reply(B_REG_ERROR);
reply.AddInt32("error", error);
request->SendReply(&reply);
if (request->IsSourceWaiting()) {
if (error == B_OK) {
BMessage reply(B_REG_SUCCESS);
request->SendReply(&reply);
} else {
BMessage reply(B_REG_ERROR);
reply.AddInt32("error", error);
request->SendReply(&reply);
}
}
FUNCTION_END();
@ -1193,7 +1198,7 @@ TRoster::RemoveApp(RosterAppInfo *info)
// ActivateApp
/*! \brief Activates the application identified by \a info.
The currently activate application is deactivated and the one whose
The currently active application is deactivated and the one whose
info is supplied is activated. \a info may be \c NULL, which only
deactivates the currently active application.