Added support for roster watching.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1578 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2002-10-18 14:05:25 +00:00
parent edb7407e80
commit 7a0335c8a3
4 changed files with 129 additions and 0 deletions
+3
View File
@@ -8,6 +8,7 @@ Server obos_registrar :
AppInfoList.cpp AppInfoList.cpp
ClipboardHandler.cpp ClipboardHandler.cpp
Event.cpp Event.cpp
EventMaskWatcher.cpp
EventQueue.cpp EventQueue.cpp
MessageEvent.cpp MessageEvent.cpp
MessageRunnerManager.cpp MessageRunnerManager.cpp
@@ -15,6 +16,8 @@ Server obos_registrar :
Registrar.cpp Registrar.cpp
RosterAppInfo.cpp RosterAppInfo.cpp
TRoster.cpp TRoster.cpp
Watcher.cpp
WatchingService.cpp
; ;
LinkSharedOSLibs obos_registrar : LinkSharedOSLibs obos_registrar :
<boot!home!config!lib>libopenbeos.so <boot!home!config!lib>libopenbeos.so
+6
View File
@@ -131,6 +131,12 @@ Registrar::MessageReceived(BMessage *message)
case B_REG_BROADCAST: case B_REG_BROADCAST:
fRoster->HandleBroadcast(message); fRoster->HandleBroadcast(message);
break; break;
case B_REG_START_WATCHING:
fRoster->HandleStartWatching(message);
break;
case B_REG_STOP_WATCHING:
fRoster->HandleStopWatching(message);
break;
// message runner requests // message runner requests
case B_REG_REGISTER_MESSAGE_RUNNER: case B_REG_REGISTER_MESSAGE_RUNNER:
fMessageRunnerManager->HandleRegisterRunner(message); fMessageRunnerManager->HandleRegisterRunner(message);
+113
View File
@@ -34,6 +34,7 @@
#include "RegistrarDefs.h" #include "RegistrarDefs.h"
#include "RosterAppInfo.h" #include "RosterAppInfo.h"
#include "TRoster.h" #include "TRoster.h"
#include "EventMaskWatcher.h"
/*! /*!
\class TRoster \class TRoster
@@ -74,6 +75,7 @@ TRoster::TRoster()
fEarlyPreRegisteredApps(), fEarlyPreRegisteredApps(),
fIAPRRequests(), fIAPRRequests(),
fActiveApp(NULL), fActiveApp(NULL),
fWatchingService(),
fLastToken(0) fLastToken(0)
{ {
} }
@@ -685,6 +687,79 @@ TRoster::HandleBroadcast(BMessage *request)
FUNCTION_END(); FUNCTION_END();
} }
// HandleStartWatching
/*! \brief Handles a StartWatching() request.
\param request The request message
*/
void
TRoster::HandleStartWatching(BMessage *request)
{
FUNCTION_START();
status_t error = B_OK;
// get the parameters
BMessenger target;
uint32 events;
if (error == B_OK && request->FindMessenger("target", &target) != B_OK)
error = B_BAD_VALUE;
if (request->FindInt32("events", (int32*)&events) != B_OK)
error = B_BAD_VALUE;
// add the new watcher
if (error == B_OK) {
Watcher *watcher = new(nothrow) EventMaskWatcher(target, events);
if (watcher) {
if (!fWatchingService.AddWatcher(watcher)) {
error = B_NO_MEMORY;
delete watcher;
}
} else
error = B_NO_MEMORY;
}
// 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);
}
FUNCTION_END();
}
// HandleStopWatching
/*! \brief Handles a StopWatching() request.
\param request The request message
*/
void
TRoster::HandleStopWatching(BMessage *request)
{
FUNCTION_START();
status_t error = B_OK;
// get the parameters
BMessenger target;
if (error == B_OK && request->FindMessenger("target", &target) != B_OK)
error = B_BAD_VALUE;
// remove the watcher
if (error == B_OK) {
if (!fWatchingService.RemoveWatcher(target))
error = B_BAD_VALUE;
}
// 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);
}
FUNCTION_END();
}
// Init // Init
/*! \brief Initializes the roster. /*! \brief Initializes the roster.
@@ -827,6 +902,11 @@ TRoster::CheckSanity()
void void
TRoster::_AppAdded(RosterAppInfo *info) TRoster::_AppAdded(RosterAppInfo *info)
{ {
// notify the watchers
BMessage message(B_SOME_APP_LAUNCHED);
_AddMessageWatchingInfo(&message, info);
EventMaskWatcherFilter filter(B_REQUEST_LAUNCHED);
fWatchingService.NotifyWatchers(&message, &filter);
} }
// _AppRemoved // _AppRemoved
@@ -840,6 +920,11 @@ TRoster::_AppRemoved(RosterAppInfo *info)
// deactivate the app, if it was the active one // deactivate the app, if it was the active one
if (info == fActiveApp) if (info == fActiveApp)
ActivateApp(NULL); ActivateApp(NULL);
// notify the watchers
BMessage message(B_SOME_APP_QUIT);
_AddMessageWatchingInfo(&message, info);
EventMaskWatcherFilter filter(B_REQUEST_QUIT);
fWatchingService.NotifyWatchers(&message, &filter);
} }
} }
@@ -858,6 +943,11 @@ TRoster::_AppActivated(RosterAppInfo *info)
BMessage message(B_APP_ACTIVATED); BMessage message(B_APP_ACTIVATED);
message.AddBool("active", true); message.AddBool("active", true);
messenger.SendMessage(&message); messenger.SendMessage(&message);
// notify the watchers
BMessage watcherMessage(B_SOME_APP_ACTIVATED);
_AddMessageWatchingInfo(&watcherMessage, info);
EventMaskWatcherFilter filter(B_REQUEST_ACTIVATED);
fWatchingService.NotifyWatchers(&watcherMessage, &filter);
} }
} }
} }
@@ -908,6 +998,29 @@ TRoster::_AddMessageAppInfo(BMessage *message, const app_info *info)
sizeof(flat_app_info)); sizeof(flat_app_info));
} }
// _AddMessageWatchingInfo
/*! \brief Adds application monitoring related fields to a message.
\param message The message.
\param info The app_info of the concerned application.
\return \c B_OK if everything went fine, an error code otherwise.
*/
status_t
TRoster::_AddMessageWatchingInfo(BMessage *message, const app_info *info)
{
status_t error = B_OK;
if (error == B_OK)
error = message->AddString("be:signature", info->signature);
if (error == B_OK)
error = message->AddInt32("be:team", info->team);
if (error == B_OK)
error = message->AddInt32("be:thread", info->thread);
if (error == B_OK)
error = message->AddInt32("be:flags", (int32)info->flags);
if (error == B_OK)
error = message->AddRef("be:ref", &info->ref);
return error;
}
// _NextToken // _NextToken
/*! \brief Returns the next available token. /*! \brief Returns the next available token.
\return The token. \return The token.
+7
View File
@@ -33,8 +33,10 @@
#include <SupportDefs.h> #include <SupportDefs.h>
#include "AppInfoList.h" #include "AppInfoList.h"
#include "WatchingService.h"
class BMessage; class BMessage;
class WatchingService;
struct IAPRRequest { struct IAPRRequest {
entry_ref ref; entry_ref ref;
@@ -63,6 +65,8 @@ public:
void HandleGetAppList(BMessage *request); void HandleGetAppList(BMessage *request);
void HandleActivateApp(BMessage *request); void HandleActivateApp(BMessage *request);
void HandleBroadcast(BMessage *request); void HandleBroadcast(BMessage *request);
void HandleStartWatching(BMessage *request);
void HandleStopWatching(BMessage *request);
status_t Init(); status_t Init();
@@ -82,6 +86,8 @@ private:
// helper functions // helper functions
static status_t _AddMessageAppInfo(BMessage *message, static status_t _AddMessageAppInfo(BMessage *message,
const app_info *info); const app_info *info);
static status_t _AddMessageWatchingInfo(BMessage *message,
const app_info *info);
uint32 _NextToken(); uint32 _NextToken();
void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info); void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info);
@@ -90,6 +96,7 @@ private:
AppInfoList fEarlyPreRegisteredApps; AppInfoList fEarlyPreRegisteredApps;
IAPRRequestMap fIAPRRequests; IAPRRequestMap fIAPRRequests;
RosterAppInfo *fActiveApp; RosterAppInfo *fActiveApp;
WatchingService fWatchingService;
uint32 fLastToken; uint32 fLastToken;
}; };