gint
main (gint argc, gchar *argv[])
{
    GDBusObjectManager *manager;
    GMainLoop *loop;
    GError *error;
    gchar *name_owner;

    manager = NULL;
    loop = NULL;

    loop = g_main_loop_new (NULL, FALSE);

    error = NULL;
    manager = example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
              G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
              "org.gtk.GDBus.Examples.ObjectManager",
              "/example/Animals",
              NULL, /* GCancellable */
              &error);
    if (manager == NULL)
    {
        g_printerr ("Error getting object manager client: %s", error->message);
        g_error_free (error);
        goto out;
    }

    name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
    g_print ("name-owner: %s\n", name_owner);
    g_free (name_owner);

    print_objects (manager);

    g_signal_connect (manager,
                      "notify::name-owner",
                      G_CALLBACK (on_notify_name_owner),
                      NULL);
    g_signal_connect (manager,
                      "object-added",
                      G_CALLBACK (on_object_added),
                      NULL);
    g_signal_connect (manager,
                      "object-removed",
                      G_CALLBACK (on_object_removed),
                      NULL);
    g_signal_connect (manager,
                      "interface-proxy-properties-changed",
                      G_CALLBACK (on_interface_proxy_properties_changed),
                      NULL);

    g_main_loop_run (loop);

out:
    if (manager != NULL)
        g_object_unref (manager);
    if (loop != NULL)
        g_main_loop_unref (loop);

    return 0;
}
예제 #2
0
static void
on_manager_new (GObject *source,
                GAsyncResult *result,
                gpointer user_data)
{
        GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
        NewClosure *closure = g_simple_async_result_get_op_res_gpointer (async);
        GDBusConnection *connection;
        GError *error = NULL;
        GObject *object;

        object = g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error);
        if (error == NULL) {
                closure->manager = UM_REALM_MANAGER (object);
                connection = g_dbus_object_manager_client_get_connection (G_DBUS_OBJECT_MANAGER_CLIENT (object));

                g_debug ("Connected to realmd");

                um_realm_provider_proxy_new (connection,
                                             G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
                                             "org.freedesktop.realmd",
                                             "/org/freedesktop/realmd",
                                             closure->cancellable,
                                             on_provider_new, g_object_ref (async));
        } else {
                g_simple_async_result_take_error (async, error);
                g_simple_async_result_complete (async);
        }

        g_object_unref (async);
}
예제 #3
0
MMManager *
mmcli_get_manager_sync (GDBusConnection *connection)
{
    MMManager *manager;
    gchar *name_owner;
    GError *error = NULL;

    manager = mm_manager_new_sync (connection,
                                   G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
                                   NULL,
                                   &error);
    if (!manager) {
        g_printerr ("error: couldn't create manager: %s\n",
                    error ? error->message : "unknown error");
        exit (EXIT_FAILURE);
    }

    name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
    if (!name_owner) {
        g_printerr ("error: couldn't find the ModemManager process in the bus\n");
        exit (EXIT_FAILURE);
    }

    g_debug ("ModemManager process found at '%s'", name_owner);
    g_free (name_owner);

    return manager;
}
예제 #4
0
static void
manager_new_ready (GDBusConnection *connection,
                   GAsyncResult *res,
                   GSimpleAsyncResult *simple)
{
    MMManager *manager;
    gchar *name_owner;
    GError *error = NULL;

    manager = mm_manager_new_finish (res, &error);
    if (!manager) {
        g_printerr ("error: couldn't create manager: %s\n",
                    error ? error->message : "unknown error");
        exit (EXIT_FAILURE);
    }

    name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
    if (!name_owner) {
        g_printerr ("error: couldn't find the ModemManager process in the bus\n");
        exit (EXIT_FAILURE);
    }

    g_debug ("ModemManager process found at '%s'", name_owner);
    g_free (name_owner);



    g_simple_async_result_set_op_res_gpointer (simple, manager, NULL);
    g_simple_async_result_complete (simple);
    g_object_unref (simple);
}
static void
on_object_removed (GDBusObjectManager *manager,
                   GDBusObject        *object,
                   gpointer            user_data)
{
    gchar *owner;
    owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
    g_print ("Removed object at %s (owner %s)\n", g_dbus_object_get_object_path (object), owner);
    g_free (owner);
}
static void
on_notify_name_owner (GObject    *object,
                      GParamSpec *pspec,
                      gpointer    user_data)
{
    GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (object);
    gchar *name_owner;

    name_owner = g_dbus_object_manager_client_get_name_owner (manager);
    g_print ("name-owner: %s\n", name_owner);
    g_free (name_owner);
}
예제 #7
0
/*
 * the DBus.Tracker.Properties1 interface returns a list of strings
 * where each selected item brings up both its URI and its Caja
 * mime type.
 *
 * We return to the caller a GList of NASelectedInfo objects
 */
