I want to write a short program, which triggers the Thumbnail creation for all pictures on my network share recursively (e.g. over night) - so that when I access a folder in Thunar, the thumbs are displayed immediately.
I would say, that when I can access the API via gdbus call
, then the system is setup correctly:
$ gdbus call --session --dest org.freedesktop.thumbnails.Thumbnailer1 \
--object-path /org/freedesktop/thumbnails/Thumbnailer1 \
--method org.freedesktop.thumbnails.Thumbnailer1.GetSchedulers
(['default', 'foreground', 'background'],)
$
But when I call my binary, I get the following error:
$ cc -Wall -Werror -pthread -I/usr/include/libmount -I/usr/include \
/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
-c -o main.o main.c
$ cc main.o -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o tumbler-bin
$ ./tumbler-bin
**
ERROR:main.c:26:main: assertion failed (error == NULL):
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface
?org.freedesktop.thumbnails.Thumbnailer1? on object at path \
/org/freedesktop/thumbnails/Thumbnailer1 (g-dbus-error-quark, 19)
Bail out! ERROR:main.c:26:main: assertion failed (error == NULL):
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface
?org.freedesktop.thumbnails.Thumbnailer1? on object at path \
/org/freedesktop/thumbnails/Thumbnailer1 (g-dbus-error-quark, 19)
Aborted (core dumped)
$
The code is the following. In general I create a proxy for org.freedesktop.thumbnails.Thumbnailer1
and call GetSchedulers()
:
#include <stdio.h>
#include <gio/gio.h>
const char *THUMBNAILER_IFACE = "org.freedesktop.thumbnails.Thumbnailer1";
const char *THUMBNAILER_SERVICE = "/org/freedesktop/thumbnails/Thumbnailer1";
const char *THIS_NAME = "de.test.tumbler-bin";
int main() {
GError *error = NULL;
GDBusConnection *con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error(error);
g_assert(con != NULL);
guint name_id = g_bus_own_name_on_connection(con, THIS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
g_assert(name_id != 0);
GDBusProxy *proxy = g_dbus_proxy_new_sync(con, G_DBUS_PROXY_FLAGS_NONE,
NULL, THIS_NAME, THUMBNAILER_SERVICE, THUMBNAILER_IFACE,
NULL, &error);
g_assert_no_error(error);
if (proxy == NULL) printf("proxy is NULL\n");
g_assert(proxy != NULL);
GVariant *schedulers = g_dbus_proxy_call_sync(proxy, "GetSchedulers",
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
g_assert_no_error(error);
if (schedulers == NULL) printf("schedulers is NULL\n");
g_assert(schedulers != NULL);
return 0;
}
Later on I want to call the method Queue()
- but to test whether D-Bus is working, I use GetSchedulers()
.
Have you checked what is happening with
dbus-monitor
? I'm not familiar with how gdbus works, but it looks like you're trying to call yourself:Since you want to call the method on a different service, it looks like what you really want is:
See the documentation for g_dbus_proxy_new_sync for the method arguments.