/* rpc_transport.c generated by valac 0.56.19, the Vala compiler
 * generated from rpc_transport.vala, do not modify */

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <sigpipe_compat.h>
#include <json-glib/json-glib.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_RPC_TRANSPORT (dc_rpc_transport_get_type ())
#define DC_RPC_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_TRANSPORT, DcRpcTransport))
#define DC_RPC_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_TRANSPORT, DcRpcTransportClass))
#define DC_IS_RPC_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_TRANSPORT))
#define DC_IS_RPC_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_TRANSPORT))
#define DC_RPC_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_TRANSPORT, DcRpcTransportClass))

typedef struct _DcRpcTransport DcRpcTransport;
typedef struct _DcRpcTransportClass DcRpcTransportClass;
typedef struct _DcRpcTransportPrivate DcRpcTransportPrivate;

#define DC_TYPE_PENDING_CALL (dc_pending_call_get_type ())
#define DC_PENDING_CALL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PENDING_CALL, DcPendingCall))
#define DC_PENDING_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PENDING_CALL, DcPendingCallClass))
#define DC_IS_PENDING_CALL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PENDING_CALL))
#define DC_IS_PENDING_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PENDING_CALL))
#define DC_PENDING_CALL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PENDING_CALL, DcPendingCallClass))

typedef struct _DcPendingCall DcPendingCall;
typedef struct _DcPendingCallClass DcPendingCallClass;

#define DC_TYPE_PENDING_WRITE (dc_pending_write_get_type ())
#define DC_PENDING_WRITE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PENDING_WRITE, DcPendingWrite))
#define DC_PENDING_WRITE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PENDING_WRITE, DcPendingWriteClass))
#define DC_IS_PENDING_WRITE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PENDING_WRITE))
#define DC_IS_PENDING_WRITE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PENDING_WRITE))
#define DC_PENDING_WRITE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PENDING_WRITE, DcPendingWriteClass))

typedef struct _DcPendingWrite DcPendingWrite;
typedef struct _DcPendingWriteClass DcPendingWriteClass;
enum  {
	DC_RPC_TRANSPORT_0_PROPERTY,
	DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY,
	DC_RPC_TRANSPORT_NUM_PROPERTIES
};
static GParamSpec* dc_rpc_transport_properties[DC_RPC_TRANSPORT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _g_thread_pool_free0(var) ((var == NULL) ? NULL : (var = (g_thread_pool_free (var, FALSE, TRUE), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block12Data Block12Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define DC_TYPE_PARAMS (dc_params_get_type ())
#define DC_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PARAMS, DcParams))
#define DC_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PARAMS, DcParamsClass))
#define DC_IS_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PARAMS))
#define DC_IS_PARAMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PARAMS))
#define DC_PARAMS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PARAMS, DcParamsClass))

typedef struct _DcParams DcParams;
typedef struct _DcParamsClass DcParamsClass;
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
typedef struct _DcRpcTransportStartData DcRpcTransportStartData;
typedef struct _DcPendingCallPrivate DcPendingCallPrivate;
#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL)))
#define _dc_pending_call_unref0(var) ((var == NULL) ? NULL : (var = (dc_pending_call_unref (var), NULL)))
typedef struct _DcRpcTransportCallData DcRpcTransportCallData;
typedef struct _DcRpcTransportDrainStderrData DcRpcTransportDrainStderrData;
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
typedef struct _DcRpcTransportReadLoopData DcRpcTransportReadLoopData;
typedef struct _Block13Data Block13Data;
#define _dc_pending_write_unref0(var) ((var == NULL) ? NULL : (var = (dc_pending_write_unref (var), NULL)))
typedef struct _DcPendingWritePrivate DcPendingWritePrivate;
typedef struct _DcRpcTransportNapData DcRpcTransportNapData;
enum  {
	DC_RPC_TRANSPORT_DISCONNECTED_SIGNAL,
	DC_RPC_TRANSPORT_NUM_SIGNALS
};
static guint dc_rpc_transport_signals[DC_RPC_TRANSPORT_NUM_SIGNALS] = {0};
typedef struct _DcParamSpecPendingCall DcParamSpecPendingCall;
typedef struct _DcParamSpecPendingWrite DcParamSpecPendingWrite;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _DcRpcTransport {
	GObject parent_instance;
	DcRpcTransportPrivate * priv;
};

struct _DcRpcTransportClass {
	GObjectClass parent_class;
};

struct _DcRpcTransportPrivate {
	GSubprocess* process;
	GDataInputStream* reader;
	GOutputStream* writer;
	GInputStream* err_pipe;
	gint next_id;
	GPtrArray* pending;
	GThreadPool* write_pool;
	guint connection_generation;
	GCancellable* io_cancellable;
	gchar* last_stderr;
	gboolean _is_connected;
};

struct _Block12Data {
	int _ref_count_;
	DcRpcTransport* self;
	guint generation;
	gboolean timed_out;
	gpointer _async_data_;
};

struct _DcRpcTransportStartData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcTransport* self;
	gchar** argv;
	gint argv_length1;
	gchar* cwd;
	gchar* accounts_path;
	Block12Data* _data12_;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GCancellable* _tmp3_;
	GSubprocess* _tmp4_;
	GDataInputStream* _tmp5_;
	GOutputStream* _tmp6_;
	guint _tmp7_;
	GCancellable* cancellable;
	GCancellable* _tmp8_;
	GCancellable* _tmp9_;
	GCancellable* _tmp10_;
	gchar* _tmp11_;
	GSubprocessFlags flags;
	GSubprocessLauncher* launcher;
	GSubprocessLauncher* _tmp12_;
	GSubprocessLauncher* _tmp13_;
	GSubprocessLauncher* _tmp14_;
	GSubprocess* _tmp15_;
	GSubprocessLauncher* _tmp16_;
	GSubprocess* _tmp17_;
	GSubprocess* _tmp18_;
	GSubprocess* _tmp19_;
	GOutputStream* _tmp20_;
	GOutputStream* _tmp21_;
	GSubprocess* _tmp22_;
	GInputStream* _tmp23_;
	GDataInputStream* _tmp24_;
	GSubprocess* _tmp25_;
	GInputStream* _tmp26_;
	GInputStream* _tmp27_;
	GError* e;
	GError* _tmp28_;
	GError* _tmp29_;
	GDataInputStream* connection_reader;
	GDataInputStream* _tmp30_;
	GDataInputStream* _tmp31_;
	GOutputStream* connection_writer;
	GOutputStream* _tmp32_;
	GOutputStream* _tmp33_;
	GInputStream* connection_err;
	GInputStream* _tmp34_;
	GInputStream* _tmp35_;
	gboolean _tmp36_;
	gboolean _tmp37_;
	GDataInputStream* _tmp38_;
	GOutputStream* _tmp39_;
	GInputStream* _tmp40_;
	GError* _tmp41_;
	GDataInputStream* _tmp42_;
	GInputStream* _tmp43_;
	GDataInputStream* _tmp44_;
	GCancellable* _tmp45_;
	guint handshake_timeout;
	DcParams* _tmp46_;
	DcParams* _tmp47_;
	JsonNode* _tmp48_;
	JsonNode* _tmp49_;
	JsonNode* _tmp50_;
	JsonNode* _tmp51_;
	GError* _tmp52_;
	GError* _vala1_e;
	const gchar* _tmp53_;
	gint _tmp54_;
	gint _tmp55_;
	const gchar* _tmp56_;
	GError* _tmp57_;
	GError* _tmp58_;
	GError* _tmp59_;
	GError* _inner_error0_;
};

struct _DcPendingCall {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcPendingCallPrivate * priv;
	gint id;
	guint generation;
	GSource* resume_source;
	JsonNode* result;
	gchar* error_msg;
};

struct _DcPendingCallClass {
	GTypeClass parent_class;
	void (*finalize) (DcPendingCall *self);
};

struct _DcRpcTransportCallData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcTransport* self;
	gchar* method;
	JsonNode* params;
	JsonNode* result;
	guint generation;
	GOutputStream* connection_writer;
	GOutputStream* _tmp0_;
	GOutputStream* _tmp1_;
	GCancellable* cancellable;
	GCancellable* _tmp2_;
	GCancellable* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	GOutputStream* _tmp7_;
	GDataInputStream* _tmp8_;
	GCancellable* _tmp9_;
	GError* _tmp10_;
	gint id;
	gint _tmp11_;
	DcPendingCall* pc;
	DcPendingCall* _tmp12_;
	GSource* resume_source;
	GSource* _tmp13_;
	GSource* _tmp14_;
	DcPendingCall* _tmp15_;
	GSource* _tmp16_;
	GSource* _tmp17_;
	GPtrArray* _tmp18_;
	DcPendingCall* _tmp19_;
	DcPendingCall* _tmp20_;
	DcPendingCall* _tmp21_;
	GOutputStream* _tmp22_;
	GCancellable* _tmp23_;
	DcPendingCall* _tmp24_;
	const gchar* _tmp25_;
	DcPendingCall* _tmp26_;
	const gchar* _tmp27_;
	GError* _tmp28_;
	DcPendingCall* _tmp29_;
	JsonNode* _tmp30_;
	JsonNode* _tmp31_;
	GError* _inner_error0_;
};

struct _DcRpcTransportDrainStderrData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcTransport* self;
	guint generation;
	GInputStream* pipe;
	GDataInputStream* err_stream;
	GDataInputStream* _tmp0_;
	gchar* line;
	gsize len;
	gchar* _tmp1_;
	GDataInputStream* _tmp2_;
	gsize _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	GError* _inner_error0_;
};

struct _DcRpcTransportReadLoopData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcTransport* self;
	guint generation;
	GDataInputStream* stream;
	GCancellable* cancellable;
	gchar* reason;
	gchar* _tmp0_;
	gsize len;
	gchar* line;
	gsize _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gboolean _tmp9_;
	JsonParser* parser;
	JsonParser* _tmp10_;
	JsonParser* _tmp11_;
	const gchar* _tmp12_;
	JsonNode* root;
	JsonParser* _tmp13_;
	JsonNode* _tmp14_;
	JsonNode* _tmp15_;
	gboolean _tmp16_;
	JsonNode* _tmp17_;
	JsonNode* _tmp18_;
	JsonObject* obj;
	JsonNode* _tmp19_;
	JsonObject* _tmp20_;
	JsonObject* _tmp21_;
	JsonObject* _tmp22_;
	gint resp_id;
	JsonObject* _tmp23_;
	DcPendingCall* pc;
	DcPendingCall* _tmp24_;
	DcPendingCall* _tmp25_;
	gboolean _tmp26_;
	JsonObject* _tmp27_;
	JsonObject* _tmp28_;
	JsonNode* _tmp29_;
	JsonObject* err;
	JsonObject* _tmp30_;
	JsonObject* _tmp31_;
	JsonObject* _tmp32_;
	const gchar* _tmp33_;
	JsonObject* _tmp34_;
	JsonObject* _tmp35_;
	const gchar* _tmp36_;
	DcPendingCall* _tmp37_;
	gchar* _tmp38_;
	JsonObject* _tmp39_;
	JsonNode* result_member;
	JsonObject* _tmp40_;
	JsonNode* _tmp41_;
	JsonNode* _tmp42_;
	JsonNode* _tmp43_;
	JsonNode* _tmp44_;
	JsonNode* _tmp45_;
	JsonNode* _tmp46_;
	DcPendingCall* _tmp47_;
	JsonNode* _tmp48_;
	DcPendingCall* _tmp49_;
	GError* e;
	gboolean _tmp50_;
	GError* _tmp51_;
	GError* _tmp52_;
	const gchar* _tmp53_;
	GError* _tmp54_;
	const gchar* _tmp55_;
	gchar* _tmp56_;
	const gchar* _tmp57_;
	GError* _inner_error0_;
};

