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

#include "http-files.h"
#include "libdino.h"
#include <glib.h>
#include <glib-object.h>
#include "qlite.h"
#include <stdlib.h>
#include <string.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

enum  {
	DINO_PLUGINS_HTTP_FILES_PLUGIN_0_PROPERTY,
	DINO_PLUGINS_HTTP_FILES_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_http_files_plugin_properties[DINO_PLUGINS_HTTP_FILES_PLUGIN_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))

static gpointer dino_plugins_http_files_plugin_parent_class = NULL;
static DinoPluginsRootInterfaceIface * dino_plugins_http_files_plugin_dino_plugins_root_interface_parent_iface = NULL;

static void dino_plugins_http_files_plugin_real_registered (DinoPluginsRootInterface* base,
                                                     DinoApplication* app);
static void dino_plugins_http_files_plugin_real_shutdown (DinoPluginsRootInterface* base);
static void dino_plugins_http_files_plugin_finalize (GObject * obj);
static GType dino_plugins_http_files_plugin_get_type_once (void);
VALA_EXTERN gboolean dino_plugins_http_files_message_is_file (DinoDatabase* db,
                                                  DinoEntitiesMessage* message);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

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

static void
dino_plugins_http_files_plugin_real_registered (DinoPluginsRootInterface* base,
                                                DinoApplication* app)
{
	DinoPluginsHttpFilesPlugin * self;
	DinoApplication* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoStreamInteractor* _tmp2_;
	DinoDatabase* _tmp3_;
	DinoDatabase* _tmp4_;
	DinoPluginsHttpFilesFileProvider* _tmp5_;
	DinoStreamInteractor* _tmp6_;
	DinoStreamInteractor* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabase* _tmp9_;
	DinoPluginsHttpFilesHttpFileSender* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoStreamInteractor* _tmp12_;
	DinoModuleIdentity* _tmp13_;
	gpointer _tmp14_;
	DinoFileManager* _tmp15_;
	DinoPluginsHttpFilesFileProvider* _tmp16_;
	DinoStreamInteractor* _tmp17_;
	DinoStreamInteractor* _tmp18_;
	DinoModuleIdentity* _tmp19_;
	gpointer _tmp20_;
	DinoFileManager* _tmp21_;
	DinoFileSender* _tmp22_;
	self = (DinoPluginsHttpFilesPlugin*) base;
	g_return_if_fail (app != NULL);
	_tmp0_ = _g_object_ref0 (app);
	_g_object_unref0 (self->app);
	self->app = _tmp0_;
	_tmp1_ = dino_application_get_stream_interactor (app);
	_tmp2_ = _tmp1_;
	_tmp3_ = dino_application_get_db (app);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_plugins_http_files_file_provider_new (_tmp2_, _tmp4_);
	_g_object_unref0 (self->file_provider);
	self->file_provider = _tmp5_;
	_tmp6_ = dino_application_get_stream_interactor (app);
	_tmp7_ = _tmp6_;
	_tmp8_ = dino_application_get_db (app);
	_tmp9_ = _tmp8_;
	_tmp10_ = dino_plugins_http_files_http_file_sender_new (_tmp7_, _tmp9_);
	_g_object_unref0 (self->file_sender);
	self->file_sender = (DinoFileSender*) _tmp10_;
	_tmp11_ = dino_application_get_stream_interactor (app);
	_tmp12_ = _tmp11_;
	_tmp13_ = dino_file_manager_IDENTITY;
	_tmp14_ = dino_stream_interactor_get_module (_tmp12_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp13_);
	_tmp15_ = (DinoFileManager*) _tmp14_;
	_tmp16_ = self->file_provider;
	dino_file_manager_add_provider (_tmp15_, (DinoFileProvider*) _tmp16_);
	_g_object_unref0 (_tmp15_);
	_tmp17_ = dino_application_get_stream_interactor (app);
	_tmp18_ = _tmp17_;
	_tmp19_ = dino_file_manager_IDENTITY;
	_tmp20_ = dino_stream_interactor_get_module (_tmp18_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp19_);
	_tmp21_ = (DinoFileManager*) _tmp20_;
	_tmp22_ = self->file_sender;
	dino_file_manager_add_sender (_tmp21_, _tmp22_);
	_g_object_unref0 (_tmp21_);
}

static void
dino_plugins_http_files_plugin_real_shutdown (DinoPluginsRootInterface* base)
{
	DinoPluginsHttpFilesPlugin * self;
	self = (DinoPluginsHttpFilesPlugin*) base;
}

DinoPluginsHttpFilesPlugin*
dino_plugins_http_files_plugin_construct (GType object_type)
{
	DinoPluginsHttpFilesPlugin * self = NULL;
	self = (DinoPluginsHttpFilesPlugin*) g_object_new (object_type, NULL);
	return self;
}

DinoPluginsHttpFilesPlugin*
dino_plugins_http_files_plugin_new (void)
{
	return dino_plugins_http_files_plugin_construct (DINO_PLUGINS_HTTP_FILES_TYPE_PLUGIN);
}

