Git init
[framework/multimedia/pulseaudio.git] / src / modules / reserve.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*-*/
2
3 #ifndef fooreservehfoo
4 #define fooreservehfoo
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 rd_device rd_device;
38
39 /* Prototype for a function that is called whenever someone else wants
40  * your application to release the device it has locked. A return
41  * value <= 0 denies the request, a positive return value agrees to
42  * it. Before returning your application should close the device in
43  * question completely to make sure the new application may access
44  * it. */
45 typedef int (*rd_request_cb_t)(
46         rd_device *d,
47         int forced);                  /* Non-zero if an application forcibly took the lock away without asking. If this is the case then the return value of this call is ignored. */
48
49 /* Try to lock the device. Returns 0 on success, a negative errno
50  * style return value on error. The DBus error might be set as well if
51  * the error was caused D-Bus. */
52 int rd_acquire(
53         rd_device **d,                /* On success a pointer to the newly allocated rd_device object will be filled in here */
54         DBusConnection *connection,   /* Session bus (when D-Bus learns about user busses we should switchg to user busses) */
55         const char *device_name,      /* The device to lock, e.g. "Audio0" */
56         const char *application_name, /* A human readable name of the application, e.g. "PulseAudio Sound Server" */
57         int32_t priority,             /* The priority for this application. If unsure use 0 */
58         rd_request_cb_t request_cb,   /* Will be called whenever someone requests that this device shall be released. May be NULL if priority is INT32_MAX */
59         DBusError *error);            /* If we fail due to a D-Bus related issue the error will be filled in here. May be NULL. */
60
61 /* Unlock (if needed) and destroy an rd_device object again */
62 void rd_release(rd_device *d);
63
64 /* Set the application device name for an rd_device object. Returns 0
65  * on success, a negative errno style return value on error. */
66 int rd_set_application_device_name(rd_device *d, const char *name);
67
68 /* Attach a userdata pointer to an rd_device */
69 void rd_set_userdata(rd_device *d, void *userdata);
70
71 /* Query the userdata pointer from an rd_device. Returns NULL if no
72  * userdata was set. */
73 void* rd_get_userdata(rd_device *d);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif