From 18b5424c5f12197d3979cf38dc69149c5e98150c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 24 Jul 2005 21:10:33 +0000 Subject: [PATCH] * 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 --- headers/private/app/ServerProtocol.h | 1 + src/kits/app/LinkSender.cpp | 1 + src/kits/app/Roster.cpp | 80 +++++++++++++++++----------- src/kits/interface/Window.cpp | 5 -- src/servers/app/AppServer.cpp | 32 +++++++++++ src/servers/registrar/TRoster.cpp | 21 +++++--- 6 files changed, 96 insertions(+), 44 deletions(-) diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 0a7c5dab7b..416da3b8c2 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -30,6 +30,7 @@ enum { AS_CREATE_APP, AS_DELETE_APP, AS_QUIT_APP, + AS_ACTIVATE_APP, AS_SET_SERVER_PORT, diff --git a/src/kits/app/LinkSender.cpp b/src/kits/app/LinkSender.cpp index bfb883dd9d..ee5bbb26f0 100644 --- a/src/kits/app/LinkSender.cpp +++ b/src/kits/app/LinkSender.cpp @@ -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", diff --git a/src/kits/app/Roster.cpp b/src/kits/app/Roster.cpp index ec5145caf9..d62a4add9d 100644 --- a/src/kits/app/Roster.cpp +++ b/src/kits/app/Roster.cpp @@ -47,10 +47,12 @@ #include #include #include +#include #include #include #include #include +#include #include 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 diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 725f879125..dd9e5e5457 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -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)' diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index 8f9d3d56c0..da4ffe20c1 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -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)); diff --git a/src/servers/registrar/TRoster.cpp b/src/servers/registrar/TRoster.cpp index 7ab17bdfa0..1da5bf1c28 100644 --- a/src/servers/registrar/TRoster.cpp +++ b/src/servers/registrar/TRoster.cpp @@ -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.