struct _Block13Data {
	int _ref_count_;
	DcRpcTransport* self;
	DcPendingWrite* request;
};

struct _DcPendingWrite {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcPendingWritePrivate * priv;
	DcRpcTransport* transport;
	DcPendingCall* pending;
	GOutputStream* stream;
	GCancellable* cancellable;
	gchar* line;
	gchar* error_msg;
	GSource* completion_source;
	gint handoff_phase;
};

struct _DcPendingWriteClass {
	GTypeClass parent_class;
	void (*finalize) (DcPendingWrite *self);
};

struct _DcRpcTransportNapData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcRpcTransport* self;
	guint ms;
};

struct _DcParamSpecPendingCall {
	GParamSpec parent_instance;
};

struct _DcParamSpecPendingWrite {
	GParamSpec parent_instance;
};

static gint DcRpcTransport_private_offset;
static gpointer dc_rpc_transport_parent_class = NULL;
static gpointer dc_pending_call_parent_class = NULL;
static gpointer dc_pending_write_parent_class = NULL;

VALA_EXTERN GType dc_rpc_transport_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcTransport, g_object_unref)
VALA_EXTERN gpointer dc_pending_call_ref (gpointer instance);
VALA_EXTERN void dc_pending_call_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_param_spec_pending_call (const gchar* name,
                                        const gchar* nick,
                                        const gchar* blurb,
                                        GType object_type,
                                        GParamFlags flags);
VALA_EXTERN void dc_value_set_pending_call (GValue* value,
                                gpointer v_object);
VALA_EXTERN void dc_value_take_pending_call (GValue* value,
                                 gpointer v_object);
VALA_EXTERN gpointer dc_value_get_pending_call (const GValue* value);
VALA_EXTERN GType dc_pending_call_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPendingCall, dc_pending_call_unref)
VALA_EXTERN gpointer dc_pending_write_ref (gpointer instance);
VALA_EXTERN void dc_pending_write_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_param_spec_pending_write (const gchar* name,
                                         const gchar* nick,
                                         const gchar* blurb,
                                         GType object_type,
                                         GParamFlags flags);
VALA_EXTERN void dc_value_set_pending_write (GValue* value,
                                 gpointer v_object);
VALA_EXTERN void dc_value_take_pending_write (GValue* value,
                                  gpointer v_object);
VALA_EXTERN gpointer dc_value_get_pending_write (const GValue* value);
VALA_EXTERN GType dc_pending_write_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPendingWrite, dc_pending_write_unref)
static void _dc_pending_call_unref0_ (gpointer var);
static void dc_rpc_transport_start_data_free (gpointer _data);
VALA_EXTERN void dc_rpc_transport_start (DcRpcTransport* self,
                             gchar** argv,
                             gint argv_length1,
                             const gchar* cwd,
                             const gchar* accounts_path,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_);
VALA_EXTERN void dc_rpc_transport_start_finish (DcRpcTransport* self,
                                    GAsyncResult* _res_,
                                    GError** error);
static gboolean dc_rpc_transport_start_co (DcRpcTransportStartData* _data_);
static Block12Data* block12_data_ref (Block12Data* _data12_);
static void block12_data_unref (void * _userdata_);
VALA_EXTERN void dc_rpc_transport_stop (DcRpcTransport* self);
VALA_EXTERN GSubprocess* dc_subprocess_util_spawnv (GSubprocessLauncher* launcher,
                                        gchar** argv,
                                        gint argv_length1,
                                        GError** error);
static void dc_rpc_transport_finish_generation (DcRpcTransport* self,
                                         guint generation,
                                         const gchar* reason,
                                         gboolean emit_disconnected);
static void dc_rpc_transport_drain_stderr (DcRpcTransport* self,
                                    guint generation,
                                    GInputStream* pipe,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
static void dc_rpc_transport_drain_stderr_finish (DcRpcTransport* self,
                                           GAsyncResult* _res_);
static void dc_rpc_transport_read_loop (DcRpcTransport* self,
                                 guint generation,
                                 GDataInputStream* stream,
                                 GCancellable* cancellable,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
static void dc_rpc_transport_read_loop_finish (DcRpcTransport* self,
                                        GAsyncResult* _res_);
static gboolean __lambda4_ (Block12Data* _data12_);
static gboolean dc_rpc_transport_generation_is_active (DcRpcTransport* self,
                                                guint generation);
static gboolean ___lambda4__gsource_func (gpointer self);
VALA_EXTERN void dc_rpc_transport_call (DcRpcTransport* self,
                            const gchar* method,
                            JsonNode* params,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_);
VALA_EXTERN JsonNode* dc_rpc_transport_call_finish (DcRpcTransport* self,
                                        GAsyncResult* _res_,
                                        GError** error);
VALA_EXTERN GType dc_params_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcParams, g_object_unref)
VALA_EXTERN DcParams* dc_params_begin (void);
VALA_EXTERN JsonNode* dc_params_build (DcParams* self);
static void dc_rpc_transport_start_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_);
static void _vala_JsonNode_free (JsonNode* self);
static void dc_rpc_transport_nap (DcRpcTransport* self,
                           guint ms,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_);
static void dc_rpc_transport_nap_finish (DcRpcTransport* self,
                                  GAsyncResult* _res_);
static void dc_rpc_transport_set_is_connected (DcRpcTransport* self,
                                        gboolean value);
static void dc_rpc_transport_fail_pending (DcRpcTransport* self,
                                    const gchar* reason,
                                    guint generation);
static void dc_rpc_transport_call_data_free (gpointer _data);
static JsonNode* _vala_JsonNode_copy (JsonNode* self);
static gboolean dc_rpc_transport_call_co (DcRpcTransportCallData* _data_);
VALA_EXTERN DcPendingCall* dc_pending_call_new (gint id,
                                    guint generation);
VALA_EXTERN DcPendingCall* dc_pending_call_construct (GType object_type,
                                          gint id,
                                          guint generation);
static gboolean _dc_rpc_transport_call_co_gsource_func (gpointer self);
static void dc_rpc_transport_queue_request (DcRpcTransport* self,
                                     DcPendingCall* pc,
                                     const gchar* method,
                                     JsonNode* params,
                                     GOutputStream* stream,
                                     GCancellable* cancellable);
static void dc_rpc_transport_remove_pending (DcRpcTransport* self,
                                      gint id,
                                      guint generation);
static void dc_rpc_transport_drain_stderr_data_free (gpointer _data);
static gboolean dc_rpc_transport_drain_stderr_co (DcRpcTransportDrainStderrData* _data_);
static void dc_rpc_transport_drain_stderr_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void dc_rpc_transport_read_loop_data_free (gpointer _data);
static gboolean dc_rpc_transport_read_loop_co (DcRpcTransportReadLoopData* _data_);
static void dc_rpc_transport_read_loop_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static DcPendingCall* dc_rpc_transport_find_pending (DcRpcTransport* self,
                                              gint id,
                                              guint generation);
static void dc_rpc_transport_resume_pending (DcRpcTransport* self,
                                      DcPendingCall* pc);
static Block13Data* block13_data_ref (Block13Data* _data13_);
static void block13_data_unref (void * _userdata_);
VALA_EXTERN DcPendingWrite* dc_pending_write_new (DcRpcTransport* transport,
                                      DcPendingCall* pending,
                                      GOutputStream* stream,
                                      GCancellable* cancellable,
                                      const gchar* line);
VALA_EXTERN DcPendingWrite* dc_pending_write_construct (GType object_type,
                                            DcRpcTransport* transport,
                                            DcPendingCall* pending,
                                            GOutputStream* stream,
                                            GCancellable* cancellable,
                                            const gchar* line);
static void dc_rpc_transport_fail_write (DcRpcTransport* self,
                                  DcPendingWrite* request,
                                  const gchar* reason);
static gboolean __lambda5_ (Block13Data* _data13_);
VALA_EXTERN void dc_pending_write_acquire_on_main (DcPendingWrite* self);
static void dc_rpc_transport_write_completed (DcRpcTransport* self,
                                       DcPendingWrite* request);
static gboolean ___lambda5__gsource_func (gpointer self);
VALA_EXTERN void dc_pending_write_release_to_worker (DcPendingWrite* self);
VALA_EXTERN void dc_pending_write_discard_completion (DcPendingWrite* self);
static void dc_rpc_transport_perform_write (DcPendingWrite* request);
VALA_EXTERN void dc_pending_write_acquire_in_worker (DcPendingWrite* self);
VALA_EXTERN void dc_pending_write_release_from_worker (DcPendingWrite* self);
static void dc_rpc_transport_nap_data_free (gpointer _data);
static gboolean dc_rpc_transport_nap_co (DcRpcTransportNapData* _data_);
static gboolean _dc_rpc_transport_nap_co_gsource_func (gpointer self);
VALA_EXTERN DcRpcTransport* dc_rpc_transport_new (void);
VALA_EXTERN DcRpcTransport* dc_rpc_transport_construct (GType object_type);
VALA_EXTERN gboolean dc_rpc_transport_get_is_connected (DcRpcTransport* self);
static GObject * dc_rpc_transport_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void _dc_rpc_transport_perform_write_gfunc (gpointer data,
                                            gpointer self);
static void dc_rpc_transport_finalize (GObject * obj);
static GType dc_rpc_transport_get_type_once (void);
static void _vala_dc_rpc_transport_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_dc_rpc_transport_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
static void dc_pending_call_finalize (DcPendingCall * obj);
static GType dc_pending_call_get_type_once (void);
static void dc_pending_write_finalize (DcPendingWrite * obj);
static GType dc_pending_write_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_rpc_transport_get_instance_private (DcRpcTransport* self)
{
	return G_STRUCT_MEMBER_P (self, DcRpcTransport_private_offset);
}

static void
_dc_pending_call_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (dc_pending_call_unref (var), NULL));
}

static void
dc_rpc_transport_start_data_free (gpointer _data)
{
	DcRpcTransportStartData* _data_;
	_data_ = _data;
	_g_free0 (_data_->cwd);
	_g_free0 (_data_->accounts_path);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcTransportStartData, _data_);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
dc_rpc_transport_start (DcRpcTransport* self,
                        gchar** argv,
                        gint argv_length1,
                        const gchar* cwd,
                        const gchar* accounts_path,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_)
{
	DcRpcTransportStartData* _data_;
	DcRpcTransport* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcRpcTransportStartData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_transport_start_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->argv = argv;
	_data_->argv_length1 = argv_length1;
	_tmp1_ = g_strdup (cwd);
	_g_free0 (_data_->cwd);
	_data_->cwd = _tmp1_;
	_tmp2_ = g_strdup (accounts_path);
	_g_free0 (_data_->accounts_path);
	_data_->accounts_path = _tmp2_;
	dc_rpc_transport_start_co (_data_);
}

