A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Miika Pekkarinen
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _EVENTS_H
23#define _EVENTS_H
24
25#include <stdbool.h>
26/**
27 * Synchronouos event system.
28 *
29 * Callbacks are subscribed with add_event() or add_event_ex(). events
30 * are fired using send_event().
31 *
32 * Events are always dispatched synchronously: the callbacks are called
33 * in the thread context of the event sender, without context switch. This
34 * also means that callbacks should be as simple as possible to avoid
35 * blocking the sender and other callbacks
36 *
37 * Use the kernel-level event_queue for cross-thread event dispatching.
38 * */
39
40/*
41 * Only CLASS defines and firmware/ level events should be defined here.
42 * apps/ level events are defined in apps/appevents.h
43 *
44 * High byte = Event class definition
45 * Low byte = Event ID
46 */
47
48#define EVENT_CLASS_DISK 0x0100
49#define EVENT_CLASS_PLAYBACK 0x0200
50#define EVENT_CLASS_BUFFERING 0x0400
51#define EVENT_CLASS_GUI 0x0800
52#define EVENT_CLASS_RECORDING 0x1000
53#define EVENT_CLASS_LCD 0x2000
54#define EVENT_CLASS_VOICE 0x4000
55#define EVENT_CLASS_SYSTEM 0x8000 /*LAST ONE */
56/**
57 * Subscribe to an event with a simple callback. The callback will be called
58 * synchronously everytime the event fires, passing the event id and data to
59 * the callback.
60 *
61 * Must be removed with remove_event().
62 */
63bool add_event(unsigned short id, void (*handler)(unsigned short id, void *event_data));
64
65/**
66 * Subscribe to an event with a detailed callback. The callback will be called
67 * synchronously everytime the event fires, passing the event id and data, as
68 * well as the user_data pointer passed here, to the callback.
69 *
70 * With oneshot == true, the callback is unsubscribed automatically after
71 * the event fired for the first time. In this case the event need not to be
72 * removed with remove_event_ex().
73 *
74 * Must be removed with remove_event_ex(). remove_event() will never remove
75 * events added with this function.
76 */
77bool add_event_ex(unsigned short id, bool oneshot, void (*handler)(unsigned short id, void *event_data, void *user_data), void *user_data);
78
79/**
80 * Unsubscribe a callback from an event. The handler pointer is matched.
81 *
82 * This will only work for subscriptions made with add_event().
83 */
84void remove_event(unsigned short id, void (*handler)(unsigned short id, void *data));
85
86/**
87 * Unsubscribe a callback from an event. The handler and user_data pointers
88 * are matched. That means the same user_data that was passed to add_event_ex()
89 * must be passed to this too.
90 *
91 * This will only work for subscriptions made with add_event_ex().
92 */
93void remove_event_ex(unsigned short id, void (*handler)(unsigned short id, void *event_data, void *user_data), void *user_data);
94
95/**
96 * Fire an event, which synchronously calls all subscribed callbacks. The
97 * event id and data pointer are passed to the callbacks as well, and
98 * optionally the user_data pointer from add_event_ex().
99 */
100void send_event(unsigned short id, void *data);
101
102/** System events **/
103enum {
104 /* USB_INSERTED
105 data = &usbmode */
106 SYS_EVENT_USB_INSERTED = (EVENT_CLASS_SYSTEM|1),
107 /* USB_EXTRACTED
108 data = NULL */
109 SYS_EVENT_USB_EXTRACTED,
110};
111
112#endif