/**************************************************
 *
 * Generated by build/generate-future-functions.py.
 *
 * DO NOT EDIT THIS FILE.
 *
 *************************************************/
/* clang-format off */

/*
 * Define two sets of functions: background functions and future functions.

 * A background function like background_mongoc_cursor_next runs a driver
 * operation on a thread.

 * A future function like future_mongoc_cursor_next launches the background
 * operation and returns a future_t that will resolve when the operation
 * finishes.
 *
 * These are used with mock_server_t so you can run the driver on a thread while
 * controlling the server from the main thread.
 */

#include "mongoc/mongoc-topology-private.h"

#include "future-functions.h"


static
BSON_THREAD_FUN (background_mongoc_async_run, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_async_run (
      future_value_get_mongoc_async_ptr (future_get_param (future, 0)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_bulk_operation_execute, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_uint32_t_type;

   future_value_set_uint32_t (
      &return_value,
      mongoc_bulk_operation_execute (
         future_value_get_mongoc_bulk_operation_ptr (future_get_param (future, 0)),
         future_value_get_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_read_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_database_read_command_with_opts (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_read_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_database_read_write_command_with_opts (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_database_write_command_with_opts (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_command_simple, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_client_command_simple (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_client_command_with_opts (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
         future_value_get_const_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_ptr (future_get_param (future, 5)),
         future_value_get_bson_error_ptr (future_get_param (future, 6))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_read_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_client_read_command_with_opts (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
         future_value_get_const_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_ptr (future_get_param (future, 5)),
         future_value_get_bson_error_ptr (future_get_param (future, 6))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_client_write_command_with_opts (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_read_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_client_read_write_command_with_opts (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
         future_value_get_const_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_ptr (future_get_param (future, 5)),
         future_value_get_bson_error_ptr (future_get_param (future, 6))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_kill_cursor, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_client_kill_cursor (
      future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
      future_value_get_int64_t (future_get_param (future, 1)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_watch, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_change_stream_ptr_type;

   future_value_set_mongoc_change_stream_ptr (
      &return_value,
      mongoc_client_watch (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_aggregate, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_cursor_ptr_type;

   future_value_set_mongoc_cursor_ptr (
      &return_value,
      mongoc_collection_aggregate (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_query_flags_t (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_count, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_int64_t_type;

   future_value_set_int64_t (
      &return_value,
      mongoc_collection_count (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_query_flags_t (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_int64_t (future_get_param (future, 3)),
         future_value_get_int64_t (future_get_param (future, 4)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 5)),
         future_value_get_bson_error_ptr (future_get_param (future, 6))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_count_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_int64_t_type;

   future_value_set_int64_t (
      &return_value,
      mongoc_collection_count_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_query_flags_t (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_int64_t (future_get_param (future, 3)),
         future_value_get_int64_t (future_get_param (future, 4)),
         future_value_get_const_bson_ptr (future_get_param (future, 5)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 6)),
         future_value_get_bson_error_ptr (future_get_param (future, 7))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_create_index_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_create_index_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_index_opt_t (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_drop_index_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_drop_index_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_drop_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_drop_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_find_and_modify_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_find_and_modify_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_find_and_modify_opts_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_find_and_modify, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_find_and_modify (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_const_bson_ptr (future_get_param (future, 4)),
         future_value_get_bool (future_get_param (future, 5)),
         future_value_get_bool (future_get_param (future, 6)),
         future_value_get_bool (future_get_param (future, 7)),
         future_value_get_bson_ptr (future_get_param (future, 8)),
         future_value_get_bson_error_ptr (future_get_param (future, 9))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_find_indexes_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_cursor_ptr_type;

   future_value_set_mongoc_cursor_ptr (
      &return_value,
      mongoc_collection_find_indexes_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_stats, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_stats (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_insert_many, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_insert_many (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr_ptr (future_get_param (future, 1)),
         future_value_get_size_t (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_insert_one, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_insert_one (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_read_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_read_command_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_read_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_read_write_command_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_write_command_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_write_command_with_opts (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_insert_bulk, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_insert_bulk (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_insert_flags_t (future_get_param (future, 1)),
         future_value_get_const_bson_ptr_ptr (future_get_param (future, 2)),
         future_value_get_uint32_t (future_get_param (future, 3)),
         future_value_get_const_mongoc_write_concern_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_cluster_run_command_parts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_cluster_run_command_parts (
         future_value_get_mongoc_cluster_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_server_stream_ptr (future_get_param (future, 1)),
         future_value_get_mongoc_cmd_parts_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_cursor_destroy, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_cursor_destroy (
      future_value_get_mongoc_cursor_ptr (future_get_param (future, 0)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_cursor_next, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_cursor_next (
         future_value_get_mongoc_cursor_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr_ptr (future_get_param (future, 1))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_get_database_names_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_char_ptr_ptr_type;

   future_value_set_char_ptr_ptr (
      &return_value,
      mongoc_client_get_database_names_with_opts (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_select_server, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_server_description_ptr_type;

   future_value_set_mongoc_server_description_ptr (
      &return_value,
      mongoc_client_select_server (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_bool (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_destroy, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_client_destroy (
      future_value_get_mongoc_client_ptr (future_get_param (future, 0)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_pool_destroy, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_client_pool_destroy (
      future_value_get_mongoc_client_pool_ptr (future_get_param (future, 0)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_command_simple, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_database_command_simple (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_drop_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_database_drop_with_opts (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_get_collection_names_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_char_ptr_ptr_type;

   future_value_set_char_ptr_ptr (
      &return_value,
      mongoc_database_get_collection_names_with_opts (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_database_watch, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_change_stream_ptr_type;

   future_value_set_mongoc_change_stream_ptr (
      &return_value,
      mongoc_database_watch (
         future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_file_readv, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_ssize_t_type;

   future_value_set_ssize_t (
      &return_value,
      mongoc_gridfs_file_readv (
         future_value_get_mongoc_gridfs_file_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_iovec_ptr (future_get_param (future, 1)),
         future_value_get_size_t (future_get_param (future, 2)),
         future_value_get_size_t (future_get_param (future, 3)),
         future_value_get_uint32_t (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_find_one, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_gridfs_file_ptr_type;

   future_value_set_mongoc_gridfs_file_ptr (
      &return_value,
      mongoc_gridfs_find_one (
         future_value_get_mongoc_gridfs_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_bson_error_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_file_remove, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_gridfs_file_remove (
         future_value_get_mongoc_gridfs_file_ptr (future_get_param (future, 0)),
         future_value_get_bson_error_ptr (future_get_param (future, 1))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_file_seek, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_int_type;

   future_value_set_int (
      &return_value,
      mongoc_gridfs_file_seek (
         future_value_get_mongoc_gridfs_file_ptr (future_get_param (future, 0)),
         future_value_get_int64_t (future_get_param (future, 1)),
         future_value_get_int (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_file_writev, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_ssize_t_type;

   future_value_set_ssize_t (
      &return_value,
      mongoc_gridfs_file_writev (
         future_value_get_mongoc_gridfs_file_ptr (future_get_param (future, 0)),
         future_value_get_const_mongoc_iovec_ptr (future_get_param (future, 1)),
         future_value_get_size_t (future_get_param (future, 2)),
         future_value_get_uint32_t (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_find_one_with_opts, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_gridfs_file_ptr_type;

   future_value_set_mongoc_gridfs_file_ptr (
      &return_value,
      mongoc_gridfs_find_one_with_opts (
         future_value_get_mongoc_gridfs_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_topology_select, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_server_description_ptr_type;

   future_value_set_mongoc_server_description_ptr (
      &return_value,
      mongoc_topology_select (
         future_value_get_mongoc_topology_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_ss_optype_t (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         NULL /* chosen read mode, unused here */,
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_client_get_gridfs, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_gridfs_ptr_type;

   future_value_set_mongoc_gridfs_ptr (
      &return_value,
      mongoc_client_get_gridfs (
         future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
         future_value_get_const_char_ptr (future_get_param (future, 1)),
         future_value_get_const_char_ptr (future_get_param (future, 2)),
         future_value_get_bson_error_ptr (future_get_param (future, 3))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_watch, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_mongoc_change_stream_ptr_type;

   future_value_set_mongoc_change_stream_ptr (
      &return_value,
      mongoc_collection_watch (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_change_stream_next, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_change_stream_next (
         future_value_get_mongoc_change_stream_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr_ptr (future_get_param (future, 1))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_change_stream_destroy, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_void_type;

   mongoc_change_stream_destroy (
      future_value_get_mongoc_change_stream_ptr (future_get_param (future, 0)));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_delete_one, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_delete_one (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_delete_many, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_delete_many (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_remove, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_remove (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_mongoc_remove_flags_t (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_write_concern_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_update_one, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_update_one (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_update_many, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_update_many (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_replace_one, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_bool_type;

   future_value_set_bool (
      &return_value,
      mongoc_collection_replace_one (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_count_documents, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_int64_t_type;

   future_value_set_int64_t (
      &return_value,
      mongoc_collection_count_documents (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_bson_ptr (future_get_param (future, 2)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
         future_value_get_bson_ptr (future_get_param (future, 4)),
         future_value_get_bson_error_ptr (future_get_param (future, 5))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_collection_estimated_document_count, data)
{
   future_t *future = (future_t *) data;
   future_value_t return_value;

   return_value.type = future_value_int64_t_type;

   future_value_set_int64_t (
      &return_value,
      mongoc_collection_estimated_document_count (
         future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
         future_value_get_const_bson_ptr (future_get_param (future, 1)),
         future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
         future_value_get_bson_ptr (future_get_param (future, 3)),
         future_value_get_bson_error_ptr (future_get_param (future, 4))
      ));

   future_resolve (future, return_value);

   BSON_THREAD_RETURN;
}



future_t *
future_async_run (
   mongoc_async_ptr async)
{
   future_t *future = future_new (future_value_void_type,
                                  1);
   
   future_value_set_mongoc_async_ptr (
      future_get_param (future, 0), async);
   
   future_start (future, background_mongoc_async_run);
   return future;
}

future_t *
future_bulk_operation_execute (
   mongoc_bulk_operation_ptr bulk,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_uint32_t_type,
                                  3);
   
   future_value_set_mongoc_bulk_operation_ptr (
      future_get_param (future, 0), bulk);
   
   future_value_set_bson_ptr (
      future_get_param (future, 1), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_bulk_operation_execute);
   return future;
}

future_t *
future_database_read_command_with_opts (
   mongoc_database_ptr database,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_database_read_command_with_opts);
   return future;
}

future_t *
future_database_read_write_command_with_opts (
   mongoc_database_ptr database,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_database_read_write_command_with_opts);
   return future;
}

future_t *
future_database_write_command_with_opts (
   mongoc_database_ptr database,
   const_bson_ptr command,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_database_write_command_with_opts);
   return future;
}

future_t *
future_client_command_simple (
   mongoc_client_ptr client,
   const_char_ptr db_name,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 3), read_prefs);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_client_command_simple);
   return future;
}

future_t *
future_client_command_with_opts (
   mongoc_client_ptr client,
   const_char_ptr db_name,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  7);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 3), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 4), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 5), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 6), error);
   
   future_start (future, background_mongoc_client_command_with_opts);
   return future;
}

future_t *
future_client_read_command_with_opts (
   mongoc_client_ptr client,
   const_char_ptr db_name,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  7);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 3), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 4), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 5), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 6), error);
   
   future_start (future, background_mongoc_client_read_command_with_opts);
   return future;
}

future_t *
future_client_write_command_with_opts (
   mongoc_client_ptr client,
   const_char_ptr db_name,
   const_bson_ptr command,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), command);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_client_write_command_with_opts);
   return future;
}

future_t *
future_client_read_write_command_with_opts (
   mongoc_client_ptr client,
   const_char_ptr db_name,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  7);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 3), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 4), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 5), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 6), error);
   
   future_start (future, background_mongoc_client_read_write_command_with_opts);
   return future;
}

future_t *
future_client_kill_cursor (
   mongoc_client_ptr client,
   int64_t cursor_id)
{
   future_t *future = future_new (future_value_void_type,
                                  2);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_int64_t (
      future_get_param (future, 1), cursor_id);
   
   future_start (future, background_mongoc_client_kill_cursor);
   return future;
}

future_t *
future_client_watch (
   mongoc_client_ptr client,
   const_bson_ptr pipeline,
   const_bson_ptr opts)
{
   future_t *future = future_new (future_value_mongoc_change_stream_ptr_type,
                                  3);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), pipeline);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_start (future, background_mongoc_client_watch);
   return future;
}

future_t *
future_collection_aggregate (
   mongoc_collection_ptr collection,
   mongoc_query_flags_t flags,
   const_bson_ptr pipeline,
   const_bson_ptr options,
   const_mongoc_read_prefs_ptr read_prefs)
{
   future_t *future = future_new (future_value_mongoc_cursor_ptr_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_mongoc_query_flags_t (
      future_get_param (future, 1), flags);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), pipeline);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), options);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 4), read_prefs);
   
   future_start (future, background_mongoc_collection_aggregate);
   return future;
}

future_t *
future_collection_count (
   mongoc_collection_ptr collection,
   mongoc_query_flags_t flags,
   const_bson_ptr query,
   int64_t skip,
   int64_t limit,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_int64_t_type,
                                  7);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_mongoc_query_flags_t (
      future_get_param (future, 1), flags);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), query);
   
   future_value_set_int64_t (
      future_get_param (future, 3), skip);
   
   future_value_set_int64_t (
      future_get_param (future, 4), limit);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 5), read_prefs);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 6), error);
   
   future_start (future, background_mongoc_collection_count);
   return future;
}

future_t *
future_collection_count_with_opts (
   mongoc_collection_ptr collection,
   mongoc_query_flags_t flags,
   const_bson_ptr query,
   int64_t skip,
   int64_t limit,
   const_bson_ptr opts,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_int64_t_type,
                                  8);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_mongoc_query_flags_t (
      future_get_param (future, 1), flags);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), query);
   
   future_value_set_int64_t (
      future_get_param (future, 3), skip);
   
   future_value_set_int64_t (
      future_get_param (future, 4), limit);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 5), opts);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 6), read_prefs);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 7), error);
   
   future_start (future, background_mongoc_collection_count_with_opts);
   return future;
}

future_t *
future_collection_create_index_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr keys,
   const_mongoc_index_opt_t opt,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), keys);
   
   future_value_set_const_mongoc_index_opt_t (
      future_get_param (future, 2), opt);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_create_index_with_opts);
   return future;
}

future_t *
future_collection_drop_index_with_opts (
   mongoc_collection_ptr collection,
   const_char_ptr index_name,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  4);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), index_name);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_collection_drop_index_with_opts);
   return future;
}

future_t *
future_collection_drop_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  3);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_collection_drop_with_opts);
   return future;
}

future_t *
future_collection_find_and_modify_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr query,
   const_mongoc_find_and_modify_opts_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), query);
   
   future_value_set_const_mongoc_find_and_modify_opts_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_find_and_modify_with_opts);
   return future;
}

future_t *
future_collection_find_and_modify (
   mongoc_collection_ptr collection,
   const_bson_ptr query,
   const_bson_ptr sort,
   const_bson_ptr update,
   const_bson_ptr fields,
   bool _remove,
   bool upsert,
   bool _new,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  10);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), query);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), sort);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), update);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 4), fields);
   
   future_value_set_bool (
      future_get_param (future, 5), _remove);
   
   future_value_set_bool (
      future_get_param (future, 6), upsert);
   
   future_value_set_bool (
      future_get_param (future, 7), _new);
   
   future_value_set_bson_ptr (
      future_get_param (future, 8), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 9), error);
   
   future_start (future, background_mongoc_collection_find_and_modify);
   return future;
}

future_t *
future_collection_find_indexes_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr opts)
{
   future_t *future = future_new (future_value_mongoc_cursor_ptr_type,
                                  2);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_start (future, background_mongoc_collection_find_indexes_with_opts);
   return future;
}

future_t *
future_collection_stats (
   mongoc_collection_ptr collection,
   const_bson_ptr options,
   bson_ptr stats,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  4);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), options);
   
   future_value_set_bson_ptr (
      future_get_param (future, 2), stats);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_collection_stats);
   return future;
}

future_t *
future_collection_insert_many (
   mongoc_collection_ptr collection,
   const_bson_ptr_ptr documents,
   size_t n_documents,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr_ptr (
      future_get_param (future, 1), documents);
   
   future_value_set_size_t (
      future_get_param (future, 2), n_documents);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_insert_many);
   return future;
}

future_t *
future_collection_insert_one (
   mongoc_collection_ptr collection,
   const_bson_ptr document,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), document);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_insert_one);
   return future;
}

