Merge pull request #210 from ZoiteChat/dbus_gdbus_migration

Migrate to gdbus.
This commit is contained in:
deepend-tildeclub
2026-04-27 13:38:52 -06:00
committed by GitHub
11 changed files with 805 additions and 846 deletions

View File

@@ -28,7 +28,7 @@ jobs:
sudo apt-get install -y --no-install-recommends \ sudo apt-get install -y --no-install-recommends \
build-essential pkg-config meson ninja-build cmake \ build-essential pkg-config meson ninja-build cmake \
gettext \ gettext \
libcanberra-dev libdbus-glib-1-dev libglib2.0-dev \ libcanberra-dev libglib2.0-dev \
libarchive-dev \ libarchive-dev \
libgtk-3-dev \ libgtk-3-dev \
libwayland-client0 libwayland-cursor0 libwayland-egl1 \ libwayland-client0 libwayland-cursor0 libwayland-egl1 \

View File

@@ -32,7 +32,6 @@ jobs:
glib2-devel \ glib2-devel \
gtk3 \ gtk3 \
openssl \ openssl \
dbus-glib \
libcanberra \ libcanberra \
libayatana-appindicator \ libayatana-appindicator \
luajit \ luajit \

View File

@@ -22,7 +22,7 @@ if get_option('gtk-frontend')
endif endif
desktop_conf = configuration_data() desktop_conf = configuration_data()
if dbus_glib_dep.found() if dbus_dep.found()
desktop_conf.set('exec_command', 'zoitechat --existing %U') desktop_conf.set('exec_command', 'zoitechat --existing %U')
else else
desktop_conf.set('exec_command', 'zoitechat %U') desktop_conf.set('exec_command', 'zoitechat %U')

View File

@@ -33,7 +33,6 @@
} }
}, },
"modules": [ "modules": [
"shared-modules/dbus-glib/dbus-glib.json",
"shared-modules/lua5.4/lua-5.4.json", "shared-modules/lua5.4/lua-5.4.json",
"shared-modules/libcanberra/libcanberra.json", "shared-modules/libcanberra/libcanberra.json",
"shared-modules/libayatana-appindicator/libayatana-appindicator-gtk3.json", "shared-modules/libayatana-appindicator/libayatana-appindicator-gtk3.json",

View File

@@ -18,7 +18,7 @@ libgmodule_dep = dependency('gmodule-2.0')
libcanberra_dep = dependency('libcanberra', version: '>= 0.22', libcanberra_dep = dependency('libcanberra', version: '>= 0.22',
required: get_option('libcanberra')) required: get_option('libcanberra'))
dbus_glib_dep = dependency('dbus-glib-1', required: get_option('dbus')) dbus_dep = dependency('gio-2.0', required: get_option('dbus'))
global_deps = [] global_deps = []
if cc.get_id() == 'msvc' if cc.get_id() == 'msvc'
@@ -39,7 +39,7 @@ config_h.set10('ENABLE_NLS', true)
# Optional features # Optional features
config_h.set('USE_OPENSSL', libssl_dep.found()) config_h.set('USE_OPENSSL', libssl_dep.found())
config_h.set('USE_LIBCANBERRA', libcanberra_dep.found()) config_h.set('USE_LIBCANBERRA', libcanberra_dep.found())
config_h.set('USE_DBUS', dbus_glib_dep.found()) config_h.set('USE_DBUS', dbus_dep.found())
config_h.set('USE_PLUGIN', get_option('plugin')) config_h.set('USE_PLUGIN', get_option('plugin'))
config_h.set('USE_GTK_FRONTEND', get_option('gtk-frontend')) config_h.set('USE_GTK_FRONTEND', get_option('gtk-frontend'))
@@ -181,7 +181,7 @@ if meson.version().version_compare('>= 0.55.0')
'GTK Frontend': get_option('gtk-frontend') ? 'enabled (GTK+ 3.22+)' : 'disabled', 'GTK Frontend': get_option('gtk-frontend') ? 'enabled (GTK+ 3.22+)' : 'disabled',
'TLS (openssl)': libssl_dep.found(), 'TLS (openssl)': libssl_dep.found(),
'Plugin Support': get_option('plugin'), 'Plugin Support': get_option('plugin'),
'DBus Support': dbus_glib_dep.found(), 'DBus Support': dbus_dep.found(),
'libcanberra': libcanberra_dep.found(), 'libcanberra': libcanberra_dep.found(),
}, section: 'Features') }, section: 'Features')

View File

