コード例 #1
0
static void
miner_data_free (MinerData *data)
{
	if (data->watch_name_id != 0) {
		g_bus_unwatch_name (data->watch_name_id);
	}

	if (data->progress_signal) {
		g_dbus_connection_signal_unsubscribe (data->connection,
		                                      data->progress_signal);
	}

	if (data->paused_signal) {
		g_dbus_connection_signal_unsubscribe (data->connection,
		                                      data->paused_signal);
	}

	if (data->resumed_signal) {
		g_dbus_connection_signal_unsubscribe (data->connection,
		                                      data->resumed_signal);
	}

	if (data->connection) {
		g_object_unref (data->connection);
	}

	if (data->manager) {
		g_object_weak_unref (data->manager, data_manager_weak_notify, data);
	}

	g_free (data->dbus_path);
	g_free (data->display_name);
	g_slice_free (MinerData, data);
}
コード例 #2
0
static void CALETearDownDBus(CALEContext * context)
{
    assert(context != NULL);

    /*
      Minimize the time we hold the global lock by only clearing the
      global state, and pushing resource finalization outside the global
      lock.
    */
    ca_mutex_lock(context->lock);

    GDBusConnection * const connection = context->connection;
    context->connection = NULL;

    GDBusObjectManager * const object_manager = context->object_manager;
    context->object_manager = NULL;

    GList * const objects = context->objects;
    context->objects = NULL;

    GList * const adapters = context->adapters;
    context->adapters = NULL;

    GList * const devices = context->devices;
    context->devices = NULL;

    guint const interfaces_added   = context->interfaces_added_sub_id;
    guint const interfaces_removed = context->interfaces_removed_sub_id;

    context->interfaces_added_sub_id   = 0;
    context->interfaces_removed_sub_id = 0;

    ca_mutex_unlock(context->lock);

    // Destroy the device proxies list.
    g_list_free_full(devices, g_object_unref);

    // Destroy the adapter proxies list.
    g_list_free_full(adapters, g_object_unref);

    // Destroy the list of objects obtained from the ObjectManager.
    g_list_free_full(objects, g_object_unref);

    // Destroy the ObjectManager proxy.
    if (object_manager != NULL)
    {
        g_object_unref(object_manager);
    }

    // Tear down the D-Bus connection to the system bus.
    if (connection != NULL)
    {
        g_dbus_connection_signal_unsubscribe(connection,
                                             interfaces_added);
        g_dbus_connection_signal_unsubscribe(connection,
                                             interfaces_removed);
        g_object_unref(connection);
    }
}
コード例 #3
0
static void
gdm_local_display_factory_stop_monitor (GdmLocalDisplayFactory *factory)
{
        if (factory->priv->seat_new_id) {
                g_dbus_connection_signal_unsubscribe (factory->priv->connection,
                                                      factory->priv->seat_new_id);
                factory->priv->seat_new_id = 0;
        }
        if (factory->priv->seat_removed_id) {
                g_dbus_connection_signal_unsubscribe (factory->priv->connection,
                                                      factory->priv->seat_removed_id);
                factory->priv->seat_removed_id = 0;
        }
}
コード例 #4
0
ファイル: tlm-manager.c プロジェクト: zenny/tlm
static void
_manager_unsubsribe_seat_changes (TlmManager *manager)
{
    if (manager->priv->seat_added_id) {
        g_dbus_connection_signal_unsubscribe (manager->priv->connection,
                                              manager->priv->seat_added_id);
        manager->priv->seat_added_id = 0;
    }

    if (manager->priv->seat_removed_id) {
        g_dbus_connection_signal_unsubscribe (manager->priv->connection,
                                              manager->priv->seat_removed_id);
        manager->priv->seat_removed_id = 0;
    }
}
コード例 #5
0
ファイル: secret-prompt.c プロジェクト: Arkhont/libsecret
static void
perform_prompt_complete (GSimpleAsyncResult *res,
                         gboolean dismissed)
{
	PerformClosure *closure = g_simple_async_result_get_op_res_gpointer (res);

	closure->dismissed = dismissed;
	if (closure->completed)
		return;
	closure->completed = TRUE;

	if (closure->signal)
		g_dbus_connection_signal_unsubscribe (closure->connection, closure->signal);
	closure->signal = 0;

	if (closure->watch)
		g_bus_unwatch_name (closure->watch);
	closure->watch = 0;

	if (closure->cancelled_sig)
		g_signal_handler_disconnect (closure->async_cancellable, closure->cancelled_sig);
	closure->cancelled_sig = 0;

	g_simple_async_result_complete (res);
}
コード例 #6
0
ファイル: gdbusnamewatching.c プロジェクト: GNOME/glib
/* Could be called from any thread, so it could be called after client_unref()
 * has started finalising the #Client. Avoid that by looking up the #Client
 * atomically. */
