Re: [pulseaudio-discuss] [PATCH] rtkit: Add client-side testing of properties

2010-02-16 Thread Lennart Poettering
On Sun, 07.02.10 13:59, David Henningsson (launchpad@epost.diwic.se) wrote:

 To complete the previous patch that implemented properties in rtkit,
 here's the client-side code that tests that the properties work, and make
 them more accessible for the casual C programmer.

Thanks a lot!

Applied (with trivial changes).

Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/   GnuPG 0x1A015CC4
___
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH] rtkit: Add client-side testing of properties

2010-02-07 Thread David Henningsson
To complete the previous patch that implemented properties in rtkit,
here's the client-side code that tests that the properties work, and make
them more accessible for the casual C programmer.

// David
From 309659d47396544cd2b8d97ac5dac4460f543723 Mon Sep 17 00:00:00 2001
From: David Henningsson di...@ubuntu.com
Date: Sun, 7 Feb 2010 13:18:00 +0100
Subject: [PATCH] Implement client-side testing of property retrieval

---
 rtkit-test.c |   22 ++--
 rtkit.c  |  114 ++
 rtkit.h  |   17 +
 3 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/rtkit-test.c b/rtkit-test.c
index 2841b52..9d2703f 100644
--- a/rtkit-test.c
+++ b/rtkit-test.c
@@ -76,7 +76,8 @@ static void print_status(const char *t) {
 int main(int argc, char *argv[]) {
 DBusError error;
 DBusConnection *bus;
-int r;
+int r, r2;
+long long r3;
 struct rlimit rlim;
 
 dbus_error_init(error);
@@ -86,6 +87,21 @@ int main(int argc, char *argv[]) {
 return 1;
 }
 
+if ((r = rtkit_get_max_realtime_priority(bus))  0) 
+fprintf(stderr, Failed to retrieve max realtime priority: %s\n, strerror(-r));
+else
+printf(Max realtime priority is: %d\n, r);
+
+if ((r2 = rtkit_get_min_nice_level(bus, r))) 
+fprintf(stderr, Failed to retrieve min nice level: %s\n, strerror(-r2));
+else
+printf(Min nice level is: %d\n, r);
+
+if ((r3 = rtkit_get_rttime_nsec_max(bus))  0) 
+fprintf(stderr, Failed to retrieve rttime limit: %s\n, strerror(-r3));
+else
+printf(Rttime limit is: %lld ns\n, r3);
+
 memset(rlim, 0, sizeof(rlim));
 rlim.rlim_cur = rlim.rlim_max = 1ULL; /* 100ms */
 if ((setrlimit(RLIMIT_RTTIME, rlim)  0))
@@ -96,14 +112,14 @@ int main(int argc, char *argv[]) {
 if ((r = rtkit_make_high_priority(bus, 0, -10))  0)
 fprintf(stderr, Failed to become high priority: %s\n, strerror(-r));
 else
-printf(Sucessfully became high priority.\n);
+printf(Successfully became high priority.\n);
 
 print_status(after high priority);
 
 if ((r = rtkit_make_realtime(bus, 0, 10))  0)
 fprintf(stderr, Failed to become realtime: %s\n, strerror(-r));
 else
-printf(Sucessfully became realtime.\n);
+printf(Successfully became realtime.\n);
 
 print_status(after realtime);
 
diff --git a/rtkit.c b/rtkit.c
index aecc4e3..181f3de 100644
--- a/rtkit.c
+++ b/rtkit.c
@@ -2,6 +2,7 @@
 
 /***
   Copyright 2009 Lennart Poettering
+  Copyright 2010 David Henningsson di...@ubuntu.com
 
   Permission is hereby granted, free of charge, to any person
   obtaining a copy of this software and associated documentation files
@@ -56,6 +57,107 @@ static int translate_error(const char *name) {
 return -EIO;
 }
 
+
+static long long rtkit_get_int_property(DBusConnection *connection, const char* propname, long long* propval) {
+DBusMessage *m = NULL, *r = NULL;
+DBusMessageIter iter, subiter;
+dbus_int64_t i64;
+dbus_int32_t i32;
+DBusError error;
+int current_type;
+long long ret;
+const char * interfacestr = org.freedesktop.RealtimeKit1;
+
+dbus_error_init(error);
+
+if (!(m = dbus_message_new_method_call(
+  RTKIT_SERVICE_NAME,
+  RTKIT_OBJECT_PATH,
+  org.freedesktop.DBus.Properties, 
+  Get))) {
+ret = -ENOMEM;
+goto finish;
+}
+
+if (!dbus_message_append_args(
+m,
+DBUS_TYPE_STRING, interfacestr, 
+DBUS_TYPE_STRING, propname,
+DBUS_TYPE_INVALID)) {
+ret = -ENOMEM;
+goto finish;
+}
+
+if (!(r = dbus_connection_send_with_reply_and_block(connection, m, -1, error))) {
+ret = translate_error(error.name);
+goto finish;
+}
+
+if (dbus_set_error_from_message(error, r)) {
+ret = translate_error(error.name);
+goto finish;
+}
+
+	ret = -EBADMSG;
+dbus_message_iter_init(r, iter);
+while ((current_type = dbus_message_iter_get_arg_type (iter)) != DBUS_TYPE_INVALID) {
+if (current_type == DBUS_TYPE_VARIANT) {
+dbus_message_iter_recurse(iter, subiter);
+while ((current_type = dbus_message_iter_get_arg_type (subiter)) != DBUS_TYPE_INVALID) {
+if (current_type == DBUS_TYPE_INT32) {
+