Module: DBus::Binding

Defined in:
ext/ruby-dbus-connection.c,
lib/dbus/binding.rb,
ext/ruby-dbus-common.c

Overview

The DBus::Binding module contains the internal binding classes that map directly to the D-BUS C API.

Defined Under Namespace

Classes: DBusConnection, DBusMessage, DBusMessageIter, DBusPendingCall, DBusServer

Class Method Summary collapse

Class Method Details

.bus_acquire_service(connection, service_name, [flags = 0]) ⇒ Object

Asks the bus connected to the given connection to acquire a service. This can be useful for ensuring only one instance of your program is running.


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'ext/ruby-dbus-bus.c', line 121

static VALUE
mDBusBinding_bus_acquire_service(int argc, VALUE *argv)
{
  VALUE conn;
  VALUE name;
  VALUE flags; int service_flags;
  int ret;

  conn = name = flags = Qnil;
  service_flags = 0;
  rb_scan_args(argc, argv, "21", &conn, &name, &flags);
  if (flags != Qnil)
    service_flags = NUM2INT(flags);
  ret = 0;
  RDBUS_TRY(
    ret = dbus_bus_acquire_service(CONN_GET(conn),
                                   StringValuePtr(name),
                                   service_flags,
                                   &error)
  );
  return INT2FIX(ret);
}

.bus_activate_service(connection, service_name, [flags = 0]) ⇒ Array

Activates the given service. The flags parameter currently (D-BUS 0.22) does nothing.

Returns:

  • (Array)

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'ext/ruby-dbus-bus.c', line 213

static VALUE
mDBusBinding_bus_activate_service(int argc, VALUE *argv)
{
  VALUE conn;
  VALUE name;
  VALUE flags;
  dbus_uint32_t service_flags;
  dbus_uint32_t result;
  VALUE ret;
  dbus_bool_t dbus_ret;

  conn = name = flags = Qnil;
  service_flags = 0;
  rb_scan_args(argc, argv, "21", &conn, &name, &flags);
  if (flags != Qnil)
    service_flags = NUM2INT(flags);

  result = 0;
  dbus_ret = FALSE;
  RDBUS_TRY(
    dbus_ret = dbus_bus_activate_service(CONN_GET(conn), StringValuePtr(name),
                                         service_flags, &result, &error)
  );

  ret = rb_ary_new();
  rb_ary_push(ret, dbus_ret ? Qtrue : Qfalse);
  rb_ary_push(ret, INT2NUM(result));
  return ret;
}

.bus_add_match(connection, rule) ⇒ nil

Adds a match rule on the given connection to match messages passing through the bus. A match rule is a string with key=value pairs seperated by commas.

Match keys:

type

matches the message type, which can be one of method_call, method_return, signal or error

interface

matches the interface field of a message

member

matches the member field of a message

path

matches the path field of a message

destination

matches the destination (recipient) of a message

In order to receive the messages matching rules added by this method, you will need to install a message filter on the connection using DBusConnection#add_filter

Returns:

  • (nil)

186
187
188
189
190
191
# File 'ext/ruby-dbus-bus.c', line 186

static VALUE
mDBusBinding_bus_add_match(VALUE klass, VALUE conn, VALUE rule)
{
  RDBUS_TRY(dbus_bus_add_match(CONN_GET(conn), StringValuePtr(rule), &error));
  return Qnil;
}

.bus_get_base_service(connection) ⇒ Object

Gets the base service name of the given connection. This value can be used for the destination field of a DBusMessage.


89
90
91
92
93
# File 'ext/ruby-dbus-bus.c', line 89

static VALUE
mDBusBinding_bus_get_base_service(VALUE klass, VALUE conn)
{
  return rb_str_new2(dbus_bus_get_base_service(CONN_GET(conn)));
}

.bus_get_unix_user(connection, service_name) ⇒ Object

Gets the UNIX user ID for for the given service on this bus.


101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/ruby-dbus-bus.c', line 101

static VALUE
mDBusBinding_bus_get_unix_user(VALUE klass, VALUE conn, VALUE name)
{
  VALUE uid;

  uid = -1;
  RDBUS_TRY(
    uid = LONG2NUM(dbus_bus_get_unix_user(CONN_GET(conn),
                                          StringValuePtr(name), &error))
  );
  return uid;
}

.bus_register(connection) ⇒ Object

Registers a connection with the bus


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'ext/ruby-dbus-bus.c', line 52

static VALUE
mDBusBinding_bus_register(VALUE klass, VALUE conn)
{
  dbus_bool_t ret;

  ret = FALSE;
  RDBUS_TRY(
    ret = dbus_bus_register(CONN_GET(conn), &error)
  );

  if (ret)
    return Qtrue;
  return Qfalse;
}

.bus_remove_match(connection, rule) ⇒ nil

Removes a match rule previously added with DBus::Binding#bus_add_match

Returns:

  • (nil)

199
200
201
202
203
204
# File 'ext/ruby-dbus-bus.c', line 199

static VALUE
mDBusBinding_bus_remove_match(VALUE klass, VALUE conn, VALUE rule)
{
  RDBUS_TRY(dbus_bus_remove_match(CONN_GET(conn), StringValuePtr(rule), &error));
  return Qnil;
}

.bus_service_exists(connection, service_name) ⇒ Object

Checks whether the given service exists on the bus, true is returned if it does, false otherwise.


151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'ext/ruby-dbus-bus.c', line 151

static VALUE
mDBusBinding_bus_service_exists(VALUE klass, VALUE conn, VALUE name)
{
  dbus_bool_t ret;

  ret = FALSE;
  RDBUS_TRY(
    ret = dbus_bus_service_exists(CONN_GET(conn), StringValuePtr(name),
                                  &error)
  );
  if (ret)
    return Qtrue;
  return Qfalse;
}

.bus_set_base_service(connection, base_service) ⇒ Object

Sets the base service name of the given connection.


74
75
76
77
78
79
80
# File 'ext/ruby-dbus-bus.c', line 74

static VALUE
mDBusBinding_bus_set_base_service(VALUE klass, VALUE conn, VALUE name)
{
  if (!dbus_bus_set_base_service(CONN_GET(conn), StringValuePtr(name)))
    return Qfalse;
  return Qtrue;
}

.init_gthreadsObject

Initializes Glib GThreads for usage by D-BUS.

This is only necessary for applications that will be using GThreads.


33
34
35
36
37
38
# File 'ext/ruby-dbus-common.c', line 33

static VALUE
mDBusBinding_init_gthreads(VALUE klass)
{
  dbus_g_thread_init();
  return Qnil;
}