Git init
[framework/multimedia/pulseaudio.git] / src / modules / reserve-monitor.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*-*/
2
3 #ifndef fooreservemonitorhfoo
4 #define fooreservemonitorhfoo
5
6 /***
7   Copyright 2009 Lennart Poettering
8
9   Permission is hereby granted, free of charge, to any person
10   obtaining a copy of this software and associated documentation files
11   (the "Software"), to deal in the Software without restriction,
12   including without limitation the rights to use, copy, modify, merge,
13   publish, distribute, sublicense, and/or sell copies of the Software,
14   and to permit persons to whom the Software is furnished to do so,
15   subject to the following conditions:
16
17   The above copyright notice and this permission notice shall be
18   included in all copies or substantial portions of the Software.
19
20   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27   SOFTWARE.
28 ***/
29
30 #include <dbus/dbus.h>
31 #include <inttypes.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef struct rm_monitor rm_monitor;
38
39 /* Prototype for a function that is called whenever the reservation
40  * device of a device changes. Use rm_monitor_busy() to find out the
41  * new state.*/
42 typedef void (*rm_change_cb_t)(rm_monitor *m);
43
44 /* Creates a monitor for watching the lock status of a device. Returns
45  * 0 on success, a negative errno style return value on error.  The
46  * DBus error might be set as well if the error was caused D-Bus. */
47 int rm_watch(
48         rm_monitor **m,              /* On success a pointer to the newly allocated rm_device object will be filled in here */
49         DBusConnection *connection,  /* Session bus (when D-Bus learns about user busses we should switchg to user busses) */
50         const char *device_name,     /* The device to monitor, e.g. "Audio0" */
51         rm_change_cb_t change_cb,    /* Will be called whenever the lock status changes. May be NULL */
52         DBusError *error);           /* If we fail due to a D-Bus related issue the error will be filled in here. May be NULL. */
53
54 /* Free a rm_monitor object */
55 void rm_release(rm_monitor *m);
56
57 /* Checks whether the device is currently reserved, and returns 1
58  * then, 0 if not, negative errno style error code value on error. */
59 int rm_busy(rm_monitor *m);
60
61 /* Attach a userdata pointer to an rm_monitor */
62 void rm_set_userdata(rm_monitor *m, void *userdata);
63
64 /* Query the userdata pointer from an rm_monitor. Returns NULL if no
65  * userdata was set. */
66 void* rm_get_userdata(rm_monitor *m);
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72 #endif