Esempio n. 1
0
static void
do_lookup_by_name (GTask         *task,
                   gpointer       source_object,
                   gpointer       task_data,
                   GCancellable  *cancellable)
{
  const char *hostname = task_data;
  struct addrinfo *res = NULL;
  GList *addresses;
  gint retval;

  retval = getaddrinfo (hostname, NULL, &addrinfo_hints, &res);

  if (retval == 0)
    {
      struct addrinfo *ai;
      GSocketAddress *sockaddr;
      GInetAddress *addr;

      addresses = NULL;
      for (ai = res; ai; ai = ai->ai_next)
        {
          sockaddr = g_socket_address_new_from_native (ai->ai_addr, ai->ai_addrlen);
          if (!sockaddr || !G_IS_INET_SOCKET_ADDRESS (sockaddr))
            continue;

          addr = g_object_ref (g_inet_socket_address_get_address ((GInetSocketAddress *)sockaddr));
          addresses = g_list_prepend (addresses, addr);
          g_object_unref (sockaddr);
        }

      if (addresses != NULL)
        {
          addresses = g_list_reverse (addresses);
          g_task_return_pointer (task, addresses,
                                 (GDestroyNotify)g_resolver_free_addresses);
        }
      else
        {
          /* All addresses failed to be converted to GSocketAddresses. */
          g_task_return_new_error (task,
                                   G_RESOLVER_ERROR,
                                   G_RESOLVER_ERROR_NOT_FOUND,
                                   _("Error resolving '%s': %s"),
                                   hostname,
                                   _("No valid addresses were found"));
        }
    }
  else
    {
      g_task_return_new_error (task,
                               G_RESOLVER_ERROR,
                               g_resolver_error_from_addrinfo_error (retval),
                               _("Error resolving '%s': %s"),
                               hostname, gai_strerror (retval));
    }

  if (res)
    freeaddrinfo (res);
}
Esempio n. 2
0
static void
gdk_clipboard_read_local_async (GdkClipboard        *clipboard,
                                GdkContentFormats   *formats,
                                int                  io_priority,
                                GCancellable        *cancellable,
                                GAsyncReadyCallback  callback,
                                gpointer             user_data)
{
  GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
  GdkContentFormats *content_formats;
  const char *mime_type;
  GTask *task;

  task = g_task_new (clipboard, cancellable, callback, user_data);
  g_task_set_priority (task, io_priority);
  g_task_set_source_tag (task, gdk_clipboard_read_local_async);

  if (priv->content == NULL)
    {
      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                                     _("Cannot read from empty clipboard."));
      g_object_unref (task);
      return;
    }

  content_formats = gdk_content_provider_ref_formats (priv->content);
  content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
  mime_type = gdk_content_formats_match_mime_type (content_formats, formats);

  if (mime_type != NULL)
    {
      GOutputStream *output_stream;
      GIOStream *stream;
      
      stream = gdk_pipe_io_stream_new ();
      output_stream = g_io_stream_get_output_stream (stream);
      gdk_clipboard_write_async (clipboard,
                                 mime_type,
                                 output_stream,
                                 io_priority,
                                 cancellable,
                                 gdk_clipboard_read_local_write_done,
                                 g_object_ref (output_stream));
      g_task_set_task_data (task, (gpointer) mime_type, NULL);
      g_task_return_pointer (task, g_object_ref (g_io_stream_get_input_stream (stream)), g_object_unref);

      g_object_unref (stream);
    }
  else
    {
      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                     _("No compatible formats to transfer clipboard contents."));
    }

  gdk_content_formats_unref (content_formats);
  g_object_unref (task);
}
Esempio n. 3
0
void
cd_sensor_set_options_async (CdSensor *sensor,
			     GHashTable *options,
			     GCancellable *cancellable,
			     GAsyncReadyCallback callback,
			     gpointer user_data)
{
	CdSensorDummyPrivate *priv = cd_sensor_dummy_get_private (sensor);
	GList *l;
	const gchar *key_name;
	GVariant *value;
	g_autoptr(GTask) task = NULL;
	g_autoptr(GList) keys = NULL;

	g_return_if_fail (CD_IS_SENSOR (sensor));

	task = g_task_new (sensor, cancellable, callback, user_data);

	/* look for any keys we recognise */
	keys = g_hash_table_get_keys (options);
	for (l = keys; l != NULL; l = l->next) {
		key_name = (const gchar *) l->data;
		value = g_hash_table_lookup (options, key_name);
		if (g_strcmp0 (g_variant_get_type_string (value), "d") != 0) {
			g_task_return_new_error (task,
						 CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "unexpected type '%s' not supported",
						 g_variant_get_type_string (value));
			return;
		}
		if (g_strcmp0 (key_name, "sample[red]") == 0) {
			priv->sample_fake.R = g_variant_get_double (value);
		} else if (g_strcmp0 (key_name, "sample[green]") == 0) {
			priv->sample_fake.G = g_variant_get_double (value);
		} else if (g_strcmp0 (key_name, "sample[blue]") == 0) {
			priv->sample_fake.B = g_variant_get_double (value);
		} else {
			g_task_return_new_error (task,
						 CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "option '%s' is not supported",
						 key_name);
			return;
		}
	}

	/* success */
	g_task_return_boolean (task, TRUE);
}
Esempio n. 4
0
static void
cd_sensor_dtp94_lock_thread_cb (GTask *task,
				gpointer source_object,
				gpointer task_data,
				GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	CdSensorDtp94Private *priv = cd_sensor_dtp94_get_private (sensor);
	g_autoptr(GError) error = NULL;
	g_autofree gchar *serial = NULL;

	/* try to find the USB device */
	priv->device = cd_sensor_open_usb_device (sensor,
						  0x01, /* config */
						  0x00, /* interface */
						  &error);
	if (priv->device == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		return;
	}

	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_STARTING);

	/* do startup sequence */
	if (!dtp94_device_setup (priv->device, &error)) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		return;
	}

	/* get serial */
	serial = dtp94_device_get_serial (priv->device, &error);
	if (serial == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_NO_DATA,
					 "%s", error->message);
		return;
	}
	cd_sensor_set_serial (sensor, serial);

	/* success */
	g_task_return_boolean (task, TRUE);
}
static gboolean
gvir_input_stream_read_ready(GVirStream *stream,
                             GVirStreamIOCondition cond,
                             void *opaque)
{
    GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque);
    GVirInputStreamPrivate *priv = input_stream->priv;
    GTask *task = priv->task;
    GCancellable *cancellable = g_task_get_cancellable(task);
    GError *error = NULL;
    gssize result;

    priv->task = NULL;

    if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) {
        g_warn_if_reached();
        g_task_return_new_error(task,
                                G_IO_ERROR,
                                G_IO_ERROR_INVALID_ARGUMENT,
                                "%s",
                                "Expected stream to be readable");
        goto cleanup;
    }

    result = gvir_stream_receive(stream, priv->buffer, priv->count,
                                 cancellable, &error);
    if (error != NULL) {
        if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
            g_warn_if_reached();
            g_task_return_new_error(task,
                                    G_IO_ERROR,
                                    G_IO_ERROR_INVALID_ARGUMENT,
                                    "%s",
                                    "Expected stream to be readable");
            g_error_free (error);
        } else {
            g_task_return_error(task, error);
        }

        goto cleanup;
    }

    g_task_return_int(task, result);