future_t *
future_collection_read_command_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_read_command_with_opts);
   return future;
}

future_t *
future_collection_read_write_command_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_read_write_command_with_opts);
   return future;
}

future_t *
future_collection_write_command_with_opts (
   mongoc_collection_ptr collection,
   const_bson_ptr command,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_write_command_with_opts);
   return future;
}

future_t *
future_collection_insert_bulk (
   mongoc_collection_ptr collection,
   mongoc_insert_flags_t flags,
   const_bson_ptr_ptr documents,
   uint32_t n_documents,
   const_mongoc_write_concern_ptr write_concern,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), collection);
   
   future_value_set_mongoc_insert_flags_t (
      future_get_param (future, 1), flags);
   
   future_value_set_const_bson_ptr_ptr (
      future_get_param (future, 2), documents);
   
   future_value_set_uint32_t (
      future_get_param (future, 3), n_documents);
   
   future_value_set_const_mongoc_write_concern_ptr (
      future_get_param (future, 4), write_concern);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_insert_bulk);
   return future;
}

future_t *
future_cluster_run_command_parts (
   mongoc_cluster_ptr cluster,
   mongoc_server_stream_ptr server_stream,
   mongoc_cmd_parts_ptr parts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_cluster_ptr (
      future_get_param (future, 0), cluster);
   
   future_value_set_mongoc_server_stream_ptr (
      future_get_param (future, 1), server_stream);
   
   future_value_set_mongoc_cmd_parts_ptr (
      future_get_param (future, 2), parts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_cluster_run_command_parts);
   return future;
}

