From 72deb8c17675fe99a1c82ff9810f75e0dfed29a3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 2 Feb 2009 23:18:24 +0100 Subject: initial commit --- reserve-test.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 reserve-test.c (limited to 'reserve-test.c') diff --git a/reserve-test.c b/reserve-test.c new file mode 100644 index 0000000..d90f420 --- /dev/null +++ b/reserve-test.c @@ -0,0 +1,110 @@ +/*** + Copyright 2009 Lennart Poettering + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +***/ + +#include +#include +#include +#include +#include +#include + +#include "reserve.h" + +#define RUN_FOR_SECS 10 + +static int quit = 0; +rd_device *device = NULL; + +static int request_cb(rd_device *d, int forced, int show_ui) { + printf("Giving up device. (forced=%i, show_ui=%i)\n", forced, show_ui); + + rd_release(d); + device = NULL; + + quit = 1; + return 1; +} + +int main(int argc, char *argv[]) { + DBusError error; + DBusConnection *c; + int r = 1, e; + time_t started_at; + int32_t priority = 0; + + dbus_error_init(&error); + + if (argc >= 2) + priority = atoi(argv[1]); + + printf("Using priority %i.\n", priority); + + if (!(c = dbus_bus_get(DBUS_BUS_SESSION, &error))) { + fprintf(stderr, "Failed to connect to session bus: %s\n", error.message); + goto finish; + } + + if ((e = rd_acquire( + &device, + c, + "Audio0", + "ReserveTest", + priority, + 1, + request_cb, + &error)) < 0) { + + fprintf(stderr, "Failed to acquire device: %s\n", + error.message ? error.message : strerror(-e)); + goto finish; + } + + printf("Successfully acquired device.\n"); + + started_at = time(NULL); + + while (!quit) { + time_t t; + + t = time(NULL); + + if (t >= started_at + RUN_FOR_SECS) + break; + + if (!dbus_connection_read_write_dispatch(c, (started_at + RUN_FOR_SECS - t) * 1000)) + break; + } + + r = 0; + +finish: + + if (device) + rd_release(device); + + if (c) + dbus_connection_unref(c); + + return r; +} -- cgit