cleanup:
    g_object_unref(task);
    return FALSE;
}
Esempio n. 6
0
static void
cd_sensor_unlock_thread_cb (GTask *task,
			    gpointer source_object,
			    gpointer task_data,
			    GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	CdSensorDtp94Private *priv = cd_sensor_dtp94_get_private (sensor);
	g_autoptr(GError) error = NULL;

	/* close */
	if (priv->device != NULL) {
		if (!g_usb_device_close (priv->device, &error)) {
			g_task_return_new_error (task,
						 CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_INTERNAL,
						 "%s", error->message);
			return;
		}
		g_clear_object (&priv->device);
	}

	/* success */
	g_task_return_boolean (task, TRUE);
}
static void
dspy_introspection_model_init_async (GAsyncInitable      *initiable,
                                     gint                 io_priority,
                                     GCancellable        *cancellable,
                                     GAsyncReadyCallback  callback,
                                     gpointer             user_data)
{
  DspyIntrospectionModel *self = (DspyIntrospectionModel *)initiable;
  GDBusConnection *bus = NULL;
  DspyConnection *connection = NULL;
  g_autoptr(GTask) task = NULL;

  g_assert (DSPY_IS_INTROSPECTION_MODEL (self));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (self, cancellable, callback, user_data);
  g_task_set_source_tag (task, dspy_introspection_model_init_async);
  g_task_set_task_data (task, g_new0 (gint, 1), g_free);
  g_task_set_priority (task, io_priority);

  if (self->name == NULL ||
      !(connection = dspy_name_get_connection (self->name)) ||
      !(bus = dspy_connection_get_connection (connection)))
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_NOT_INITIALIZED,
                               "%s has not been intialized with a name",
                               G_OBJECT_TYPE_NAME (self));
      return;
    }

  dspy_introspection_model_introspect (task, bus, "/");
}
Esempio n. 8
0
static gboolean
cd_sensor_get_sample_wait_cb (GTask *task)
{
	CdSensor *sensor = CD_SENSOR (g_task_get_source_object (task));
	CdSensorDummyPrivate *priv = cd_sensor_dummy_get_private (sensor);
	CdColorXYZ *sample = NULL;
	g_autoptr(GError) error = NULL;

	/* never setup */
	if (priv->transform_fake == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_NO_SUPPORT,
					 "no fake transfor set up");
		return G_SOURCE_REMOVE;
	}

	/* run the sample through the profile */
	sample = cd_color_xyz_new ();
	cmsDoTransform (priv->transform_fake, &priv->sample_fake, sample, 1);

	/* emulate */
	cd_sensor_button_pressed (sensor);

	/* just return without a problem */
	g_task_return_pointer (task, sample, (GDestroyNotify) cd_color_xyz_free);
	return G_SOURCE_REMOVE;
}
Esempio n. 9
0
static void
on_import_message_complete (SoupSession *session,
                            SoupMessage *message,
                            gpointer user_data)
{
    g_autoptr(GTask) task = G_TASK (user_data);
    source_import_closure *closure = g_task_get_task_data (task);
    g_autoptr(GError) error = NULL;
    g_autofree gchar *errmsg = NULL;

    g_assert (closure->requests > 0);
    seahorse_progress_end (closure->cancellable, GUINT_TO_POINTER (closure->requests));
    closure->requests--;

    if (hkp_message_propagate_error (closure->source, message, &error)) {
        g_task_return_error (task, g_steal_pointer (&error));
        return;
    }

    if ((errmsg = get_send_result (message->response_body->data)) != NULL) {
        g_task_return_new_error (task, HKP_ERROR_DOMAIN, message->status_code,
                                 "%s", errmsg);
        return;
    }

    /* A successful status from the server is all we want in this case */
    if (closure->requests == 0) {
        /* We don't know which keys got imported, so just return NULL */
        g_task_return_pointer (task, NULL, NULL);
    }
}
Esempio n. 10
0
static void
cd_sensor_unlock_thread_cb (GTask *task,
			    gpointer source_object,
			    gpointer task_data,
			    GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (object);
	CdSensorMunkiPrivate *priv = cd_sensor_munki_get_private (sensor);
	gboolean ret = FALSE;
	g_autoptr(GError) error = NULL;

	/* stop watching the dial */
	libusb_cancel_transfer (priv->transfer_interrupt);
	libusb_cancel_transfer (priv->transfer_state);

	/* close */
	if (priv->device != NULL) {
		if (!g_usb_device_close (priv->device, &error)) {
			g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
			return;
		}
		g_clear_object (&priv->device);
	}

	/* success */
	g_task_return_boolean (task, TRUE);
}
Esempio n. 11
0
static void
gdk_clipboard_store_default_async (GdkClipboard        *clipboard,
                                   int                  io_priority,
                                   GCancellable        *cancellable,
                                   GAsyncReadyCallback  callback,
                                   gpointer             user_data)
{
  GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
  GTask *task;

  task = g_task_new (clipboard, cancellable, callback, user_data);
  g_task_set_priority (task, io_priority);
  g_task_set_source_tag (task, gdk_clipboard_store_default_async);

  if (priv->local)
    {
      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                               _("This clipboard cannot store data."));
    }
  else
    {
      g_task_return_boolean (task, TRUE);
    }

  g_object_unref (task);
}
Esempio n. 12
0
static void
cd_sensor_munki_sample_thread_cb (GSimpleAsyncResult *res,
				 GObject *object,
				 GCancellable *cancellable)
{
	g_autoptr(GError) error = NULL;
	CdSensor *sensor = CD_SENSOR (object);
//	CdSensorMunkiPrivate *priv = cd_sensor_munki_get_private (sensor);

	/* no hardware support */
	if (task->current_cap == CD_SENSOR_CAP_PROJECTOR) {
		g_set_error_literal (&error, CD_SENSOR_ERROR,
				     CD_SENSOR_ERROR_NO_SUPPORT,
				     "MUNKI cannot measure in projector mode");
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}

	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_MEASURING);

	/* save result */
	task->sample = cd_color_xyz_new ();
	g_task_return_error (task, NULL);
