changed media kit internal messaging and notification support
these files will be replaced soon git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1339 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,13 +1,29 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
#include <Locker.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <MediaNode.h>
|
||||||
|
#include <Debug.h>
|
||||||
|
#include "NotificationManager.h"
|
||||||
#include "NotificationProcessor.h"
|
#include "NotificationProcessor.h"
|
||||||
|
#include "ServerInterface.h"
|
||||||
|
#include "DataExchange.h"
|
||||||
#include "Queue.h"
|
#include "Queue.h"
|
||||||
|
|
||||||
#define NOTIFICATION_THREAD_PRIORITY 19
|
#define NOTIFICATION_THREAD_PRIORITY 19
|
||||||
|
|
||||||
|
struct RegisteredHandler
|
||||||
|
{
|
||||||
|
BMessenger messenger;
|
||||||
|
media_node_id nodeid;
|
||||||
|
int32 mask;
|
||||||
|
team_id team;
|
||||||
|
};
|
||||||
|
|
||||||
NotificationProcessor::NotificationProcessor()
|
NotificationProcessor::NotificationProcessor()
|
||||||
: fNotificationQueue(new Queue),
|
: fNotificationQueue(new Queue),
|
||||||
fNotificationThreadId(-1)
|
fNotificationThreadId(-1),
|
||||||
|
fLocker(new BLocker)
|
||||||
{
|
{
|
||||||
fNotificationThreadId = spawn_thread(NotificationProcessor::worker_thread, "notification broadcast", NOTIFICATION_THREAD_PRIORITY, this);
|
fNotificationThreadId = spawn_thread(NotificationProcessor::worker_thread, "notification broadcast", NOTIFICATION_THREAD_PRIORITY, this);
|
||||||
resume_thread(fNotificationThreadId);
|
resume_thread(fNotificationThreadId);
|
||||||
@@ -20,23 +36,53 @@ NotificationProcessor::~NotificationProcessor()
|
|||||||
fNotificationQueue->Terminate();
|
fNotificationQueue->Terminate();
|
||||||
wait_for_thread(fNotificationThreadId, &dummy);
|
wait_for_thread(fNotificationThreadId, &dummy);
|
||||||
delete fNotificationQueue;
|
delete fNotificationQueue;
|
||||||
|
delete fLocker;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NotificationProcessor::EnqueueMessage(BMessage *msg)
|
||||||
|
{
|
||||||
|
// queue a copy of the message to be processed later
|
||||||
|
fNotificationQueue->AddItem(new BMessage(*msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationProcessor::RequestNotifications(BMessage *msg)
|
NotificationProcessor::RequestNotifications(BMessage *msg)
|
||||||
{
|
{
|
||||||
|
BMessenger messenger;
|
||||||
|
const media_node *node;
|
||||||
|
ssize_t nodesize;
|
||||||
|
team_id team;
|
||||||
|
int32 mask;
|
||||||
|
|
||||||
|
msg->FindMessenger(NOTIFICATION_PARAM_MESSENGER, &messenger);
|
||||||
|
msg->FindInt32(NOTIFICATION_PARAM_TEAM, &team);
|
||||||
|
msg->FindInt32(NOTIFICATION_PARAM_MASK, &mask);
|
||||||
|
msg->FindData("node", B_RAW_TYPE, reinterpret_cast<const void **>(&node), &nodesize);
|
||||||
|
ASSERT(nodesize == sizeof(node));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationProcessor::CancelNotifications(BMessage *msg)
|
NotificationProcessor::CancelNotifications(BMessage *msg)
|
||||||
{
|
{
|
||||||
|
BMessenger messenger;
|
||||||
|
const media_node *node;
|
||||||
|
ssize_t nodesize;
|
||||||
|
team_id team;
|
||||||
|
int32 mask;
|
||||||
|
|
||||||
|
msg->FindMessenger(NOTIFICATION_PARAM_MESSENGER, &messenger);
|
||||||
|
msg->FindInt32(NOTIFICATION_PARAM_TEAM, &team);
|
||||||
|
msg->FindInt32(NOTIFICATION_PARAM_MASK, &mask);
|
||||||
|
msg->FindData("node", B_RAW_TYPE, reinterpret_cast<const void **>(&node), &nodesize);
|
||||||
|
ASSERT(nodesize == sizeof(node));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationProcessor::SendNotifications(BMessage *msg)
|
NotificationProcessor::SendNotifications(BMessage *msg)
|
||||||
{
|
{
|
||||||
// queue a copy of the message to be processed later
|
|
||||||
fNotificationQueue->AddItem(new BMessage(*msg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -54,7 +100,19 @@ NotificationProcessor::WorkerThread()
|
|||||||
{
|
{
|
||||||
BMessage *msg;
|
BMessage *msg;
|
||||||
while (NULL != (msg = static_cast<BMessage *>(fNotificationQueue->RemoveItem()))) {
|
while (NULL != (msg = static_cast<BMessage *>(fNotificationQueue->RemoveItem()))) {
|
||||||
BroadcastMessages(msg);
|
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");
|
||||||
|
}
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,16 @@ class NotificationProcessor
|
|||||||
public:
|
public:
|
||||||
NotificationProcessor();
|
NotificationProcessor();
|
||||||
~NotificationProcessor();
|
~NotificationProcessor();
|
||||||
|
|
||||||
void RequestNotifications(BMessage *msg);
|
|
||||||
void CancelNotifications(BMessage *msg);
|
|
||||||
void SendNotifications(BMessage *msg);
|
|
||||||
|
|
||||||
|
void EnqueueMessage(BMessage *msg);
|
||||||
|
|
||||||
void CleanupTeam(team_id team);
|
void CleanupTeam(team_id team);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void RequestNotifications(BMessage *msg);
|
||||||
|
void CancelNotifications(BMessage *msg);
|
||||||
|
void SendNotifications(BMessage *msg);
|
||||||
|
|
||||||
void BroadcastMessages(BMessage *msg);
|
void BroadcastMessages(BMessage *msg);
|
||||||
void WorkerThread();
|
void WorkerThread();
|
||||||
static int32 worker_thread(void *arg);
|
static int32 worker_thread(void *arg);
|
||||||
@@ -21,4 +23,5 @@ private:
|
|||||||
private:
|
private:
|
||||||
Queue * fNotificationQueue;
|
Queue * fNotificationQueue;
|
||||||
thread_id fNotificationThreadId;
|
thread_id fNotificationThreadId;
|
||||||
|
BLocker * fLocker;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user