2007-07-31 20:23:40 +04:00
|
|
|
/*
|
2009-03-15 13:21:56 +03:00
|
|
|
* Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
|
2007-07-31 20:23:40 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
* Ingo Weinhold, bonefish@cs.tu-berlin.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <Notifications.h>
|
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
#include <team.h>
|
|
|
|
|
2007-07-31 20:23:40 +04:00
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
static const char* kEventMaskString = "event mask";
|
|
|
|
|
|
|
|
|
2007-07-31 20:23:40 +04:00
|
|
|
NotificationManager NotificationManager::sManager;
|
|
|
|
|
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
// #pragma mark - NotificationListener
|
2007-07-31 20:23:40 +04:00
|
|
|
|
|
|
|
|
|
|
|
NotificationListener::~NotificationListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationListener::EventOccured(NotificationService& service,
|
|
|
|
const KMessage* event)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-08-01 18:48:44 +04:00
|
|
|
NotificationListener::AllListenersNotified(NotificationService& service)
|
2007-07-31 20:23:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-01 18:48:44 +04:00
|
|
|
bool
|
|
|
|
NotificationListener::operator==(const NotificationListener& other) const
|
|
|
|
{
|
|
|
|
return &other == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-31 20:23:40 +04:00
|
|
|
// #pragma mark - UserMessagingMessageSender
|
|
|
|
|
|
|
|
|
|
|
|
UserMessagingMessageSender::UserMessagingMessageSender()
|
|
|
|
:
|
|
|
|
fMessage(NULL),
|
|
|
|
fTargetCount(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserMessagingMessageSender::SendMessage(const KMessage* message, port_id port,
|
|
|
|
int32 token)
|
|
|
|
{
|
2009-02-01 23:48:02 +03:00
|
|
|
if ((message != fMessage && fMessage != NULL)
|
2007-07-31 20:23:40 +04:00
|
|
|
|| fTargetCount == MAX_MESSAGING_TARGET_COUNT) {
|
|
|
|
FlushMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
fMessage = message;
|
|
|
|
fTargets[fTargetCount].port = port;
|
|
|
|
fTargets[fTargetCount].token = token;
|
|
|
|
fTargetCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserMessagingMessageSender::FlushMessage()
|
|
|
|
{
|
|
|
|
if (fMessage != NULL && fTargetCount > 0) {
|
|
|
|
send_message(fMessage->Buffer(), fMessage->ContentSize(),
|
|
|
|
fTargets, fTargetCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
fMessage = NULL;
|
|
|
|
fTargetCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - UserMessagingListener
|
|
|
|
|
|
|
|
|
|
|
|
UserMessagingListener::UserMessagingListener(UserMessagingMessageSender& sender,
|
|
|
|
port_id port, int32 token)
|
|
|
|
:
|
|
|
|
fSender(sender),
|
|
|
|
fPort(port),
|
|
|
|
fToken(token)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserMessagingListener::~UserMessagingListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UserMessagingListener::EventOccured(NotificationService& service,
|
|
|
|
const KMessage* event)
|
|
|
|
{
|
|
|
|
fSender.SendMessage(event, fPort, fToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-08-01 18:48:44 +04:00
|
|
|
UserMessagingListener::AllListenersNotified(NotificationService& service)
|
2007-07-31 20:23:40 +04:00
|
|
|
{
|
|
|
|
fSender.FlushMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-01 18:48:44 +04:00
|
|
|
// #pragma mark - NotificationService
|
2007-07-31 20:23:40 +04:00
|
|
|
|
|
|
|
|
|
|
|
NotificationService::~NotificationService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
// #pragma mark - default_listener
|
|
|
|
|
|
|
|
|
|
|
|
default_listener::~default_listener()
|
|
|
|
{
|
|
|
|
// Only delete the listener if it's one of ours
|
|
|
|
if (dynamic_cast<UserMessagingListener*>(listener) != NULL) {
|
|
|
|
delete listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - NotificationService
|
|
|
|
|
|
|
|
|
|
|
|
DefaultNotificationService::DefaultNotificationService(const char* name)
|
|
|
|
:
|
|
|
|
fName(name)
|
|
|
|
{
|
|
|
|
recursive_lock_init(&fLock, name);
|
|
|
|
NotificationManager::Manager().RegisterService(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DefaultNotificationService::~DefaultNotificationService()
|
|
|
|
{
|
|
|
|
NotificationManager::Manager().UnregisterService(*this);
|
|
|
|
recursive_lock_destroy(&fLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Notifies all registered listeners.
|
|
|
|
\param event The message defining the event
|
2009-04-12 01:45:25 +04:00
|
|
|
\param eventMask Only listeners with an event mask sharing at least one
|
|
|
|
common bit with this mask will receive the event.
|
2009-03-15 13:21:56 +03:00
|
|
|
*/
|
|
|
|
void
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultNotificationService::Notify(const KMessage& event, uint32 eventMask)
|
2009-03-15 13:21:56 +03:00
|
|
|
{
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
// Note: The following iterations support that the listener removes itself
|
|
|
|
// in the hook method. That's a property of the DoublyLinkedList iterator.
|
|
|
|
|
|
|
|
// notify all listeners about the event
|
2009-03-15 13:21:56 +03:00
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
2009-04-12 01:45:25 +04:00
|
|
|
if ((eventMask & listener->eventMask) != 0)
|
2009-03-15 13:21:56 +03:00
|
|
|
listener->listener->EventOccured(*this, &event);
|
|
|
|
}
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
// notify all listeners that all listeners have been notified
|
2009-03-15 13:21:56 +03:00
|
|
|
iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
2009-04-12 01:45:25 +04:00
|
|
|
if ((eventMask & listener->eventMask) != 0)
|
2009-03-15 13:21:56 +03:00
|
|
|
listener->listener->AllListenersNotified(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultNotificationService::AddListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
if (eventSpecifier == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
uint32 eventMask;
|
|
|
|
status_t status = ToEventMask(*eventSpecifier, eventMask);
|
2009-03-15 13:21:56 +03:00
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
default_listener* listener = new(std::nothrow) default_listener;
|
|
|
|
if (listener == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
listener->eventMask = eventMask;
|
2009-03-15 13:21:56 +03:00
|
|
|
listener->team = -1;
|
|
|
|
listener->listener = ¬ificationListener;
|
|
|
|
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
if (fListeners.IsEmpty())
|
2009-04-12 01:45:25 +04:00
|
|
|
FirstAdded();
|
2009-03-15 13:21:56 +03:00
|
|
|
fListeners.Add(listener);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultNotificationService::UpdateListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
return B_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultNotificationService::RemoveListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (listener->listener == ¬ificationListener) {
|
|
|
|
iterator.Remove();
|
|
|
|
delete listener;
|
2009-04-12 01:45:25 +04:00
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
if (fListeners.IsEmpty())
|
2009-04-12 01:45:25 +04:00
|
|
|
LastRemoved();
|
2009-03-15 13:21:56 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultNotificationService::ToEventMask(const KMessage& eventSpecifier,
|
|
|
|
uint32& eventMask)
|
2009-03-15 13:21:56 +03:00
|
|
|
{
|
2009-04-12 01:45:25 +04:00
|
|
|
return eventSpecifier.FindInt32("event mask", (int32*)&eventMask);
|
2009-03-15 13:21:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultNotificationService::FirstAdded()
|
2009-03-15 13:21:56 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultNotificationService::LastRemoved()
|
2009-03-15 13:21:56 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - DefaultUserNotificationService
|
|
|
|
|
|
|
|
|
|
|
|
DefaultUserNotificationService::DefaultUserNotificationService(const char* name)
|
|
|
|
: DefaultNotificationService(name)
|
|
|
|
{
|
|
|
|
NotificationManager::Manager().AddListener("teams", TEAM_REMOVED, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DefaultUserNotificationService::~DefaultUserNotificationService()
|
|
|
|
{
|
|
|
|
NotificationManager::Manager().RemoveListener("teams", NULL, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultUserNotificationService::AddListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& listener)
|
|
|
|
{
|
|
|
|
if (eventSpecifier == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
uint32 eventMask = eventSpecifier->GetInt32(kEventMaskString, 0);
|
2009-03-15 13:21:56 +03:00
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
return _AddListener(eventMask, listener);
|
2009-03-15 13:21:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultUserNotificationService::UpdateListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
if (eventSpecifier == NULL)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
uint32 eventMask = eventSpecifier->GetInt32(kEventMaskString, 0);
|
|
|
|
bool addEvents = eventSpecifier->GetBool("add events", false);
|
2009-03-15 13:21:56 +03:00
|
|
|
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (*listener->listener == notificationListener) {
|
2009-04-12 01:45:25 +04:00
|
|
|
if (addEvents)
|
|
|
|
listener->eventMask |= eventMask;
|
2009-03-15 13:21:56 +03:00
|
|
|
else
|
2009-04-12 01:45:25 +04:00
|
|
|
listener->eventMask = eventMask;
|
2009-03-15 13:21:56 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultUserNotificationService::RemoveListener(const KMessage* eventSpecifier,
|
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (listener->listener == ¬ificationListener) {
|
|
|
|
iterator.Remove();
|
|
|
|
delete listener;
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
DefaultUserNotificationService::RemoveUserListeners(port_id port, uint32 token)
|
|
|
|
{
|
|
|
|
UserMessagingListener userListener(fSender, port, token);
|
|
|
|
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (*listener->listener == userListener) {
|
|
|
|
iterator.Remove();
|
|
|
|
delete listener;
|
2009-04-12 01:45:25 +04:00
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
if (fListeners.IsEmpty())
|
2009-04-12 01:45:25 +04:00
|
|
|
LastRemoved();
|
2009-03-15 13:21:56 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultUserNotificationService::UpdateUserListener(uint32 eventMask,
|
|
|
|
port_id port, uint32 token)
|
2009-03-15 13:21:56 +03:00
|
|
|
{
|
|
|
|
UserMessagingListener userListener(fSender, port, token);
|
|
|
|
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
|
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (*listener->listener == userListener) {
|
2009-04-12 01:45:25 +04:00
|
|
|
listener->eventMask |= eventMask;
|
2009-03-15 13:21:56 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UserMessagingListener* copiedListener
|
|
|
|
= new(std::nothrow) UserMessagingListener(userListener);
|
|
|
|
if (copiedListener == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
status_t status = _AddListener(eventMask, *copiedListener);
|
2009-03-15 13:21:56 +03:00
|
|
|
if (status != B_OK)
|
|
|
|
delete copiedListener;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DefaultUserNotificationService::EventOccured(NotificationService& service,
|
|
|
|
const KMessage* event)
|
|
|
|
{
|
2009-04-12 01:45:25 +04:00
|
|
|
int32 eventCode = event->GetInt32("event", -1);
|
2009-03-15 13:21:56 +03:00
|
|
|
team_id team = event->GetInt32("team", -1);
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
if (eventCode == TEAM_REMOVED && team >= B_OK) {
|
2009-03-15 13:21:56 +03:00
|
|
|
// check if we have any listeners from that team, and remove them
|
|
|
|
RecursiveLocker _(fLock);
|
2009-04-12 01:45:25 +04:00
|
|
|
|
2009-03-15 13:21:56 +03:00
|
|
|
DefaultListenerList::Iterator iterator = fListeners.GetIterator();
|
|
|
|
while (default_listener* listener = iterator.Next()) {
|
|
|
|
if (listener->team == team) {
|
|
|
|
iterator.Remove();
|
|
|
|
delete listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DefaultUserNotificationService::AllListenersNotified(
|
|
|
|
NotificationService& service)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2009-04-12 01:45:25 +04:00
|
|
|
DefaultUserNotificationService::_AddListener(uint32 eventMask,
|
2009-03-15 13:21:56 +03:00
|
|
|
NotificationListener& notificationListener)
|
|
|
|
{
|
|
|
|
default_listener* listener = new(std::nothrow) default_listener;
|
|
|
|
if (listener == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
2009-04-12 01:45:25 +04:00
|
|
|
listener->eventMask = eventMask;
|
2009-03-15 13:21:56 +03:00
|
|
|
listener->team = team_get_current_team_id();
|
|
|
|
listener->listener = ¬ificationListener;
|
|
|
|
|
|
|
|
RecursiveLocker _(fLock);
|
|
|
|
if (fListeners.IsEmpty())
|
2009-04-12 01:45:25 +04:00
|
|
|
FirstAdded();
|
2009-03-15 13:21:56 +03:00
|
|
|
fListeners.Add(listener);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-31 20:23:40 +04:00
|
|
|
// #pragma mark - NotificationManager
|
|
|
|
|
|
|
|
|
|
|
|
/*static*/ NotificationManager&
|
|
|
|
NotificationManager::Manager()
|
|
|
|
{
|
|
|
|
return sManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*static*/ status_t
|
|
|
|
NotificationManager::CreateManager()
|
|
|
|
{
|
|
|
|
new(&sManager) NotificationManager;
|
|
|
|
return sManager._Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NotificationManager::NotificationManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NotificationManager::~NotificationManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
NotificationManager::_Init()
|
|
|
|
{
|
2008-05-02 02:07:36 +04:00
|
|
|
mutex_init(&fLock, "notification manager");
|
2007-07-31 20:23:40 +04:00
|
|
|
|
2008-06-25 02:23:57 +04:00
|
|
|
return fServiceHash.Init();
|
2007-07-31 20:23:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NotificationService*
|
|
|
|
NotificationManager::_ServiceFor(const char* name)
|
|
|
|
{
|
|
|
|
return fServiceHash.Lookup(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
NotificationManager::RegisterService(NotificationService& service)
|
|
|
|
{
|
|
|
|
MutexLocker _(fLock);
|
|
|
|
|
|
|
|
if (_ServiceFor(service.Name()))
|
|
|
|
return B_NAME_IN_USE;
|
|
|
|
|
|
|
|
status_t status = fServiceHash.Insert(&service);
|
|
|
|
if (status == B_OK)
|
|
|
|
service.AddReference();
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationManager::UnregisterService(NotificationService& service)
|
|
|
|
{
|
|
|
|
MutexLocker _(fLock);
|
|
|
|
fServiceHash.Remove(&service);
|
|
|
|
service.RemoveReference();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
NotificationManager::AddListener(const char* serviceName,
|
|
|
|
uint32 eventMask, NotificationListener& listener)
|
|
|
|
{
|
|
|
|
char buffer[96];
|
|
|
|
KMessage specifier;
|
|
|
|
specifier.SetTo(buffer, sizeof(buffer), 0);
|
2009-04-12 01:45:25 +04:00
|
|
|
specifier.AddInt32(kEventMaskString, eventMask);
|
2007-07-31 20:23:40 +04:00
|
|
|
|
|
|
|
return AddListener(serviceName, &specifier, listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
NotificationManager::AddListener(const char* serviceName,
|
|
|
|
const KMessage* eventSpecifier, NotificationListener& listener)
|
|
|
|
{
|
|
|
|
MutexLocker locker(fLock);
|
|
|
|
NotificationService* service = _ServiceFor(serviceName);
|
|
|
|
if (service == NULL)
|
|
|
|
return B_NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
Reference<NotificationService> reference(service);
|
|
|
|
locker.Unlock();
|
|
|
|
|
|
|
|
return service->AddListener(eventSpecifier, listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2007-08-01 18:48:44 +04:00
|
|
|
NotificationManager::UpdateListener(const char* serviceName,
|
|
|
|
uint32 eventMask, NotificationListener& listener)
|
2007-07-31 20:23:40 +04:00
|
|
|
{
|
|
|
|
char buffer[96];
|
|
|
|
KMessage specifier;
|
|
|
|
specifier.SetTo(buffer, sizeof(buffer), 0);
|
2009-04-12 01:45:25 +04:00
|
|
|
specifier.AddInt32(kEventMaskString, eventMask);
|
2007-07-31 20:23:40 +04:00
|
|
|
|
2007-08-01 18:48:44 +04:00
|
|
|
return UpdateListener(serviceName, &specifier, listener);
|
2007-07-31 20:23:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2007-08-01 18:48:44 +04:00
|
|
|
NotificationManager::UpdateListener(const char* serviceName,
|
2007-07-31 20:23:40 +04:00
|
|
|
const KMessage* eventSpecifier, NotificationListener& listener)
|
|
|
|
{
|
|
|
|
MutexLocker locker(fLock);
|
|
|
|
NotificationService* service = _ServiceFor(serviceName);
|
|
|
|
if (service == NULL)
|
|
|
|
return B_NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
Reference<NotificationService> reference(service);
|
|
|
|
locker.Unlock();
|
|
|
|
|
2007-08-01 18:48:44 +04:00
|
|
|
return service->UpdateListener(eventSpecifier, listener);
|
2007-07-31 20:23:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2007-08-01 18:48:44 +04:00
|
|
|
NotificationManager::RemoveListener(const char* serviceName,
|
|
|
|
const KMessage* eventSpecifier, NotificationListener& listener)
|
2007-07-31 20:23:40 +04:00
|
|
|
{
|
|
|
|
MutexLocker locker(fLock);
|
|
|
|
NotificationService* service = _ServiceFor(serviceName);
|
|
|
|
if (service == NULL)
|
|
|
|
return B_NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
Reference<NotificationService> reference(service);
|
|
|
|
locker.Unlock();
|
|
|
|
|
2007-08-01 18:48:44 +04:00
|
|
|
return service->RemoveListener(eventSpecifier, listener);
|
2007-07-31 20:23:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
notifications_init(void)
|
|
|
|
{
|
2007-07-31 21:17:51 +04:00
|
|
|
status_t status = NotificationManager::CreateManager();
|
2007-07-31 20:23:40 +04:00
|
|
|
if (status < B_OK) {
|
|
|
|
panic("Creating the notification manager failed: %s\n",
|
|
|
|
strerror(status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|