out:
	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_IDLE);
}
Esempio n. 13
0
static void
service_resolver_changed (GVfsDnsSdResolver *resolver,
                          GTask *task)
{
    ResolveData *data = g_task_get_task_data (task);

    if (resolver->is_resolved)
    {
        g_task_return_boolean (task, TRUE);
        g_object_unref (task);
    }
    else
    {
        if (data->resolver->address != NULL)
        {
            /* keep going until timeout if we're missing TXT records */
        }
        else
        {
            g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
                                     /* Translators:
                                      * - the first %s refers to the service type
                                      * - the second %s refers to the service name
                                      * - the third %s refers to the domain
                                      */
                                     _("Error resolving “%s” service “%s” on domain “%s”"),
                                     data->resolver->service_type,
                                     data->resolver->service_name,
                                     data->resolver->domain);
            g_object_unref (task);
        }
    }
}
Esempio n. 14
0
/**
 * gdata_calendar_service_query_own_calendars_async:
 * @self: a #GDataCalendarService
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
 * @progress_user_data: (closure): data to pass to the @progress_callback function
 * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
 * @callback: a #GAsyncReadyCallback to call when authentication is finished
 * @user_data: (closure): data to pass to the @callback function
 *
 * Queries the service to return a list of calendars from the authenticated account which match the given
 * @query, and the authenticated user owns. @self and @query are all reffed when this function is called,
 * so can safely be unreffed after this function returns.
 *
 * For more details, see gdata_calendar_service_query_own_calendars(), which is the synchronous version of
 * this function, and gdata_service_query_async(), which is the base asynchronous query function.
 *
 * Since: 0.9.1
 */