future_t *
future_cursor_destroy (
   mongoc_cursor_ptr cursor)
{
   future_t *future = future_new (future_value_void_type,
                                  1);
   
   future_value_set_mongoc_cursor_ptr (
      future_get_param (future, 0), cursor);
   
   future_start (future, background_mongoc_cursor_destroy);
   return future;
}

future_t *
future_cursor_next (
   mongoc_cursor_ptr cursor,
   const_bson_ptr_ptr doc)
{
   future_t *future = future_new (future_value_bool_type,
                                  2);
   
   future_value_set_mongoc_cursor_ptr (
      future_get_param (future, 0), cursor);
   
   future_value_set_const_bson_ptr_ptr (
      future_get_param (future, 1), doc);
   
   future_start (future, background_mongoc_cursor_next);
   return future;
}

future_t *
future_client_get_database_names_with_opts (
   mongoc_client_ptr client,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_char_ptr_ptr_type,
                                  3);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_client_get_database_names_with_opts);
   return future;
}

future_t *
future_client_select_server (
   mongoc_client_ptr client,
   bool for_writes,
   const_mongoc_read_prefs_ptr prefs,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_mongoc_server_description_ptr_type,
                                  4);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_bool (
      future_get_param (future, 1), for_writes);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), prefs);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_client_select_server);
   return future;
}

