Exemplo n.º 1
0
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, pa_bool_t use_rtclock, DBusBusType type, DBusError *error) {
    DBusConnection *conn;
    pa_dbus_wrap_connection *pconn;
    char *id;

    pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);

    if (!(conn = dbus_bus_get_private(type, error)))
        return NULL;

    pconn = pa_xnew(pa_dbus_wrap_connection, 1);
    pconn->mainloop = m;
    pconn->connection = conn;
    pconn->use_rtclock = use_rtclock;

    dbus_connection_set_exit_on_disconnect(conn, FALSE);
    dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL);
    dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, pconn, NULL);
    dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, pconn, NULL);
    dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL);

    pconn->dispatch_event = pconn->mainloop->defer_new(pconn->mainloop, dispatch_cb, conn);

    pa_log_debug("Successfully connected to D-Bus %s bus %s as %s",
                 type == DBUS_BUS_SYSTEM ? "system" : (type == DBUS_BUS_SESSION ? "session" : "starter"),
                 pa_strnull((id = dbus_connection_get_server_id(conn))),
                 pa_strnull(dbus_bus_get_unique_name(conn)));

    dbus_free(id);

    return pconn;
}
Exemplo n.º 2
0
SIGNAL_CALLBACK_ID add_signal_callback(JSContextRef ctx, struct DBusObjectInfo *info,
        struct Signal *sig, JSObjectRef func)
{
    g_assert(sig != NULL);
    g_assert(func != NULL);

    if (__sig_info_hash == NULL) {
        __sig_info_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_hash_table_destroy);
    }

    char* server_id = dbus_connection_get_server_id(info->connection);
    char* key = g_strdup_printf("%s:%s:%s@%s", info->path, info->iface, sig->name, server_id);
    free(server_id);

    GHashTable *cbs = g_hash_table_lookup(__sig_info_hash, key);
    if (cbs == NULL) {
	cbs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_info_free);
	g_hash_table_insert(__sig_info_hash, key, cbs);
    }

    struct SignalInfo* sig_info = g_new0(struct SignalInfo, 1);
    sig_info->name = sig->name;
    sig_info->signatures = sig->signature;
    sig_info->path = info->path;
    sig_info->iface = info->iface;
    sig_info->callback = func;
    JSValueProtect(ctx, func);

    SIGNAL_CALLBACK_ID id = (SIGNAL_CALLBACK_ID)GPOINTER_TO_INT(func);
    g_hash_table_insert(cbs, GINT_TO_POINTER((int)id), sig_info);
    return id;
}
Exemplo n.º 3
0
DBusHandlerResult watch_signal(DBusConnection* connection, DBusMessage *msg,
        void *no_use)
{
    NOUSED(no_use);
    if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    if (__sig_info_hash == NULL)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;


    const char* iface = dbus_message_get_interface(msg);
    const char* s_name = dbus_message_get_member(msg);
    const char* path = dbus_message_get_path(msg);

    char* server_id = dbus_connection_get_server_id(connection);
    char* key = g_strdup_printf("%s:%s:%s@%s", path, iface, s_name, server_id);
    free(server_id);

    GHashTable* cbs_info  = g_hash_table_lookup(__sig_info_hash, key);
    g_free(key);

    if (cbs_info == NULL) {
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    } else {
	struct HandleSignalInfo *t = g_new(struct HandleSignalInfo, 1);
	t->cbs = cbs_info;
	t->msg = dbus_message_ref(msg);
	g_timeout_add(get_timeout(), delay_handle_signal, t);
        return DBUS_HANDLER_RESULT_HANDLED;
    }
}
Exemplo n.º 4
0
static int ldbus_connection_get_server_id(lua_State *L) {
	DBusConnection *connection = check_DBusConnection(L, 1);

	char *result = dbus_connection_get_server_id(connection);
	if (result == NULL) {
		lua_pushnil(L);
	} else {
		lua_pushstring(L, result);
	}

	return 1;
}
Exemplo n.º 5
0
int
main (int    argc,
      char **argv)
{
  DBusError error;
  DBusConnection *connection;
  char *id;
  char *server_id;
  
  dbus_error_init (&error);
  connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
  if (connection == NULL)
    {
      fprintf (stderr, "*** Failed to open connection to system bus: %s\n",
               error.message);
      dbus_error_free (&error);
      return 1;
    }

  server_id = dbus_connection_get_server_id (connection);
  if (server_id == NULL)
    die ("No bus server ID retrieved\n");
  /* printf("'%s'\n", server_id); */
  if (strlen (server_id) != 32)
    die ("Bus server id should have length 32\n");
  dbus_free (server_id);

  id = dbus_bus_get_id (connection, NULL);
  if (id == NULL)
    die ("No bus ID retrieved\n");
  /* printf("'%s'\n", id); */
  if (strlen (id) != 32)
    die ("Bus ID should have length 32\n");
  dbus_free (id);  
  
  _dbus_verbose ("*** Test IDs exiting\n");
  
  return 0;
}