@@ -8,7 +8,6 @@ arch=('x86_64')
url='https://github.com/zoitechat/zoitechat' url='https://github.com/zoitechat/zoitechat'
license=('GPL-2.0-or-later') license=('GPL-2.0-or-later')
depends=( depends=(
'dbus-glib'
'glib2' 'glib2'
'gtk3' 'gtk3'
'iso-codes' 'iso-codes'

View File

@@ -82,10 +82,6 @@ has_theme_argument (void)
void void
zoitechat_remote (void) zoitechat_remote (void)
/* TODO: dbus_g_connection_unref (connection) are commented because it makes
* dbus to crash. Fixed in dbus >=0.70 ?!?
* https://launchpad.net/distros/ubuntu/+source/dbus/+bug/54375
*/
{ {
GDBusConnection *connection; GDBusConnection *connection;
GDBusProxy *dbus = NULL; GDBusProxy *dbus = NULL;

File diff suppressed because it is too large Load Diff

View File

@@ -1,203 +1,122 @@
/* example.c - program to demonstrate some D-BUS stuffs. #include <gio/gio.h>
* Copyright (C) 2006 Claessens Xavier #include <glib.h>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Claessens Xavier
* xclaesse@gmail.com
*/
#include <config.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h> #include <stdlib.h>
#include "../marshal.c"
#define DBUS_SERVICE "org.zoitechat.service" #define DBUS_SERVICE "org.zoitechat.service"
#define DBUS_REMOTE "/org/zoitechat/Remote" #define DBUS_CONNECTION_PATH "/org/zoitechat"
#define DBUS_REMOTE_CONNECTION_INTERFACE "org.zoitechat.connection" #define DBUS_CONNECTION_INTERFACE "org.zoitechat.connection"
#define DBUS_REMOTE_PLUGIN_INTERFACE "org.zoitechat.plugin" #define DBUS_PLUGIN_INTERFACE "org.zoitechat.plugin"
guint command_id; static gboolean
guint server_id; call_sync (GDBusProxy *proxy, const char *method, GVariant *params, GVariant **out)
static void
write_error (const char *message,
GError **error)
{
if (error == NULL || *error == NULL) {
return;
}
g_printerr ("%s: %s\n", message, (*error)->message);
g_clear_error (error);
}
static void
test_server_cb (DBusGProxy *proxy,
char *word[],
char *word_eol[],
guint hook_id,
guint context_id,
gpointer user_data)
{
if (hook_id == server_id) {
g_print ("message: %s\n", word_eol[0]);
}
}
static void
test_command_cb (DBusGProxy *proxy,
char *word[],
char *word_eol[],
guint hook_id,
guint context_id,
gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
GVariant *result;
if (hook_id == command_id) { result = g_dbus_proxy_call_sync (proxy,
if (!dbus_g_proxy_call (proxy, "Unhook", method,
&error, params,
G_TYPE_UINT, hook_id, G_DBUS_CALL_FLAGS_NONE,
G_TYPE_INVALID, G_TYPE_INVALID)) { -1,
write_error ("Failed to complete unhook", &error); NULL,
} &error);
/* Now if you write "/test blah" again in the ZoiteChat window if (!result)
* you'll get a "Unknown command" error message */ {
g_print ("test command received: %s\n", word_eol[1]); g_printerr ("%s failed: %s\n", method, error->message);
if (!dbus_g_proxy_call (proxy, "Print", g_clear_error (&error);
&error, return FALSE;
G_TYPE_STRING, "test command succeed",
G_TYPE_INVALID,
G_TYPE_INVALID)) {
write_error ("Failed to complete Print", &error);
}
} }
}
static void if (out)
unload_cb (void) *out = result;
{ else
g_print ("Good bye !\n"); g_variant_unref (result);
exit (EXIT_SUCCESS);
return TRUE;
} }
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
DBusGConnection *connection; GDBusConnection *connection;
DBusGProxy *remote_object; GDBusProxy *connection_proxy;
GMainLoop *mainloop; GDBusProxy *plugin_proxy;
gchar *path; GVariant *connect_result = NULL;
gchar *remote_path = NULL;
gchar *command = NULL;
const char *path_tmp;
int status = EXIT_FAILURE;
GError *error = NULL; GError *error = NULL;
#if ! GLIB_CHECK_VERSION (2, 36, 0) connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_type_init (); if (!connection)
#endif {
g_printerr ("Bus connection failed: %s\n", error->message);
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); g_clear_error (&error);
if (connection == NULL) {
write_error ("Couldn't connect to session bus", &error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
remote_object = dbus_g_proxy_new_for_name (connection, connection_proxy = g_dbus_proxy_new_sync (connection,
DBUS_SERVICE, G_DBUS_PROXY_FLAGS_NONE,
DBUS_REMOTE, NULL,
DBUS_REMOTE_CONNECTION_INTERFACE); DBUS_SERVICE,
if (!dbus_g_proxy_call (remote_object, "Connect", DBUS_CONNECTION_PATH,
&error, DBUS_CONNECTION_INTERFACE,
G_TYPE_STRING, argv[0], NULL,
G_TYPE_STRING, "example", &error);
G_TYPE_STRING, "Example of a D-Bus client", if (!connection_proxy)
G_TYPE_STRING, "1.0", {
G_TYPE_INVALID, g_printerr ("Connection proxy failed: %s\n", error->message);
G_TYPE_STRING, &path, G_TYPE_INVALID)) { g_clear_error (&error);
write_error ("Failed to complete Connect", &error); g_object_unref (connection);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
g_object_unref (remote_object);
remote_object = dbus_g_proxy_new_for_name (connection, if (!call_sync (connection_proxy,
DBUS_SERVICE, "Connect",
path, g_variant_new ("(ssss)", "example", "example", "GDBus example", "1.0"),
DBUS_REMOTE_PLUGIN_INTERFACE); &connect_result))
g_free (path); goto cleanup;
if (!dbus_g_proxy_call (remote_object, "HookCommand", g_variant_get (connect_result, "(&s)", &path_tmp);
&error, remote_path = g_strdup (path_tmp);
G_TYPE_STRING, "test", g_variant_unref (connect_result);
G_TYPE_INT, 0, connect_result = NULL;
G_TYPE_STRING, "Simple D-BUS example",
G_TYPE_INT, 1, G_TYPE_INVALID, plugin_proxy = g_dbus_proxy_new_sync (connection,
G_TYPE_UINT, &command_id, G_TYPE_INVALID)) { G_DBUS_PROXY_FLAGS_NONE,
write_error ("Failed to complete HookCommand", &error); NULL,
return EXIT_FAILURE; DBUS_SERVICE,
remote_path,
DBUS_PLUGIN_INTERFACE,
NULL,
&error);
if (!plugin_proxy)
{
g_printerr ("Plugin proxy failed: %s\n", error->message);
g_clear_error (&error);
goto cleanup;
} }
g_print ("Command hook id=%d\n", command_id);
if (!dbus_g_proxy_call (remote_object, "HookServer", if (argc > 1)
&error, command = g_strjoinv (" ", &argv[1]);
G_TYPE_STRING, "RAW LINE", else
G_TYPE_INT, 0, command = g_strdup ("gui focus");
G_TYPE_INT, 0, G_TYPE_INVALID,
G_TYPE_UINT, &server_id, G_TYPE_INVALID)) { if (!call_sync (plugin_proxy, "Command", g_variant_new ("(s)", command), NULL))
write_error ("Failed to complete HookServer", &error); {
return EXIT_FAILURE; g_object_unref (plugin_proxy);
goto cleanup;
} }
g_print ("Server hook id=%d\n", server_id);
dbus_g_object_register_marshaller ( call_sync (connection_proxy, "Disconnect", g_variant_new ("()"), NULL);
_zoitechat_marshal_VOID__POINTER_POINTER_UINT_UINT, status = EXIT_SUCCESS;
G_TYPE_NONE, g_object_unref (plugin_proxy);
G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_object_register_marshaller ( cleanup:
g_cclosure_marshal_VOID__VOID, g_free (command);
G_TYPE_NONE, g_free (remote_path);
G_TYPE_INVALID); g_object_unref (connection_proxy);
g_object_unref (connection);
dbus_g_proxy_add_signal (remote_object, "CommandSignal", return status;
G_TYPE_STRV,
G_TYPE_STRV,
G_TYPE_UINT,
G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (remote_object, "CommandSignal",
G_CALLBACK (test_command_cb),
NULL, NULL);
dbus_g_proxy_add_signal (remote_object, "ServerSignal",
G_TYPE_STRV,
G_TYPE_STRV,
G_TYPE_UINT,
G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (remote_object, "ServerSignal",
G_CALLBACK (test_server_cb),
NULL, NULL);
dbus_g_proxy_add_signal (remote_object, "UnloadSignal",
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (remote_object, "UnloadSignal",
G_CALLBACK (unload_cb),
NULL, NULL);
/* Now you can write on the ZoiteChat windows: "/test arg1 arg2 ..." */
mainloop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (mainloop);
return EXIT_SUCCESS;
} }

View File

@@ -1,6 +1,4 @@
dbus_deps = [ dbus_deps = []
dbus_glib_dep
]
dbus_sources = [ dbus_sources = [
'dbus-plugin.c', 'dbus-plugin.c',
@@ -35,16 +33,8 @@ configure_file(
install_dir: dbus_service_dir install_dir: dbus_service_dir
) )
dbus_binding_tool = find_program('dbus-binding-tool')
dbus_remote_object = custom_target('remote-object-glue',
input: 'remote-object.xml',
output: 'remote-object-glue.h',
command: [dbus_binding_tool, '--prefix=remote_object', '--mode=glib-server',
'--output=@OUTPUT@', '@INPUT@']
)
zoitechat_dbus = static_library('zoitechatdbus', zoitechat_dbus = static_library('zoitechatdbus',
sources: [dbus_remote_object, marshal] + dbus_sources, sources: marshal + dbus_sources,
c_args: dbus_cargs, c_args: dbus_cargs,
dependencies: common_deps + dbus_deps, dependencies: common_deps + dbus_deps,
include_directories: dbus_includes, include_directories: dbus_includes,

View File

@@ -115,7 +115,7 @@ if libssl_dep.found()
common_deps += libssl_dep common_deps += libssl_dep
endif endif
if dbus_glib_dep.found() if dbus_dep.found()
subdir('dbus') subdir('dbus')
common_deps += zoitechat_dbus_dep common_deps += zoitechat_dbus_dep
common_includes += include_directories('dbus') common_includes += include_directories('dbus')