static void
remove_account_remove_tp_account_cb (GObject       *source_object,
                                     GAsyncResult  *res,
                                     gpointer       user_data)
{
  GError *error;
  GTask *task = G_TASK (user_data);

  error = NULL;
  if (!goa_tp_account_linker_remove_tp_account_finish (tp_linker, res, &error))
    {
      g_task_return_error (task, error);
      goto out;
    }

  g_task_return_boolean (task, TRUE);

 out:
  g_object_unref (task);
}
/**
 * latexila_post_processor_process_finish:
 * @pp: a post-processor.
 * @result: a #GAsyncResult.
 * @succeeded: whether the subprocess has succeeded.
 *
 * Finishes an operation started with latexila_post_processor_process_async().
 * After calling this function, you can get the filtered messages with
 * latexila_post_processor_get_messages().
 */
void
latexila_post_processor_process_finish (LatexilaPostProcessor *pp,
                                        GAsyncResult          *result,
                                        gboolean               succeeded)
{
  g_return_if_fail (g_task_is_valid (result, pp));

  g_task_propagate_boolean (G_TASK (result), NULL);

  latexila_post_processor_end (pp, succeeded);

  g_clear_object (&pp->priv->task);
  g_clear_object (&pp->priv->stream);

  if (pp->priv->line_buffer != NULL)
    {
      g_string_free (pp->priv->line_buffer, TRUE);
      pp->priv->line_buffer = NULL;
    }
}
Example #3
0
/**
 * g_volume_eject_with_operation_finish:
 * @volume: a #GVolume
 * @result: a #GAsyncResult
 * @error: a #GError location to store the error occurring, or %NULL
 *
 * Finishes ejecting a volume. If any errors occurred during the operation,
 * @error will be set to contain the errors and %FALSE will be returned.
 *
 * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise
 *
 * Since: 2.22
 **/
