Ejemplo n.º 1
0
PpDevicesList *
pp_host_get_snmp_devices_finish (PpHost        *host,
                                 GAsyncResult  *res,
                                 GError       **error)
{
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
  GSDData            *data;
  PpDevicesList      *result;

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_host_get_snmp_devices_async);

  if (g_simple_async_result_propagate_error (simple, error))
    return NULL;

  data = g_simple_async_result_get_op_res_gpointer (simple);
  result = data->devices;
  data->devices = NULL;

  return result;
}
Ejemplo n.º 2
0
static void
async_verify_chain_thread (GSimpleAsyncResult *res,
                           GObject            *object,
                           GCancellable       *cancellable)
{
  AsyncVerifyChain *args = g_simple_async_result_get_op_res_gpointer (res);
  GError *error = NULL;

  args->verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
                                                     args->chain,
                                                     args->purpose,
                                                     args->identity,
                                                     args->interaction,
                                                     args->flags,
                                                     cancellable,
                                                     &error);

  if (error)
      g_simple_async_result_take_error (res, error);
}
Ejemplo n.º 3
0
static gboolean
connect_finish (MMBearer *self,
                GAsyncResult *res,
                MMPort **data,
                MMBearerIpConfig **ipv4_config,
                MMBearerIpConfig **ipv6_config,
                GError **error)
{
    ConnectResult *result;

    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
        return FALSE;

    result = (ConnectResult *) g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
    *data = MM_PORT (g_object_ref (result->data));
    *ipv4_config = (result->ipv4_config ? g_object_ref (result->ipv4_config) : NULL);
    *ipv6_config = (result->ipv6_config ? g_object_ref (result->ipv6_config) : NULL);

    return TRUE;
}
Ejemplo n.º 4
0
/**
 * gdk_pixbuf_new_from_stream_finish:
 * @async_result: a #GAsyncResult
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous pixbuf creation operation started with
 * gdk_pixbuf_new_from_stream_async().
 *
 * Return value: a #GdkPixbuf or %NULL on error. Free the returned
 * object with g_object_unref().
 *
 * Since: 2.18
 **/