future_t *
future_client_destroy (
   mongoc_client_ptr client)
{
   future_t *future = future_new (future_value_void_type,
                                  1);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_start (future, background_mongoc_client_destroy);
   return future;
}

future_t *
future_client_pool_destroy (
   mongoc_client_pool_ptr pool)
{
   future_t *future = future_new (future_value_void_type,
                                  1);
   
   future_value_set_mongoc_client_pool_ptr (
      future_get_param (future, 0), pool);
   
   future_start (future, background_mongoc_client_pool_destroy);
   return future;
}

future_t *
future_database_command_simple (
   mongoc_database_ptr database,
   bson_ptr command,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_bson_ptr (
      future_get_param (future, 1), command);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_database_command_simple);
   return future;
}

future_t *
future_database_drop_with_opts (
   mongoc_database_ptr database,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  3);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_database_drop_with_opts);
   return future;
}

future_t *
future_database_get_collection_names_with_opts (
   mongoc_database_ptr database,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_char_ptr_ptr_type,
                                  3);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_database_get_collection_names_with_opts);
   return future;
}

future_t *
future_database_watch (
   mongoc_database_ptr database,
   const_bson_ptr pipeline,
   const_bson_ptr opts)
{
   future_t *future = future_new (future_value_mongoc_change_stream_ptr_type,
                                  3);
   
   future_value_set_mongoc_database_ptr (
      future_get_param (future, 0), database);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), pipeline);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_start (future, background_mongoc_database_watch);
   return future;
}