static void
dino_plugins_http_files_plugin_class_init (DinoPluginsHttpFilesPluginClass * klass,
                                           gpointer klass_data)
{
	dino_plugins_http_files_plugin_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_http_files_plugin_finalize;
}

static void
dino_plugins_http_files_plugin_dino_plugins_root_interface_interface_init (DinoPluginsRootInterfaceIface * iface,
                                                                           gpointer iface_data)
{
	dino_plugins_http_files_plugin_dino_plugins_root_interface_parent_iface = g_type_interface_peek_parent (iface);
	iface->registered = (void (*) (DinoPluginsRootInterface*, DinoApplication*)) dino_plugins_http_files_plugin_real_registered;
	iface->shutdown = (void (*) (DinoPluginsRootInterface*)) dino_plugins_http_files_plugin_real_shutdown;
}

static void
dino_plugins_http_files_plugin_instance_init (DinoPluginsHttpFilesPlugin * self,
                                              gpointer klass)
{
}

static void
dino_plugins_http_files_plugin_finalize (GObject * obj)
{
	DinoPluginsHttpFilesPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_HTTP_FILES_TYPE_PLUGIN, DinoPluginsHttpFilesPlugin);
	_g_object_unref0 (self->app);
	_g_object_unref0 (self->file_provider);
	_g_object_unref0 (self->file_sender);
	G_OBJECT_CLASS (dino_plugins_http_files_plugin_parent_class)->finalize (obj);
}

static GType
dino_plugins_http_files_plugin_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsHttpFilesPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_http_files_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsHttpFilesPlugin), 0, (GInstanceInitFunc) dino_plugins_http_files_plugin_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_root_interface_info = { (GInterfaceInitFunc) dino_plugins_http_files_plugin_dino_plugins_root_interface_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_http_files_plugin_type_id;
	dino_plugins_http_files_plugin_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsHttpFilesPlugin", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_http_files_plugin_type_id, DINO_PLUGINS_TYPE_ROOT_INTERFACE, &dino_plugins_root_interface_info);
	return dino_plugins_http_files_plugin_type_id;
}

GType
dino_plugins_http_files_plugin_get_type (void)
{
	static volatile gsize dino_plugins_http_files_plugin_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_http_files_plugin_type_id__once)) {
		GType dino_plugins_http_files_plugin_type_id;
		dino_plugins_http_files_plugin_type_id = dino_plugins_http_files_plugin_get_type_once ();
		g_once_init_leave (&dino_plugins_http_files_plugin_type_id__once, dino_plugins_http_files_plugin_type_id);
	}
	return dino_plugins_http_files_plugin_type_id__once;
}

static gpointer
_qlite_column_ref0 (gpointer self)
{
	return self ? qlite_column_ref (self) : NULL;
}

gboolean
dino_plugins_http_files_message_is_file (DinoDatabase* db,
                                         DinoEntitiesMessage* message)
{
	QliteQueryBuilder* builder = NULL;
	DinoDatabaseFileTransferTable* _tmp0_;
	DinoDatabaseFileTransferTable* _tmp1_;
	DinoDatabaseFileTransferTable* _tmp2_;
	DinoDatabaseFileTransferTable* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn** _tmp6_;
	QliteColumn** _tmp7_;
	gint _tmp7__length1;
	QliteQueryBuilder* _tmp8_;
	QliteQueryBuilder* _tmp9_;
	DinoDatabaseFileTransferTable* _tmp10_;
	DinoDatabaseFileTransferTable* _tmp11_;
	QliteColumn* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	QliteQueryBuilder* _tmp18_;
	gboolean result;
	g_return_val_if_fail (db != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	_tmp0_ = dino_database_get_file_transfer (db);
	_tmp1_ = _tmp0_;
	_tmp2_ = dino_database_get_file_transfer (db);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_->id;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = g_new0 (QliteColumn*, 1 + 1);
	_tmp6_[0] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 1;
	_tmp8_ = qlite_table_select ((QliteTable*) _tmp1_, _tmp7_, (gint) 1);
	_tmp9_ = _tmp8_;
	_tmp10_ = dino_database_get_file_transfer (db);
	_tmp11_ = _tmp10_;
	_tmp12_ = _tmp11_->info;
	_tmp13_ = dino_entities_message_get_id (message);
	_tmp14_ = _tmp13_;
	_tmp15_ = g_strdup_printf ("%i", _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = qlite_query_builder_with (_tmp9_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp12_, "=", _tmp16_);
	_tmp18_ = _tmp17_;
	_g_free0 (_tmp16_);
	_qlite_statement_builder_unref0 (_tmp9_);
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) qlite_column_unref), NULL);
	builder = _tmp18_;
	result = qlite_query_builder_count (builder) > ((gint64) 0);
	_qlite_statement_builder_unref0 (builder);
	return result;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

