Repository: libsdl-org/SDL
File: src/core/linux/SDL_dbus.c (C)

Code before:
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_dbus.h"
#include "../../stdlib/SDL_vacopy.h"

#ifdef SDL_USE_LIBDBUS
// we never link directly to libdbus.
#define SDL_DRIVER_DBUS_DYNAMIC "libdbus-1.so.3"
static const char *dbus_library = SDL_DRIVER_DBUS_DYNAMIC;
static SDL_SharedObject *dbus_handle = NULL;
static char *inhibit_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus;

SDL_ELF_NOTE_DLOPEN(
    "core-libdbus",
    "Support for DBus RPC",
    SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED,
    SDL_DRIVER_DBUS_DYNAMIC
);

static bool LoadDBUSSyms(void)
{
#define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y)                   \
    dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y)

#define SDL_DBUS_SYM2(TYPE, x, y)                            \
    if (!(dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y))) \
        return false

#define SDL_DBUS_SYM_OPTIONAL(TYPE, x) \
    SDL_DBUS_SYM2_OPTIONAL(TYPE, x, dbus_##x)

#define SDL_DBUS_SYM(TYPE, x) \
    SDL_DBUS_SYM2(TYPE, x, dbus_##x)

    SDL_DBUS_SYM(DBusConnection *(*)(DBusBusType, DBusError *), bus_get_private);
    SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, DBusError *), bus_register);
    SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_add_match);
    SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_remove_match);
    SDL_DBUS_SYM(const char *(*)(DBusConnection *), bus_get_unique_name);
    SDL_DBUS_SYM(DBusConnection *(*)(const char *, DBusError *), connection_open_private);

Review comment (suggestion):
```suggestion
    "Support for D-Bus IPC",
```

It's called D-Bus, and using it in a way that is genuinely remote (between computers) is strongly discouraged this decade.

Code after:
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_dbus.h"
#include "../../stdlib/SDL_vacopy.h"

#ifdef SDL_USE_LIBDBUS
// we never link directly to libdbus.
#define SDL_DRIVER_DBUS_DYNAMIC "libdbus-1.so.3"
static const char *dbus_library = SDL_DRIVER_DBUS_DYNAMIC;
static SDL_SharedObject *dbus_handle = NULL;
static char *inhibit_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus;

SDL_ELF_NOTE_DLOPEN(
    "core-libdbus",
    "Support for D-Bus IPC",
    SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
    SDL_DRIVER_DBUS_DYNAMIC
);

static bool LoadDBUSSyms(void)
{
#define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y)                   \
    dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y)

#define SDL_DBUS_SYM2(TYPE, x, y)                            \
    if (!(dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y))) \
        return false

#define SDL_DBUS_SYM_OPTIONAL(TYPE, x) \
    SDL_DBUS_SYM2_OPTIONAL(TYPE, x, dbus_##x)

#define SDL_DBUS_SYM(TYPE, x) \
    SDL_DBUS_SYM2(TYPE, x, dbus_##x)

    SDL_DBUS_SYM(DBusConnection *(*)(DBusBusType, DBusError *), bus_get_private);
    SDL_DBUS_SYM(dbus_bool_t (*)(DBusConnection *, DBusError *), bus_register);
    SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_add_match);
    SDL_DBUS_SYM(void (*)(DBusConnection *, const char *, DBusError *), bus_remove_match);
    SDL_DBUS_SYM(const char *(*)(DBusConnection *), bus_get_unique_name);
    SDL_DBUS_SYM(DBusConnection *(*)(const char *, DBusError *), connection_open_private);