static GdkPixbuf *
totem_gdk_pixbuf_new_from_stream_finish (GAsyncResult  *async_result,
				   GError       **error)
{
	GdkPixbuf *pixbuf;
	GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);

	g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL);
	g_warn_if_fail (g_simple_async_result_get_source_tag (result) == totem_gdk_pixbuf_new_from_stream_async ||
			g_simple_async_result_get_source_tag (result) == totem_gdk_pixbuf_new_from_stream_at_scale_async);

	if (g_simple_async_result_propagate_error (result, error))
		return NULL;

	pixbuf = GDK_PIXBUF (g_simple_async_result_get_op_res_gpointer (result));
	if (pixbuf != NULL)
		return g_object_ref (pixbuf);

	return NULL;
}
Ejemplo n.º 5
0
static void
save_to_buffer_thread (GSimpleAsyncResult *result,
		       GObject	 	  *object,
		       GCancellable	  *cancellable)
{
	SaveArguments    *arguments;
	GthImageSaveData *data;
	GError           *error = NULL;

	arguments = g_simple_async_result_get_op_res_gpointer (result);
	data = _gth_image_save_to_buffer_common (arguments->image,
						 arguments->mime_type,
						 arguments->file_data,
						 cancellable,
						 &error);
	if (data != NULL)
		g_simple_async_result_set_op_res_gpointer (result, data, NULL);
	else
		g_simple_async_result_take_error (result, error);
}
Ejemplo n.º 6
0
static GList*
g_tls_database_real_lookup_certificates_issued_by_finish (GTlsDatabase          *self,
                                                          GAsyncResult          *result,
                                                          GError               **error)
{
  AsyncLookupCertificatesIssuedBy *args;
  GList *results;

  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
                        g_tls_database_real_lookup_certificates_issued_by_async), FALSE);

  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
    return NULL;

  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
  results = args->results;
  args->results = NULL;
  return results;
}
Ejemplo n.º 7
0
gboolean
ostree_checksum_file_async_finish (GFile          *f,
                                   GAsyncResult   *result,
                                   guchar        **out_csum,
                                   GError        **error)
{
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
  ChecksumFileAsyncData *data;

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == ostree_checksum_file_async);

  if (g_simple_async_result_propagate_error (simple, error))
    return FALSE;

  data = g_simple_async_result_get_op_res_gpointer (simple);
  /* Transfer ownership */
  *out_csum = data->csum;
  data->csum = NULL;
  return TRUE;
}
Ejemplo n.º 8
0
static GTlsCertificate*
g_tls_database_real_lookup_certificate_for_handle_finish (GTlsDatabase          *self,
                                                          GAsyncResult          *result,
                                                          GError               **error)
{
  AsyncLookupCertificateForHandle *args;
  GTlsCertificate *certificate;

  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
                        g_tls_database_real_lookup_certificate_for_handle_async), FALSE);

  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
    return NULL;

  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
  certificate = args->result;
  args->result = NULL;
  return certificate;
}
Ejemplo n.º 9
0
static void
on_export_connect_completed (GObject *source,
                             GAsyncResult *result,
                             gpointer user_data)
{
	GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
	ExportClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
	GError *error = NULL;

	closure->ldap = seahorse_ldap_source_connect_finish (SEAHORSE_LDAP_SOURCE (source),
	                                                     result, &error);
	if (error != NULL) {
		g_simple_async_result_take_error (res, error);
		g_simple_async_result_complete (res);
	} else {
		export_retrieve_key (SEAHORSE_LDAP_SOURCE (source), res);
	}

	g_object_unref (res);
}
Ejemplo n.º 10
0
const char *
nm_bluez_device_connect_finish (NMBluezDevice *self,
                                GAsyncResult *result,
                                GError **error)
{
	GSimpleAsyncResult *simple;
	const char *device;

	g_return_val_if_fail (g_simple_async_result_is_valid (result,
	                                                      G_OBJECT (self),
	                                                      nm_bluez_device_connect_async),
	                      NULL);

	simple = (GSimpleAsyncResult *) result;

	if (g_simple_async_result_propagate_error (simple, error))
		return NULL;

	device = (const char *) g_simple_async_result_get_op_res_gpointer (simple);
	return device;
}
Ejemplo n.º 11
0
gboolean
fr_process_execute_finish (FrProcess     *process,
			   GAsyncResult  *result,
			   FrError      **error)
{
	ExecuteData *exec_data;

	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (process), fr_process_execute), FALSE);

	exec_data = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
	if (exec_data->error == NULL)
		return TRUE;

	if (error != NULL) {
		if (exec_data->error->gerror == NULL)
			exec_data->error->gerror = g_error_new_literal (FR_ERROR, exec_data->error->type, "");
		*error = fr_error_copy (exec_data->error);
	}

	return FALSE;
}
Ejemplo n.º 12
0
static void
get_stream_thread_func (GSimpleAsyncResult *res,
                        GObject            *object,
                        GCancellable       *cancellable)
{
  GetStreamData *data;
  GError *error;

  data = g_simple_async_result_get_op_res_gpointer (res);

  error = NULL;
  data->stream = g_dbus_address_get_stream_sync (data->address,
                                                 &data->guid,
                                                 cancellable,
                                                 &error);
  if (data->stream == NULL)
    {
      g_simple_async_result_set_from_error (res, error);
      g_error_free (error);
    }
}
Ejemplo n.º 13
0
GVariant *
mm_base_modem_at_sequence_full_finish (MMBaseModem *self,
                                       GAsyncResult *res,
                                       gpointer *response_processor_context,
                                       GError **error)
{
    AtSequenceContext *ctx;

    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res),
                                               error))
        return NULL;

    ctx = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
    if (response_processor_context)
        /* transfer none, no need to free the context ourselves, if
         * we gave a response_processor_context_free callback */
        *response_processor_context = ctx->response_processor_context;

    /* transfer-none! (so that we can ignore it) */
    return ctx->result;
}
Ejemplo n.º 14
0
static void
metadata_get_coverart_thread (GSimpleAsyncResult *result,
			      GObject            *object,
			      GCancellable       *cancellable)
{
	GetCoverArtData *data;
	CaaCoverArt      cover_art;
	CaaImageData     image_data;

	data = g_simple_async_result_get_op_res_gpointer (result);

	cover_art = caa_coverart_new (PACKAGE_NAME "-" PACKAGE_VERSION);
	image_data = caa_coverart_fetch_front (cover_art, data->album->id);
	if (image_data != NULL) {
		data->size = caa_imagedata_size (image_data);
		data->buffer = g_new (guchar, data->size);
		memcpy (data->buffer, caa_imagedata_data (image_data), data->size);
	}

	caa_coverart_delete (cover_art);
}
Ejemplo n.º 15
0
static gchar *
lookup_by_address_finish (GResolver     *resolver,
                          GAsyncResult  *result,
                          GError       **error)
{
  GSimpleAsyncResult *simple;
  GUnixResolverRequest *req;
  gchar *name;

  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_address_async), FALSE);
  simple = G_SIMPLE_ASYNC_RESULT (result);

  if (g_simple_async_result_propagate_error (simple, error))
    return NULL;

  req = g_simple_async_result_get_op_res_gpointer (simple);
  name = req->u.address.hostname;
  req->u.address.hostname = NULL;

  return name;
}
Ejemplo n.º 16
0
static GList *
lookup_service_finish (GResolver     *resolver,
                       GAsyncResult  *result,
		       GError       **error)
{
  GSimpleAsyncResult *simple;
  GUnixResolverRequest *req;
  GList *targets;

  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_service_async), FALSE);
  simple = G_SIMPLE_ASYNC_RESULT (result);

  if (g_simple_async_result_propagate_error (simple, error))
    return NULL;

  req = g_simple_async_result_get_op_res_gpointer (simple);
  targets = req->u.service.targets;
  req->u.service.targets = NULL;

  return targets;
}
static gssize
data_wrapper_decode_to_stream_finish (CamelDataWrapper *data_wrapper,
                                      GAsyncResult *result,
                                      GError **error)
{
	GSimpleAsyncResult *simple;
	AsyncContext *async_context;

	g_return_val_if_fail (
		g_simple_async_result_is_valid (
		result, G_OBJECT (data_wrapper),
		data_wrapper_decode_to_stream), -1);

	simple = G_SIMPLE_ASYNC_RESULT (result);
	async_context = g_simple_async_result_get_op_res_gpointer (simple);

	if (g_simple_async_result_propagate_error (simple, error))
		return -1;

	return async_context->bytes_written;
}
Ejemplo n.º 18
0
static GInputStream *
g_loadable_icon_real_load_finish (GLoadableIcon        *icon,
				  GAsyncResult         *res,
				  char                **type,
				  GError              **error)
{
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
  LoadData *data;

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_loadable_icon_real_load_async);

  data = g_simple_async_result_get_op_res_gpointer (simple);

  if (type)
    {
      *type = data->type;
      data->type = NULL;
    }

  return g_object_ref (data->stream);
}
static void
data_wrapper_decode_to_stream_thread (GSimpleAsyncResult *simple,
                                      GObject *object,
                                      GCancellable *cancellable)
{
	AsyncContext *async_context;
	GError *error = NULL;

	async_context = g_simple_async_result_get_op_res_gpointer (simple);

	async_context->bytes_written =
		camel_data_wrapper_decode_to_stream_sync (
			CAMEL_DATA_WRAPPER (object),
			async_context->stream,
			cancellable, &error);

	if (error != NULL) {
		g_simple_async_result_set_from_error (simple, error);
		g_error_free (error);
	}
}
static void
create_channel_cb (GObject *acr,
    GAsyncResult *res,
    gpointer user_data)
{
  GSimpleAsyncResult *simple = user_data;
  CreateTubeData *data;
  GError *error = NULL;

  data = g_simple_async_result_get_op_res_gpointer (simple);

  data->channel = tp_account_channel_request_create_and_handle_channel_finish (
      TP_ACCOUNT_CHANNEL_REQUEST (acr), res, NULL, &error);
  if (!TP_IS_STREAM_TUBE_CHANNEL (data->channel))
    {
      tp_clear_object (&data->channel);

      if (error == NULL)
        error = g_error_new_literal (TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
            "Not supported channel type");

      create_tube_complete (simple, error);

      g_clear_error (&error);
      g_object_unref (simple);
      return;
    }

  g_signal_connect (data->channel, "invalidated",
      G_CALLBACK (create_tube_channel_invalidated_cb), simple);

  g_signal_connect_data (data->channel, "incoming",
      G_CALLBACK (create_tube_incoming_cb),
      g_object_ref (simple), (GClosureNotify) g_object_unref, 0);

  tp_stream_tube_channel_offer_async (TP_STREAM_TUBE_CHANNEL (data->channel),
      NULL, create_tube_offer_cb, g_object_ref (simple));

  g_object_unref (simple);
}
Ejemplo n.º 21
0
/**
 * json_parser_load_from_stream_finish:
 * @parser: a #JsonParser
 * @result: a #GAsyncResult
 * @error: the return location for a #GError or %NULL
 *
 * Finishes an asynchronous stream loading started with
 * json_parser_load_from_stream_async().
 *
 * Return value: %TRUE if the content of the stream was successfully retrieves
 *   and parsed, and %FALSE otherwise. In case of error, the #GError will be
 *   filled accordingly.
 *
 * Since: 0.12
 */