static void
on_connection_disconnected (GDBusConnection *connection,
                            gboolean         remote_peer_vanished,
                            GError          *error,
                            gpointer         user_data)
{
  guint watcher_id = GPOINTER_TO_UINT (user_data);
  Client *client = NULL;

  client = dup_client (watcher_id);
  if (client == NULL)
    return;

  if (client->name_owner_changed_subscription_id > 0)
    g_dbus_connection_signal_unsubscribe (client->connection, client->name_owner_changed_subscription_id);
  if (client->disconnected_signal_handler_id > 0)
    g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
  g_object_unref (client->connection);
  client->disconnected_signal_handler_id = 0;
  client->name_owner_changed_subscription_id = 0;
  client->connection = NULL;

  call_vanished_handler (client, FALSE);

  client_unref (client);
}
コード例 #7
0
static void
gkd_secret_service_dispose (GObject *obj)
{
	GkdSecretService *self = GKD_SECRET_SERVICE (obj);

	if (self->name_owner_id) {
		g_dbus_connection_signal_unsubscribe (self->connection, self->name_owner_id);
		self->name_owner_id = 0;
	}

	if (self->filter_id) {
		g_dbus_connection_remove_filter (self->connection, self->filter_id);
		self->filter_id = 0;
	}

	/* Closes all the clients */
	g_hash_table_remove_all (self->clients);

	/* Hide all the objects */
	if (self->objects) {
		g_object_run_dispose (G_OBJECT (self->objects));
		g_object_unref (self->objects);
		self->objects = NULL;
	}

	g_clear_object (&self->connection);

	if (self->internal_session) {
		dispose_and_unref (self->internal_session);
		self->internal_session = NULL;
	}

	G_OBJECT_CLASS (gkd_secret_service_parent_class)->dispose (obj);
}
コード例 #8
0
LauncherEntryRemoteModel::~LauncherEntryRemoteModel()
{
  if (_conn)
  {
    if (_launcher_entry_dbus_signal_id)
    {
      g_dbus_connection_signal_unsubscribe(_conn,
                                           _launcher_entry_dbus_signal_id);
    }

    if (_dbus_name_owner_changed_signal_id)
    {
      g_dbus_connection_signal_unsubscribe(_conn,
                                           _dbus_name_owner_changed_signal_id);
    }
  }
}
コード例 #9
0
ファイル: loginkitd.c プロジェクト: Happy-Ferret/LoginKit
static void signals_unsubscribe(void)
{
	GDBusConnection *bus;

	bus = bus_get();
	if (NULL == bus)
		return;

	if (0 != g_added_signal) {
		g_dbus_connection_signal_unsubscribe(bus, g_added_signal);
		g_added_signal = 0;
	}

	if (0 != g_removed_signal) {
		g_dbus_connection_signal_unsubscribe(bus, g_removed_signal);
		g_removed_signal = 0;
	}
}
コード例 #10
0
ファイル: login1.c プロジェクト: davvid/lightdm
static void
login1_service_finalize (GObject *object)
{
    Login1Service *self = LOGIN1_SERVICE (object);

    g_list_free_full (self->priv->seats, g_object_unref);
    g_dbus_connection_signal_unsubscribe (self->priv->connection, self->priv->signal_id);
    g_object_unref (self->priv->connection);

    G_OBJECT_CLASS (login1_service_parent_class)->finalize (object);
}
コード例 #11
0
ファイル: login1.c プロジェクト: davvid/lightdm
static void
login1_seat_finalize (GObject *object)
{
    Login1Seat *self = LOGIN1_SEAT (object);

    g_free (self->priv->id);
    g_free (self->priv->path);
    g_dbus_connection_signal_unsubscribe (self->priv->connection, self->priv->signal_id);
    g_object_unref (self->priv->connection);

    G_OBJECT_CLASS (login1_seat_parent_class)->finalize (object);
}
コード例 #12
0
static void
on_connection_disconnected (GDBusConnection *connection,
                            gboolean         remote_peer_vanished,
                            GError          *error,
                            gpointer         user_data)
{
  Client *client = user_data;

  if (client->disconnected_signal_handler_id > 0)
    g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
  if (client->name_acquired_subscription_id > 0)
    g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
  if (client->name_lost_subscription_id > 0)
    g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
  g_object_unref (client->connection);
  client->disconnected_signal_handler_id = 0;
  client->name_acquired_subscription_id = 0;
  client->name_lost_subscription_id = 0;
  client->connection = NULL;

  call_lost_handler (client);
}
コード例 #13
0
static void
client_unref (Client *client)
{
  if (g_atomic_int_dec_and_test (&client->ref_count))
    {
      if (client->connection != NULL)
        {
          if (client->disconnected_signal_handler_id > 0)
            g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
          if (client->name_acquired_subscription_id > 0)
            g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
          if (client->name_lost_subscription_id > 0)
            g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
          g_object_unref (client->connection);
        }
      if (client->main_context != NULL)
        g_main_context_unref (client->main_context);
      g_free (client->name);
      if (client->user_data_free_func != NULL)
        client->user_data_free_func (client->user_data);
      g_free (client);
    }
}
コード例 #14
0
static void
dis_connection_cb (NMBusManager *mgr,
                   GDBusConnection *connection,
                   NMDhcpListener *self)
{
	NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
	guint id;

	id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->signal_handlers, connection));
	if (id) {
		g_dbus_connection_signal_unsubscribe (connection, id);
		g_hash_table_remove (priv->signal_handlers, connection);
	}
}
コード例 #15
0
BT_EXPORT_API int bluetooth_telephony_deinit(void)
{
	GDBusConnection *conn = NULL;
	BT_DBG("+");

	BT_TELEPHONY_CHECK_INITIALIZED();

	is_initialized = FALSE;

	conn = _bt_init_system_gdbus_conn();
	if (!conn) {
		is_initialized = FALSE;
		return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
	}

	g_dbus_connection_signal_unsubscribe(conn,
		telephony_dbus_info.monitor_filter_id_bluez_headset);

	g_dbus_connection_signal_unsubscribe(conn,
		telephony_dbus_info.monitor_filter_id_hfp_agent);

	if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED)
		__bluetooth_telephony_unregister();

	/*__bluetooth_telephony_proxy_deinit();*/
	telephony_info.cb = NULL;
	telephony_info.user_data = NULL;
	telephony_info.call_count = 0;
	telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;

	g_dbus_connection_signal_unsubscribe(conn,
		telephony_dbus_info.monitor_filter_id_bluez_manager);

	BT_DBG("-");
	return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
