added default sound events

implemented system_beep() by sending an event to the media addon server


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20728 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-16 19:15:46 +00:00
parent 4ee088419f
commit 31ebfe61e4
7 changed files with 85 additions and 47 deletions
+6 -7
View File
@@ -75,9 +75,14 @@ enum {
MEDIA_SERVER_GET_FORMATS,
MEDIA_SERVER_MAKE_FORMAT_FOR,
MEDIA_SERVER_SYSTEM_BEEP_EVENT
// add_system_beep_event()
MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT,
// media addon server
MEDIA_ADDON_SERVER_PLAY_MEDIA = '_TRU'
};
// Raw port based communication
enum {
ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS = 0x50,
@@ -1014,10 +1019,4 @@ struct controllable_set_parameter_data_reply : public reply_data
{
};
enum {
SYSTEM_BEEP_EVENT_INVOKE = 1,
SYSTEM_BEEP_EVENT_ADD
};
#endif // _DATA_EXCHANGE_H
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2007, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MEDIA_SOUNDS_H
#define _MEDIA_SOUNDS_H
#define MEDIA_NAME_KEY "be:media_name"
#define MEDIA_TYPE_KEY "be:media_type"
#define MEDIA_FLAGS_KEY "be:media_flags"
#define MEDIA_TYPE_SOUNDS "Sounds"
#define MEDIA_SOUNDS_BEEP "Beep"
#define MEDIA_SOUNDS_STARTUP "Startup"
#define MEDIA_SOUNDS_KEY_DOWN "Key Down"
#define MEDIA_SOUNDS_KEY_REPEAT "Key Repeat"
#define MEDIA_SOUNDS_KEY_UP "Key Up"
#define MEDIA_SOUNDS_MOUSE_DOWN "Mouse Down"
#define MEDIA_SOUNDS_MOUSE_UP "Mouse Up"
#define MEDIA_SOUNDS_WINDOW_ACTIVATED "Window Activated"
#define MEDIA_SOUNDS_WINDOW_CLOSE "Window Close"
#define MEDIA_SOUNDS_WINDOW_MINIMIZED "Window Minimized"
#define MEDIA_SOUNDS_WINDOW_OPEN "Window Open"
#define MEDIA_SOUNDS_WINDOW_RESTORED "Window Restored"
#define MEDIA_SOUNDS_WINDOW_ZOOMED "Window Zoomed"
#endif // _MEDIA_SOUNDS_H
+10 -9
View File
@@ -8,17 +8,18 @@
#include <stdio.h>
#include "DataExchange.h"
#include "MediaSounds.h"
status_t
system_beep(const char *eventName)
{
BMessenger messenger("application/x-vnd.Be.media-server");
BMessenger messenger("application/x-vnd.Be.addon-host");
if (!messenger.IsValid())
return B_ERROR;
BMessage msg(MEDIA_SERVER_SYSTEM_BEEP_EVENT), reply;
msg.AddInt32("action", SYSTEM_BEEP_EVENT_INVOKE);
msg.AddString("event", eventName);
BMessage msg(MEDIA_ADDON_SERVER_PLAY_MEDIA), reply;
msg.AddString(MEDIA_NAME_KEY, eventName ? eventName : MEDIA_SOUNDS_BEEP);
msg.AddString(MEDIA_TYPE_KEY, MEDIA_TYPE_SOUNDS);
status_t err = messenger.SendMessage(&msg, &reply);
if ((err != B_OK)
@@ -36,15 +37,15 @@ beep()
status_t
add_system_beep_event(const char *eventName, uint32 flags)
add_system_beep_event(const char *name, uint32 flags)
{
BMessenger messenger("application/x-vnd.Be.media-server");
if (!messenger.IsValid())
return B_ERROR;
BMessage msg(MEDIA_SERVER_SYSTEM_BEEP_EVENT), reply;
msg.AddInt32("action", SYSTEM_BEEP_EVENT_ADD);
msg.AddString("event", eventName);
msg.AddInt32("flags", flags);
BMessage msg(MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT), reply;
msg.AddString(MEDIA_NAME_KEY, name);
msg.AddString(MEDIA_TYPE_KEY, MEDIA_TYPE_SOUNDS);
msg.AddInt32(MEDIA_FLAGS_KEY, flags);
status_t err = messenger.SendMessage(&msg, &reply);
if ((err != B_OK)
+28 -26
View File
@@ -9,6 +9,7 @@
#include <storage/FindDirectory.h>
#include <storage/Path.h>
#include "MMediaFilesManager.h"
#include "MediaSounds.h"
#include "debug.h"
@@ -18,6 +19,21 @@ MMediaFilesManager::MMediaFilesManager()
fRunner(NULL)
{
CALLED();
entry_ref ref;
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_BEEP, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_STARTUP, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_KEY_DOWN, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_KEY_REPEAT, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_KEY_UP, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_MOUSE_DOWN, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_MOUSE_UP, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_ACTIVATED, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_CLOSE, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_MINIMIZED, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_OPEN, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_RESTORED, ref, false);
SetRefFor(MEDIA_TYPE_SOUNDS, MEDIA_SOUNDS_WINDOW_ZOOMED, ref, false);
LoadState();
#if DEBUG >=3
Dump();
@@ -366,35 +382,21 @@ MMediaFilesManager::TimerMessage()
void
MMediaFilesManager::HandleSystemBeepEvent(BMessage *msg)
MMediaFilesManager::HandleAddSystemBeepEvent(BMessage *msg)
{
int32 action, flags;
BString event;
status_t err = B_OK;
if ((msg->FindString("event", &event) != B_OK)
|| (msg->FindInt32("action", &action) != B_OK)) {
err = B_BAD_VALUE;
}
if (action == SYSTEM_BEEP_EVENT_ADD) {
if (msg->FindInt32("flags", &flags) != B_OK)
err = B_BAD_VALUE;
}
if (err != B_OK) {
msg->SendReply(err);
uint32 flags;
const char *name, *type;
if ((msg->FindString(MEDIA_NAME_KEY, &name) != B_OK)
|| (msg->FindString(MEDIA_TYPE_KEY, &type) != B_OK)
|| (msg->FindInt32(MEDIA_FLAGS_KEY, (int32 *) &flags) != B_OK)) {
msg->SendReply(B_BAD_VALUE);
return;
}
switch (action) {
case SYSTEM_BEEP_EVENT_ADD: {
entry_ref ref;
SetRefFor(BMediaFiles::B_SOUNDS, event.String(), ref);
break;
}
case SYSTEM_BEEP_EVENT_INVOKE: {
// TODO play the sound
}
}
entry_ref *pRef = NULL;
if (GetRefFor(type, name, &pRef) == B_ENTRY_NOT_FOUND) {
entry_ref ref;
SetRefFor(type, name, ref);
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ class MMediaFilesManager
void TimerMessage();
void HandleSystemBeepEvent(BMessage *msg);
void HandleAddSystemBeepEvent(BMessage *msg);
private:
static int32 ReadPascalString(BFile &file, char **str);
+2 -2
View File
@@ -803,8 +803,8 @@ ServerApp::MessageReceived(BMessage *msg)
gFormatManager->MakeFormatFor(*msg);
break;
case MEDIA_SERVER_SYSTEM_BEEP_EVENT:
gMMediaFilesManager->HandleSystemBeepEvent(msg);
case MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT:
gMMediaFilesManager->HandleAddSystemBeepEvent(msg);
break;
default:
inherited::MessageReceived(msg);
+9 -2
View File
@@ -43,6 +43,7 @@
#include "Notifications.h"
#include "MediaMisc.h"
#include "MediaRosterEx.h"
#include "MediaSounds.h"
#include "SystemTimeSource.h"
#include "MediaFilePlayer.h"
@@ -627,9 +628,15 @@ MediaAddonServer::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
case '_TRU':
case MEDIA_ADDON_SERVER_PLAY_MEDIA:
{
PlayMediaFile(msg->FindString("be:media_type"), msg->FindString("be:media_name"));
const char *name, *type;
if ((msg->FindString(MEDIA_NAME_KEY, &name) != B_OK)
|| (msg->FindString(MEDIA_TYPE_KEY, &type) != B_OK)) {
msg->SendReply(B_ERROR);
}
PlayMediaFile(type, name);
msg->SendReply(B_OK); // XXX don't know which reply is expected
return;
}