static GList *
targets_from_selection( void )
{
	static const gchar *thisfn = "caja_actions_run_targets_from_selection";
	GList *selection;
	GError *error;
	gchar **paths;

	g_debug( "%s", thisfn );

	selection = NULL;
	error = NULL;
	paths = NULL;

#ifdef HAVE_GDBUS
	GDBusObjectManager *manager;
	gchar *name_owner;
	GDBusObject *object;
	GDBusInterface *iface;

	manager = na_tracker_object_manager_client_new_for_bus_sync(
			G_BUS_TYPE_SESSION,
			G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
			CAJA_ACTIONS_DBUS_SERVICE,
			CAJA_ACTIONS_DBUS_TRACKER_PATH,
			NULL,
			&error );

	if( !manager ){
		g_printerr( "%s: unable to allocate an ObjectManagerClient: %s\n", thisfn, error->message );
		g_error_free( error );
		return( NULL );
	}

	name_owner = g_dbus_object_manager_client_get_name_owner( G_DBUS_OBJECT_MANAGER_CLIENT( manager ));
	g_debug( "%s: name_owner=%s", thisfn, name_owner );
	g_free( name_owner );

	object = g_dbus_object_manager_get_object( manager, CAJA_ACTIONS_DBUS_TRACKER_PATH "/0" );
	if( !object ){
		g_printerr( "%s: unable to get object at %s path\n", thisfn, CAJA_ACTIONS_DBUS_TRACKER_PATH "/0" );
		g_object_unref( manager );
		return( NULL );
	}

	iface = g_dbus_object_get_interface( object, CAJA_ACTIONS_DBUS_TRACKER_IFACE );
	if( !iface ){
		g_printerr( "%s: unable to get %s interface\n", thisfn, CAJA_ACTIONS_DBUS_TRACKER_IFACE );
		g_object_unref( object );
		g_object_unref( manager );
		return( NULL );
	}

	/* note that @iface is really a GDBusProxy instance
	 * and additionally also a NATrackerProperties1 instance
	 */
	na_tracker_properties1_call_get_selected_paths_sync(
			NA_TRACKER_PROPERTIES1( iface ),
			&paths,
			NULL,
			&error );

#else
# ifdef HAVE_DBUS_GLIB
	DBusGConnection *connection;
	DBusGProxy *proxy = NULL;

	connection = dbus_g_bus_get( DBUS_BUS_SESSION, &error );
	if( !connection ){
		if( error ){
			g_printerr( _( "Error: unable to get a connection to session DBus: %s" ), error->message );
			g_error_free( error );
		}
		return( NULL );
	}
	g_debug( "%s: connection is ok", thisfn );

	proxy = dbus_g_proxy_new_for_name( connection,
			CAJA_ACTIONS_DBUS_SERVICE,
			CAJA_ACTIONS_DBUS_TRACKER_PATH "/0",
			CAJA_ACTIONS_DBUS_TRACKER_IFACE );

	if( !proxy ){
		g_printerr( _( "Error: unable to get a proxy on %s service" ), CAJA_ACTIONS_DBUS_SERVICE );
		dbus_g_connection_unref( connection );
		return( NULL );
	}
	g_debug( "%s: proxy is ok", thisfn );

	if( !dbus_g_proxy_call( proxy, "GetSelectedPaths", &error,
			G_TYPE_INVALID,
			G_TYPE_STRV, &paths, G_TYPE_INVALID )){

		g_printerr( _( "Error on GetSelectedPaths call: %s" ), error->message );
		g_error_free( error );
		/* TODO: unref proxy */
		dbus_g_connection_unref( connection );
		return( NULL );
	}
	g_debug( "%s: function call is ok", thisfn );

	/* TODO: unref proxy */
	dbus_g_connection_unref( connection );
# endif
#endif

	selection = get_selection_from_strv(( const gchar ** ) paths, TRUE );

	g_strfreev( paths );

	return( selection );
}