future_t *
future_gridfs_file_readv (
   mongoc_gridfs_file_ptr file,
   mongoc_iovec_ptr iov,
   size_t iovcnt,
   size_t min_bytes,
   uint32_t timeout_msec)
{
   future_t *future = future_new (future_value_ssize_t_type,
                                  5);
   
   future_value_set_mongoc_gridfs_file_ptr (
      future_get_param (future, 0), file);
   
   future_value_set_mongoc_iovec_ptr (
      future_get_param (future, 1), iov);
   
   future_value_set_size_t (
      future_get_param (future, 2), iovcnt);
   
   future_value_set_size_t (
      future_get_param (future, 3), min_bytes);
   
   future_value_set_uint32_t (
      future_get_param (future, 4), timeout_msec);
   
   future_start (future, background_mongoc_gridfs_file_readv);
   return future;
}

future_t *
future_gridfs_find_one (
   mongoc_gridfs_ptr gridfs,
   const_bson_ptr query,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_mongoc_gridfs_file_ptr_type,
                                  3);
   
   future_value_set_mongoc_gridfs_ptr (
      future_get_param (future, 0), gridfs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), query);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 2), error);
   
   future_start (future, background_mongoc_gridfs_find_one);
   return future;
}

future_t *
future_gridfs_file_remove (
   mongoc_gridfs_file_ptr file,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  2);
   
   future_value_set_mongoc_gridfs_file_ptr (
      future_get_param (future, 0), file);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 1), error);
   
   future_start (future, background_mongoc_gridfs_file_remove);
   return future;
}

