[aravis/realtime] realtime: new API for making stream thread realtime



commit 6c8f9be25d1fac2264c9e0db5cab74a4a5c8b0f1
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Tue Dec 2 11:25:22 2014 +0100

    realtime: new API for making stream thread realtime

 .gitignore                                |    1 +
 docs/reference/aravis/Makefile.am         |    1 +
 docs/reference/aravis/aravis-sections.txt |    2 +
 src/Makefile.am                           |    9 +-
 src/arv.h                                 |    1 +
 src/arvrealtime.c                         |  294 +++++++++++++++++++++++++++++
 src/arvrealtime.h                         |   13 ++
 src/arvrealtimeprivate.h                  |   13 ++
 tests/.gitignore                          |    1 +
 tests/arvcameratest.c                     |   26 +++-
 tests/realtimetest.c                      |  191 +------------------
 11 files changed, 361 insertions(+), 191 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 16a86d9..d99e6cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,5 +41,6 @@ massif.out.*
 messages.mo
 aravis-*.tar.bz2
 aravis-*.tar.gz
+aravis-*.tar.xz
 INSTALL
 compile
diff --git a/docs/reference/aravis/Makefile.am b/docs/reference/aravis/Makefile.am
index d014a23..cdaa864 100644
--- a/docs/reference/aravis/Makefile.am
+++ b/docs/reference/aravis/Makefile.am
@@ -67,6 +67,7 @@ IGNORE_HFILES=\
        arvchunkparserprivate.h         \
        arvdeviceprivate.h              \
        arvstreamprivate.h              \
+       arvrealtimeprivate.h            \
        arv.h
 
 # Images to copy into HTML directory.
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 7812b85..70e3a47 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -642,6 +642,8 @@ arv_stream_get_n_buffers
 arv_stream_get_statistics
 arv_stream_get_emit_signals
 arv_stream_set_emit_signals
+arv_make_thread_realtime
+arv_make_thread_high_priority
 <SUBSECTION Standard>
 ARV_STREAM
 ARV_IS_STREAM
diff --git a/src/Makefile.am b/src/Makefile.am
index b14e195..c6626a9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,7 +75,8 @@ ARAVIS_SRCS =                                 \
        arvfakeinterface.c                      \
        arvfakedevice.c                         \
        arvfakestream.c                         \
-       arvfakecamera.c
+       arvfakecamera.c                         \
+       arvrealtime.c
 
 ARAVIS_SRCS_NO_INTRO =                         \
        arvmisc.c                               \
@@ -138,7 +139,8 @@ ARAVIS_HDRS =                                       \
        arvfakeinterface.h                      \
        arvfakedevice.h                         \
        arvfakestream.h                         \
-       arvfakecamera.h
+       arvfakecamera.h                         \
+       arvrealtime.h
 
 ARAVIS_HDRS_NO_INTRO =                         \
        arvmisc.h                               \
@@ -151,7 +153,8 @@ noinst_HEADERS =                            \
        arvbufferprivate.h                      \
        arvchunkparserprivate.h                 \
        arvdeviceprivate.h                      \
-       arvstreamprivate.h
+       arvstreamprivate.h                      \
+       arvrealtimeprivate.h
 
 arv_fake_cameradir = $(aravis_datadir)
 arv_fake_camera_DATA = arv-fake-camera.xml
diff --git a/src/arv.h b/src/arv.h
index 9aa3284..fe8475e 100644
--- a/src/arv.h
+++ b/src/arv.h
@@ -72,5 +72,6 @@
 #include <arvfakedevice.h>
 #include <arvfakestream.h>
 #include <arvfakecamera.h>
+#include <arvrealtime.h>
 
 #endif