コード例 #16
0
ファイル: ev-daemon.c プロジェクト: Achal-Aggarwal/atril
static void
document_loaded_cb (GDBusConnection *connection,
		    const gchar     *sender_name,
		    const gchar     *object_path,
		    const gchar     *interface_name,
		    const gchar     *signal_name,
		    GVariant        *parameters,
		    EvDoc           *doc)
{
	const gchar *uri;

	g_variant_get (parameters, "(&s)", &uri);
	if (strcmp (uri, doc->uri) == 0)
		process_pending_invocations (uri, sender_name);
	g_dbus_connection_signal_unsubscribe (connection, doc->loaded_id);
}
コード例 #17
0
static void
gupnp_connman_manager_dispose (GObject *object)
{
        GUPnPConnmanManager        *manager;
        GUPnPConnmanManagerPrivate *priv;
        GObjectClass               *object_class;
        GDBusConnection            *cnx;

        manager = GUPNP_CONNMAN_MANAGER (object);
        priv = manager->priv;
        cnx = g_dbus_proxy_get_connection (priv->manager_proxy);

        if (priv->sig_change_id) {
                g_dbus_connection_signal_unsubscribe (cnx, priv->sig_change_id);
                priv->sig_change_id = 0;
        }

        if (priv->idle_context_creation_src) {
                g_source_destroy (priv->idle_context_creation_src);
                priv->idle_context_creation_src = NULL;
        }

        if (priv->manager_proxy != NULL) {
                g_object_unref (priv->manager_proxy);
                priv->manager_proxy = NULL;
        }

        if (priv->cm_services) {
                g_hash_table_destroy (priv->cm_services);
                priv->cm_services = NULL;
        }

        if (priv->cancellable != NULL)  {
                g_cancellable_cancel (priv->cancellable);
                g_object_unref (priv->cancellable);
                priv->cancellable = NULL;
        }

        g_clear_object (&(priv->system_bus));

        /* Call super */
        object_class = G_OBJECT_CLASS (gupnp_connman_manager_parent_class);
        object_class->dispose (object);
}
コード例 #18
0
static void testDocumentLoadedSignal(WebViewTest* test, gconstpointer)
{
    GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
        "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
    GDBusConnection* connection = g_dbus_proxy_get_connection(proxy.get());
    guint id = g_dbus_connection_signal_subscribe(connection,
        0,
        "org.webkit.gtk.WebExtensionTest",
        "DocumentLoaded",
        "/org/webkit/gtk/WebExtensionTest",
        0,
        G_DBUS_SIGNAL_FLAGS_NONE,
        reinterpret_cast<GDBusSignalCallback>(documentLoadedCallback),
        test,
        0);
    g_assert(id);

    test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0);
    g_main_loop_run(test->m_mainLoop);
    g_dbus_connection_signal_unsubscribe(connection, id);
}
コード例 #19
0
static void
filechooser_portal_data_free (FilechooserPortalData *data)
{
  if (data->portal_response_signal_id != 0)
    g_dbus_connection_signal_unsubscribe (data->connection,
                                          data->portal_response_signal_id);

  g_object_unref (data->connection);

  if (data->grab_widget)
    {
      gtk_grab_remove (data->grab_widget);
      gtk_widget_destroy (data->grab_widget);
    }

  g_clear_object (&data->self);

  g_free (data->portal_handle);

  g_free (data);
}
コード例 #20
0
static void
namespace_watcher_stop (gpointer data)
{
  NamespaceWatcher *watcher = data;

  g_cancellable_cancel (watcher->cancellable);
  g_object_unref (watcher->cancellable);

  if (watcher->subscription_id)
    g_dbus_connection_signal_unsubscribe (watcher->connection, watcher->subscription_id);

  if (watcher->vanished_handler)
    {
      GHashTableIter it;
      const gchar *name;

      g_hash_table_iter_init (&it, watcher->names);
      while (g_hash_table_iter_next (&it, (gpointer *) &name, NULL))
        watcher->vanished_handler (watcher->connection, name, watcher->user_data);
    }

  if (watcher->user_data_destroy)
    watcher->user_data_destroy (watcher->user_data);

  if (watcher->connection)
    {
      g_signal_handlers_disconnect_by_func (watcher->connection, connection_closed, watcher);
      g_object_unref (watcher->connection);
    }

  g_hash_table_unref (watcher->names);

  g_hash_table_remove (namespace_watcher_watchers, GUINT_TO_POINTER (watcher->id));
  if (g_hash_table_size (namespace_watcher_watchers) == 0)
    g_clear_pointer (&namespace_watcher_watchers, g_hash_table_destroy);

  g_free (watcher->name_space);

  g_free (watcher);
}
コード例 #21
0
static void
ephy_embed_shell_shutdown (GApplication* application)
{
  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (EPHY_EMBED_SHELL (application));

  G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->shutdown (application);

  webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "overview");
  webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "tlsErrorPage");
  webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "formAuthData");
  webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "aboutApps");

  if (priv->web_extensions_page_created_signal_id > 0) {
    g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_page_created_signal_id);
    priv->web_extensions_page_created_signal_id = 0;
  }

  g_list_foreach (priv->web_extensions, (GFunc)ephy_embed_shell_unwatch_web_extension, application);

  g_object_unref (ephy_embed_prefs_get_settings ());
  ephy_embed_utils_shutdown ();
}
コード例 #22
0
ファイル: wait4signal.c プロジェクト: kraused/ptywatch
int main(int argc, char **argv)
{
	GMainLoop *loop;
	GDBusConnection *conn;
	GError *error;
	guint subscr;

	loop = g_main_loop_new(NULL, FALSE);

	error = NULL;
	conn  = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
	if (UNLIKELY(!conn)) {
		PTYWATCH_ERROR("Failed to get bus: %s\n", error->message);
		g_error_free(error);
		return -1;
	}

	subscr = g_dbus_connection_signal_subscribe(conn,
	                                            NULL, /* sender */
	                                            "org.freedesktop.PtyWatchDbusSignal", /* interface */
	                                            NULL, /* member */
	                                            "/org/freedesktop/PtyWatchDbusSignal", /* object path */
	                                            NULL, /* arg0 */
	                                            G_DBUS_SIGNAL_FLAGS_NONE,
	                                            On_Caught_Signal,
	                                            argv[1],
	                                            NULL);

	g_main_loop_run(loop);

	g_dbus_connection_signal_unsubscribe(conn, subscr);
	g_object_unref(G_OBJECT(conn));
	g_main_loop_unref(loop);

	return 0;
}
コード例 #23
0
static void
cm_service_free (CMService *cm_service)
{
        if (cm_service->proxy != NULL) {
                GDBusConnection *cnx;

                cnx = g_dbus_proxy_get_connection (cm_service->proxy);

                if (cm_service->sig_prop_id) {
                        g_dbus_connection_signal_unsubscribe (cnx,
                                                              cm_service->sig_prop_id);
                        cm_service->sig_prop_id = 0;
                }

                g_object_unref (cm_service->proxy);
        }

        if (cm_service->cancellable != NULL) {
                g_cancellable_cancel (cm_service->cancellable);
                g_object_unref (cm_service->cancellable);
        }

        service_context_remove_creation_timeout (cm_service);

        if (cm_service->context != NULL) {
                g_signal_emit_by_name (cm_service->manager,
                                       "context-unavailable",
                                       cm_service->context);

                g_object_unref (cm_service->context);
        }

        g_free (cm_service->iface);
        g_free (cm_service->name);
        g_slice_free (CMService, cm_service);
}
コード例 #24
0
void eas_gdbus_progress_unsubscribe (struct eas_gdbus_client *client,
				     guint handle)
{
	g_dbus_connection_signal_unsubscribe (client->connection, handle);
}
コード例 #25
0
/**
 * g_bus_unown_name:
 * @owner_id: An identifier obtained from g_bus_own_name()
 *
 * Stops owning a name.
 *
 * Since: 2.26
 */