future_t *
future_gridfs_file_seek (
   mongoc_gridfs_file_ptr file,
   int64_t delta,
   int whence)
{
   future_t *future = future_new (future_value_int_type,
                                  3);
   
   future_value_set_mongoc_gridfs_file_ptr (
      future_get_param (future, 0), file);
   
   future_value_set_int64_t (
      future_get_param (future, 1), delta);
   
   future_value_set_int (
      future_get_param (future, 2), whence);
   
   future_start (future, background_mongoc_gridfs_file_seek);
   return future;
}

future_t *
future_gridfs_file_writev (
   mongoc_gridfs_file_ptr file,
   const_mongoc_iovec_ptr iov,
   size_t iovcnt,
   uint32_t timeout_msec)
{
   future_t *future = future_new (future_value_ssize_t_type,
                                  4);
   
   future_value_set_mongoc_gridfs_file_ptr (
      future_get_param (future, 0), file);
   
   future_value_set_const_mongoc_iovec_ptr (
      future_get_param (future, 1), iov);
   
   future_value_set_size_t (
      future_get_param (future, 2), iovcnt);
   
   future_value_set_uint32_t (
      future_get_param (future, 3), timeout_msec);
   
   future_start (future, background_mongoc_gridfs_file_writev);
   return future;
}

future_t *
future_gridfs_find_one_with_opts (
   mongoc_gridfs_ptr gridfs,
   const_bson_ptr filter,
   const_bson_ptr opts,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_mongoc_gridfs_file_ptr_type,
                                  4);
   
   future_value_set_mongoc_gridfs_ptr (
      future_get_param (future, 0), gridfs);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), filter);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_gridfs_find_one_with_opts);
   return future;
}

future_t *
future_topology_select (
   mongoc_topology_ptr topology,
   mongoc_ss_optype_t optype,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_mongoc_server_description_ptr_type,
                                  4);
   
   future_value_set_mongoc_topology_ptr (
      future_get_param (future, 0), topology);
   
   future_value_set_mongoc_ss_optype_t (
      future_get_param (future, 1), optype);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_topology_select);
   return future;
}