diff --git a/src/arvrealtime.c b/src/arvrealtime.c
new file mode 100644
index 0000000..f9136ec
--- /dev/null
+++ b/src/arvrealtime.c
@@ -0,0 +1,294 @@
+/***
+  Copyright 2009 Lennart Poettering
+  Copyright 2010 David Henningsson <diwic ubuntu com>
+  Copyright 2014 Emmanuel Pacaud <emmanuel gnome org>
+
+  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.
+
+  This file is based on rtkit sources, ported from libdbus to glib gdbus API.
+
+***/
+
+#include <arvrealtimeprivate.h>
+#include <arvdebug.h>
+#include <memory.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+
+#define RTKIT_SERVICE_NAME "org.freedesktop.RealtimeKit1"
+#define RTKIT_OBJECT_PATH "/org/freedesktop/RealtimeKit1"
+
+#define ARV_RTKIT_ERROR arv_rtkit_error_quark ()
+
+typedef enum {
+       ARV_RTKIT_ERROR_PERMISSION_DENIED,
+       ARV_RTKIT_ERROR_WRONG_REPLY
+} ArvRtkitError;
+
+static GQuark
+arv_rtkit_error_quark (void)
+{
+  return g_quark_from_static_string ("arv-rtkit-error-quark");
+}
+
+static gint64
+arv_rtkit_get_int_property (GDBusConnection *connection, const char* propname, GError **error) {
+
+       GDBusMessage *message;
+       GDBusMessage *reply;
+       GError *local_error = NULL;
+       GVariant *body;
+       GVariant *parameter;
+       GVariant *variant;
+       const GVariantType *variant_type;
+       gint64 value;
+
+       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
+                                                 RTKIT_OBJECT_PATH,
+                                                 "org.freedesktop.DBus.Properties",
+                                                 "Get");
+       g_dbus_message_set_body (message, g_variant_new ("(ss)", "org.freedesktop.RealtimeKit1", propname));
+
+       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
+                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
+                                                               &local_error);
+       g_object_unref (message);
+
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return 0;
+       }
+
+       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
+               local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_PERMISSION_DENIED,
+                                          "%s", g_dbus_message_get_error_name (reply));
+               g_propagate_error (error, local_error);
+               g_object_unref (reply);
+               return 0;
+       }
+
+       if (!g_variant_type_equal ("v", g_dbus_message_get_signature (reply))) {
+               local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_WRONG_REPLY,
+                                          "Invalid reply signature");
+               g_propagate_error (error, local_error);
+               g_object_unref (reply);
+               return 0;
+       }
+
+       body = g_dbus_message_get_body (reply);
+       parameter = g_variant_get_child_value (body, 0);
+       variant = g_variant_get_variant (parameter);
+
+       variant_type = g_variant_get_type (variant);
+
+       if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT32))
+               value = g_variant_get_int32 (variant);
+       else if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT64))
+               value = g_variant_get_int64 (variant);
+       else
+               value = 0;
+
+       g_variant_unref (parameter);
+       g_variant_unref (variant);
+       g_object_unref (reply);
+
+       return value;
+}
+
+int
+arv_rtkit_get_max_realtime_priority (GDBusConnection *connection, GError **error)
+{
+       return arv_rtkit_get_int_property (connection, "MaxRealtimePriority", error);
+}
+
+int
+arv_rtkit_get_min_nice_level (GDBusConnection *connection, GError **error)
+{
+       return arv_rtkit_get_int_property (connection, "MinNiceLevel", error);
+}
+
+gint64
+arv_rtkit_get_rttime_usec_max (GDBusConnection *connection, GError **error)
+{
+       GError *local_error = NULL;
+       gint64 rttime_usec_max;
+
+       rttime_usec_max = arv_rtkit_get_int_property (connection, "RTTimeUSecMax", &local_error);
+       if (local_error == NULL)
+               return rttime_usec_max;
+
+       g_error_free (local_error);
+
+       return arv_rtkit_get_int_property (connection, "RTTimeNSecMax", error) / 1000;
+}
+
+void
+arv_rtkit_make_realtime (GDBusConnection *connection, pid_t thread, int priority, GError **error)
+{
+       GDBusMessage *message;
+       GDBusMessage *reply;
+       GError *local_error = NULL;
+
+       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
+                                                 RTKIT_OBJECT_PATH,
+                                                 "org.freedesktop.RealtimeKit1",
+                                                 "MakeThreadRealtime");
+       g_dbus_message_set_body (message, g_variant_new ("(tu)", thread, priority));
+
+       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
+                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
+                                                               &local_error);
+       g_object_unref (message);
+
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return;
+       }
+
+       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
+               local_error = g_error_new (ARV_RTKIT_ERROR, 0, "%s", g_dbus_message_get_error_name (reply));
+               g_propagate_error (error, local_error);
+               g_object_unref (reply);
+               return;
+       }
+
+       g_object_unref (reply);
+}
+
+void
+arv_rtkit_make_high_priority (GDBusConnection *connection, pid_t thread, int nice_level, GError **error)
+{
+       GDBusMessage *message;
+       GDBusMessage *reply;
+       GError *local_error = NULL;
+
+       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
+                                                 RTKIT_OBJECT_PATH,
+                                                 "org.freedesktop.RealtimeKit1",
+                                                 "MakeThreadHighPriority");
+       g_dbus_message_set_body (message, g_variant_new ("(ti)", thread, nice_level));
+
+       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
+                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
+                                                               &local_error);
+       g_object_unref (message);
+
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return;
+       }
+
+       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
+               local_error = g_error_new (ARV_RTKIT_ERROR, 0, "%s", g_dbus_message_get_error_name (reply));
+               g_propagate_error (error, local_error);
+               g_object_unref (reply);
+               return;
+       }
+
+       g_object_unref (reply);
+}
+
+#ifndef SCHED_RESET_ON_FORK
+#define SCHED_RESET_ON_FORK 0x40000000
+#endif
+
+#ifndef RLIMIT_RTTIME
+#define RLIMIT_RTTIME 15
+#endif
+
+static pid_t _gettid(void) {
+        return (pid_t) syscall(SYS_gettid);
+}
+
+gboolean
+arv_make_thread_realtime (int priority)
+{
+       struct sched_param p;
+
+       memset(&p, 0, sizeof(p));
+       p.sched_priority = priority;
+
+       if (sched_setscheduler(_gettid (), SCHED_RR|SCHED_RESET_ON_FORK, &p) < 0
+           && errno == EPERM) {
+               struct rlimit rlim;
+               GDBusConnection *bus;
+               GError *error = NULL;
+
+               memset(&rlim, 0, sizeof(rlim));
+               rlim.rlim_cur = rlim.rlim_max = 100000000ULL; /* 100ms */
+               if ((setrlimit(RLIMIT_RTTIME, &rlim) < 0)) {
+                       arv_warning_misc ("Failed to set RLIMIT_RTTIME: %s", strerror (errno));
+                       return FALSE;
+               }
+
+               bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (error != NULL) {
+                       arv_warning_misc ("Failed to connect to system bus: %s", error->message);
+                       g_error_free (error);
+                       return FALSE;
+               }
+
+               arv_rtkit_make_realtime(bus, _gettid (), p.sched_priority, &error);
+               g_object_unref (bus);
+
+               if (error != NULL) {
+                       arv_warning_misc ("Failed to connect make realtime: %s", error->message);
+                       g_error_free (error);
+                       return FALSE;
+               }
+
+               arv_debug_misc ("Thread became realtime with priority %d", priority);
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+gboolean
+arv_make_thread_high_priority (int nice_level)
+{
+       GDBusConnection *bus;
+       GError *error = NULL;
+
+       bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error != NULL) {
+               arv_warning_misc ("Failed to connect to system bus: %s", error->message);
+               g_error_free (error);
+               return FALSE;
+       }
+
+       arv_rtkit_make_high_priority (bus, _gettid(), nice_level, &error);
+       g_object_unref (bus);
+
+       if (error != NULL) {
+               arv_warning_misc ("Failed to connect high priority: %s", error->message);
+               g_error_free (error);
+               return FALSE;
+       }
+
+       arv_debug_misc ("Nice level successfully changed to %d", nice_level);
+
+       return TRUE;
+}
diff --git a/src/arvrealtime.h b/src/arvrealtime.h
new file mode 100644
index 0000000..7234722
--- /dev/null
+++ b/src/arvrealtime.h
@@ -0,0 +1,13 @@
+#ifndef ARV_REALTIME_H
+#define ARV_REALTIME_H
+
+#include <arvtypes.h>
+
+G_BEGIN_DECLS
+
+gboolean       arv_make_thread_realtime                (int priority);
+gboolean       arv_make_thread_high_priority           (int nice_level);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvrealtimeprivate.h b/src/arvrealtimeprivate.h
new file mode 100644
index 0000000..5e9d44d
--- /dev/null
+++ b/src/arvrealtimeprivate.h
@@ -0,0 +1,13 @@
+#ifndef ARV_REALTIME_PRIVATE_H
+#define ARV_REALTIME_PRIVATE_H
+
+#include <arvrealtime.h>
+#include <gio/gio.h>
+
+int            arv_rtkit_get_max_realtime_priority     (GDBusConnection *connection, GError **error);
+int            arv_rtkit_get_min_nice_level            (GDBusConnection *connection, GError **error);
+gint64         arv_rtkit_get_rttime_usec_max           (GDBusConnection *connection, GError **error);
+void           arv_rtkit_make_realtime                 (GDBusConnection *connection, pid_t thread, int 
priority, GError **error);
+void           arv_rtkit_make_high_priority            (GDBusConnection *connection, pid_t thread, int 
nice_level, GError **error);
+
+#endif
diff --git a/tests/.gitignore b/tests/.gitignore
index 998fdcd..b9a1e6c 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -13,3 +13,4 @@ arv-chunk-parser-test
 arv-heartbeat-test
 arv-example
 time-test
+realtime-test
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index 2d101b5..cb1cbbc 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -23,6 +23,8 @@ static unsigned int arv_option_frame_retention = 100;
 static int arv_option_gv_stream_channel = -1;
 static int arv_option_gv_packet_delay = -1;
 static int arv_option_gv_packet_size = -1;
+static gboolean arv_option_realtime = FALSE;
+static gboolean arv_option_high_priority = FALSE;
 static char *arv_option_chunks = NULL;
 
 static const GOptionEntry arv_option_entries[] =
@@ -104,6 +106,14 @@ static const GOptionEntry arv_option_entries[] =
                &arv_option_chunks,                     "Chunks", NULL
        },
        {
+               "realtime",                             '\0', 0, G_OPTION_ARG_NONE,
+               &arv_option_realtime,                   "Make stream thread realtime", NULL
+       },
+       {
+               "high-priority",                        '\0', 0, G_OPTION_ARG_NONE,
+               &arv_option_high_priority,              "Make stream thread high priority", NULL
+       },
+       {
                "debug",                                'd', 0, G_OPTION_ARG_STRING,
                &arv_option_debug_domains,              "Debug domains", NULL
        },
