xref: /haiku/src/kits/support/Beep.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Copyright 2007, Jérôme Duval. All rights reserved.
4 ** Distributed under the terms of the Haiku License.
5 */
6 
7 
8 #include <Beep.h>
9 #include <stdio.h>
10 
11 #include "DataExchange.h"
12 #include "MediaSounds.h"
13 
14 
15 status_t
16 system_beep(const char *eventName)
17 {
18 	BMessenger messenger("application/x-vnd.Be.addon-host");
19 	if (!messenger.IsValid())
20 		return B_ERROR;
21 	BMessage msg(MEDIA_ADDON_SERVER_PLAY_MEDIA), reply;
22 	msg.AddString(MEDIA_NAME_KEY, eventName ? eventName : MEDIA_SOUNDS_BEEP);
23 	msg.AddString(MEDIA_TYPE_KEY, MEDIA_TYPE_SOUNDS);
24 
25 	status_t err = messenger.SendMessage(&msg, &reply);
26 	if ((err != B_OK)
27 		|| (reply.FindInt32("error", &err) != B_OK))
28 		err = B_BAD_REPLY;
29 	return err;
30 }
31 
32 
33 status_t
34 beep()
35 {
36 	return system_beep(NULL);
37 }
38 
39 
40 status_t
41 add_system_beep_event(const char *name, uint32 flags)
42 {
43 	BMessenger messenger("application/x-vnd.Be.media-server");
44 	if (!messenger.IsValid())
45 		return B_ERROR;
46 	BMessage msg(MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT), reply;
47 	msg.AddString(MEDIA_NAME_KEY, name);
48 	msg.AddString(MEDIA_TYPE_KEY, MEDIA_TYPE_SOUNDS);
49 	msg.AddInt32(MEDIA_FLAGS_KEY, flags);
50 
51 	status_t err = messenger.SendMessage(&msg, &reply);
52 	if ((err != B_OK)
53 		|| (reply.FindInt32("error", &err) != B_OK))
54 		err = B_BAD_REPLY;
55 	return err;
56 }
57 
58