future_t *
future_client_get_gridfs (
   mongoc_client_ptr client,
   const_char_ptr db,
   const_char_ptr prefix,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_mongoc_gridfs_ptr_type,
                                  4);
   
   future_value_set_mongoc_client_ptr (
      future_get_param (future, 0), client);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 1), db);
   
   future_value_set_const_char_ptr (
      future_get_param (future, 2), prefix);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 3), error);
   
   future_start (future, background_mongoc_client_get_gridfs);
   return future;
}

future_t *
future_collection_watch (
   mongoc_collection_ptr coll,
   const_bson_ptr pipeline,
   const_bson_ptr opts)
{
   future_t *future = future_new (future_value_mongoc_change_stream_ptr_type,
                                  3);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), pipeline);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_start (future, background_mongoc_collection_watch);
   return future;
}

future_t *
future_change_stream_next (
   mongoc_change_stream_ptr stream,
   const_bson_ptr_ptr bson)
{
   future_t *future = future_new (future_value_bool_type,
                                  2);
   
   future_value_set_mongoc_change_stream_ptr (
      future_get_param (future, 0), stream);
   
   future_value_set_const_bson_ptr_ptr (
      future_get_param (future, 1), bson);
   
   future_start (future, background_mongoc_change_stream_next);
   return future;
}

future_t *
future_change_stream_destroy (
   mongoc_change_stream_ptr stream)
{
   future_t *future = future_new (future_value_void_type,
                                  1);
   
   future_value_set_mongoc_change_stream_ptr (
      future_get_param (future, 0), stream);
   
   future_start (future, background_mongoc_change_stream_destroy);
   return future;
}

future_t *
future_collection_delete_one (
   mongoc_collection_ptr coll,
   const_bson_ptr selector,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), selector);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_delete_one);
   return future;
}

future_t *
future_collection_delete_many (
   mongoc_collection_ptr coll,
   const_bson_ptr selector,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), selector);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_delete_many);
   return future;
}

future_t *
future_collection_remove (
   mongoc_collection_ptr coll,
   mongoc_remove_flags_t flags,
   const_bson_ptr selector,
   const_mongoc_write_concern_ptr write_concern,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_mongoc_remove_flags_t (
      future_get_param (future, 1), flags);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), selector);
   
   future_value_set_const_mongoc_write_concern_ptr (
      future_get_param (future, 3), write_concern);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_remove);
   return future;
}

future_t *
future_collection_update_one (
   mongoc_collection_ptr coll,
   const_bson_ptr selector,
   const_bson_ptr update,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), selector);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), update);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_update_one);
   return future;
}

future_t *
future_collection_update_many (
   mongoc_collection_ptr coll,
   const_bson_ptr selector,
   const_bson_ptr update,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), selector);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), update);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_update_many);
   return future;
}

future_t *
future_collection_replace_one (
   mongoc_collection_ptr coll,
   const_bson_ptr selector,
   const_bson_ptr replacement,
   const_bson_ptr opts,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_bool_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), selector);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), replacement);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 3), opts);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_replace_one);
   return future;
}

future_t *
future_collection_count_documents (
   mongoc_collection_ptr coll,
   const_bson_ptr filter,
   const_bson_ptr opts,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_int64_t_type,
                                  6);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), filter);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 2), opts);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 3), read_prefs);
   
   future_value_set_bson_ptr (
      future_get_param (future, 4), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 5), error);
   
   future_start (future, background_mongoc_collection_count_documents);
   return future;
}

future_t *
future_collection_estimated_document_count (
   mongoc_collection_ptr coll,
   const_bson_ptr opts,
   const_mongoc_read_prefs_ptr read_prefs,
   bson_ptr reply,
   bson_error_ptr error)
{
   future_t *future = future_new (future_value_int64_t_type,
                                  5);
   
   future_value_set_mongoc_collection_ptr (
      future_get_param (future, 0), coll);
   
   future_value_set_const_bson_ptr (
      future_get_param (future, 1), opts);
   
   future_value_set_const_mongoc_read_prefs_ptr (
      future_get_param (future, 2), read_prefs);
   
   future_value_set_bson_ptr (
      future_get_param (future, 3), reply);
   
   future_value_set_bson_error_ptr (
      future_get_param (future, 4), error);
   
   future_start (future, background_mongoc_collection_estimated_document_count);
   return future;
}