@@ -150,6 +160,20 @@ new_buffer_cb (ArvStream *stream, ApplicationData *data)
        }
 }
 
+static void
+stream_cb (void *user_data, ArvStreamCallbackType type, ArvBuffer *buffer)
+{
+       if (type == ARV_STREAM_CALLBACK_TYPE_INIT) {
+               if (arv_option_realtime) {
+                       if (!arv_make_thread_realtime (10))
+                               printf ("Failed to make stream thread realtime\n");
+               } else if (arv_option_high_priority) {
+                       if (!arv_make_thread_high_priority (-10))
+                               printf ("Failed to make stream thread high priority\n");
+               }
+       }
+}
+
 static gboolean
 periodic_task_cb (void *abstract_data)
 {
@@ -287,7 +311,7 @@ main (int argc, char **argv)
                        printf ("gv packet size        = %d bytes\n", arv_camera_gv_get_packet_size (camera));
                }
 
-               stream = arv_camera_create_stream (camera, NULL, NULL);
+               stream = arv_camera_create_stream (camera, stream_cb, NULL);
                if (stream != NULL) {
                        if (ARV_IS_GV_STREAM (stream)) {
                                if (arv_option_auto_socket_buffer)
diff --git a/tests/realtimetest.c b/tests/realtimetest.c
index 331270c..73ccb64 100644
--- a/tests/realtimetest.c
+++ b/tests/realtimetest.c
@@ -24,198 +24,15 @@
   SOFTWARE.
 ***/
 
-#include <errno.h>
-#include <sys/types.h>
-
-#define RTKIT_SERVICE_NAME "org.freedesktop.RealtimeKit1"
-#define RTKIT_OBJECT_PATH "/org/freedesktop/RealtimeKit1"
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
+#include <../src/arvrealtimeprivate.h>
 
-#include <string.h>
-#include <unistd.h>
-#include <string.h>
-#include <sched.h>
 #include <stdio.h>
-#include <sys/syscall.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 
-#include <gio/gio.h>
-#include <stdlib.h>
-
-#define ARV_RTKIT_ERROR arv_rtkit_error_quark ()
-
-typedef enum {
-       ARV_RTKIT_ERROR_PERMISSION_DENIED,
-       ARV_RTKIT_ERROR_WRONG_REPLY
-} ArvRtkitError;
-
-GQuark
-arv_rtkit_error_quark (void)
-{
-  return g_quark_from_static_string ("arv-rtkit-error-quark");
-}
-
-gint64
-arv_rtkit_get_int_property (GDBusConnection *connection, const char* propname, GError **error) {
-
-       GDBusMessage *message;
-       GDBusMessage *reply;
-       GError *local_error = NULL;
-       GVariant *body;
-       GVariant *parameter;
-       GVariant *variant;
-       const GVariantType *variant_type;
-       gint64 value;
-
-       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
-                                                 RTKIT_OBJECT_PATH,
-                                                 "org.freedesktop.DBus.Properties",
-                                                 "Get");
-       g_dbus_message_set_body (message, g_variant_new ("(ss)", "org.freedesktop.RealtimeKit1", propname));
-
-       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
-                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
-                                                               &local_error);
-       g_object_unref (message);
-
-       if (local_error != NULL) {
-               g_propagate_error (error, local_error);
-               return 0;
-       }
-
-       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
-               local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_PERMISSION_DENIED,
-                                          "%s", g_dbus_message_get_error_name (reply));
-               g_propagate_error (error, local_error);
-               g_object_unref (reply);
-               return 0;
-       }
-
-       if (!g_variant_type_equal ("v", g_dbus_message_get_signature (reply))) {
-               local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_WRONG_REPLY,
-                                          "Invalid reply signature");
-               g_propagate_error (error, local_error);
-               g_object_unref (reply);
-               return 0;
-       }
-
-       body = g_dbus_message_get_body (reply);
-       parameter = g_variant_get_child_value (body, 0);
-       variant = g_variant_get_variant (parameter);
-
-       variant_type = g_variant_get_type (variant);
-
-       if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT32))
-               value = g_variant_get_int32 (variant);
-       else if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT64))
-               value = g_variant_get_int64 (variant);
-       else
-               value = 0;
-
-       g_variant_unref (parameter);
-       g_variant_unref (variant);
-       g_object_unref (reply);
-
-       return value;
-}
-
-int
-arv_rtkit_get_max_realtime_priority (GDBusConnection *connection, GError **error)
-{
-       return arv_rtkit_get_int_property (connection, "MaxRealtimePriority", error);
-}
-
-int
-arv_rtkit_get_min_nice_level (GDBusConnection *connection, GError **error)
-{
-       return arv_rtkit_get_int_property (connection, "MinNiceLevel", error);
-}
-
-gint64
-arv_rtkit_get_rttime_usec_max (GDBusConnection *connection, GError **error)
-{
-       GError *local_error = NULL;
-       gint64 rttime_usec_max;
-
-       rttime_usec_max = arv_rtkit_get_int_property (connection, "RTTimeUSecMax", &local_error);
-       if (error == NULL)
-               return rttime_usec_max;
-
-       g_error_free (local_error);
-
-       return arv_rtkit_get_int_property (connection, "RTTimeNSecMax", error) / 1000;
-}
-
-void
-arv_rtkit_make_realtime (GDBusConnection *connection, pid_t thread, int priority, GError **error) {
-
-       GDBusMessage *message;
-       GDBusMessage *reply;
-       GError *local_error = NULL;
-
-       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
-                                                 RTKIT_OBJECT_PATH,
-                                                 "org.freedesktop.RealtimeKit1",
-                                                 "MakeThreadRealtime");
-       g_dbus_message_set_body (message, g_variant_new ("(tu)", thread, priority));
-
-       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
-                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
-                                                               &local_error);
-       g_object_unref (message);
-
-       if (local_error != NULL) {
-               g_propagate_error (error, local_error);
-               return;
-       }
-
-       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
-               local_error = g_error_new (ARV_RTKIT_ERROR, 0, "%s", g_dbus_message_get_error_name (reply));
-               g_propagate_error (error, local_error);
-               g_object_unref (reply);
-               return;
-       }
-
-       g_object_unref (reply);
-}
-
-void
-arv_rtkit_make_high_priority (GDBusConnection *connection, pid_t thread, int nice_level, GError **error) {
-
-       GDBusMessage *message;
-       GDBusMessage *reply;
-       GError *local_error = NULL;
-
-       message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
-                                                 RTKIT_OBJECT_PATH,
-                                                 "org.freedesktop.RealtimeKit1",
-                                                 "MakeThreadHighPriority");
-       g_dbus_message_set_body (message, g_variant_new ("(ti)", thread, nice_level));
-
-       reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
-                                                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, 
NULL,
-                                                               &local_error);
-       g_object_unref (message);
-
-       if (local_error != NULL) {
-               g_propagate_error (error, local_error);
-               return;
-       }
-
-       if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
-               local_error = g_error_new (ARV_RTKIT_ERROR, 0, "%s", g_dbus_message_get_error_name (reply));
-               g_propagate_error (error, local_error);
-               g_object_unref (reply);
-               return;
-       }
-
-       g_object_unref (reply);
-}
-
 #ifndef SCHED_RESET_ON_FORK
 #define SCHED_RESET_ON_FORK 0x40000000
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]