void
gdata_calendar_service_query_own_calendars_async (GDataCalendarService *self, GDataQuery *query, GCancellable *cancellable,
                                                  GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                                  GDestroyNotify destroy_progress_user_data,
                                                  GAsyncReadyCallback callback, gpointer user_data)
{
	gchar *request_uri;

	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
	g_return_if_fail (callback != NULL);

	/* Ensure we're authenticated first */
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
	                                               get_calendar_authorization_domain ()) == FALSE) {
		g_autoptr(GTask) task = NULL;

		task = g_task_new (self, cancellable, callback, user_data);
		g_task_set_source_tag (task, gdata_service_query_async);
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
		                         _("You must be authenticated to query your own calendars."));

		return;
	}

	request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=owner", NULL);
	gdata_service_query_async (GDATA_SERVICE (self), get_calendar_authorization_domain (), request_uri, query, GDATA_TYPE_CALENDAR_CALENDAR,
	                           cancellable, progress_callback, progress_user_data, destroy_progress_user_data, callback, user_data);
	g_free (request_uri);
}
Esempio n. 15
0
void
cd_sensor_unlock_async (CdSensor *sensor,
			GCancellable *cancellable,
			GAsyncReadyCallback callback,
			gpointer user_data)
{
	CdSensorArgyllPrivate *priv = cd_sensor_argyll_get_private (sensor);
	CdSensorTaskData *data;
	GTask *task = NULL;

	g_return_if_fail (CD_IS_SENSOR (sensor));

	task = g_task_new (sensor, cancellable, callback, user_data);

	/* set state */
	data = g_new0 (CdSensorTaskData, 1);
	data->sensor = g_object_ref (sensor);
	g_task_set_task_data (task, data, (GDestroyNotify) cd_sensor_task_data_free);

	/* wait for exit */
	data->exit_id = g_signal_connect (priv->spawn,
					  "exit",
					  G_CALLBACK (cd_sensor_unlock_exit_cb),
					  task);
	/* kill spotread */
	if (!cd_spawn_kill (priv->spawn)) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "failed to kill spotread");
		g_object_unref (task);
		return;
	}
}
Esempio n. 16
0
static void
aws_s3_client_read_got_chunk (SoupMessage *message,
                              SoupBuffer  *buffer,
                              GTask       *task)
{
  AwsS3Client *client;
  ReadState *state;

  g_assert (SOUP_IS_MESSAGE (message));
  g_assert (buffer != NULL);
  g_assert (G_IS_TASK (task));

  client = g_task_get_source_object (task);
  g_assert (AWS_IS_S3_CLIENT (client));

  state = g_task_get_task_data (task);
  g_assert (state != NULL);
  g_assert (state->handler != NULL);

  if (!state->handler (client, message, buffer, state->handler_data))
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_CANCELLED,
                               "The request was cancelled");
      soup_session_cancel_message (SOUP_SESSION (client), message, SOUP_STATUS_CANCELLED);
   }
}
Esempio n. 17
0
static void
ide_git_vcs_list_status_worker (GTask        *task,
                                gpointer      source_object,
                                gpointer      task_data,
                                GCancellable *cancellable)
{
  ListStatus *state = task_data;
  g_autoptr(GListStore) store = NULL;
  g_autoptr(GFile) workdir = NULL;
  g_autoptr(GgitRepository) repository = NULL;
  g_autoptr(GgitStatusOptions) options = NULL;
  g_autoptr(GString) pathspec = NULL;
  g_autoptr(GError) error = NULL;
  g_autofree gchar *relative = NULL;
  gchar *strv[] = { NULL, NULL };

  g_assert (G_IS_TASK (task));
  g_assert (IDE_IS_GIT_VCS (source_object));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
  g_assert (state != NULL);
  g_assert (G_IS_FILE (state->repository_location));

  if (!(repository = ggit_repository_open (state->repository_location, &error)))
    {
      g_task_return_error (task, g_steal_pointer (&error));
      return;
    }

  if (!(workdir = ggit_repository_get_workdir (repository)))
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_FAILED,
                               "Failed to locate working directory");
      return;
    }

  g_set_object (&state->workdir, workdir);

  if (state->directory_or_file != NULL)
    relative = g_file_get_relative_path (workdir, state->directory_or_file);

  strv[0] = relative;
  options = ggit_status_options_new (GGIT_STATUS_OPTION_DEFAULT,
                                     GGIT_STATUS_SHOW_INDEX_AND_WORKDIR,
                                     (const gchar **)strv);

  store = g_list_store_new (IDE_TYPE_VCS_FILE_INFO);
  g_set_object (&state->store, store);

  if (!ggit_repository_file_status_foreach (repository,
                                            options,
                                            ide_git_vcs_list_status_cb,
                                            state,
                                            &error))
    g_task_return_error (task, g_steal_pointer (&error));
  else
    g_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
}
static void
ide_autotools_build_system_discover_file_worker (GTask        *task,
                                                 gpointer      source_object,
                                                 gpointer      task_data,
                                                 GCancellable *cancellable)
{
  GFile *file = task_data;
  GFile *parent;

  g_assert (G_IS_TASK (task));
  g_assert (G_IS_FILE (file));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  if (is_configure (file) && g_file_query_exists (file, cancellable))
    {
      g_task_return_pointer (task, g_object_ref (file), g_object_unref);
      return;
    }

  parent = g_object_ref (file);

  while (parent != NULL)
    {
      GFile *child;
      GFile *tmp;

      child = g_file_get_child (parent, "configure.ac");
      if (g_file_query_exists (child, cancellable))
        {
          g_task_return_pointer (task, g_object_ref (child), g_object_unref);
          g_clear_object (&child);
          g_clear_object (&parent);
          return;
        }

      child = g_file_get_child (parent, "configure.in");
      if (g_file_query_exists (child, cancellable))
        {
          g_task_return_pointer (task, g_object_ref (child), g_object_unref);
          g_clear_object (&child);
          g_clear_object (&parent);
          return;
        }

      g_clear_object (&child);

      tmp = parent;
      parent = g_file_get_parent (parent);
      g_clear_object (&tmp);
    }

  g_clear_object (&parent);

  g_task_return_new_error (task,
                           G_IO_ERROR,
                           G_IO_ERROR_NOT_FOUND,
                           _("Failed to locate configure.ac"));
}
Esempio n. 19
0
static void
gdav_propfind_request_cb (GObject *source_object,
                          GAsyncResult *result,
                          gpointer user_data)
{
	SoupRequestHTTP *request;
	GTask *task = G_TASK (user_data);
	SoupURI *base_uri;
	gpointer parsable;
	guint status_code;
	AsyncContext *async_context;
	GError *local_error = NULL;

	request = SOUP_REQUEST_HTTP (source_object);
	async_context = g_task_get_task_data (task);
	status_code = async_context->message->status_code;

	gdav_request_send_finish (request, result, &local_error);

	if (local_error != NULL)
		goto exit;

	if (status_code != SOUP_STATUS_MULTI_STATUS) {
		g_task_return_new_error (
			task, GDAV_PARSABLE_ERROR,
			GDAV_PARSABLE_ERROR_INTERNAL,
			_("Expected status %u (%s), but got (%u) (%s)"),
			SOUP_STATUS_MULTI_STATUS,
			soup_status_get_phrase (SOUP_STATUS_MULTI_STATUS),
			async_context->message->status_code,
			async_context->message->reason_phrase);
		goto exit;
	}

	base_uri = soup_message_get_uri (async_context->message);

	parsable = gdav_parsable_new_from_data (
		GDAV_TYPE_MULTI_STATUS, base_uri,
		async_context->message->response_body->data,
		async_context->message->response_body->length,
		&local_error);

	/* Sanity check */
	g_warn_if_fail (
		((parsable != NULL) && (local_error == NULL)) ||
		((parsable == NULL) && (local_error != NULL)));

	if (parsable != NULL) {
		g_warn_if_fail (GDAV_IS_MULTI_STATUS (parsable));
		g_task_return_pointer (task, parsable, g_object_unref);
	}

exit:
	if (local_error != NULL)
		g_task_return_error (task, local_error);

	g_object_unref (task);
}
Esempio n. 20
0
static void
do_run_async (IdeRunManager *self,
              GTask         *task)
{
  IdeBuildTarget *build_target;
  IdeContext *context;
  IdeConfigurationManager *config_manager;
  IdeConfiguration *config;
  IdeRuntime *runtime;
  g_autoptr(IdeRunner) runner = NULL;
  GCancellable *cancellable;

  g_assert (IDE_IS_RUN_MANAGER (self));
  g_assert (G_IS_TASK (task));

  build_target = g_task_get_task_data (task);
  context = ide_object_get_context (IDE_OBJECT (self));

  g_assert (IDE_IS_BUILD_TARGET (build_target));
  g_assert (IDE_IS_CONTEXT (context));

  config_manager = ide_context_get_configuration_manager (context);
  config = ide_configuration_manager_get_current (config_manager);
  runtime = ide_configuration_get_runtime (config);

  if (runtime == NULL)
    {
      g_task_return_new_error (task,
                               IDE_RUNTIME_ERROR,
                               IDE_RUNTIME_ERROR_NO_SUCH_RUNTIME,
                               "%s “%s”",
                               _("Failed to locate runtime"),
                               ide_configuration_get_runtime_id (config));
      IDE_EXIT;
    }

  runner = ide_runtime_create_runner (runtime, build_target);
  cancellable = g_task_get_cancellable (task);

  g_assert (IDE_IS_RUNNER (runner));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  /*
   * If the current handler has a callback specified (our default "run" handler
   * does not), then we need to allow that handler to prepare the runner.
   */
  if (self->handler != NULL && self->handler->handler != NULL)
    self->handler->handler (self, runner, self->handler->handler_data);

  g_signal_emit (self, signals [RUN], 0, runner);

  ide_runner_run_async (runner,
                        cancellable,
                        ide_run_manager_run_cb,
                        g_object_ref (task));
}
Esempio n. 21
0
/**
 * ide_clang_service_get_translation_unit_async:
 *
 * This function is used to asynchronously retrieve the translation unit for
 * a particular file.
 *
 * If the translation unit is up to date, then no parsing will occur and the
 * existing translation unit will be used.
 *
 * If the translation unit is out of date, then the source file(s) will be
 * parsed via clang_parseTranslationUnit() asynchronously.
 */