gboolean
g_volume_eject_with_operation_finish (GVolume        *volume,
                                      GAsyncResult  *result,
                                      GError       **error)
{
  GVolumeIface *iface;

  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);

  if (g_async_result_legacy_propagate_error (result, error))
    return FALSE;
  else if (g_async_result_is_tagged (result, g_volume_eject_with_operation))
    return g_task_propagate_boolean (G_TASK (result), error);

  iface = G_VOLUME_GET_IFACE (volume);
  if (iface->eject_with_operation_finish != NULL)
    return (* iface->eject_with_operation_finish) (volume, result, error);
  else
    return (* iface->eject_finish) (volume, result, error);
}
Example #4
0
static void
on_get_pid_ready (GObject      *source_object,
                  GAsyncResult *res,
                  gpointer      user_data)
{
        GTask *task = G_TASK (user_data);
        gpointer *info = g_task_get_source_object (task);
        GClueClientInfoPrivate *priv = GCLUE_CLIENT_INFO (info)->priv;
        guint32 pid;
        GError *error = NULL;
        GVariant *results = NULL;

        results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
                                            res,
                                            &error);
        if (results == NULL) {
                g_task_return_error (task, error);
                g_object_unref (task);

                return;
        }

        g_assert (g_variant_n_children (results) > 0);
        g_variant_get_child (results, 0, "u", &pid);
        g_variant_unref (results);

        priv->xdg_id = get_xdg_id (pid);

        priv->watch_id = g_bus_watch_name_on_connection (priv->connection,
                                                         priv->bus_name,
                                                         G_BUS_NAME_WATCHER_FLAGS_NONE,
                                                         NULL,
                                                         on_name_vanished,
                                                         info,
                                                         NULL);

        g_task_return_boolean (task, TRUE);

        g_object_unref (task);
}
static gboolean
g_async_initable_real_init_finish (GAsyncInitable  *initable,
				   GAsyncResult    *res,
				   GError         **error)
{
  /* For backward compatibility we have to process GSimpleAsyncResults
   * even though g_async_initable_real_init_async doesn't generate
   * them any more.
   */
  if (G_IS_SIMPLE_ASYNC_RESULT (res))
    {
      GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
      if (g_simple_async_result_propagate_error (simple, error))
        return FALSE;
      else
        return TRUE;
    }

  g_return_val_if_fail (g_task_is_valid (res, initable), FALSE);

  return g_task_propagate_boolean (G_TASK (res), error);
}
Example #6
0
static void
download_banner_cb(GObject* source,
                   GAsyncResult* res,
                   gpointer udata)
{
    GError* error = NULL;

    GdkPixbuf* pic = g_task_propagate_pointer(G_TASK(res), &error);

    if (error)
    {
        g_error_free(error);
        return;
    }
    GtChannel* self = GT_CHANNEL(udata);
    GtChannelPrivate* priv = gt_channel_get_instance_private(self);

    set_banner(self, pic, TRUE, TRUE);

    priv->updating = FALSE;
    g_object_notify_by_pspec(G_OBJECT(self), props[PROP_UPDATING]);
}
static void
photos_single_item_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GTask *task = G_TASK (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor;
  GError *error;

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  tracker_sparql_cursor_next_async (cursor,
                                    g_task_get_cancellable (task),
                                    photos_single_item_job_cursor_next,
                                    g_object_ref (task));
  g_object_unref (cursor);
}
Example #8
0
static void
cd_profile_install_system_wide_cb (GObject *source_object,
				   GAsyncResult *res,
				   gpointer user_data)
{
	g_autoptr(GError) error = NULL;
	g_autoptr(GTask) task = G_TASK (user_data);
	g_autoptr(GVariant) result = NULL;

	result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
					   res,
					   &error);
	if (result == NULL) {
		cd_profile_fixup_dbus_error (error);
		g_task_return_error (task, error);
		error = NULL;
		return;
	}

	/* success */
	g_task_return_boolean (task, TRUE);
}
static void
search_providers_discover_ready (GObject *source,
                                 GAsyncResult *result,
                                 gpointer user_data)
{
  GList *providers, *l;
  GFile *provider;
  CcSearchPanel *self = CC_SEARCH_PANEL (source);
  GError *error = NULL;

  providers = g_task_propagate_pointer (G_TASK (result), &error);

  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
    {
      g_error_free (error);
      return;
    }

  g_clear_object (&self->priv->load_cancellable);

  if (providers == NULL)
    {
      search_panel_set_no_providers (self);
      return;
    }

  for (l = providers; l != NULL; l = l->next)
    {
      provider = l->data;
      search_panel_add_one_provider (self, provider);
      g_object_unref (provider);
    }

  /* propagate a write to GSettings, to make sure we always have
   * all the providers in the list.
   */
  search_panel_propagate_sort_order (self);
  g_list_free (providers);
}
Example #10
0
static void
photos_glib_file_copy_create (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GFile) unique_file = NULL;
  GFile *destination = G_FILE (source_object);
  GFile *source;
  g_autoptr (GFileOutputStream) ostream = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  PhotosGLibFileCopyData *data;

  cancellable = g_task_get_cancellable (task);
  data = (PhotosGLibFileCopyData *) g_task_get_task_data (task);
  source = G_FILE (g_task_get_source_object (task));

  {
    g_autoptr (GError) error = NULL;

    ostream = photos_glib_file_create_finish (destination, res, &unique_file, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->ostream);
  g_assert_true (G_IS_FILE_OUTPUT_STREAM (ostream));
  data->ostream = g_object_ref (ostream);

  g_assert_null (data->unique_file);
  g_assert_true (G_IS_FILE (unique_file));
  data->unique_file = g_object_ref (unique_file);

  g_file_read_async (source, data->io_priority, cancellable, photos_glib_file_copy_read, g_object_ref (task));

 out:
  return;
}
static void
done_cb (GObject         *const object,
         GAsyncResult    *const result,
         NulMusicService *const music)
{

  g_autoptr(GError) error = NULL;
  g_autoptr(GTask) task = G_TASK (result);

  AsyncSparqlWork *const work = (AsyncSparqlWork *) g_task_propagate_pointer (
    task,
    &error
  );

  GDBusMethodInvocation *const invo = work->invo;
  GVariant *const variant = work->variant;

  g_dbus_method_invocation_return_value (
    invo,
    g_variant_new_tuple (&variant, 1)
  );

}
Example #12
0
static gboolean
ide_langserv_rename_provider_rename_finish (IdeRenameProvider  *provider,
                                            GAsyncResult       *result,
                                            GPtrArray         **edits,
                                            GError            **error)
{
  IdeLangservRenameProvider *self = (IdeLangservRenameProvider *)provider;
  g_autoptr(GPtrArray) ar = NULL;
  gboolean ret;

  IDE_ENTRY;

  g_assert (IDE_IS_LANGSERV_RENAME_PROVIDER (self));
  g_assert (G_IS_TASK (result));

  ar = g_task_propagate_pointer (G_TASK (result), error);
  ret = (ar != NULL);

  if (edits != NULL)
    *edits = g_steal_pointer (&ar);

  IDE_RETURN (ret);
}
Example #13
0
static void
photos_thumbnailer_generate_thumbnail_stream_close (GObject *source_object,
                                                    GAsyncResult *res,
                                                    gpointer user_data)
{
  GOutputStream *stream = G_OUTPUT_STREAM (source_object);
  g_autoptr (GTask) task = G_TASK (user_data);

  {
    g_autoptr (GError) error = NULL;

    if (!g_output_stream_close_finish (stream, res, &error))
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_task_return_boolean (task, TRUE);

 out:
  return;
}
Example #14
0
static GInputStream *
g_loadable_icon_real_load_finish (GLoadableIcon        *icon,
				  GAsyncResult         *res,
				  char                **type,
				  GError              **error)
{
  GTask *task;
  LoadData *data;
  GInputStream *stream;

  g_return_val_if_fail (g_task_is_valid (res, icon), NULL);

  task = G_TASK (res);
  data = g_task_get_task_data (task);

  stream = g_task_propagate_pointer (task, error);
  if (stream && type)
    {
      *type = data->type;
      data->type = NULL;
    }

  return stream;
}
Example #15
0
/**
 * g_dbus_address_get_stream_finish:
 * @res: A #GAsyncResult obtained from the GAsyncReadyCallback passed to g_dbus_address_get_stream().
 * @out_guid: %NULL or return location to store the GUID extracted from @address, if any.
 * @error: Return location for error or %NULL.
 *
 * Finishes an operation started with g_dbus_address_get_stream().
 *
 * Returns: (transfer full): A #GIOStream or %NULL if @error is set.
 *
 * Since: 2.26
 */
GIOStream *
g_dbus_address_get_stream_finish (GAsyncResult        *res,
                                  gchar              **out_guid,
                                  GError             **error)
{
  GTask *task;
  GetStreamData *data;
  GIOStream *ret;

  g_return_val_if_fail (g_task_is_valid (res, NULL), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  task = G_TASK (res);
  ret = g_task_propagate_pointer (task, error);

  if (ret != NULL && out_guid != NULL)
    {
      data = g_task_get_task_data (task);
      *out_guid = data->guid;
      data->guid = NULL;
    }

  return ret;
}
Example #16
0
static void
cd_profile_set_property_cb (GObject *source_object,
			    GAsyncResult *res,
			    gpointer user_data)
{
	g_autoptr(GError) error = NULL;
	g_autoptr(GTask) task = G_TASK (user_data);
	g_autoptr(GVariant) result = NULL;

	result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
					   res,
					   &error);
	if (result == NULL) {
		g_task_return_new_error (task,
						 CD_PROFILE_ERROR,
						 CD_PROFILE_ERROR_INTERNAL,
						 "Failed to SetProperty: %s",
						 error->message);
		return;
	}

	/* success */
	g_task_return_boolean (task, TRUE);
}
Example #17
0
/**
 * g_tls_interaction_ask_password_finish:
 * @interaction: a #GTlsInteraction object
 * @result: the result passed to the callback
 * @error: an optional location to place an error on failure
 *
 * Complete an ask password user interaction request. This should be once
 * the g_tls_interaction_ask_password_async() completion callback is called.
 *
 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsPassword passed
 * to g_tls_interaction_ask_password() will have its password filled in.
 *
 * If the interaction is cancelled by the cancellation object, or by the
 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
 * contains a %G_IO_ERROR_CANCELLED error code.
 *
 * Returns: The status of the ask password interaction.
 *
 * Since: 2.30
 */
GTlsInteractionResult
g_tls_interaction_ask_password_finish (GTlsInteraction    *interaction,
                                       GAsyncResult       *result,
                                       GError            **error)
{
  GTlsInteractionClass *klass;

  g_return_val_if_fail (G_IS_TLS_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED);
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), G_TLS_INTERACTION_UNHANDLED);

  klass = G_TLS_INTERACTION_GET_CLASS (interaction);
  if (klass->ask_password_finish)
    {
      g_return_val_if_fail (klass->ask_password_async != NULL, G_TLS_INTERACTION_UNHANDLED);

      return (klass->ask_password_finish) (interaction, result, error);
    }
  else
    {
      g_return_val_if_fail (g_async_result_is_tagged (result, g_tls_interaction_ask_password_async), G_TLS_INTERACTION_UNHANDLED);

      return g_task_propagate_int (G_TASK (result), error);
    }
}
Example #18
0
static GdkPixbuf *
load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **error)
{
  return g_task_propagate_pointer (G_TASK (result), error);
}
Example #19
0
static void
photos_thumbnailer_generate_thumbnail_pipeline (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GTask) task = G_TASK (user_data);
  g_autoptr (PhotosPipeline) pipeline = NULL;
  PhotosThumbnailerGenerateData *data;
  gboolean has_crop;
  g_autofree gchar *path = NULL;
  g_autofree gchar *uri = NULL;
  gdouble height;
  gdouble width;
  gdouble x;
  gdouble y;
  gint load_height;
  gint load_width;

  cancellable = g_task_get_cancellable (task);
  data = g_task_get_task_data (task);

  {
    g_autoptr (GError) error = NULL;

    pipeline = photos_pipeline_new_finish (res, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->pipeline);
  data->pipeline = g_object_ref (pipeline);

  uri = g_file_get_uri (data->file);

  has_crop = photos_pipeline_get (pipeline,
                                  "gegl:crop",
                                  "height", &height,
                                  "width", &width,
                                  "x", &x,
                                  "y", &y,
                                  NULL);
  if (has_crop)
    {
      if (height < 0.0 || width < 0.0 || x < 0.0 || y < 0.0)
        {
          g_warning ("Unable to crop the thumbnail for %s: Invalid parameters", uri);

          photos_pipeline_remove (pipeline, "gegl:crop");
          has_crop = FALSE;
        }
    }

  if (has_crop
      || (0 < data->original_height
          && data->original_height < data->thumbnail_size
          && 0 < data->original_width
          && data->original_width < data->thumbnail_size))
    {
      load_height = (gint) data->original_height;
      load_width = (gint) data->original_width;
    }
  else
    {
      load_height = data->thumbnail_size;
      load_width = data->thumbnail_size;
    }

  path = g_file_get_path (data->file);
  if (!g_file_is_native (data->file))
    photos_debug (PHOTOS_DEBUG_NETWORK, "Downloading %s (%s)", uri, path);

  photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Loading %s at %d×%d", uri, load_width, load_height);
  photos_pixbuf_new_from_file_at_size_async (path,
                                             load_width,
                                             load_height,
                                             cancellable,
                                             photos_thumbnailer_generate_thumbnail_pixbuf,
                                             g_object_ref (task));

 out:
  return;
}
Example #20
0
static void
photos_thumbnailer_generate_thumbnail_process (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GFile) thumbnail_file = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  GeglNode *pipeline_node;
  GeglProcessor *processor = GEGL_PROCESSOR (source_object);
  PhotosThumbnailerGenerateData *data;
  g_autofree gchar *thumbnail_dir = NULL;
  gdouble zoom = 0.0;
  gint pixbuf_height;
  gint pixbuf_width;
  gint pixbuf_zoomed_height;
  gint pixbuf_zoomed_width;

  cancellable = g_task_get_cancellable (task);
  data = g_task_get_task_data (task);

  {
    g_autoptr (GError) error = NULL;

    if (!photos_gegl_processor_process_finish (processor, res, &error))
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->pixbuf_thumbnail);

  pipeline_node = photos_pipeline_get_graph (data->pipeline);
  data->pixbuf_thumbnail = photos_gegl_create_pixbuf_from_node (pipeline_node);
  pixbuf_height = gdk_pixbuf_get_height (data->pixbuf_thumbnail);
  pixbuf_width = gdk_pixbuf_get_width (data->pixbuf_thumbnail);

  if (pixbuf_height > pixbuf_width && pixbuf_height > data->thumbnail_size)
    {
      zoom = (gdouble) data->thumbnail_size / (gdouble) pixbuf_height;
      pixbuf_zoomed_height = data->thumbnail_size;
      pixbuf_zoomed_width = (gint) (zoom * (gdouble) pixbuf_width + 0.5);
    }
  else if (pixbuf_height <= pixbuf_width && pixbuf_width > data->thumbnail_size)
    {
      zoom = (gdouble) data->thumbnail_size / (gdouble) pixbuf_width;
      pixbuf_zoomed_height = (gint) (zoom * (gdouble) pixbuf_height + 0.5);
      pixbuf_zoomed_width = data->thumbnail_size;
    }

  if (zoom > 0.0)
    {
      g_autoptr (GdkPixbuf) pixbuf_scaled = NULL;

      photos_debug (PHOTOS_DEBUG_THUMBNAILER,
                    "Scaling thumbnail to %d×%d",
                    pixbuf_zoomed_width,
                    pixbuf_zoomed_height);

      pixbuf_scaled = gdk_pixbuf_scale_simple (data->pixbuf_thumbnail,
                                               pixbuf_zoomed_width,
                                               pixbuf_zoomed_height,
                                               GDK_INTERP_BILINEAR);

      g_set_object (&data->pixbuf_thumbnail, pixbuf_scaled);
    }

  thumbnail_dir = g_path_get_dirname (data->thumbnail_path);
  g_mkdir_with_parents (thumbnail_dir, 0700);

  thumbnail_file = g_file_new_for_path (data->thumbnail_path);

  photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Saving thumbnail to %s", data->thumbnail_path);
  g_file_replace_async (thumbnail_file,
                        NULL,
                        FALSE,
                        G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
                        G_PRIORITY_DEFAULT,
                        cancellable,
                        photos_thumbnailer_generate_thumbnail_replace,
                        g_object_ref (task));

 out:
  return;
}
void
metadata_fetch_finished (GObject *object,
                         GAsyncResult *res,
                         gpointer user_data)
{
  EosUpdater *updater = EOS_UPDATER (object);
  GTask *task;
  GError *error = NULL;
  EosUpdaterData *data = user_data;
  OstreeRepo *repo = data->repo;
  g_autoptr(EosUpdateInfo) info = NULL;

  if (!g_task_is_valid (res, object))
    goto invalid_task;

  /* get the info about the fetched update */
  task = G_TASK (res);
  info = g_task_propagate_pointer (task, &error);

  if (info != NULL)
    {
      gint64 archived = -1;
      gint64 unpacked = -1;
      gint64 new_archived = 0;
      gint64 new_unpacked = 0;
      const gchar *label;
      const gchar *message;

      g_set_object (&data->extensions, info->extensions);
      g_strfreev (data->overridden_urls);
      data->overridden_urls = g_steal_pointer (&info->urls);

      /* Everything is happy thusfar */
      /* if we have a checksum for the remote upgrade candidate
       * and it's ≠ what we're currently booted into, advertise it as such.
       */
      eos_updater_clear_error (updater, EOS_UPDATER_STATE_UPDATE_AVAILABLE);
      eos_updater_set_update_id (updater, info->checksum);
      eos_updater_set_update_refspec (updater, info->refspec);
      eos_updater_set_original_refspec (updater, info->original_refspec);

      g_variant_get_child (info->commit, 3, "&s", &label);
      g_variant_get_child (info->commit, 4, "&s", &message);
      eos_updater_set_update_label (updater, label ? label : "");
      eos_updater_set_update_message (updater, message ? message : "");

      if (ostree_repo_get_commit_sizes (repo, info->checksum,
                                        &new_archived, &new_unpacked,
                                        NULL,
                                        &archived, &unpacked,
                                        NULL,
                                        g_task_get_cancellable (task),
                                        &error))
        {
          eos_updater_set_full_download_size (updater, archived);
          eos_updater_set_full_unpacked_size (updater, unpacked);
          eos_updater_set_download_size (updater, new_archived);
          eos_updater_set_unpacked_size (updater, new_unpacked);
          eos_updater_set_downloaded_bytes (updater, 0);
        }
      else /* no size data available (may or may not be an error) */
        {
          eos_updater_set_full_download_size (updater, -1);
          eos_updater_set_full_unpacked_size (updater, -1);
          eos_updater_set_download_size (updater, -1);
          eos_updater_set_unpacked_size (updater, -1);
          eos_updater_set_downloaded_bytes (updater, -1);

          /* shouldn't actually stop us offering an update, as long
           * as the branch itself is resolvable in the next step,
           * but log it anyway.
           */
          if (error)
            {
              g_message ("No size summary data: %s", error->message);
              g_clear_error (&error);
            }
        }
    }
  else /* info == NULL means OnHold=true, nothing to do here */
    eos_updater_clear_error (updater, EOS_UPDATER_STATE_READY);

  if (error)
    {
      eos_updater_set_error (updater, error);
      g_clear_error (&error);
    }
  return;

 invalid_task:
  /* Either the threading or the memory management is shafted. Or both.
   * We're boned. Log an error and activate the self destruct mechanism.
   */
  g_error ("Invalid async task object when returning from Poll() thread!");
  g_assert_not_reached ();
}
gchar *
screenshot_build_filename_finish (GAsyncResult *result,
                                  GError **error)
{
  return g_task_propagate_pointer (G_TASK (result), error);
}
Example #23
0
gboolean
cd_sensor_set_options_finish (CdSensor *sensor, GAsyncResult *res, GError **error)
{
	g_return_val_if_fail (g_task_is_valid (res, sensor), FALSE);
	return g_task_propagate_boolean (G_TASK (res), error);
}
Example #24
0
static gboolean initiate_authentication_finish(PolkitAgentListener *listener,
				 GAsyncResult *res, GError **error)
{
	g_debug("initiate_authentication_finish");
	return !g_task_propagate_boolean(G_TASK(res), error);
}
Example #25
0
CdColorXYZ *
cd_sensor_get_sample_finish (CdSensor *sensor, GAsyncResult *res, GError **error)
{
	g_return_val_if_fail (g_task_is_valid (res, sensor), NULL);
	return g_task_propagate_pointer (G_TASK (res), error);
}
Example #26
0
gboolean
gd_queue_thumbnail_job_for_file_finish (GAsyncResult *res, GError **error)
{
  GTask *task = G_TASK (res);
  return g_task_propagate_boolean (task, error);
}
Example #27
0
static void abrt_p2_task_finish_gtask(GObject *source_object,
           GAsyncResult *result,
           gpointer user_data)
{
    AbrtP2Task *task = ABRT_P2_TASK(source_object);

    if (!g_task_is_valid(result, task))
    {
        error_msg("BUG:%s:%s: invalid GTask", __FILE__, __func__);
        return;
    }

    GError *error = NULL;
    const gint32 code = g_task_propagate_int(G_TASK(result), &error);

    if (code == ABRT_P2_TASK_CODE_STOP)
    {
        log_debug("Task stopped");

        abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_STOPPED);
    }
    else if (code >= ABRT_P2_TASK_CODE_DONE)
    {
        log_debug("Task done");

        task->pv->p2t_code = code - ABRT_P2_TASK_CODE_DONE;
        abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_DONE);
    }
    else if (abrt_p2_task_is_cancelled(task))
    {
        if (error != NULL)
        {
            log_debug("Task canceled with error: %s", error->message);

            g_error_free(error);
            error = NULL;
        }
        else
            log_debug("Task canceled");

        ABRT_P2_TASK_VIRTUAL_CANCEL(task, &error);
        abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_CANCELED);
    }
    else
    {
        GVariantDict response;
        g_variant_dict_init(&response, NULL);

        if (error != NULL)
        {
            log_debug("Task failed with error: %s", error->message);

            g_variant_dict_insert(&response,
                                  "Error.Message",
                                  "s",
                                  error->message);

            g_error_free(error);
        }
        else if (code == ABRT_P2_TASK_CODE_ERROR)
        {
            log_debug("Task failed without error message");

            g_variant_dict_insert(&response,
                                  "Error.Message",
                                  "s",
                                  "Task failed");
        }
        else
        {
            error_msg("BUG:%s:%s: unknown Task return code: %d",
                      __FILE__,
                      __func__,
                      code);

            g_variant_dict_insert(&response,
                                  "Error.Message",
                                  "s",
                                  "Internal error: Invalid Task return code");
        }

        abrt_p2_task_set_response(task, g_variant_dict_end(&response));
        abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_FAILED);
    }

    g_object_unref(task->pv->p2t_cancellable);
    task->pv->p2t_cancellable = NULL;
}
Example #28
0
static void
cd_profile_connect_cb (GObject *source_object,
		       GAsyncResult *res,
		       gpointer user_data)
{
	CdProfile *profile;
	CdProfilePrivate *priv;
	g_autoptr(GError) error = NULL;
	g_autoptr(GTask) task = G_TASK (user_data);
	g_autoptr(GVariant) colorspace = NULL;
	g_autoptr(GVariant) created = NULL;
	g_autoptr(GVariant) filename = NULL;
	g_autoptr(GVariant) format = NULL;
	g_autoptr(GVariant) has_vcgt = NULL;
	g_autoptr(GVariant) id = NULL;
	g_autoptr(GVariant) is_system_wide = NULL;
	g_autoptr(GVariant) kind = NULL;
	g_autoptr(GVariant) metadata = NULL;
	g_autoptr(GVariant) owner = NULL;
	g_autoptr(GVariant) qualifier = NULL;
	g_autoptr(GVariant) scope = NULL;
	g_autoptr(GVariant) title = NULL;
	g_autoptr(GVariant) warnings = NULL;

	profile = CD_PROFILE (g_task_get_source_object (task));
	priv = GET_PRIVATE (profile);
	priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
	if (priv->proxy == NULL) {
		g_task_return_new_error (task,
						 CD_PROFILE_ERROR,
						 CD_PROFILE_ERROR_INTERNAL,
						 "Failed to connect to profile %s: %s",
						 cd_profile_get_object_path (profile),
						 error->message);
		return;
	}

	/* get profile id */
	id = g_dbus_proxy_get_cached_property (priv->proxy,
					       CD_PROFILE_PROPERTY_ID);
	if (id != NULL)
		priv->id = g_variant_dup_string (id, NULL);

	/* if the profile is missing, then fail */
	if (id == NULL) {
		g_task_return_new_error (task,
						 CD_PROFILE_ERROR,
						 CD_PROFILE_ERROR_INTERNAL,
						 "Failed to connect to missing profile %s",
						 cd_profile_get_object_path (profile));
		return;
	}

	/* get filename */
	filename = g_dbus_proxy_get_cached_property (priv->proxy,
						     CD_PROFILE_PROPERTY_FILENAME);
	if (filename != NULL)
		priv->filename = cd_profile_get_nullable_str (filename);

	/* get qualifier */
	qualifier = g_dbus_proxy_get_cached_property (priv->proxy,
						      CD_PROFILE_PROPERTY_QUALIFIER);
	if (qualifier != NULL)
		priv->qualifier = cd_profile_get_nullable_str (qualifier);

	/* get format */
	format = g_dbus_proxy_get_cached_property (priv->proxy,
						   CD_PROFILE_PROPERTY_FORMAT);
	if (format != NULL)
		priv->format = cd_profile_get_nullable_str (format);

	/* get title */
	title = g_dbus_proxy_get_cached_property (priv->proxy,
						  CD_PROFILE_PROPERTY_TITLE);
	if (title != NULL)
		priv->title = cd_profile_get_nullable_str (title);

	/* get kind */
	kind = g_dbus_proxy_get_cached_property (priv->proxy,
						 CD_PROFILE_PROPERTY_KIND);
	if (kind != NULL)
		priv->kind = cd_profile_kind_from_string (g_variant_get_string (kind, NULL));

	/* get colorspace */
	colorspace = g_dbus_proxy_get_cached_property (priv->proxy,
						       CD_PROFILE_PROPERTY_COLORSPACE);
	if (colorspace != NULL)
		priv->colorspace = cd_colorspace_from_string (g_variant_get_string (colorspace, NULL));

	/* get scope */
	scope = g_dbus_proxy_get_cached_property (priv->proxy,
						  CD_PROFILE_PROPERTY_SCOPE);
	if (scope != NULL)
		priv->scope = cd_object_scope_from_string (g_variant_get_string (scope, NULL));

	/* get owner */
	owner = g_dbus_proxy_get_cached_property (priv->proxy,
						  CD_PROFILE_PROPERTY_OWNER);
	if (owner != NULL)
		priv->owner = g_variant_get_uint32 (owner);

	/* get warnings */
	warnings = g_dbus_proxy_get_cached_property (priv->proxy,
						  CD_PROFILE_PROPERTY_WARNINGS);
	if (warnings != NULL)
		priv->warnings = g_variant_dup_strv (warnings, NULL);

	/* get created */
	created = g_dbus_proxy_get_cached_property (priv->proxy,
						    CD_PROFILE_PROPERTY_CREATED);
	if (created != NULL)
		priv->created = g_variant_get_int64 (created);

	/* get VCGT */
	has_vcgt = g_dbus_proxy_get_cached_property (priv->proxy,
						     CD_PROFILE_PROPERTY_HAS_VCGT);
	if (has_vcgt != NULL)
		priv->has_vcgt = g_variant_get_boolean (has_vcgt);

	/* get if system wide */
	is_system_wide = g_dbus_proxy_get_cached_property (priv->proxy,
							   CD_PROFILE_PROPERTY_IS_SYSTEM_WIDE);
	if (is_system_wide != NULL)
		priv->is_system_wide = g_variant_get_boolean (is_system_wide);

	/* get if system wide */
	metadata = g_dbus_proxy_get_cached_property (priv->proxy,
						     CD_PROFILE_PROPERTY_METADATA);
	if (metadata != NULL)
		cd_profile_set_metadata_from_variant (profile, metadata);

	/* get signals from DBus */
	g_signal_connect_object (priv->proxy,
				 "g-signal",
				 G_CALLBACK (cd_profile_dbus_signal_cb),
				 profile, 0);

	/* watch if any remote properties change */
	g_signal_connect_object (priv->proxy,
				 "g-properties-changed",
				 G_CALLBACK (cd_profile_dbus_properties_changed_cb),
				 profile, 0);

	/* success */
	g_task_return_boolean (task, TRUE);
}
Example #29
0
static void
lvm_update_vgs (GObject      *source_obj,
                GAsyncResult *result,
                gpointer      user_data)
{
  UDisksLVM2State *state;
  UDisksDaemon *daemon = UDISKS_DAEMON (source_obj);
  GDBusObjectManagerServer *manager;

  GTask *task = G_TASK (result);
  GError *error = NULL;
  VGsPVsData *data = g_task_propagate_pointer (task, &error);
  BDLVMVGdata **vgs = NULL;
  BDLVMPVdata **pvs = NULL;

  GHashTableIter vg_name_iter;
  gpointer key, value;
  const gchar *vg_name;

  if (!data)
    {
      if (error)
        udisks_warning ("LVM2 plugin: %s", error->message);
      else
        /* this should never happen */
        udisks_warning ("LVM2 plugin: failure but no error when getting VGs!");

      return;
    }
  vgs = data->vgs;
  pvs = data->pvs;

  /* free the data container (but not 'vgs' and 'pvs') */
  g_free (data);

  manager = udisks_daemon_get_object_manager (daemon);
  state = get_module_state (daemon);

  /* Remove obsolete groups */
  g_hash_table_iter_init (&vg_name_iter,
                          udisks_lvm2_state_get_name_to_volume_group (state));
  while (g_hash_table_iter_next (&vg_name_iter, &key, &value))
    {
      UDisksLinuxVolumeGroupObject *group;
      gboolean found = FALSE;

      vg_name = key;
      group = value;

      for (BDLVMVGdata **vgs_p=vgs; !found && (*vgs_p); vgs_p++)
          found = g_strcmp0 ((*vgs_p)->name, vg_name) == 0;

      if (!found)
        {
          udisks_linux_volume_group_object_destroy (group);
          g_dbus_object_manager_server_unexport (manager,
                                                 g_dbus_object_get_object_path (G_DBUS_OBJECT (group)));
          g_hash_table_iter_remove (&vg_name_iter);
        }
    }

  /* Add new groups and update existing groups */
  for (BDLVMVGdata **vgs_p=vgs; *vgs_p; vgs_p++)
    {
      UDisksLinuxVolumeGroupObject *group;
      GSList *vg_pvs = NULL;
      vg_name = (*vgs_p)->name;
      group = g_hash_table_lookup (udisks_lvm2_state_get_name_to_volume_group (state),
                                   vg_name);

      if (group == NULL)
        {
          group = udisks_linux_volume_group_object_new (daemon, vg_name);
          g_hash_table_insert (udisks_lvm2_state_get_name_to_volume_group (state),
                               g_strdup (vg_name), group);
        }

      for (BDLVMPVdata **pvs_p=pvs; *pvs_p; pvs_p++)
        if (g_strcmp0 ((*pvs_p)->vg_name, vg_name) == 0)
            vg_pvs = g_slist_prepend (vg_pvs, *pvs_p);

      udisks_linux_volume_group_object_update (group, *vgs_p, vg_pvs);
    }

  /* this is safe to do -- all BDLVMPVdata objects are still existing because
     the function that frees them is scheduled in main loop by the
     udisks_linux_volume_group_object_update() call above */
  for (BDLVMPVdata **pvs_p=pvs; *pvs_p; pvs_p++)
    if ((*pvs_p)->vg_name == NULL)
      bd_lvm_pvdata_free (*pvs_p);

  /* only free the containers, the contents were passed further */
  g_free (vgs);
  g_free (pvs);
}