void
g_bus_unown_name (guint owner_id)
{
  Client *client;

  g_return_if_fail (owner_id > 0);

  client = NULL;

  G_LOCK (lock);
  if (owner_id == 0 || map_id_to_client == NULL ||
      (client = g_hash_table_lookup (map_id_to_client, GUINT_TO_POINTER (owner_id))) == NULL)
    {
      g_warning ("Invalid id %d passed to g_bus_unown_name()", owner_id);
      goto out;
    }

  client->cancelled = TRUE;
  g_warn_if_fail (g_hash_table_remove (map_id_to_client, GUINT_TO_POINTER (owner_id)));

 out:
  G_UNLOCK (lock);

  /* do callback without holding lock */
  if (client != NULL)
    {
      /* Release the name if needed */
      if (client->needs_release && client->connection != NULL)
        {
          GVariant *result;
          GError *error;
          guint32 release_name_reply;

          /* TODO: it kinda sucks having to do a sync call to release the name - but if
           * we don't, then a subsequent grab of the name will make the bus daemon return
           * IN_QUEUE which will trigger name_lost().
           *
           * I believe this is a bug in the bus daemon.
           */
          error = NULL;
          result = g_dbus_connection_call_sync (client->connection,
                                                "org.freedesktop.DBus",  /* bus name */
                                                "/org/freedesktop/DBus", /* object path */
                                                "org.freedesktop.DBus",  /* interface name */
                                                "ReleaseName",           /* method name */
                                                g_variant_new ("(s)", client->name),
                                                G_VARIANT_TYPE ("(u)"),
                                                G_DBUS_CALL_FLAGS_NONE,
                                                -1,
                                                NULL,
                                                &error);
          if (result == NULL)
            {
              g_warning ("Error releasing name %s: %s", client->name, error->message);
              g_error_free (error);
            }
          else
            {
              g_variant_get (result, "(u)", &release_name_reply);
              if (release_name_reply != 1 /* DBUS_RELEASE_NAME_REPLY_RELEASED */)
                {
                  g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
                }
              g_variant_unref (result);
            }
        }

      if (client->disconnected_signal_handler_id > 0)
        g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
      if (client->name_acquired_subscription_id > 0)
        g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
      if (client->name_lost_subscription_id > 0)
        g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
      client->disconnected_signal_handler_id = 0;
      client->name_acquired_subscription_id = 0;
      client->name_lost_subscription_id = 0;
      if (client->connection != NULL)
        {
          g_object_unref (client->connection);
          client->connection = NULL;
        }

      client_unref (client);
    }
}
コード例 #26
0
static void
prepare_print_response (GDBusConnection *connection,
                        const char      *sender_name,
                        const char      *object_path,
                        const char      *interface_name,
                        const char      *signal_name,
                        GVariant        *parameters,
                        gpointer         data)
{
  PortalData *portal = data;
  guint32 response;
  GVariant *options;

  if (portal->response_signal_id != 0)
    {
      g_dbus_connection_signal_unsubscribe (connection,
                                            portal->response_signal_id);
      portal->response_signal_id = 0;
    }

  g_variant_get (parameters, "(u@a{sv})", &response, &options);

  portal->do_print = (response == 0);

  if (portal->do_print)
    {
      GVariant *v;
      GtkPrintSettings *settings;
      GtkPageSetup *page_setup;
      GtkPrinter *printer;
      char *filename;
      char *uri;
      int fd;

      portal->result = GTK_PRINT_OPERATION_RESULT_APPLY;

      v = g_variant_lookup_value (options, "settings", G_VARIANT_TYPE_VARDICT);
      settings = gtk_print_settings_new_from_gvariant (v);
      g_variant_unref (v);

      v = g_variant_lookup_value (options, "page-setup", G_VARIANT_TYPE_VARDICT);
      page_setup = gtk_page_setup_new_from_gvariant (v);
      g_variant_unref (v);

      g_variant_lookup (options, "token", "u", &portal->token);

      printer = find_file_printer ();

      fd = g_file_open_tmp ("gtkprintXXXXXX", &filename, NULL);
      uri = g_filename_to_uri (filename, NULL, NULL);
      gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
      g_free (uri);
      close (fd);

      finish_print (portal, printer, page_setup, settings);
      g_free (filename);
    }
  else
    portal->result = GTK_PRINT_OPERATION_RESULT_CANCEL;

  if (portal->loop)
    g_main_loop_quit (portal->loop);
}
コード例 #27
0
static void
g_dbus_menu_path_deactivate (GDBusMenuPath *path)
{
  if (--path->active == 0)
    g_dbus_connection_signal_unsubscribe (path->id->connection, path->watch_id);
}
コード例 #28
0
ファイル: builder-utils.c プロジェクト: sanjayankur31/flatpak
gboolean
builder_host_spawnv (GFile                *dir,
                     char                **output,
                     GError              **error,
                     const gchar * const  *argv)
{
  guint32 client_pid;
  GVariantBuilder *fd_builder = g_variant_builder_new (G_VARIANT_TYPE("a{uh}"));
  GVariantBuilder *env_builder = g_variant_builder_new (G_VARIANT_TYPE("a{ss}"));
  g_autoptr(GUnixFDList) fd_list = g_unix_fd_list_new ();
  gint stdout_handle, stdin_handle, stderr_handle;
  g_autoptr(GDBusConnection) connection = NULL;
  g_autoptr(GVariant) ret = NULL;
  g_autoptr(GMainLoop) loop = NULL;
  g_auto(GStrv) env_vars = NULL;
  guint subscription;
  HostCommandCallData data = { NULL };
  guint sigterm_id = 0, sigint_id = 0;
  g_autofree gchar *commandline = NULL;
  g_autoptr(GOutputStream) out = NULL;
  int pipefd[2];
  int i;

  commandline = flatpak_quote_argv ((const char **) argv);
  g_debug ("Running '%s' on host", commandline);

  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
  if (connection == NULL)
    return FALSE;

  loop = g_main_loop_new (NULL, FALSE);
  data.connection = connection;
  data.loop = loop;
  data.refs = 1;

  subscription = g_dbus_connection_signal_subscribe (connection,
                                                     NULL,
                                                     "org.freedesktop.Flatpak.Development",
                                                     "HostCommandExited",
                                                     "/org/freedesktop/Flatpak/Development",
                                                     NULL,
                                                     G_DBUS_SIGNAL_FLAGS_NONE,
                                                     host_command_exited_cb,
                                                     &data, NULL);

  stdin_handle = g_unix_fd_list_append (fd_list, 0, error);
  if (stdin_handle == -1)
    return FALSE;

  if (output)
    {
      g_autoptr(GInputStream) in = NULL;

      if (pipe2 (pipefd, O_CLOEXEC) != 0)
        {
          glnx_set_error_from_errno (error);
          return FALSE;
        }

      data.refs++;
      in = g_unix_input_stream_new (pipefd[0], TRUE);
      out = g_memory_output_stream_new_resizable ();
      g_output_stream_splice_async (out,
                                    in,
                                    G_OUTPUT_STREAM_SPLICE_NONE,
                                    0,
                                    NULL,
                                    output_spliced_cb,
                                    &data);
      stdout_handle = g_unix_fd_list_append (fd_list, pipefd[1], error);
      close (pipefd[1]);
      if (stdout_handle == -1)
        return FALSE;
    }
  else
    {
      stdout_handle = g_unix_fd_list_append (fd_list, 1, error);
      if (stdout_handle == -1)
        return FALSE;
    }

  stderr_handle = g_unix_fd_list_append (fd_list, 2, error);
  if (stderr_handle == -1)
    return FALSE;

  g_variant_builder_add (fd_builder, "{uh}", 0, stdin_handle);
  g_variant_builder_add (fd_builder, "{uh}", 1, stdout_handle);
  g_variant_builder_add (fd_builder, "{uh}", 2, stderr_handle);

  env_vars = g_listenv ();
  for (i = 0; env_vars[i] != NULL; i++)
    {
      const char *env_var = env_vars[i];
      g_variant_builder_add (env_builder, "{ss}", env_var, g_getenv (env_var));
    }

  sigterm_id = g_unix_signal_add (SIGTERM, sigterm_handler, &data);
  sigint_id = g_unix_signal_add (SIGINT, sigint_handler, &data);

  ret = g_dbus_connection_call_with_unix_fd_list_sync (connection,
                                                       "org.freedesktop.Flatpak",
                                                       "/org/freedesktop/Flatpak/Development",
                                                       "org.freedesktop.Flatpak.Development",
                                                       "HostCommand",
                                                       g_variant_new ("(^ay^aay@a{uh}@a{ss}u)",
                                                                      dir ? flatpak_file_get_path_cached (dir) : "",
                                                                      argv,
                                                                      g_variant_builder_end (fd_builder),
                                                                      g_variant_builder_end (env_builder),
                                                                      FLATPAK_HOST_COMMAND_FLAGS_CLEAR_ENV),
                                                       G_VARIANT_TYPE ("(u)"),
                                                       G_DBUS_CALL_FLAGS_NONE, -1,
                                                       fd_list, NULL,
                                                       NULL, error);

  if (ret == NULL)
    return FALSE;


  g_variant_get (ret, "(u)", &client_pid);
  data.client_pid = client_pid;

  g_main_loop_run (loop);

  g_source_remove (sigterm_id);
  g_source_remove (sigint_id);
  g_dbus_connection_signal_unsubscribe (connection, subscription);

  if (!g_spawn_check_exit_status (data.exit_status, error))
    return FALSE;

  if (out)
    {
      if (data.splice_error)
        {
          g_propagate_error (error, data.splice_error);
          return FALSE;
        }

      /* Null terminate */
      g_output_stream_write (out, "\0", 1, NULL, NULL);
      g_output_stream_close (out, NULL, NULL);
      *output = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (out));
    }

  return TRUE;
}