gboolean
json_parser_load_from_stream_finish (JsonParser    *parser,
                                     GAsyncResult  *result,
                                     GError       **error)
{
  GSimpleAsyncResult *simple;
  GError *internal_error;
  LoadStreamData *data;
  gboolean res;

  g_return_val_if_fail (JSON_IS_PARSER (parser), FALSE);
  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);

  simple = G_SIMPLE_ASYNC_RESULT (result);

  if (g_simple_async_result_propagate_error (simple, error))
    return FALSE;

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == json_parser_load_from_stream_async);

  data = g_simple_async_result_get_op_res_gpointer (simple);

  if (data->error)
    {
      g_propagate_error (error, data->error);
      data->error = NULL;
      return FALSE;
    }

  g_byte_array_set_size (data->content, data->pos + 1);
  data->content->data[data->pos] = 0;

  internal_error = NULL;
  res = json_parser_load (parser, (const gchar *) data->content->data, data->content->len, &internal_error);

  if (internal_error != NULL)
    g_propagate_error (error, internal_error);

  return res;
}
Ejemplo n.º 22
0
static void g_simple_async_config_thread_handler(GSimpleAsyncResult *simple,
			GObject *object, GCancellable *cancellable)
{
	HevSerialPort *self = HEV_SERIAL_PORT(object);
	HevSerialPortPrivate *priv = HEV_SERIAL_PORT_GET_PRIVATE(self);
	struct termios *options = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	options = g_simple_async_result_get_op_res_gpointer(simple);

	if(-1 == tcflush(priv->fd, TCIFLUSH))
	{
		GError *error = NULL;

		error = g_error_new(G_IO_ERROR, g_io_error_from_errno(errno),
					"%s", strerror(errno));
		g_simple_async_result_take_error(simple, error);
		g_simple_async_result_set_op_res_gboolean(simple, FALSE);

		goto ret;
	}
	if(-1 == tcsetattr(priv->fd, TCSANOW, options))
	{
		GError *error = NULL;

		error = g_error_new(G_IO_ERROR, g_io_error_from_errno(errno),
					"%s", strerror(errno));
		g_simple_async_result_take_error(simple, error);
		g_simple_async_result_set_op_res_gboolean(simple, FALSE);

		goto ret;
	}

	g_simple_async_result_set_op_res_gboolean(simple, TRUE);

ret:
	g_free(options);
}
static void
rejilla_track_image_cfg_get_info_cb (GObject *object,
				     GAsyncResult *result,
				     gpointer user_data)
{
	RejillaTrackImageInfo *info;
	RejillaTrackImageCfgPrivate *priv;

	priv = REJILLA_TRACK_IMAGE_CFG_PRIVATE (object);

	info = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
	if (priv->cancel == info->cancel) {
		g_object_unref (priv->cancel);
		priv->cancel = NULL;
	}

	if (g_cancellable_is_cancelled (info->cancel)) {
		rejilla_track_changed (REJILLA_TRACK (object));
		return;
	}

	if (info->format == REJILLA_IMAGE_FORMAT_NONE
	||  info->blocks == 0) {
		GError *error = NULL;

		g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), &error);
		priv->error = error;

		rejilla_track_changed (REJILLA_TRACK (object));
		return;
	}

	rejilla_track_image_cfg_set_uri (REJILLA_TRACK_IMAGE_CFG (object),
	                                 info->uri,
	                                 priv->format != REJILLA_IMAGE_FORMAT_NONE? priv->format:info->format);

	REJILLA_TRACK_IMAGE_CLASS (rejilla_track_image_cfg_parent_class)->set_block_num (REJILLA_TRACK_IMAGE (object), info->blocks);
	rejilla_track_changed (REJILLA_TRACK (object));
}
gboolean
um_user_manager_cache_user_finish (UmUserManager       *manager,
                                   GAsyncResult        *result,
                                   UmUser             **user,
                                   GError             **error)
{
        gchar *path;
        GSimpleAsyncResult *res;

        res = G_SIMPLE_ASYNC_RESULT (result);

        *user = NULL;

        if (g_simple_async_result_propagate_error (res, error)) {
                return FALSE;
        }

        path = g_simple_async_result_get_op_res_gpointer (res);
        *user = g_hash_table_lookup (manager->user_by_object_path, path);

        return TRUE;
}
Ejemplo n.º 25
0
static GList *
lookup_by_name_finish (GResolver     *resolver,
                       GAsyncResult  *result,
                       GError       **error)
{
  GSimpleAsyncResult *simple;
  GUnixResolverRequest *req;
  GList *addresses;

  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_name_async), NULL);

  simple = G_SIMPLE_ASYNC_RESULT (result);

  if (g_simple_async_result_propagate_error (simple, error))
    return NULL;

  req = g_simple_async_result_get_op_res_gpointer (simple);
  addresses = req->u.name.addresses;
  req->u.name.addresses = NULL;

  return addresses;
}
static void
_lookup_async (GSimpleAsyncResult *simple,
	       GObject *object,
	       GCancellable *cancellable)
{
  GLibProxyResolver *resolver = G_LIBPROXY_RESOLVER (object);
  GError *error = NULL;
  gchar **proxies = NULL;
  gchar *uri;

  uri = g_simple_async_result_get_op_res_gpointer (simple);

  proxies = get_libproxy_proxies (resolver, uri, cancellable, &error);

  if (error)
    {
      g_simple_async_result_set_from_error (simple, error);
      g_error_free (error);
    }
  else
    g_simple_async_result_set_op_res_gpointer (simple, proxies, (GDestroyNotify)free_libproxy_proxies);
}
Ejemplo n.º 27
0
static CockpitCreds *
cockpit_auth_remote_login_finish (CockpitAuth *self,
                                  GAsyncResult *result,
                                  GHashTable *headers,
                                  CockpitTransport **transport,
                                  GError **error)
{
  RemoteLoginData *rl;

  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
                        cockpit_auth_remote_login_async), NULL);

  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
    return NULL;

  rl = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));

  if (transport)
    *transport = g_object_ref (rl->transport);

  return cockpit_creds_ref (rl->creds);
}
Ejemplo n.º 28
0
static gpointer
seahorse_hkp_source_export_finish (SeahorseServerSource *source,
                                   GAsyncResult *result,
                                   gsize *size,
                                   GError **error)
{
	ExportClosure *closure;
	gpointer output;

	g_return_val_if_fail (size != NULL, NULL);
	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (source),
	                      seahorse_hkp_source_export_async), NULL);

	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
		return NULL;

	closure = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
	*size = closure->data->len;
	output = g_string_free (closure->data, FALSE);
	closure->data = NULL;
	return output;
}
Ejemplo n.º 29
0
static void
save_snapshot_replace_cb (GFile *snapshot_file,
                          GAsyncResult *result,
                          GSimpleAsyncResult *simple)
{
	GObject *object;
	SaveContext *context;
	GFileOutputStream *output_stream;
	GError *local_error = NULL;

	context = g_simple_async_result_get_op_res_gpointer (simple);

	/* Output stream might be NULL, so don't use cast macro. */
	output_stream = g_file_replace_finish (
		snapshot_file, result, &local_error);
	context->output_stream = (GOutputStream *) output_stream;

	if (local_error != NULL) {
		g_warn_if_fail (output_stream == NULL);
		g_simple_async_result_take_error (simple, local_error);
		g_simple_async_result_complete (simple);
		g_object_unref (simple);
		return;
	}

	g_return_if_fail (G_IS_OUTPUT_STREAM (output_stream));

	/* g_async_result_get_source_object() returns a new reference. */
	object = g_async_result_get_source_object (G_ASYNC_RESULT (simple));

	/* Extract a MIME message from the composer. */
	e_msg_composer_get_message_draft (
		E_MSG_COMPOSER (object), G_PRIORITY_DEFAULT,
		context->cancellable, (GAsyncReadyCallback)
		save_snapshot_get_message_cb, simple);

	g_object_unref (object);
}
Ejemplo n.º 30
0
gboolean
mongo_cursor_count_finish (MongoCursor   *cursor,
                           GAsyncResult  *result,
                           guint64       *count,
                           GError       **error)
{
   GSimpleAsyncResult *simple = (GSimpleAsyncResult *)result;
   MongoMessageReply *reply;
   MongoBsonIter iter;
   gboolean ret = FALSE;
   GList *list;

   g_return_val_if_fail(MONGO_IS_CURSOR(cursor), FALSE);
   g_return_val_if_fail(G_IS_SIMPLE_ASYNC_RESULT(simple), FALSE);
   g_return_val_if_fail(count, FALSE);

   if (!(reply = g_simple_async_result_get_op_res_gpointer(simple))) {
      g_simple_async_result_propagate_error(simple, error);
      GOTO(failure);
   }

   if (!(list = mongo_message_reply_get_documents(reply))) {
      GOTO(failure);
   }

   mongo_bson_iter_init(&iter, list->data);
   if (!mongo_bson_iter_find(&iter, "n") ||
       (mongo_bson_iter_get_value_type(&iter) != MONGO_BSON_DOUBLE)) {
      GOTO(failure);
   }

   *count = mongo_bson_iter_get_value_double(&iter);
   ret = TRUE;

failure:

   RETURN(ret);
}