void
ide_clang_service_get_translation_unit_async (IdeClangService     *self,
                                              IdeFile             *file,
                                              gint64               min_serial,
                                              GCancellable        *cancellable,
                                              GAsyncReadyCallback  callback,
                                              gpointer             user_data)
{
  IdeClangTranslationUnit *cached;
  g_autoptr(GTask) task = NULL;

  g_return_if_fail (IDE_IS_CLANG_SERVICE (self));
  g_return_if_fail (IDE_IS_FILE (file));
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (self, cancellable, callback, user_data);

  /*
   * Clang likes to crash on our temporary files.
   */
  if (ide_file_get_is_temporary (file))
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_NOT_FOUND,
                               "File does not yet exist, ignoring translation unit request.");
      return;
    }

  if (min_serial == 0)
    {
      IdeContext *context;
      IdeUnsavedFiles *unsaved_files;

      context = ide_object_get_context (IDE_OBJECT (self));
      unsaved_files = ide_context_get_unsaved_files (context);
      min_serial = ide_unsaved_files_get_sequence (unsaved_files);
    }

  /*
   * If we have a cached unit, and it is new enough, then re-use it.
   */
  if ((cached = egg_task_cache_peek (self->units_cache, file)) &&
      (ide_clang_translation_unit_get_serial (cached) >= min_serial))
    {
      g_task_return_pointer (task, g_object_ref (cached), g_object_unref);
      return;
    }

  egg_task_cache_get_async (self->units_cache,
                            file,
                            TRUE,
                            cancellable,
                            ide_clang_service_get_translation_unit_cb,
                            g_object_ref (task));
}
Esempio n. 22
0
static gboolean
ensure_qmi_client (GTask       *task,
                   MMSimQmi    *self,
                   QmiService   service,
                   QmiClient  **o_client)
{
    MMBaseModem *modem = NULL;
    QmiClient *client;
    MMPortQmi *port;

    g_object_get (self,
                  MM_BASE_SIM_MODEM, &modem,
                  NULL);
    g_assert (MM_IS_BASE_MODEM (modem));

    port = mm_base_modem_peek_port_qmi (modem);
    g_object_unref (modem);

    if (!port) {
        if (task) {
            g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
                                     "Couldn't peek QMI port");
            g_object_unref (task);
        }
        return FALSE;
    }

    client = mm_port_qmi_peek_client (port,
                                      service,
                                      MM_PORT_QMI_FLAG_DEFAULT);
    if (!client) {
        if (task) {
            g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
                                     "Couldn't peek client for service '%s'",
                                     qmi_service_get_string (service));
            g_object_unref (task);
        }
        return FALSE;
    }

    *o_client = client;
    return TRUE;
}
Esempio n. 23
0
static gboolean
cd_sensor_get_sample_timeout_cb (GTask *task)
{
	g_task_return_new_error (task,
				 CD_SENSOR_ERROR,
				 CD_SENSOR_ERROR_INTERNAL,
				 "spotread timed out");
	g_object_unref (task);
	return G_SOURCE_REMOVE;
}
Esempio n. 24
0
static void
aws_s3_client_read_got_headers (SoupMessage *message,
                                GTask       *task)
{
  AwsS3Client *client;

  g_assert (SOUP_IS_MESSAGE(message));
  g_assert (G_IS_TASK (task));

  client = g_task_get_source_object (task);
  g_assert (AWS_IS_S3_CLIENT (client));

  if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code))
    {
      /*
       * Extract the given error type.
       */
      if (message->status_code == SOUP_STATUS_NOT_FOUND)
        {
          g_task_return_new_error (task,
                                   AWS_S3_CLIENT_ERROR,
                                   AWS_S3_CLIENT_ERROR_NOT_FOUND,
                                   "The requested object was not found.");
         soup_session_cancel_message (SOUP_SESSION (client), message, message->status_code);
        }
      else if (SOUP_STATUS_IS_CLIENT_ERROR (message->status_code))
        {
          g_task_return_new_error (task,
                                   AWS_S3_CLIENT_ERROR,
                                   AWS_S3_CLIENT_ERROR_BAD_REQUEST,
                                   "The request was invalid.");
          soup_session_cancel_message (SOUP_SESSION (client), message, message->status_code);
        }
      else
        {
          g_task_return_new_error (task,
                                   AWS_S3_CLIENT_ERROR,
                                   AWS_S3_CLIENT_ERROR_UNKNOWN,
                                   "An unknown error occurred.");
          soup_session_cancel_message (SOUP_SESSION (client), message, SOUP_STATUS_CANCELLED);
        }
    }
}
void WebSoupRequestManager::didFailURIRequest(const WebCore::ResourceError& error, uint64_t requestID)
{
    WebSoupRequestAsyncData* data = m_requestMap.get(requestID);
    ASSERT(data);
    GRefPtr<GTask> task = data->releaseTask();
    ASSERT(task.get());

    g_task_return_new_error(task.get(), g_quark_from_string(error.domain().utf8().data()),
        error.errorCode(), "%s", error.localizedDescription().utf8().data());
    m_requestMap.remove(requestID);
}
Esempio n. 26
0
static void
photos_glib_file_create_create (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  GFile *file = G_FILE (source_object);
  g_autoptr (GFileOutputStream) stream = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  PhotosGLibFileCreateData *data;

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

  {
    g_autoptr (GError) error = NULL;

    stream = g_file_create_finish (file, res, &error);
    if (error != NULL)
      {
        g_autoptr (GFile) unique_file = NULL;
        g_autofree gchar *filename = NULL;

        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
          {
            g_task_return_error (task, g_steal_pointer (&error));
            goto out;
          }

        if (data->count == G_MAXUINT)
          {
            g_task_return_new_error (task, PHOTOS_ERROR, 0, "Exceeded number of copies of a file");
            goto out;
          }

        data->count++;

        filename = photos_glib_file_create_data_get_filename (data);
        unique_file = g_file_get_child (data->dir, filename);

        g_file_create_async (unique_file,
                             data->flags,
                             data->io_priority,
                             cancellable,
                             photos_glib_file_create_create,
                             g_object_ref (task));

        goto out;
      }
  }

  g_task_return_pointer (task, g_object_ref (stream), g_object_unref);

 out:
  return;
}
Esempio n. 27
0
static void
cd_sensor_get_sample_exit_cb (CdSpawn *spawn,
			      CdSpawnExitType exit_type,
			      GTask *task)
{
	g_task_return_new_error (task,
				 CD_SENSOR_ERROR,
				 CD_SENSOR_ERROR_INTERNAL,
				 "spotread exited unexpectedly");
	g_object_unref (task);
}
void
ide_recent_projects_discover_async (IdeRecentProjects   *self,
                                    gboolean             recent_only,
                                    GCancellable        *cancellable,
                                    GAsyncReadyCallback  callback,
                                    gpointer             user_data)
{
  g_autoptr(GTask) task = NULL;
  gsize i;

  g_return_if_fail (IDE_IS_RECENT_PROJECTS (self));
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (self, cancellable, callback, user_data);

  if (self->discovered)
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_FAILED,
                               _("%s() may only be executed once"),
                               G_STRFUNC);
      return;
    }

  self->discovered = TRUE;

  ide_recent_projects_load_recent (self);

  if (recent_only)
    {
      g_task_return_boolean (task, TRUE);
      return;
    }

  self->active = self->miners->len;

  if (self->active == 0)
    {
      g_task_return_boolean (task, TRUE);
      return;
    }

  for (i = 0; i < self->miners->len; i++)
    {
      IdeProjectMiner *miner;

      miner = g_ptr_array_index (self->miners, i);
      ide_project_miner_mine_async (miner,
                                    self->cancellable,
                                    ide_recent_projects__miner_mine_cb,
                                    g_object_ref (task));
    }
}
Esempio n. 29
0
static gboolean
service_resolver_timed_out (GTask *task)
{
    ResolveData *data = g_task_get_task_data (task);

    if (data->resolver->address != NULL)
    {
        /* special case if one of the required TXT records are missing */
        g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
                                 /* Translators:
                                  * - the first %s refers to the service type
                                  * - the second %s refers to the service name
                                  * - the third %s refers to the domain
                                  * - the fourth %s refers to the required TXT keys
                                  */
                                 _("Error resolving “%s” service “%s” on domain “%s”. "
                                   "One or more TXT records are missing. Keys required: “%s”."),
                                 data->resolver->service_type,
                                 data->resolver->service_name,
                                 data->resolver->domain,
                                 data->resolver->required_txt_keys);
    }
    else
    {
        g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
                                 /* Translators:
                                  * - the first %s refers to the service type
                                  * - the second %s refers to the service name
                                  * - the third %s refers to the domain
                                  */
                                 _("Timed out resolving “%s” service “%s” on domain “%s”"),
                                 data->resolver->service_type,
                                 data->resolver->service_name,
                                 data->resolver->domain);
    }

    data->timeout_id = 0;
    g_object_unref (task);

    return FALSE;
}
void CustomProtocolManagerImpl::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError& error)
{
    WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID);
    ASSERT(data);

    GRefPtr<GTask> task = data->releaseTask();
    ASSERT(task.get());
    g_task_return_new_error(task.get(), g_quark_from_string(error.domain().utf8().data()),
        error.errorCode(), "%s", error.localizedDescription().utf8().data());

    m_customProtocolMap.remove(customProtocolID);
}