void
dc_rpc_transport_start_finish (DcRpcTransport* self,
                               GAsyncResult* _res_,
                               GError** error)
{
	DcRpcTransportStartData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block12Data*
block12_data_ref (Block12Data* _data12_)
{
	g_atomic_int_inc (&_data12_->_ref_count_);
	return _data12_;
}

static void
block12_data_unref (void * _userdata_)
{
	Block12Data* _data12_;
	_data12_ = (Block12Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data12_->_ref_count_)) {
		DcRpcTransport* self;
		self = _data12_->self;
		_g_object_unref0 (self);
		g_slice_free (Block12Data, _data12_);
	}
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
__lambda4_ (Block12Data* _data12_)
{
	DcRpcTransport* self;
	gboolean result;
	self = _data12_->self;
	if (!dc_rpc_transport_generation_is_active (self, _data12_->generation)) {
		result = FALSE;
		return result;
	}
	_data12_->timed_out = TRUE;
	dc_rpc_transport_finish_generation (self, _data12_->generation, "RPC server is not responding", FALSE);
	result = FALSE;
	return result;
}

static gboolean
___lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda4_ (self);
	return result;
}

static void
dc_rpc_transport_start_ready (GObject* source_object,
                              GAsyncResult* _res_,
                              gpointer _user_data_)
{
	DcRpcTransportStartData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_transport_start_co (_data_);
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static gboolean
dc_rpc_transport_start_co (DcRpcTransportStartData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data12_ = g_slice_new0 (Block12Data);
	_data_->_data12_->_ref_count_ = 1;
	_data_->_data12_->self = g_object_ref (_data_->self);
	_data_->_data12_->_async_data_ = _data_;
	_data_->_tmp3_ = _data_->self->priv->io_cancellable;
	if (_data_->_tmp3_ != NULL) {
		_data_->_tmp2_ = TRUE;
	} else {
		_data_->_tmp4_ = _data_->self->priv->process;
		_data_->_tmp2_ = _data_->_tmp4_ != NULL;
	}
	if (_data_->_tmp2_) {
		_data_->_tmp1_ = TRUE;
	} else {
		_data_->_tmp5_ = _data_->self->priv->reader;
		_data_->_tmp1_ = _data_->_tmp5_ != NULL;
	}
	if (_data_->_tmp1_) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp6_ = _data_->self->priv->writer;
		_data_->_tmp0_ = _data_->_tmp6_ != NULL;
	}
	if (_data_->_tmp0_) {
		dc_rpc_transport_stop (_data_->self);
	}
	_data_->self->priv->connection_generation = _data_->self->priv->connection_generation + 1;
	_data_->_tmp7_ = _data_->self->priv->connection_generation;
	_data_->_data12_->generation = _data_->_tmp7_;
	_data_->_tmp8_ = g_cancellable_new ();
	_data_->cancellable = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->cancellable;
	_data_->_tmp10_ = _g_object_ref0 (_data_->_tmp9_);
	_g_object_unref0 (_data_->self->priv->io_cancellable);
	_data_->self->priv->io_cancellable = _data_->_tmp10_;
	_data_->_tmp11_ = g_strdup ("");
	_g_free0 (_data_->self->priv->last_stderr);
	_data_->self->priv->last_stderr = _data_->_tmp11_;
	{
		_data_->flags = (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE) | G_SUBPROCESS_FLAGS_STDERR_PIPE;
		_data_->_tmp12_ = g_subprocess_launcher_new (_data_->flags);
		_data_->launcher = _data_->_tmp12_;
		if (_data_->cwd != NULL) {
			_data_->_tmp13_ = _data_->launcher;
			g_subprocess_launcher_set_cwd (_data_->_tmp13_, _data_->cwd);
		}
		if (_data_->accounts_path != NULL) {
			_data_->_tmp14_ = _data_->launcher;
			g_subprocess_launcher_setenv (_data_->_tmp14_, "DC_ACCOUNTS_PATH", _data_->accounts_path, TRUE);
		}
		_data_->_tmp16_ = _data_->launcher;
		_data_->_tmp17_ = dc_subprocess_util_spawnv (_data_->_tmp16_, _data_->argv, (gint) _data_->argv_length1, &_data_->_inner_error0_);
		_data_->_tmp15_ = _data_->_tmp17_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->launcher);
			goto __catch0_g_error;
		}
		_data_->_tmp18_ = _data_->_tmp15_;
		_data_->_tmp15_ = NULL;
		_g_object_unref0 (_data_->self->priv->process);
		_data_->self->priv->process = _data_->_tmp18_;
		_data_->_tmp19_ = _data_->self->priv->process;
		_data_->_tmp20_ = g_subprocess_get_stdin_pipe (_data_->_tmp19_);
		_data_->_tmp21_ = _g_object_ref0 (_data_->_tmp20_);
		_g_object_unref0 (_data_->self->priv->writer);
		_data_->self->priv->writer = _data_->_tmp21_;
		_data_->_tmp22_ = _data_->self->priv->process;
		_data_->_tmp23_ = g_subprocess_get_stdout_pipe (_data_->_tmp22_);
		_data_->_tmp24_ = g_data_input_stream_new (_data_->_tmp23_);
		_g_object_unref0 (_data_->self->priv->reader);
		_data_->self->priv->reader = _data_->_tmp24_;
		_data_->_tmp25_ = _data_->self->priv->process;
		_data_->_tmp26_ = g_subprocess_get_stderr_pipe (_data_->_tmp25_);
		_data_->_tmp27_ = _g_object_ref0 (_data_->_tmp26_);
		_g_object_unref0 (_data_->self->priv->err_pipe);
		_data_->self->priv->err_pipe = _data_->_tmp27_;
		_g_object_unref0 (_data_->_tmp15_);
		_g_object_unref0 (_data_->launcher);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		dc_rpc_transport_finish_generation (_data_->self, _data_->_data12_->generation, "RPC server failed to start", FALSE);
		_data_->_tmp28_ = _data_->e;
		_data_->_tmp29_ = _g_error_copy0 (_data_->_tmp28_);
		_data_->_inner_error0_ = _data_->_tmp29_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cancellable);
		block12_data_unref (_data_->_data12_);
		_data_->_data12_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp30_ = _data_->self->priv->reader;
	_data_->_tmp31_ = _g_object_ref0 (_data_->_tmp30_);
	_data_->connection_reader = _data_->_tmp31_;
	_data_->_tmp32_ = _data_->self->priv->writer;
	_data_->_tmp33_ = _g_object_ref0 (_data_->_tmp32_);
	_data_->connection_writer = _data_->_tmp33_;
	_data_->_tmp34_ = _data_->self->priv->err_pipe;
	_data_->_tmp35_ = _g_object_ref0 (_data_->_tmp34_);
	_data_->connection_err = _data_->_tmp35_;
	_data_->_tmp38_ = _data_->connection_reader;
	if (_data_->_tmp38_ == NULL) {
		_data_->_tmp37_ = TRUE;
	} else {
		_data_->_tmp39_ = _data_->connection_writer;
		_data_->_tmp37_ = _data_->_tmp39_ == NULL;
	}
	if (_data_->_tmp37_) {
		_data_->_tmp36_ = TRUE;
	} else {
		_data_->_tmp40_ = _data_->connection_err;
		_data_->_tmp36_ = _data_->_tmp40_ == NULL;
	}
	if (_data_->_tmp36_) {
		dc_rpc_transport_finish_generation (_data_->self, _data_->_data12_->generation, "RPC server pipes are unavailable", FALSE);
		_data_->_tmp41_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "RPC server pipes are unavailable");
		_data_->_inner_error0_ = _data_->_tmp41_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->connection_err);
		_g_object_unref0 (_data_->connection_writer);
		_g_object_unref0 (_data_->connection_reader);
		_g_object_unref0 (_data_->cancellable);
		block12_data_unref (_data_->_data12_);
		_data_->_data12_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp42_ = _data_->connection_reader;
	g_data_input_stream_set_newline_type (_data_->_tmp42_, G_DATA_STREAM_NEWLINE_TYPE_LF);
	_data_->_tmp43_ = _data_->connection_err;
	dc_rpc_transport_drain_stderr (_data_->self, _data_->_data12_->generation, _data_->_tmp43_, NULL, NULL);
	_data_->_tmp44_ = _data_->connection_reader;
	_data_->_tmp45_ = _data_->cancellable;
	dc_rpc_transport_read_loop (_data_->self, _data_->_data12_->generation, _data_->_tmp44_, _data_->_tmp45_, NULL, NULL);
	_data_->_data12_->timed_out = FALSE;
	_data_->handshake_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 20, ___lambda4__gsource_func, block12_data_ref (_data_->_data12_), block12_data_unref);
	{
		_data_->_tmp46_ = dc_params_begin ();
		_data_->_tmp47_ = _data_->_tmp46_;
		_data_->_tmp48_ = dc_params_build (_data_->_tmp47_);
		_data_->_tmp49_ = _data_->_tmp48_;
		_data_->_state_ = 1;
		dc_rpc_transport_call (_data_->self, "get_system_info", _data_->_tmp49_, dc_rpc_transport_start_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp50_ = dc_rpc_transport_call_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp51_ = _data_->_tmp50_;
		__vala_JsonNode_free0 (_data_->_tmp51_);
		__vala_JsonNode_free0 (_data_->_tmp49_);
		_g_object_unref0 (_data_->_tmp47_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		if (!_data_->_data12_->timed_out) {
			g_source_remove (_data_->handshake_timeout);
		}
		if (!dc_rpc_transport_generation_is_active (_data_->self, _data_->_data12_->generation)) {
			_data_->_tmp52_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "RPC connection changed during startup");
			_data_->_inner_error0_ = _data_->_tmp52_;
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		if (!_data_->_data12_->timed_out) {
			g_source_remove (_data_->handshake_timeout);
		}
		if (dc_rpc_transport_generation_is_active (_data_->self, _data_->_data12_->generation)) {
			dc_rpc_transport_finish_generation (_data_->self, _data_->_data12_->generation, "RPC server failed to start", FALSE);
		}
		_data_->_state_ = 2;
		dc_rpc_transport_nap (_data_->self, (guint) 200, dc_rpc_transport_start_ready, _data_);
		return FALSE;
		_state_2:
		dc_rpc_transport_nap_finish (_data_->self, _data_->_res_);
		_data_->_tmp53_ = _data_->self->priv->last_stderr;
		_data_->_tmp54_ = strlen (_data_->_tmp53_);
		_data_->_tmp55_ = _data_->_tmp54_;
		if (_data_->_tmp55_ > 0) {
			_data_->_tmp56_ = _data_->self->priv->last_stderr;
			_data_->_tmp57_ = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED, "%s", _data_->_tmp56_);
			_data_->_inner_error0_ = _data_->_tmp57_;
			_g_error_free0 (_data_->_vala1_e);
			goto __finally1;
		}
		_data_->_tmp58_ = _data_->_vala1_e;
		_data_->_tmp59_ = _g_error_copy0 (_data_->_tmp58_);
		_data_->_inner_error0_ = _data_->_tmp59_;
		_g_error_free0 (_data_->_vala1_e);
		goto __finally1;
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->connection_err);
		_g_object_unref0 (_data_->connection_writer);
		_g_object_unref0 (_data_->connection_reader);
		_g_object_unref0 (_data_->cancellable);
		block12_data_unref (_data_->_data12_);
		_data_->_data12_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	dc_rpc_transport_set_is_connected (_data_->self, TRUE);
	_g_object_unref0 (_data_->connection_err);
	_g_object_unref0 (_data_->connection_writer);
	_g_object_unref0 (_data_->connection_reader);
	_g_object_unref0 (_data_->cancellable);
	block12_data_unref (_data_->_data12_);
	_data_->_data12_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
dc_rpc_transport_stop (DcRpcTransport* self)
{
	g_return_if_fail (self != NULL);
	dc_rpc_transport_finish_generation (self, self->priv->connection_generation, "RPC client stopped", FALSE);
}

static void
dc_rpc_transport_finish_generation (DcRpcTransport* self,
                                    guint generation,
                                    const gchar* reason,
                                    gboolean emit_disconnected)
{
	GCancellable* cancellable = NULL;
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	GCancellable* _tmp2_;
	GSubprocess* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (reason != NULL);
	if (!dc_rpc_transport_generation_is_active (self, generation)) {
		return;
	}
	dc_rpc_transport_set_is_connected (self, FALSE);
	_tmp0_ = self->priv->io_cancellable;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	cancellable = _tmp1_;
	_g_object_unref0 (self->priv->io_cancellable);
	self->priv->io_cancellable = NULL;
	_g_object_unref0 (self->priv->writer);
	self->priv->writer = NULL;
	_g_object_unref0 (self->priv->reader);
	self->priv->reader = NULL;
	_g_object_unref0 (self->priv->err_pipe);
	self->priv->err_pipe = NULL;
	_tmp2_ = cancellable;
	if (_tmp2_ != NULL) {
		GCancellable* _tmp3_;
		_tmp3_ = cancellable;
		g_cancellable_cancel (_tmp3_);
	}
	dc_rpc_transport_fail_pending (self, reason, generation);
	_tmp4_ = self->priv->process;
	if (_tmp4_ != NULL) {
		GSubprocess* _tmp5_;
		_tmp5_ = self->priv->process;
		g_subprocess_force_exit (_tmp5_);
		_g_object_unref0 (self->priv->process);
		self->priv->process = NULL;
	}
	if (emit_disconnected) {
		g_signal_emit (self, dc_rpc_transport_signals[DC_RPC_TRANSPORT_DISCONNECTED_SIGNAL], 0, reason);
	}
	_g_object_unref0 (cancellable);
}

static gboolean
dc_rpc_transport_generation_is_active (DcRpcTransport* self,
                                       guint generation)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (generation == self->priv->connection_generation) {
		GCancellable* _tmp2_;
		_tmp2_ = self->priv->io_cancellable;
		_tmp1_ = _tmp2_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GCancellable* _tmp3_;
		_tmp3_ = self->priv->io_cancellable;
		_tmp0_ = !g_cancellable_is_cancelled (_tmp3_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
dc_rpc_transport_call_data_free (gpointer _data)
{
	DcRpcTransportCallData* _data_;
	_data_ = _data;
	_g_free0 (_data_->method);
	__vala_JsonNode_free0 (_data_->params);
	__vala_JsonNode_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcTransportCallData, _data_);
}

static JsonNode*
_vala_JsonNode_copy (JsonNode* self)
{
	return g_boxed_copy (json_node_get_type (), self);
}

static gpointer
__vala_JsonNode_copy0 (gpointer self)
{
	return self ? _vala_JsonNode_copy (self) : NULL;
}

void
dc_rpc_transport_call (DcRpcTransport* self,
                       const gchar* method,
                       JsonNode* params,
                       GAsyncReadyCallback _callback_,
                       gpointer _user_data_)
{
	DcRpcTransportCallData* _data_;
	DcRpcTransport* _tmp0_;
	gchar* _tmp1_;
	JsonNode* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (method != NULL);
	g_return_if_fail (params != NULL);
	_data_ = g_slice_new0 (DcRpcTransportCallData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_transport_call_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (method);
	_g_free0 (_data_->method);
	_data_->method = _tmp1_;
	_tmp2_ = __vala_JsonNode_copy0 (params);
	__vala_JsonNode_free0 (_data_->params);
	_data_->params = _tmp2_;
	dc_rpc_transport_call_co (_data_);
}

JsonNode*
dc_rpc_transport_call_finish (DcRpcTransport* self,
                              GAsyncResult* _res_,
                              GError** error)
{
	JsonNode* result;
	DcRpcTransportCallData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
_dc_rpc_transport_call_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dc_rpc_transport_call_co (self);
	return result;
}

static gpointer
_g_source_ref0 (gpointer self)
{
	return self ? g_source_ref (self) : NULL;
}

static gpointer
_dc_pending_call_ref0 (gpointer self)
{
	return self ? dc_pending_call_ref (self) : NULL;
}

static gboolean
dc_rpc_transport_call_co (DcRpcTransportCallData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->generation = _data_->self->priv->connection_generation;
	_data_->_tmp0_ = _data_->self->priv->writer;
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->connection_writer = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->io_cancellable;
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->cancellable = _data_->_tmp3_;
	_data_->_tmp7_ = _data_->connection_writer;
	if (_data_->_tmp7_ == NULL) {
		_data_->_tmp6_ = TRUE;
	} else {
		_data_->_tmp8_ = _data_->self->priv->reader;
		_data_->_tmp6_ = _data_->_tmp8_ == NULL;
	}
	if (_data_->_tmp6_) {
		_data_->_tmp5_ = TRUE;
	} else {
		_data_->_tmp9_ = _data_->cancellable;
		_data_->_tmp5_ = _data_->_tmp9_ == NULL;
	}
	if (_data_->_tmp5_) {
		_data_->_tmp4_ = TRUE;
	} else {
		_data_->_tmp4_ = !dc_rpc_transport_generation_is_active (_data_->self, _data_->generation);
	}
	if (_data_->_tmp4_) {
		_data_->_tmp10_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "RPC client not connected");
		_data_->_inner_error0_ = _data_->_tmp10_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cancellable);
		_g_object_unref0 (_data_->connection_writer);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->self->priv->next_id;
	_data_->self->priv->next_id = _data_->_tmp11_ + 1;
	_data_->id = _data_->_tmp11_;
	_data_->_tmp12_ = dc_pending_call_new (_data_->id, _data_->generation);
	_data_->pc = _data_->_tmp12_;
	_data_->_tmp13_ = g_idle_source_new ();
	_data_->resume_source = _data_->_tmp13_;
	_data_->_tmp14_ = _data_->resume_source;
	g_source_set_callback (_data_->_tmp14_, _dc_rpc_transport_call_co_gsource_func, _data_, NULL);
	_data_->_tmp15_ = _data_->pc;
	_data_->_tmp16_ = _data_->resume_source;
	_data_->_tmp17_ = _g_source_ref0 (_data_->_tmp16_);
	_g_source_unref0 (_data_->_tmp15_->resume_source);
	_data_->_tmp15_->resume_source = _data_->_tmp17_;
	_data_->_tmp18_ = _data_->self->priv->pending;
	_data_->_tmp19_ = _data_->pc;
	_data_->_tmp20_ = _dc_pending_call_ref0 (_data_->_tmp19_);
	g_ptr_array_add (_data_->_tmp18_, _data_->_tmp20_);
	_data_->_tmp21_ = _data_->pc;
	_data_->_tmp22_ = _data_->connection_writer;
	_data_->_tmp23_ = _data_->cancellable;
	dc_rpc_transport_queue_request (_data_->self, _data_->_tmp21_, _data_->method, _data_->params, _data_->_tmp22_, _data_->_tmp23_);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	dc_rpc_transport_remove_pending (_data_->self, _data_->id, _data_->generation);
	_data_->_tmp24_ = _data_->pc;
	_data_->_tmp25_ = _data_->_tmp24_->error_msg;
	if (_data_->_tmp25_ != NULL) {
		_data_->_tmp26_ = _data_->pc;
		_data_->_tmp27_ = _data_->_tmp26_->error_msg;
		_data_->_tmp28_ = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED, "RPC %s: %s", _data_->method, _data_->_tmp27_);
		_data_->_inner_error0_ = _data_->_tmp28_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_source_unref0 (_data_->resume_source);
		_dc_pending_call_unref0 (_data_->pc);
		_g_object_unref0 (_data_->cancellable);
		_g_object_unref0 (_data_->connection_writer);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp29_ = _data_->pc;
	_data_->_tmp30_ = _data_->_tmp29_->result;
	_data_->_tmp31_ = __vala_JsonNode_copy0 (_data_->_tmp30_);
	_data_->result = _data_->_tmp31_;
	_g_source_unref0 (_data_->resume_source);
	_dc_pending_call_unref0 (_data_->pc);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->connection_writer);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_rpc_transport_drain_stderr_data_free (gpointer _data)
{
	DcRpcTransportDrainStderrData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->pipe);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcTransportDrainStderrData, _data_);
}

