Пример #1
0
/**
 * Process a list_win D-Bus request.
 */
static bool
cdbus_process_list_win(session_t *ps, DBusMessage *msg) {
  cdbus_reply(ps, msg, cdbus_apdarg_wids, NULL);

  return true;
}
Пример #2
0
/**
 * Process a message from D-Bus.
 */
static void
cdbus_process(session_t *ps, DBusMessage *msg) {
  bool success = false;

#define cdbus_m_ismethod(method) \
  dbus_message_is_method_call(msg, CDBUS_INTERFACE_NAME, method)

  if (cdbus_m_ismethod("reset")) {
    ps->reset = true;
    if (!dbus_message_get_no_reply(msg))
      cdbus_reply_bool(ps, msg, true);
    success = true;
  }
  else if (cdbus_m_ismethod("repaint")) {
    force_repaint(ps);
    if (!dbus_message_get_no_reply(msg))
      cdbus_reply_bool(ps, msg, true);
    success = true;
  }
  else if (cdbus_m_ismethod("list_win")) {
    success = cdbus_process_list_win(ps, msg);
  }
  else if (cdbus_m_ismethod("win_get")) {
    success = cdbus_process_win_get(ps, msg);
  }
  else if (cdbus_m_ismethod("win_set")) {
    success = cdbus_process_win_set(ps, msg);
  }
  else if (cdbus_m_ismethod("find_win")) {
    success = cdbus_process_find_win(ps, msg);
  }
  else if (cdbus_m_ismethod("opts_get")) {
    success = cdbus_process_opts_get(ps, msg);
  }
  else if (cdbus_m_ismethod("opts_set")) {
    success = cdbus_process_opts_set(ps, msg);
  }
#undef cdbus_m_ismethod
  else if (dbus_message_is_method_call(msg,
        "org.freedesktop.DBus.Introspectable", "Introspect")) {
    success = cdbus_process_introspect(ps, msg);
  }
  else if (dbus_message_is_method_call(msg,
        "org.freedesktop.DBus.Peer", "Ping")) {
    cdbus_reply(ps, msg, NULL, NULL);
    success = true;
  }
  else if (dbus_message_is_method_call(msg,
        "org.freedesktop.DBus.Peer", "GetMachineId")) {
    char *uuid = dbus_get_local_machine_id();
    if (uuid) {
      cdbus_reply_string(ps, msg, uuid);
      dbus_free(uuid);
      success = true;
    }
  }
  else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired")
      || dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameLost")) {
    success = true;
  }
  else {
    if (DBUS_MESSAGE_TYPE_ERROR == dbus_message_get_type(msg)) {
      printf_errf("(): Error message of path \"%s\" "
          "interface \"%s\", member \"%s\", error \"%s\"",
          dbus_message_get_path(msg), dbus_message_get_interface(msg),
          dbus_message_get_member(msg), dbus_message_get_error_name(msg));
    }
    else {
      printf_errf("(): Illegal message of type \"%s\", path \"%s\" "
          "interface \"%s\", member \"%s\"",
          cdbus_repr_msgtype(msg), dbus_message_get_path(msg),
          dbus_message_get_interface(msg), dbus_message_get_member(msg));
    }
    if (DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
        && !dbus_message_get_no_reply(msg))
      cdbus_reply_err(ps, msg, CDBUS_ERROR_BADMSG, CDBUS_ERROR_BADMSG_S);
    success = true;
  }

  // If the message could not be processed, and an reply is expected, return
  // an empty reply.
  if (!success && DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
      && !dbus_message_get_no_reply(msg))
    cdbus_reply_err(ps, msg, CDBUS_ERROR_UNKNOWN, CDBUS_ERROR_UNKNOWN_S);

  // Free the message
  dbus_message_unref(msg);
}