2002-09-30 04:12:11 +04:00
|
|
|
#include <OS.h>
|
2002-10-02 05:08:54 +04:00
|
|
|
#include <Locker.h>
|
2002-09-30 04:12:11 +04:00
|
|
|
#include <Message.h>
|
2002-10-02 05:08:54 +04:00
|
|
|
#include <Messenger.h>
|
|
|
|
#include <MediaNode.h>
|
|
|
|
#include <Debug.h>
|
|
|
|
#include "DataExchange.h"
|
2002-10-02 16:01:37 +04:00
|
|
|
#include "Notifications.h"
|
|
|
|
#include "NotificationManager.h"
|
2002-09-30 04:12:11 +04:00
|
|
|
#include "Queue.h"
|
|
|
|
|
|
|
|
#define NOTIFICATION_THREAD_PRIORITY 19
|
|
|
|
|
2002-10-02 05:08:54 +04:00
|
|
|
struct RegisteredHandler
|
|
|
|
{
|
|
|
|
BMessenger messenger;
|
|
|
|
media_node_id nodeid;
|
|
|
|
int32 mask;
|
|
|
|
team_id team;
|
|
|
|
};
|
|
|
|
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::NotificationManager()
|
2002-09-30 04:12:11 +04:00
|
|
|
: fNotificationQueue(new Queue),
|
2002-10-02 05:08:54 +04:00
|
|
|
fNotificationThreadId(-1),
|
|
|
|
fLocker(new BLocker)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
2002-10-02 16:01:37 +04:00
|
|
|
fNotificationThreadId = spawn_thread(NotificationManager::worker_thread, "notification broadcast", NOTIFICATION_THREAD_PRIORITY, this);
|
2002-09-30 04:12:11 +04:00
|
|
|
resume_thread(fNotificationThreadId);
|
|
|
|
}
|
|
|
|
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::~NotificationManager()
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
|
|
|
// properly terminate the queue and wait until the worker thread has finished
|
|
|
|
status_t dummy;
|
|
|
|
fNotificationQueue->Terminate();
|
|
|
|
wait_for_thread(fNotificationThreadId, &dummy);
|
|
|
|
delete fNotificationQueue;
|
2002-10-02 05:08:54 +04:00
|
|
|
delete fLocker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::EnqueueMessage(BMessage *msg)
|
2002-10-02 05:08:54 +04:00
|
|
|
{
|
|
|
|
// queue a copy of the message to be processed later
|
|
|
|
fNotificationQueue->AddItem(new BMessage(*msg));
|
2002-09-30 04:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::RequestNotifications(BMessage *msg)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
2002-10-02 05:08:54 +04:00
|
|
|
BMessenger messenger;
|
|
|
|
const media_node *node;
|
|
|
|
ssize_t nodesize;
|
|
|
|
team_id team;
|
2002-10-02 16:01:37 +04:00
|
|
|
int32 what;
|
2002-10-02 05:08:54 +04:00
|
|
|
|
|
|
|
msg->FindMessenger(NOTIFICATION_PARAM_MESSENGER, &messenger);
|
|
|
|
msg->FindInt32(NOTIFICATION_PARAM_TEAM, &team);
|
2002-10-02 16:01:37 +04:00
|
|
|
msg->FindInt32(NOTIFICATION_PARAM_WHAT, &what);
|
2002-10-02 05:08:54 +04:00
|
|
|
msg->FindData("node", B_RAW_TYPE, reinterpret_cast<const void **>(&node), &nodesize);
|
|
|
|
ASSERT(nodesize == sizeof(node));
|
|
|
|
|
2002-09-30 04:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::CancelNotifications(BMessage *msg)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
2002-10-02 05:08:54 +04:00
|
|
|
BMessenger messenger;
|
|
|
|
const media_node *node;
|
|
|
|
ssize_t nodesize;
|
|
|
|
team_id team;
|
2002-10-02 16:01:37 +04:00
|
|
|
int32 what;
|
2002-10-02 05:08:54 +04:00
|
|
|
|
|
|
|
msg->FindMessenger(NOTIFICATION_PARAM_MESSENGER, &messenger);
|
|
|
|
msg->FindInt32(NOTIFICATION_PARAM_TEAM, &team);
|
2002-10-02 16:01:37 +04:00
|
|
|
msg->FindInt32(NOTIFICATION_PARAM_WHAT, &what);
|
2002-10-02 05:08:54 +04:00
|
|
|
msg->FindData("node", B_RAW_TYPE, reinterpret_cast<const void **>(&node), &nodesize);
|
|
|
|
ASSERT(nodesize == sizeof(node));
|
|
|
|
|
2002-09-30 04:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::SendNotifications(BMessage *msg)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::CleanupTeam(team_id team)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::BroadcastMessages(BMessage *msg)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::WorkerThread()
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
|
|
|
BMessage *msg;
|
|
|
|
while (NULL != (msg = static_cast<BMessage *>(fNotificationQueue->RemoveItem()))) {
|
2002-10-02 05:08:54 +04:00
|
|
|
switch (msg->what) {
|
|
|
|
case MEDIA_SERVER_REQUEST_NOTIFICATIONS:
|
|
|
|
RequestNotifications(msg);
|
|
|
|
break;
|
|
|
|
case MEDIA_SERVER_CANCEL_NOTIFICATIONS:
|
|
|
|
CancelNotifications(msg);
|
|
|
|
break;
|
|
|
|
case MEDIA_SERVER_SEND_NOTIFICATIONS:
|
|
|
|
SendNotifications(msg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debugger("bad notification message\n");
|
|
|
|
}
|
2002-09-30 04:12:11 +04:00
|
|
|
delete msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
2002-10-02 16:01:37 +04:00
|
|
|
NotificationManager::worker_thread(void *arg)
|
2002-09-30 04:12:11 +04:00
|
|
|
{
|
2002-10-02 16:01:37 +04:00
|
|
|
static_cast<NotificationManager *>(arg)->WorkerThread();
|
2002-09-30 04:12:11 +04:00
|
|
|
return 0;
|
|
|
|
}
|