static void
dc_rpc_transport_drain_stderr (DcRpcTransport* self,
                               guint generation,
                               GInputStream* pipe,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	DcRpcTransportDrainStderrData* _data_;
	DcRpcTransport* _tmp0_;
	GInputStream* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (pipe != NULL);
	_data_ = g_slice_new0 (DcRpcTransportDrainStderrData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_transport_drain_stderr_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->generation = generation;
	_tmp1_ = _g_object_ref0 (pipe);
	_g_object_unref0 (_data_->pipe);
	_data_->pipe = _tmp1_;
	dc_rpc_transport_drain_stderr_co (_data_);
}

static void
dc_rpc_transport_drain_stderr_finish (DcRpcTransport* self,
                                      GAsyncResult* _res_)
{
	DcRpcTransportDrainStderrData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_rpc_transport_drain_stderr_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	DcRpcTransportDrainStderrData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_transport_drain_stderr_co (_data_);
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gboolean
dc_rpc_transport_drain_stderr_co (DcRpcTransportDrainStderrData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = g_data_input_stream_new (_data_->pipe);
		_data_->err_stream = _data_->_tmp0_;
		while (TRUE) {
			_data_->_tmp2_ = _data_->err_stream;
			_data_->_tmp3_ = 0UL;
			_data_->_state_ = 1;
			g_data_input_stream_read_line_async (_data_->_tmp2_, G_PRIORITY_DEFAULT, NULL, dc_rpc_transport_drain_stderr_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp4_ = g_data_input_stream_read_line_finish_utf8 (_data_->_tmp2_, _data_->_res_, &_data_->_tmp3_, &_data_->_inner_error0_);
			_data_->len = _data_->_tmp3_;
			_data_->_tmp1_ = _data_->_tmp4_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_free0 (_data_->line);
				_g_object_unref0 (_data_->err_stream);
				goto __catch0_g_error;
			}
			_data_->_tmp5_ = _data_->_tmp1_;
			_data_->_tmp1_ = NULL;
			_g_free0 (_data_->line);
			_data_->line = _data_->_tmp5_;
			_data_->_tmp6_ = _data_->line;
			if (!(_data_->_tmp6_ != NULL)) {
				_g_free0 (_data_->_tmp1_);
				break;
			}
			if (_data_->generation != _data_->self->priv->connection_generation) {
				_g_free0 (_data_->_tmp1_);
				_g_free0 (_data_->line);
				_g_object_unref0 (_data_->err_stream);
				g_task_return_pointer (_data_->_async_result, _data_, NULL);
				if (_data_->_state_ != 0) {
					while (!g_task_get_completed (_data_->_async_result)) {
						g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
					}
				}
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp7_ = _data_->line;
			_data_->_tmp8_ = string_strip (_data_->_tmp7_);
			_g_free0 (_data_->self->priv->last_stderr);
			_data_->self->priv->last_stderr = _data_->_tmp8_;
			_g_free0 (_data_->_tmp1_);
		}
		_g_free0 (_data_->line);
		_g_object_unref0 (_data_->err_stream);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dc_rpc_transport_read_loop_data_free (gpointer _data)
{
	DcRpcTransportReadLoopData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcTransportReadLoopData, _data_);
}

static void
dc_rpc_transport_read_loop (DcRpcTransport* self,
                            guint generation,
                            GDataInputStream* stream,
                            GCancellable* cancellable,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	DcRpcTransportReadLoopData* _data_;
	DcRpcTransport* _tmp0_;
	GDataInputStream* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (DcRpcTransportReadLoopData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_transport_read_loop_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->generation = generation;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	dc_rpc_transport_read_loop_co (_data_);
}

static void
dc_rpc_transport_read_loop_finish (DcRpcTransport* self,
                                   GAsyncResult* _res_)
{
	DcRpcTransportReadLoopData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
dc_rpc_transport_read_loop_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	DcRpcTransportReadLoopData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_rpc_transport_read_loop_co (_data_);
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gboolean
dc_rpc_transport_read_loop_co (DcRpcTransportReadLoopData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup ("RPC server closed");
	_data_->reason = _data_->_tmp0_;
	{
		while (TRUE) {
			if (!dc_rpc_transport_generation_is_active (_data_->self, _data_->generation)) {
				break;
			}
			_data_->_tmp1_ = 0UL;
			_data_->_state_ = 1;
			g_data_input_stream_read_line_async (_data_->stream, G_PRIORITY_DEFAULT, _data_->cancellable, dc_rpc_transport_read_loop_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp2_ = g_data_input_stream_read_line_finish_utf8 (_data_->stream, _data_->_res_, &_data_->_tmp1_, &_data_->_inner_error0_);
			_data_->len = _data_->_tmp1_;
			_data_->line = _data_->_tmp2_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			if (!dc_rpc_transport_generation_is_active (_data_->self, _data_->generation)) {
				_g_free0 (_data_->line);
				_g_free0 (_data_->reason);
				g_task_return_pointer (_data_->_async_result, _data_, NULL);
				if (_data_->_state_ != 0) {
					while (!g_task_get_completed (_data_->_async_result)) {
						g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
					}
				}
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp3_ = _data_->line;
			if (_data_->_tmp3_ == NULL) {
				_g_free0 (_data_->line);
				break;
			}
			_data_->_tmp4_ = _data_->line;
			_data_->_tmp5_ = string_strip (_data_->_tmp4_);
			_data_->_tmp6_ = _data_->_tmp5_;
			_data_->_tmp7_ = strlen (_data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_tmp9_ = _data_->_tmp8_ == 0;
			_g_free0 (_data_->_tmp6_);
			if (_data_->_tmp9_) {
				_g_free0 (_data_->line);
				continue;
			}
			_data_->_tmp10_ = json_parser_new ();
			_data_->parser = _data_->_tmp10_;
			_data_->_tmp11_ = _data_->parser;
			_data_->_tmp12_ = _data_->line;
			json_parser_load_from_data (_data_->_tmp11_, _data_->_tmp12_, (gssize) -1, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->parser);
				_g_free0 (_data_->line);
				goto __catch0_g_error;
			}
			_data_->_tmp13_ = _data_->parser;
			_data_->_tmp14_ = json_parser_get_root (_data_->_tmp13_);
			_data_->_tmp15_ = __vala_JsonNode_copy0 (_data_->_tmp14_);
			_data_->root = _data_->_tmp15_;
			_data_->_tmp17_ = _data_->root;
			if (_data_->_tmp17_ == NULL) {
				_data_->_tmp16_ = TRUE;
			} else {
				_data_->_tmp18_ = _data_->root;
				_data_->_tmp16_ = json_node_get_node_type (_data_->_tmp18_) != JSON_NODE_OBJECT;
			}
			if (_data_->_tmp16_) {
				__vala_JsonNode_free0 (_data_->root);
				_g_object_unref0 (_data_->parser);
				_g_free0 (_data_->line);
				continue;
			}
			_data_->_tmp19_ = _data_->root;
			_data_->_tmp20_ = json_node_get_object (_data_->_tmp19_);
			_data_->_tmp21_ = _json_object_ref0 (_data_->_tmp20_);
			_data_->obj = _data_->_tmp21_;
			_data_->_tmp22_ = _data_->obj;
			if (!json_object_has_member (_data_->_tmp22_, "id")) {
				_json_object_unref0 (_data_->obj);
				__vala_JsonNode_free0 (_data_->root);
				_g_object_unref0 (_data_->parser);
				_g_free0 (_data_->line);
				continue;
			}
			_data_->_tmp23_ = _data_->obj;
			_data_->resp_id = (gint) json_object_get_int_member (_data_->_tmp23_, "id");
			_data_->_tmp24_ = dc_rpc_transport_find_pending (_data_->self, _data_->resp_id, _data_->generation);
			_data_->pc = _data_->_tmp24_;
			_data_->_tmp25_ = _data_->pc;
			if (_data_->_tmp25_ == NULL) {
				_dc_pending_call_unref0 (_data_->pc);
				_json_object_unref0 (_data_->obj);
				__vala_JsonNode_free0 (_data_->root);
				_g_object_unref0 (_data_->parser);
				_g_free0 (_data_->line);
				continue;
			}
			_data_->_tmp27_ = _data_->obj;
			if (json_object_has_member (_data_->_tmp27_, "error")) {
				_data_->_tmp28_ = _data_->obj;
				_data_->_tmp29_ = json_object_get_member (_data_->_tmp28_, "error");
				_data_->_tmp26_ = !json_node_is_null (_data_->_tmp29_);
			} else {
				_data_->_tmp26_ = FALSE;
			}
			if (_data_->_tmp26_) {
				_data_->_tmp30_ = _data_->obj;
				_data_->_tmp31_ = json_object_get_object_member (_data_->_tmp30_, "error");
				_data_->_tmp32_ = _json_object_ref0 (_data_->_tmp31_);
				_data_->err = _data_->_tmp32_;
				_data_->_tmp34_ = _data_->err;
				if (json_object_has_member (_data_->_tmp34_, "message")) {
					_data_->_tmp35_ = _data_->err;
					_data_->_tmp36_ = json_object_get_string_member (_data_->_tmp35_, "message");
					_data_->_tmp33_ = _data_->_tmp36_;
				} else {
					_data_->_tmp33_ = "Unknown RPC error";
				}
				_data_->_tmp37_ = _data_->pc;
				_data_->_tmp38_ = g_strdup (_data_->_tmp33_);
				_g_free0 (_data_->_tmp37_->error_msg);
				_data_->_tmp37_->error_msg = _data_->_tmp38_;
				_json_object_unref0 (_data_->err);
			} else {
				_data_->_tmp39_ = _data_->obj;
				if (json_object_has_member (_data_->_tmp39_, "result")) {
					_data_->_tmp40_ = _data_->obj;
					_data_->_tmp41_ = json_object_get_member (_data_->_tmp40_, "result");
					_data_->_tmp42_ = __vala_JsonNode_copy0 (_data_->_tmp41_);
					_data_->result_member = _data_->_tmp42_;
					_data_->_tmp44_ = _data_->result_member;
					if (_data_->_tmp44_ != NULL) {
						_data_->_tmp45_ = _data_->result_member;
						_data_->_tmp46_ = json_node_copy (_data_->_tmp45_);
						__vala_JsonNode_free0 (_data_->_tmp43_);
						_data_->_tmp43_ = _data_->_tmp46_;
					} else {
						__vala_JsonNode_free0 (_data_->_tmp43_);
						_data_->_tmp43_ = NULL;
					}
					_data_->_tmp47_ = _data_->pc;
					_data_->_tmp48_ = _data_->_tmp43_;
					_data_->_tmp43_ = NULL;
					__vala_JsonNode_free0 (_data_->_tmp47_->result);
					_data_->_tmp47_->result = _data_->_tmp48_;
					__vala_JsonNode_free0 (_data_->_tmp43_);
					__vala_JsonNode_free0 (_data_->result_member);
				}
			}
			_data_->_tmp49_ = _data_->pc;
			dc_rpc_transport_resume_pending (_data_->self, _data_->_tmp49_);
			_dc_pending_call_unref0 (_data_->pc);
			_json_object_unref0 (_data_->obj);
			__vala_JsonNode_free0 (_data_->root);
			_g_object_unref0 (_data_->parser);
			_g_free0 (_data_->line);
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		if (!dc_rpc_transport_generation_is_active (_data_->self, _data_->generation)) {
			_data_->_tmp50_ = TRUE;
		} else {
			_data_->_tmp51_ = _data_->e;
			_data_->_tmp50_ = g_error_matches (_data_->_tmp51_, G_IO_ERROR, G_IO_ERROR_CANCELLED);
		}
		if (_data_->_tmp50_) {
			_g_error_free0 (_data_->e);
			_g_free0 (_data_->reason);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp52_ = _data_->e;
		_data_->_tmp53_ = _data_->_tmp52_->message;
		g_warning ("rpc_transport.vala:260: RPC read loop error: %s", _data_->_tmp53_);
		_data_->_tmp54_ = _data_->e;
		_data_->_tmp55_ = _data_->_tmp54_->message;
		_data_->_tmp56_ = g_strconcat ("RPC read failed: ", _data_->_tmp55_, NULL);
		_g_free0 (_data_->reason);
		_data_->reason = _data_->_tmp56_;
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_free0 (_data_->reason);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (dc_rpc_transport_generation_is_active (_data_->self, _data_->generation)) {
		_data_->_tmp57_ = _data_->reason;
		dc_rpc_transport_finish_generation (_data_->self, _data_->generation, _data_->_tmp57_, TRUE);
	}
	_g_free0 (_data_->reason);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static Block13Data*
block13_data_ref (Block13Data* _data13_)
{
	g_atomic_int_inc (&_data13_->_ref_count_);
	return _data13_;
}

static void
block13_data_unref (void * _userdata_)
{
	Block13Data* _data13_;
	_data13_ = (Block13Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data13_->_ref_count_)) {
		DcRpcTransport* self;
		self = _data13_->self;
		_dc_pending_write_unref0 (_data13_->request);
		_g_object_unref0 (self);
		g_slice_free (Block13Data, _data13_);
	}
}

static gboolean
__lambda5_ (Block13Data* _data13_)
{
	DcRpcTransport* self;
	DcPendingWrite* _tmp0_;
	DcPendingWrite* _tmp1_;
	DcRpcTransport* _tmp2_;
	DcPendingWrite* _tmp3_;
	gboolean result;
	self = _data13_->self;
	_tmp0_ = _data13_->request;
	dc_pending_write_acquire_on_main (_tmp0_);
	_tmp1_ = _data13_->request;
	_tmp2_ = _tmp1_->transport;
	_tmp3_ = _data13_->request;
	dc_rpc_transport_write_completed (_tmp2_, _tmp3_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda5__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda5_ (self);
	return result;
}

static gpointer
_dc_pending_write_ref0 (gpointer self)
{
	return self ? dc_pending_write_ref (self) : NULL;
}

static void
dc_rpc_transport_queue_request (DcRpcTransport* self,
                                DcPendingCall* pc,
                                const gchar* method,
                                JsonNode* params,
                                GOutputStream* stream,
                                GCancellable* cancellable)
{
	Block13Data* _data13_;
	JsonBuilder* b = NULL;
	JsonBuilder* _tmp0_;
	JsonBuilder* _tmp1_;
	JsonBuilder* _tmp2_;
	JsonBuilder* _tmp3_;
	JsonBuilder* _tmp4_;
	JsonBuilder* _tmp5_;
	JsonBuilder* _tmp6_;
	JsonBuilder* _tmp7_;
	JsonBuilder* _tmp8_;
	JsonBuilder* _tmp9_;
	JsonNode* _tmp10_;
	JsonBuilder* _tmp11_;
	JsonGenerator* gen = NULL;
	JsonGenerator* _tmp12_;
	JsonGenerator* _tmp13_;
	JsonBuilder* _tmp14_;
	JsonNode* _tmp15_;
	JsonNode* _tmp16_;
	gsize json_len = 0UL;
	gchar* json = NULL;
	JsonGenerator* _tmp17_;
	gsize _tmp18_ = 0UL;
	gchar* _tmp19_;
	gchar* line = NULL;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	const gchar* _tmp22_;
	DcPendingWrite* _tmp23_;
	GThreadPool* _tmp24_;
	GSource* completed = NULL;
	GSource* _tmp26_;
	GSource* _tmp27_;
	DcPendingWrite* _tmp28_;
	GSource* _tmp29_;
	GSource* _tmp30_;
	DcPendingWrite* _tmp31_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (pc != NULL);
	g_return_if_fail (method != NULL);
	g_return_if_fail (params != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (cancellable != NULL);
	_data13_ = g_slice_new0 (Block13Data);
	_data13_->_ref_count_ = 1;
	_data13_->self = g_object_ref (self);
	_tmp0_ = json_builder_new ();
	b = _tmp0_;
	_tmp1_ = b;
	json_builder_begin_object (_tmp1_);
	_tmp2_ = b;
	json_builder_set_member_name (_tmp2_, "jsonrpc");
	_tmp3_ = b;
	json_builder_add_string_value (_tmp3_, "2.0");
	_tmp4_ = b;
	json_builder_set_member_name (_tmp4_, "id");
	_tmp5_ = b;
	json_builder_add_int_value (_tmp5_, (gint64) pc->id);
	_tmp6_ = b;
	json_builder_set_member_name (_tmp6_, "method");
	_tmp7_ = b;
	json_builder_add_string_value (_tmp7_, method);
	_tmp8_ = b;
	json_builder_set_member_name (_tmp8_, "params");
	_tmp9_ = b;
	_tmp10_ = __vala_JsonNode_copy0 (params);
	json_builder_add_value (_tmp9_, _tmp10_);
	_tmp11_ = b;
	json_builder_end_object (_tmp11_);
	_tmp12_ = json_generator_new ();
	gen = _tmp12_;
	_tmp13_ = gen;
	_tmp14_ = b;
	_tmp15_ = json_builder_get_root (_tmp14_);
	_tmp16_ = _tmp15_;
	json_generator_set_root (_tmp13_, _tmp16_);
	__vala_JsonNode_free0 (_tmp16_);
	_tmp17_ = gen;
	_tmp19_ = json_generator_to_data (_tmp17_, &_tmp18_);
	json_len = _tmp18_;
	json = _tmp19_;
	_tmp20_ = json;
	_tmp21_ = g_strconcat (_tmp20_, "\n", NULL);
	line = _tmp21_;
	_tmp22_ = line;
	_tmp23_ = dc_pending_write_new (self, pc, stream, cancellable, _tmp22_);
	_data13_->request = _tmp23_;
	_tmp24_ = self->priv->write_pool;
	if (_tmp24_ == NULL) {
		DcPendingWrite* _tmp25_;
		_tmp25_ = _data13_->request;
		dc_rpc_transport_fail_write (self, _tmp25_, "RPC writer is unavailable");
		_g_free0 (line);
		_g_free0 (json);
		_g_object_unref0 (gen);
		_g_object_unref0 (b);
		block13_data_unref (_data13_);
		_data13_ = NULL;
		return;
	}
	_tmp26_ = g_idle_source_new ();
	completed = _tmp26_;
	_tmp27_ = completed;
	g_source_set_callback (_tmp27_, ___lambda5__gsource_func, block13_data_ref (_data13_), block13_data_unref);
	_tmp28_ = _data13_->request;
	_tmp29_ = completed;
	_tmp30_ = _g_source_ref0 (_tmp29_);
	_g_source_unref0 (_tmp28_->completion_source);
	_tmp28_->completion_source = _tmp30_;
	_tmp31_ = _data13_->request;
	dc_pending_write_release_to_worker (_tmp31_);
	{
		GThreadPool* _tmp32_;
		DcPendingWrite* _tmp33_;
		DcPendingWrite* _tmp34_;
		_tmp32_ = self->priv->write_pool;
		_tmp33_ = _data13_->request;
		_tmp34_ = _dc_pending_write_ref0 (_tmp33_);
		g_thread_pool_push (_tmp32_, _tmp34_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		DcPendingWrite* _tmp35_;
		DcPendingWrite* _tmp36_;
		GError* _tmp37_;
		const gchar* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp35_ = _data13_->request;
		dc_pending_write_discard_completion (_tmp35_);
		_tmp36_ = _data13_->request;
		_tmp37_ = e;
		_tmp38_ = _tmp37_->message;
		_tmp39_ = g_strconcat ("RPC writer failed: ", _tmp38_, NULL);
		_tmp40_ = _tmp39_;
		dc_rpc_transport_fail_write (self, _tmp36_, _tmp40_);
		_g_free0 (_tmp40_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_source_unref0 (completed);
		_g_free0 (line);
		_g_free0 (json);
		_g_object_unref0 (gen);
		_g_object_unref0 (b);
		block13_data_unref (_data13_);
		_data13_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_source_unref0 (completed);
	_g_free0 (line);
	_g_free0 (json);
	_g_object_unref0 (gen);
	_g_object_unref0 (b);
	block13_data_unref (_data13_);
	_data13_ = NULL;
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
dc_rpc_transport_perform_write (DcPendingWrite* request)
{
	GCancellable* _tmp0_;
	GSource* completed = NULL;
	GSource* _tmp20_;
	GSource* _tmp21_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (request != NULL);
	dc_pending_write_acquire_in_worker (request);
	_tmp0_ = request->cancellable;
	if (g_cancellable_is_cancelled (_tmp0_)) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("RPC connection changed");
		_g_free0 (request->error_msg);
		request->error_msg = _tmp1_;
	} else {
		{
			gsize written = 0UL;
			gboolean complete = FALSE;
			GOutputStream* _tmp2_;
			const gchar* _tmp3_;
			guint8* _tmp4_;
			gint _tmp4__length1;
			gint _tmp5_ = 0;
			guint8* _tmp6_;
			gint _tmp6__length1;
			GCancellable* _tmp7_;
			gsize _tmp8_ = 0UL;
			gboolean _tmp9_;
			gboolean _tmp10_ = FALSE;
			GOutputStream* _tmp15_;
			GCancellable* _tmp16_;
			_tmp2_ = request->stream;
			_tmp3_ = request->line;
			_tmp4_ = string_get_data (_tmp3_, &_tmp5_);
			_tmp4__length1 = _tmp5_;
			_tmp6_ = _tmp4_;
			_tmp6__length1 = _tmp4__length1;
			_tmp7_ = request->cancellable;
			_tmp9_ = g_output_stream_write_all (_tmp2_, _tmp6_, (gsize) _tmp6__length1, &_tmp8_, _tmp7_, &_inner_error0_);
			written = _tmp8_;
			complete = _tmp9_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			if (!complete) {
				_tmp10_ = TRUE;
			} else {
				const gchar* _tmp11_;
				gint _tmp12_;
				gint _tmp13_;
				_tmp11_ = request->line;
				_tmp12_ = strlen (_tmp11_);
				_tmp13_ = _tmp12_;
				_tmp10_ = written != ((gsize) _tmp13_);
			}
			if (_tmp10_) {
				GError* _tmp14_;
				_tmp14_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Incomplete RPC request write");
				_inner_error0_ = _tmp14_;
				goto __catch0_g_error;
			}
			_tmp15_ = request->stream;
			_tmp16_ = request->cancellable;
			g_output_stream_flush (_tmp15_, _tmp16_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp17_;
			const gchar* _tmp18_;
			gchar* _tmp19_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp17_ = e;
			_tmp18_ = _tmp17_->message;
			_tmp19_ = g_strconcat ("RPC write failed: ", _tmp18_, NULL);
			_g_free0 (request->error_msg);
			request->error_msg = _tmp19_;
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_dc_pending_write_unref0 (request);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp20_ = request->completion_source;
	request->completion_source = NULL;
	completed = _tmp20_;
	_g_source_unref0 (request->completion_source);
	request->completion_source = NULL;
	dc_pending_write_release_from_worker (request);
	_tmp21_ = completed;
	if (_tmp21_ != NULL) {
		GSource* _tmp22_;
		GMainContext* _tmp23_;
		_tmp22_ = completed;
		_tmp23_ = g_main_context_default ();
		g_source_attach (_tmp22_, _tmp23_);
	}
	_g_source_unref0 (completed);
	_dc_pending_write_unref0 (request);
}

static void
dc_rpc_transport_write_completed (DcRpcTransport* self,
                                  DcPendingWrite* request)
{
	const gchar* _tmp0_;
	DcPendingCall* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (request != NULL);
	_tmp0_ = request->error_msg;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = request->pending;
	if (dc_rpc_transport_generation_is_active (self, _tmp1_->generation)) {
		DcPendingCall* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = request->pending;
		_tmp3_ = request->error_msg;
		dc_rpc_transport_finish_generation (self, _tmp2_->generation, _tmp3_, TRUE);
	} else {
		dc_rpc_transport_fail_write (self, request, "RPC connection changed");
	}
}

static void
dc_rpc_transport_fail_write (DcRpcTransport* self,
                             DcPendingWrite* request,
                             const gchar* reason)
{
	DcPendingCall* _tmp0_;
	GSource* _tmp1_;
	DcPendingCall* _tmp2_;
	gchar* _tmp3_;
	DcPendingCall* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (request != NULL);
	g_return_if_fail (reason != NULL);
	_tmp0_ = request->pending;
	_tmp1_ = _tmp0_->resume_source;
	if (_tmp1_ == NULL) {
		return;
	}
	_tmp2_ = request->pending;
	_tmp3_ = g_strdup (reason);
	_g_free0 (_tmp2_->error_msg);
	_tmp2_->error_msg = _tmp3_;
	_tmp4_ = request->pending;
	dc_rpc_transport_resume_pending (self, _tmp4_);
}

static gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = (gint) self->len;
	return result;
}

static DcPendingCall*
dc_rpc_transport_find_pending (DcRpcTransport* self,
                               gint id,
                               guint generation)
{
	DcPendingCall* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp2_;
				gint _tmp3_;
				gint _tmp4_;
				gboolean _tmp5_ = FALSE;
				GPtrArray* _tmp6_;
				gconstpointer _tmp7_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->pending;
				_tmp3_ = vala_g_ptr_array_get_length (_tmp2_);
				_tmp4_ = _tmp3_;
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp6_ = self->priv->pending;
				_tmp7_ = g_ptr_array_index (_tmp6_, (guint) i);
				if (((DcPendingCall*) _tmp7_)->id == id) {
					GPtrArray* _tmp8_;
					gconstpointer _tmp9_;
					_tmp8_ = self->priv->pending;
					_tmp9_ = g_ptr_array_index (_tmp8_, (guint) i);
					_tmp5_ = ((DcPendingCall*) _tmp9_)->generation == generation;
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					GPtrArray* _tmp10_;
					gconstpointer _tmp11_;
					DcPendingCall* _tmp12_;
					_tmp10_ = self->priv->pending;
					_tmp11_ = g_ptr_array_index (_tmp10_, (guint) i);
					_tmp12_ = _dc_pending_call_ref0 ((DcPendingCall*) _tmp11_);
					result = _tmp12_;
					return result;
				}
			}
		}
	}
	result = NULL;
	return result;
}

static void
dc_rpc_transport_remove_pending (DcRpcTransport* self,
                                 gint id,
                                 guint generation)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp2_;
				gint _tmp3_;
				gint _tmp4_;
				gboolean _tmp5_ = FALSE;
				GPtrArray* _tmp6_;
				gconstpointer _tmp7_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->pending;
				_tmp3_ = vala_g_ptr_array_get_length (_tmp2_);
				_tmp4_ = _tmp3_;
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp6_ = self->priv->pending;
				_tmp7_ = g_ptr_array_index (_tmp6_, (guint) i);
				if (((DcPendingCall*) _tmp7_)->id == id) {
					GPtrArray* _tmp8_;
					gconstpointer _tmp9_;
					_tmp8_ = self->priv->pending;
					_tmp9_ = g_ptr_array_index (_tmp8_, (guint) i);
					_tmp5_ = ((DcPendingCall*) _tmp9_)->generation == generation;
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					GPtrArray* _tmp10_;
					_tmp10_ = self->priv->pending;
					g_ptr_array_remove_index (_tmp10_, (guint) i);
					return;
				}
			}
		}
	}
}

static void
dc_rpc_transport_fail_pending (DcRpcTransport* self,
                               const gchar* reason,
                               guint generation)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (reason != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp2_;
				gint _tmp3_;
				gint _tmp4_;
				GPtrArray* _tmp5_;
				gconstpointer _tmp6_;
				GPtrArray* _tmp7_;
				gconstpointer _tmp8_;
				GSource* _tmp9_;
				GPtrArray* _tmp10_;
				gconstpointer _tmp11_;
				gchar* _tmp12_;
				GPtrArray* _tmp13_;
				gconstpointer _tmp14_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->pending;
				_tmp3_ = vala_g_ptr_array_get_length (_tmp2_);
				_tmp4_ = _tmp3_;
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp5_ = self->priv->pending;
				_tmp6_ = g_ptr_array_index (_tmp5_, (guint) i);
				if (((DcPendingCall*) _tmp6_)->generation != generation) {
					continue;
				}
				_tmp7_ = self->priv->pending;
				_tmp8_ = g_ptr_array_index (_tmp7_, (guint) i);
				_tmp9_ = ((DcPendingCall*) _tmp8_)->resume_source;
				if (_tmp9_ == NULL) {
					continue;
				}
				_tmp10_ = self->priv->pending;
				_tmp11_ = g_ptr_array_index (_tmp10_, (guint) i);
				_tmp12_ = g_strdup (reason);
				_g_free0 (((DcPendingCall*) _tmp11_)->error_msg);
				((DcPendingCall*) _tmp11_)->error_msg = _tmp12_;
				_tmp13_ = self->priv->pending;
				_tmp14_ = g_ptr_array_index (_tmp13_, (guint) i);
				dc_rpc_transport_resume_pending (self, (DcPendingCall*) _tmp14_);
			}
		}
	}
}

static void
dc_rpc_transport_resume_pending (DcRpcTransport* self,
                                 DcPendingCall* pc)
{
	GSource* source = NULL;
	GSource* _tmp0_;
	GSource* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (pc != NULL);
	_tmp0_ = pc->resume_source;
	pc->resume_source = NULL;
	source = _tmp0_;
	_g_source_unref0 (pc->resume_source);
	pc->resume_source = NULL;
	_tmp1_ = source;
	if (_tmp1_ != NULL) {
		GSource* _tmp2_;
		GMainContext* _tmp3_;
		_tmp2_ = source;
		_tmp3_ = g_main_context_default ();
		g_source_attach (_tmp2_, _tmp3_);
	}
	_g_source_unref0 (source);
}

static void
dc_rpc_transport_nap_data_free (gpointer _data)
{
	DcRpcTransportNapData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcRpcTransportNapData, _data_);
}

static void
dc_rpc_transport_nap (DcRpcTransport* self,
                      guint ms,
                      GAsyncReadyCallback _callback_,
                      gpointer _user_data_)
{
	DcRpcTransportNapData* _data_;
	DcRpcTransport* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcRpcTransportNapData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_rpc_transport_nap_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->ms = ms;
	dc_rpc_transport_nap_co (_data_);
}

static void
dc_rpc_transport_nap_finish (DcRpcTransport* self,
                             GAsyncResult* _res_)
{
	DcRpcTransportNapData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gboolean
_dc_rpc_transport_nap_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dc_rpc_transport_nap_co (self);
	return result;
}

static gboolean
dc_rpc_transport_nap_co (DcRpcTransportNapData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	g_timeout_add_full (G_PRIORITY_DEFAULT, _data_->ms, _dc_rpc_transport_nap_co_gsource_func, _data_, NULL);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

DcRpcTransport*
dc_rpc_transport_construct (GType object_type)
{
	DcRpcTransport * self = NULL;
	self = (DcRpcTransport*) g_object_new (object_type, NULL);
	return self;
}

DcRpcTransport*
dc_rpc_transport_new (void)
{
	return dc_rpc_transport_construct (DC_TYPE_RPC_TRANSPORT);
}

gboolean
dc_rpc_transport_get_is_connected (DcRpcTransport* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_is_connected;
	return result;
}

static void
dc_rpc_transport_set_is_connected (DcRpcTransport* self,
                                   gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_rpc_transport_get_is_connected (self);
	if (old_value != value) {
		self->priv->_is_connected = value;
		g_object_notify_by_pspec ((GObject *) self, dc_rpc_transport_properties[DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY]);
	}
}

static void
_dc_rpc_transport_perform_write_gfunc (gpointer data,
                                       gpointer self)
{
	dc_rpc_transport_perform_write ((DcPendingWrite*) data);
}

static GObject *
dc_rpc_transport_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DcRpcTransport * self;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (dc_rpc_transport_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_RPC_TRANSPORT, DcRpcTransport);
	parla_ignore_sigpipe ();
	{
		GThreadPool* _tmp0_ = NULL;
		GThreadPool* _tmp1_;
		GThreadPool* _tmp2_;
		_tmp1_ = g_thread_pool_new (_dc_rpc_transport_perform_write_gfunc, NULL, 1, FALSE, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_thread_pool_free0 (self->priv->write_pool);
		self->priv->write_pool = _tmp2_;
		_g_thread_pool_free0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("rpc_transport.vala:42: RPC writer thread: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
	}
	return obj;
}

static void
dc_rpc_transport_class_init (DcRpcTransportClass * klass,
                             gpointer klass_data)
{
	dc_rpc_transport_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcRpcTransport_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_rpc_transport_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_rpc_transport_set_property;
	G_OBJECT_CLASS (klass)->constructor = dc_rpc_transport_constructor;
	G_OBJECT_CLASS (klass)->finalize = dc_rpc_transport_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY, dc_rpc_transport_properties[DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY] = g_param_spec_boolean ("is-connected", "is-connected", "is-connected", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_rpc_transport_signals[DC_RPC_TRANSPORT_DISCONNECTED_SIGNAL] = g_signal_new ("disconnected", DC_TYPE_RPC_TRANSPORT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
dc_rpc_transport_instance_init (DcRpcTransport * self,
                                gpointer klass)
{
	GPtrArray* _tmp0_;
	gchar* _tmp1_;
	self->priv = dc_rpc_transport_get_instance_private (self);
	self->priv->process = NULL;
	self->priv->reader = NULL;
	self->priv->writer = NULL;
	self->priv->err_pipe = NULL;
	self->priv->next_id = 1;
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _dc_pending_call_unref0_);
	self->priv->pending = _tmp0_;
	self->priv->write_pool = NULL;
	self->priv->connection_generation = (guint) 0;
	self->priv->io_cancellable = NULL;
	_tmp1_ = g_strdup ("");
	self->priv->last_stderr = _tmp1_;
	self->priv->_is_connected = FALSE;
}

static void
dc_rpc_transport_finalize (GObject * obj)
{
	DcRpcTransport * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_RPC_TRANSPORT, DcRpcTransport);
	_g_object_unref0 (self->priv->process);
	_g_object_unref0 (self->priv->reader);
	_g_object_unref0 (self->priv->writer);
	_g_object_unref0 (self->priv->err_pipe);
	_g_ptr_array_unref0 (self->priv->pending);
	_g_thread_pool_free0 (self->priv->write_pool);
	_g_object_unref0 (self->priv->io_cancellable);
	_g_free0 (self->priv->last_stderr);
	G_OBJECT_CLASS (dc_rpc_transport_parent_class)->finalize (obj);
}

/**
     * JSON-RPC transport for deltachat-rpc-server over stdio.
     * Owns the subprocess, request ids, pending calls, and read loop.
     */
static GType
dc_rpc_transport_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcRpcTransportClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_rpc_transport_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcRpcTransport), 0, (GInstanceInitFunc) dc_rpc_transport_instance_init, NULL };
	GType dc_rpc_transport_type_id;
	dc_rpc_transport_type_id = g_type_register_static (G_TYPE_OBJECT, "DcRpcTransport", &g_define_type_info, 0);
	DcRpcTransport_private_offset = g_type_add_instance_private (dc_rpc_transport_type_id, sizeof (DcRpcTransportPrivate));
	return dc_rpc_transport_type_id;
}

GType
dc_rpc_transport_get_type (void)
{
	static volatile gsize dc_rpc_transport_type_id__once = 0;
	if (g_once_init_enter (&dc_rpc_transport_type_id__once)) {
		GType dc_rpc_transport_type_id;
		dc_rpc_transport_type_id = dc_rpc_transport_get_type_once ();
		g_once_init_leave (&dc_rpc_transport_type_id__once, dc_rpc_transport_type_id);
	}
	return dc_rpc_transport_type_id__once;
}

static void
_vala_dc_rpc_transport_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	DcRpcTransport * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_RPC_TRANSPORT, DcRpcTransport);
	switch (property_id) {
		case DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY:
		g_value_set_boolean (value, dc_rpc_transport_get_is_connected (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_rpc_transport_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	DcRpcTransport * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_RPC_TRANSPORT, DcRpcTransport);
	switch (property_id) {
		case DC_RPC_TRANSPORT_IS_CONNECTED_PROPERTY:
		dc_rpc_transport_set_is_connected (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

DcPendingCall*
dc_pending_call_construct (GType object_type,
                           gint id,
                           guint generation)
{
	DcPendingCall* self = NULL;
	self = (DcPendingCall*) g_type_create_instance (object_type);
	self->id = id;
	self->generation = generation;
	return self;
}

DcPendingCall*
dc_pending_call_new (gint id,
                     guint generation)
{
	return dc_pending_call_construct (DC_TYPE_PENDING_CALL, id, generation);
}

static void
dc_value_pending_call_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_value_pending_call_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_pending_call_unref (value->data[0].v_pointer);
	}
}

static void
dc_value_pending_call_copy_value (const GValue* src_value,
                                  GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_pending_call_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_value_pending_call_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_value_pending_call_collect_value (GValue* value,
                                     guint n_collect_values,
                                     GTypeCValue* collect_values,
                                     guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcPendingCall * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_pending_call_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_value_pending_call_lcopy_value (const GValue* value,
                                   guint n_collect_values,
                                   GTypeCValue* collect_values,
                                   guint collect_flags)
{
	DcPendingCall ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_pending_call_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_param_spec_pending_call (const gchar* name,
                            const gchar* nick,
                            const gchar* blurb,
                            GType object_type,
                            GParamFlags flags)
{
	DcParamSpecPendingCall* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_TYPE_PENDING_CALL), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_value_get_pending_call (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_CALL), NULL);
	return value->data[0].v_pointer;
}

void
dc_value_set_pending_call (GValue* value,
                           gpointer v_object)
{
	DcPendingCall * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_CALL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_PENDING_CALL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_pending_call_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_pending_call_unref (old);
	}
}

void
dc_value_take_pending_call (GValue* value,
                            gpointer v_object)
{
	DcPendingCall * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_CALL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_PENDING_CALL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_pending_call_unref (old);
	}
}

static void
dc_pending_call_class_init (DcPendingCallClass * klass,
                            gpointer klass_data)
{
	dc_pending_call_parent_class = g_type_class_peek_parent (klass);
	((DcPendingCallClass *) klass)->finalize = dc_pending_call_finalize;
}

static void
dc_pending_call_instance_init (DcPendingCall * self,
                               gpointer klass)
{
	self->resume_source = NULL;
	self->result = NULL;
	self->error_msg = NULL;
	self->ref_count = 1;
}

static void
dc_pending_call_finalize (DcPendingCall * obj)
{
	DcPendingCall * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_PENDING_CALL, DcPendingCall);
	g_signal_handlers_destroy (self);
	_g_source_unref0 (self->resume_source);
	__vala_JsonNode_free0 (self->result);
	_g_free0 (self->error_msg);
}

static GType
dc_pending_call_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_value_pending_call_init, dc_value_pending_call_free_value, dc_value_pending_call_copy_value, dc_value_pending_call_peek_pointer, "p", dc_value_pending_call_collect_value, "p", dc_value_pending_call_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcPendingCallClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_pending_call_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcPendingCall), 0, (GInstanceInitFunc) dc_pending_call_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_pending_call_type_id;
	dc_pending_call_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcPendingCall", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_pending_call_type_id;
}

GType
dc_pending_call_get_type (void)
{
	static volatile gsize dc_pending_call_type_id__once = 0;
	if (g_once_init_enter (&dc_pending_call_type_id__once)) {
		GType dc_pending_call_type_id;
		dc_pending_call_type_id = dc_pending_call_get_type_once ();
		g_once_init_leave (&dc_pending_call_type_id__once, dc_pending_call_type_id);
	}
	return dc_pending_call_type_id__once;
}

gpointer
dc_pending_call_ref (gpointer instance)
{
	DcPendingCall * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_pending_call_unref (gpointer instance)
{
	DcPendingCall * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_PENDING_CALL_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

DcPendingWrite*
dc_pending_write_construct (GType object_type,
                            DcRpcTransport* transport,
                            DcPendingCall* pending,
                            GOutputStream* stream,
                            GCancellable* cancellable,
                            const gchar* line)
{
	DcPendingWrite* self = NULL;
	DcRpcTransport* _tmp0_;
	DcPendingCall* _tmp1_;
	GOutputStream* _tmp2_;
	GCancellable* _tmp3_;
	gchar* _tmp4_;
	g_return_val_if_fail (transport != NULL, NULL);
	g_return_val_if_fail (pending != NULL, NULL);
	g_return_val_if_fail (stream != NULL, NULL);
	g_return_val_if_fail (cancellable != NULL, NULL);
	g_return_val_if_fail (line != NULL, NULL);
	self = (DcPendingWrite*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (transport);
	_g_object_unref0 (self->transport);
	self->transport = _tmp0_;
	_tmp1_ = _dc_pending_call_ref0 (pending);
	_dc_pending_call_unref0 (self->pending);
	self->pending = _tmp1_;
	_tmp2_ = _g_object_ref0 (stream);
	_g_object_unref0 (self->stream);
	self->stream = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (self->cancellable);
	self->cancellable = _tmp3_;
	_tmp4_ = g_strdup (line);
	_g_free0 (self->line);
	self->line = _tmp4_;
	return self;
}

DcPendingWrite*
dc_pending_write_new (DcRpcTransport* transport,
                      DcPendingCall* pending,
                      GOutputStream* stream,
                      GCancellable* cancellable,
                      const gchar* line)
{
	return dc_pending_write_construct (DC_TYPE_PENDING_WRITE, transport, pending, stream, cancellable, line);
}

void
dc_pending_write_release_to_worker (DcPendingWrite* self)
{
	g_return_if_fail (self != NULL);
	g_atomic_int_set ((volatile gint *) (&self->handoff_phase), 1);
}

void
dc_pending_write_acquire_in_worker (DcPendingWrite* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_atomic_int_get ((volatile gint *) (&self->handoff_phase));
	_vala_assert (_tmp0_ == 1, "AtomicInt.get (ref handoff_phase) == 1");
}

void
dc_pending_write_release_from_worker (DcPendingWrite* self)
{
	g_return_if_fail (self != NULL);
	g_atomic_int_set ((volatile gint *) (&self->handoff_phase), 2);
}

void
dc_pending_write_acquire_on_main (DcPendingWrite* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_atomic_int_get ((volatile gint *) (&self->handoff_phase));
	_vala_assert (_tmp0_ == 2, "AtomicInt.get (ref handoff_phase) == 2");
}

void
dc_pending_write_discard_completion (DcPendingWrite* self)
{
	g_return_if_fail (self != NULL);
	_g_source_unref0 (self->completion_source);
	self->completion_source = NULL;
}

static void
dc_value_pending_write_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_value_pending_write_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_pending_write_unref (value->data[0].v_pointer);
	}
}

static void
dc_value_pending_write_copy_value (const GValue* src_value,
                                   GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_pending_write_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_value_pending_write_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_value_pending_write_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcPendingWrite * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_pending_write_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_value_pending_write_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	DcPendingWrite ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_pending_write_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_param_spec_pending_write (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	DcParamSpecPendingWrite* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_TYPE_PENDING_WRITE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_value_get_pending_write (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_WRITE), NULL);
	return value->data[0].v_pointer;
}

void
dc_value_set_pending_write (GValue* value,
                            gpointer v_object)
{
	DcPendingWrite * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_WRITE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_PENDING_WRITE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_pending_write_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_pending_write_unref (old);
	}
}

void
dc_value_take_pending_write (GValue* value,
                             gpointer v_object)
{
	DcPendingWrite * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_PENDING_WRITE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_PENDING_WRITE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_pending_write_unref (old);
	}
}

static void
dc_pending_write_class_init (DcPendingWriteClass * klass,
                             gpointer klass_data)
{
	dc_pending_write_parent_class = g_type_class_peek_parent (klass);
	((DcPendingWriteClass *) klass)->finalize = dc_pending_write_finalize;
}

static void
dc_pending_write_instance_init (DcPendingWrite * self,
                                gpointer klass)
{
	self->error_msg = NULL;
	self->completion_source = NULL;
	self->handoff_phase = 0;
	self->ref_count = 1;
}

static void
dc_pending_write_finalize (DcPendingWrite * obj)
{
	DcPendingWrite * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_PENDING_WRITE, DcPendingWrite);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->transport);
	_dc_pending_call_unref0 (self->pending);
	_g_object_unref0 (self->stream);
	_g_object_unref0 (self->cancellable);
	_g_free0 (self->line);
	_g_free0 (self->error_msg);
	_g_source_unref0 (self->completion_source);
}

static GType
dc_pending_write_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_value_pending_write_init, dc_value_pending_write_free_value, dc_value_pending_write_copy_value, dc_value_pending_write_peek_pointer, "p", dc_value_pending_write_collect_value, "p", dc_value_pending_write_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcPendingWriteClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_pending_write_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcPendingWrite), 0, (GInstanceInitFunc) dc_pending_write_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_pending_write_type_id;
	dc_pending_write_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcPendingWrite", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_pending_write_type_id;
}

GType
dc_pending_write_get_type (void)
{
	static volatile gsize dc_pending_write_type_id__once = 0;
	if (g_once_init_enter (&dc_pending_write_type_id__once)) {
		GType dc_pending_write_type_id;
		dc_pending_write_type_id = dc_pending_write_get_type_once ();
		g_once_init_leave (&dc_pending_write_type_id__once, dc_pending_write_type_id);
	}
	return dc_pending_write_type_id__once;
}

gpointer
dc_pending_write_ref (gpointer instance)
{
	DcPendingWrite * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_pending_write_unref (gpointer instance)
{
	DcPendingWrite * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_PENDING_WRITE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

