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

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.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

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block9Data Block9Data;
#define _ft_context_unref0(var) ((var == NULL) ? NULL : (var = (ft_context_unref (var), NULL)))
typedef struct _Block10Data Block10Data;
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _ft_value_unref0(var) ((var == NULL) ? NULL : (var = (ft_value_unref (var), NULL)))
typedef struct _FtParamSpecContext FtParamSpecContext;

struct _FtContextPrivate {
	gchar* json;
};

struct _Block9Data {
	int _ref_count_;
	FtContext* self;
	JsonBuilder* builder;
};

struct _Block10Data {
	int _ref_count_;
	FtContext* self;
	JsonBuilder* builder;
};

struct _FtParamSpecContext {
	GParamSpec parent_instance;
};

static gint FtContext_private_offset;
static gpointer ft_context_parent_class = NULL;
static gchar* ft_context_current_event_source;
static gchar* ft_context_current_event_source = NULL;
static gint64 ft_context_current_event_source_timestamp;
static gint64 ft_context_current_event_source_timestamp = FT_TIMESTAMP_UNDEFINED;

VALA_EXTERN void ft_variables_ensure_initialized (void);
static void ft_context_json_add_timer_state (FtContext* self,
                                      JsonBuilder* builder);
static void ft_context_json_add_time_block (FtContext* self,
                                     JsonBuilder* builder,
                                     FtTimeBlock* time_block);
static Block9Data* block9_data_ref (Block9Data* _data9_);
static void block9_data_unref (void * _userdata_);
static void __lambda59_ (Block9Data* _data9_,
                  FtGap* gap);
static void ___lambda59__gfunc (gconstpointer data,
                         gpointer self);
static Block10Data* block10_data_ref (Block10Data* _data10_);
static void block10_data_unref (void * _userdata_);
static void ____lambda60_ (Block10Data* _data10_,
                    FtTimeBlock* time_block);
static void _____lambda60__gfunc (gconstpointer data,
                           gpointer self);
static void _vala_JsonNode_free (JsonNode* self);
static void ft_context_finalize (FtContext * obj);
static GType ft_context_get_type_once (void);

static inline gpointer
ft_context_get_instance_private (FtContext* self)
{
	return G_STRUCT_MEMBER_P (self, FtContext_private_offset);
}

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

FtContext*
ft_context_construct_build (GType object_type,
                            gint64 timestamp)
{
	FtContext* self = NULL;
	FtSessionManager* session_manager = NULL;
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp1_;
	FtTimer* timer = NULL;
	FtSessionManager* _tmp2_;
	FtTimer* _tmp3_;
	FtTimer* _tmp4_;
	FtTimer* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	FtTimer* _tmp8_;
	FtTimerState _tmp9_ = {0};
	FtTimerState _tmp10_;
	FtSessionManager* _tmp11_;
	FtTimeBlock* _tmp12_;
	FtTimeBlock* _tmp13_;
	FtTimeBlock* _tmp14_;
	FtSessionManager* _tmp15_;
	FtSession* _tmp16_;
	FtSession* _tmp17_;
	FtSession* _tmp18_;
	self = (FtContext*) g_type_create_instance (object_type);
	ft_ensure_timestamp (&timestamp);
	ft_variables_ensure_initialized ();
	_tmp0_ = ft_session_manager_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	session_manager = _tmp1_;
	_tmp2_ = session_manager;
	_tmp3_ = ft_session_manager_get_timer (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	timer = _tmp5_;
	if (ft_timestamp_is_undefined (ft_context_current_event_source_timestamp)) {
		ft_context_current_event_source_timestamp = timestamp;
	} else {
		if (ft_context_current_event_source_timestamp != timestamp) {
			ft_context_unset_event_source ();
		}
	}
	_tmp6_ = ft_context_current_event_source;
	_tmp7_ = g_strdup (_tmp6_);
	_g_free0 (self->event_source);
	self->event_source = _tmp7_;
	self->timestamp = timestamp;
	_tmp8_ = timer;
	ft_timer_get_state (_tmp8_, &_tmp9_);
	_tmp10_ = _tmp9_;
	self->timer_state = _tmp10_;
	_tmp11_ = session_manager;
	_tmp12_ = ft_session_manager_get_current_time_block (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = _g_object_ref0 (_tmp13_);
	_g_object_unref0 (self->time_block);
	self->time_block = _tmp14_;
	_tmp15_ = session_manager;
	_tmp16_ = ft_session_manager_get_current_session (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = _g_object_ref0 (_tmp17_);
	_g_object_unref0 (self->session);
	self->session = _tmp18_;
	_g_object_unref0 (timer);
	_g_object_unref0 (session_manager);
	return self;
}

FtContext*
ft_context_new_build (gint64 timestamp)
{
	return ft_context_construct_build (FT_TYPE_CONTEXT, timestamp);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

guint
ft_context_calculate_checksum (FtContext* self)
{
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	GHashFunc _tmp8_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp1_ = self->event_source;
	if (_tmp1_ != NULL) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp2_ = self->event_source;
		_tmp3_ = string_to_string (_tmp2_);
		_tmp4_ = g_strdup_printf ("%" G_GINT64_FORMAT, self->timestamp);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_strconcat (_tmp3_, " ", _tmp5_, NULL);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp6_;
		_g_free0 (_tmp5_);
	} else {
		gchar* _tmp7_;
		_tmp7_ = g_strdup_printf ("%" G_GINT64_FORMAT, self->timestamp);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp7_;
	}
	_tmp8_ = g_str_hash;
	result = _tmp8_ (_tmp0_);
	_g_free0 (_tmp0_);
	return result;
}

gchar*
ft_context_get_event_source (void)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	_tmp0_ = ft_context_current_event_source;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

gint64
ft_context_get_event_source_timestamp (void)
{
	gint64 result;
	result = ft_context_current_event_source_timestamp;
	return result;
}

void
ft_context_set_event_source (const gchar* event_source,
                             gint64 timestamp)
{
	gchar* _tmp0_;
	g_return_if_fail (event_source != NULL);
	_tmp0_ = g_strdup (event_source);
	_g_free0 (ft_context_current_event_source);
	ft_context_current_event_source = _tmp0_;
	ft_context_current_event_source_timestamp = timestamp;
}

void
ft_context_unset_event_source (void)
{
	_g_free0 (ft_context_current_event_source);
	ft_context_current_event_source = NULL;
	ft_context_current_event_source_timestamp = FT_TIMESTAMP_UNDEFINED;
}

static void
ft_context_json_add_timer_state (FtContext* self,
                                 JsonBuilder* builder)
{
	FtTimerState _tmp0_;
	FtTimerState _tmp1_;
	FtTimerState _tmp2_;
	FtTimerState _tmp3_;
	FtTimerState _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (builder != NULL);
	json_builder_begin_object (builder);
	json_builder_set_member_name (builder, "duration");
	_tmp0_ = self->timer_state;
	json_builder_add_int_value (builder, _tmp0_.duration);
	json_builder_set_member_name (builder, "offset");
	_tmp1_ = self->timer_state;
	json_builder_add_int_value (builder, _tmp1_.offset);
	json_builder_set_member_name (builder, "startedTime");
	_tmp2_ = self->timer_state;
	json_builder_add_int_value (builder, _tmp2_.started_time);
	json_builder_set_member_name (builder, "pausedTime");
	_tmp3_ = self->timer_state;
	json_builder_add_int_value (builder, _tmp3_.paused_time);
	json_builder_set_member_name (builder, "finishedTime");
	_tmp4_ = self->timer_state;
	json_builder_add_int_value (builder, _tmp4_.finished_time);
	json_builder_set_member_name (builder, "isRunning");
	json_builder_add_boolean_value (builder, ft_timer_state_is_running (&self->timer_state));
	json_builder_set_member_name (builder, "elapsed");
	json_builder_add_int_value (builder, ft_timer_state_calculate_elapsed (&self->timer_state, self->timestamp));
	json_builder_set_member_name (builder, "remaining");
	json_builder_add_int_value (builder, ft_timer_state_calculate_remaining (&self->timer_state, self->timestamp));
	json_builder_end_object (builder);
}

static Block9Data*
block9_data_ref (Block9Data* _data9_)
{
	g_atomic_int_inc (&_data9_->_ref_count_);
	return _data9_;
}

static void
block9_data_unref (void * _userdata_)
{
	Block9Data* _data9_;
	_data9_ = (Block9Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data9_->_ref_count_)) {
		FtContext* self;
		self = _data9_->self;
		_g_object_unref0 (_data9_->builder);
		_ft_context_unref0 (self);
		g_slice_free (Block9Data, _data9_);
	}
}

static void
__lambda59_ (Block9Data* _data9_,
             FtGap* gap)
{
	FtContext* self;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	self = _data9_->self;
	g_return_if_fail (gap != NULL);
	json_builder_begin_object (_data9_->builder);
	json_builder_set_member_name (_data9_->builder, "startTime");
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	json_builder_add_int_value (_data9_->builder, _tmp1_);
	json_builder_set_member_name (_data9_->builder, "endTime");
	_tmp2_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp3_ = _tmp2_;
	json_builder_add_int_value (_data9_->builder, _tmp3_);
	json_builder_end_object (_data9_->builder);
}

static void
___lambda59__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda59_ (self, (FtGap*) data);
}

static void
ft_context_json_add_time_block (FtContext* self,
                                JsonBuilder* builder,
                                FtTimeBlock* time_block)
{
	Block9Data* _data9_;
	JsonBuilder* _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	gint64 _tmp4_;
	FtState _tmp5_;
	FtState _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (builder != NULL);
	_data9_ = g_slice_new0 (Block9Data);
	_data9_->_ref_count_ = 1;
	_data9_->self = ft_context_ref (self);
	_tmp0_ = _g_object_ref0 (builder);
	_g_object_unref0 (_data9_->builder);
	_data9_->builder = _tmp0_;
	if (time_block == NULL) {
		json_builder_add_null_value (_data9_->builder);
		block9_data_unref (_data9_);
		_data9_ = NULL;
		return;
	}
	json_builder_begin_object (_data9_->builder);
	json_builder_set_member_name (_data9_->builder, "startTime");
	_tmp1_ = ft_schedulable_get_start_time ((FtSchedulable*) time_block);
	_tmp2_ = _tmp1_;
	json_builder_add_int_value (_data9_->builder, _tmp2_);
	json_builder_set_member_name (_data9_->builder, "endTime");
	_tmp3_ = ft_schedulable_get_end_time ((FtSchedulable*) time_block);
	_tmp4_ = _tmp3_;
	json_builder_add_int_value (_data9_->builder, _tmp4_);
	json_builder_set_member_name (_data9_->builder, "state");
	_tmp5_ = ft_time_block_get_state (time_block);
	_tmp6_ = _tmp5_;
	_tmp7_ = ft_state_to_string (_tmp6_);
	_tmp8_ = _tmp7_;
	json_builder_add_string_value (_data9_->builder, _tmp8_);
	_g_free0 (_tmp8_);
	json_builder_set_member_name (_data9_->builder, "status");
	_tmp9_ = ft_time_block_status_to_string (ft_time_block_get_status (time_block));
	_tmp10_ = _tmp9_;
	json_builder_add_string_value (_data9_->builder, _tmp10_);
	_g_free0 (_tmp10_);
	json_builder_set_member_name (_data9_->builder, "gaps");
	json_builder_begin_array (_data9_->builder);
	ft_time_block_foreach_gap (time_block, ___lambda59__gfunc, _data9_);
	json_builder_end_array (_data9_->builder);
	json_builder_end_object (_data9_->builder);
	block9_data_unref (_data9_);
	_data9_ = NULL;
}

static Block10Data*
block10_data_ref (Block10Data* _data10_)
{
	g_atomic_int_inc (&_data10_->_ref_count_);
	return _data10_;
}

static void
block10_data_unref (void * _userdata_)
{
	Block10Data* _data10_;
	_data10_ = (Block10Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data10_->_ref_count_)) {
		FtContext* self;
		self = _data10_->self;
		_g_object_unref0 (_data10_->builder);
		_ft_context_unref0 (self);
		g_slice_free (Block10Data, _data10_);
	}
}

static void
____lambda60_ (Block10Data* _data10_,
               FtTimeBlock* time_block)
{
	FtContext* self;
	gboolean _tmp0_ = FALSE;
	FtTimeBlock* _tmp1_;
	JsonBuilder* _tmp2_;
	self = _data10_->self;
	g_return_if_fail (time_block != NULL);
	_tmp1_ = self->time_block;
	if (_tmp1_ == NULL) {
		_tmp0_ = ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_SCHEDULED;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = _data10_->builder;
	ft_context_json_add_time_block (self, _tmp2_, time_block);
}

static void
_____lambda60__gfunc (gconstpointer data,
                      gpointer self)
{
	____lambda60_ (self, (FtTimeBlock*) data);
}

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

gchar*
ft_context_to_json (FtContext* self)
{
	const gchar* _tmp0_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->json;
	if (_tmp0_ == NULL) {
		Block10Data* _data10_;
		JsonBuilder* _tmp1_;
		JsonBuilder* _tmp2_;
		JsonBuilder* _tmp3_;
		JsonBuilder* _tmp4_;
		JsonBuilder* _tmp5_;
		JsonBuilder* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		JsonBuilder* _tmp10_;
		JsonBuilder* _tmp11_;
		JsonBuilder* _tmp12_;
		JsonBuilder* _tmp13_;
		FtSession* _tmp14_;
		JsonBuilder* _tmp16_;
		JsonBuilder* _tmp17_;
		JsonGenerator* generator = NULL;
		JsonGenerator* _tmp18_;
		JsonGenerator* _tmp19_;
		JsonBuilder* _tmp20_;
		JsonNode* _tmp21_;
		JsonNode* _tmp22_;
		JsonGenerator* _tmp23_;
		JsonGenerator* _tmp24_;
		gchar* _tmp25_;
		_data10_ = g_slice_new0 (Block10Data);
		_data10_->_ref_count_ = 1;
		_data10_->self = ft_context_ref (self);
		_tmp1_ = json_builder_new ();
		_data10_->builder = _tmp1_;
		_tmp2_ = _data10_->builder;
		json_builder_begin_object (_tmp2_);
		_tmp3_ = _data10_->builder;
		json_builder_set_member_name (_tmp3_, "timestamp");
		_tmp4_ = _data10_->builder;
		json_builder_add_int_value (_tmp4_, self->timestamp);
		_tmp5_ = _data10_->builder;
		json_builder_set_member_name (_tmp5_, "_source");
		_tmp6_ = _data10_->builder;
		_tmp7_ = self->event_source;
		_tmp8_ = ft_ensure_string (_tmp7_);
		_tmp9_ = _tmp8_;
		json_builder_add_string_value (_tmp6_, _tmp9_);
		_g_free0 (_tmp9_);
		_tmp10_ = _data10_->builder;
		json_builder_set_member_name (_tmp10_, "timer");
		_tmp11_ = _data10_->builder;
		ft_context_json_add_timer_state (self, _tmp11_);
		_tmp12_ = _data10_->builder;
		json_builder_set_member_name (_tmp12_, "session");
		_tmp13_ = _data10_->builder;
		json_builder_begin_array (_tmp13_);
		_tmp14_ = self->session;
		if (_tmp14_ != NULL) {
			FtSession* _tmp15_;
			_tmp15_ = self->session;
			ft_session_foreach (_tmp15_, _____lambda60__gfunc, _data10_);
		}
		_tmp16_ = _data10_->builder;
		json_builder_end_array (_tmp16_);
		_tmp17_ = _data10_->builder;
		json_builder_end_object (_tmp17_);
		_tmp18_ = json_generator_new ();
		generator = _tmp18_;
		_tmp19_ = generator;
		_tmp20_ = _data10_->builder;
		_tmp21_ = json_builder_get_root (_tmp20_);
		_tmp22_ = _tmp21_;
		json_generator_set_root (_tmp19_, _tmp22_);
		__vala_JsonNode_free0 (_tmp22_);
		_tmp23_ = generator;
		json_generator_set_pretty (_tmp23_, TRUE);
		_tmp24_ = generator;
		_tmp25_ = json_generator_to_data (_tmp24_, NULL);
		_g_free0 (self->priv->json);
		self->priv->json = _tmp25_;
		_g_object_unref0 (generator);
		block10_data_unref (_data10_);
		_data10_ = NULL;
	}
	_tmp26_ = self->priv->json;
	_tmp27_ = g_strdup (_tmp26_);
	result = _tmp27_;
	return result;
}

FtValue*
ft_context_evaluate_variable (FtContext* self,
                              const gchar* variable_name)
{
	FtVariableSpec* variable_spec = NULL;
	FtVariableSpec* _tmp0_;
	FtValue* _tmp1_ = NULL;
	FtVariableSpec* _tmp2_;
	FtValue* _tmp5_;
	FtValue* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (variable_name != NULL, NULL);
	_tmp0_ = ft_find_variable (variable_name);
	variable_spec = _tmp0_;
	_tmp2_ = variable_spec;
	if (_tmp2_ != NULL) {
		FtVariableSpec* _tmp3_;
		FtValue* _tmp4_;
		_tmp3_ = variable_spec;
		_tmp4_ = ft_variable_spec_evaluate (_tmp3_, self);
		_ft_value_unref0 (_tmp1_);
		_tmp1_ = _tmp4_;
	} else {
		_ft_value_unref0 (_tmp1_);
		_tmp1_ = NULL;
	}
	_tmp5_ = _tmp1_;
	_tmp1_ = NULL;
	result = _tmp5_;
	_ft_value_unref0 (_tmp1_);
	return result;
}

FtContext*
ft_context_construct (GType object_type)
{
	FtContext* self = NULL;
	self = (FtContext*) g_type_create_instance (object_type);
	return self;
}

FtContext*
ft_context_new (void)
{
	return ft_context_construct (FT_TYPE_CONTEXT);
}

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

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

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

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

static gchar*
ft_value_context_collect_value (GValue* value,
                                guint n_collect_values,
                                GTypeCValue* collect_values,
                                guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		FtContext * 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 = ft_context_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
ft_value_context_lcopy_value (const GValue* value,
                              guint n_collect_values,
                              GTypeCValue* collect_values,
                              guint collect_flags)
{
	FtContext ** 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 = ft_context_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
ft_param_spec_context (const gchar* name,
                       const gchar* nick,
                       const gchar* blurb,
                       GType object_type,
                       GParamFlags flags)
{
	FtParamSpecContext* spec;
	g_return_val_if_fail (g_type_is_a (object_type, FT_TYPE_CONTEXT), 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
ft_value_get_context (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_CONTEXT), NULL);
	return value->data[0].v_pointer;
}

void
ft_value_set_context (GValue* value,
                      gpointer v_object)
{
	FtContext * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_CONTEXT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, FT_TYPE_CONTEXT));
		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;
		ft_context_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ft_context_unref (old);
	}
}

void
ft_value_take_context (GValue* value,
                       gpointer v_object)
{
	FtContext * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_CONTEXT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, FT_TYPE_CONTEXT));
		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) {
		ft_context_unref (old);
	}
}

static void
ft_context_class_init (FtContextClass * klass,
                       gpointer klass_data)
{
	ft_context_parent_class = g_type_class_peek_parent (klass);
	((FtContextClass *) klass)->finalize = ft_context_finalize;
	g_type_class_adjust_private_offset (klass, &FtContext_private_offset);
}

static void
ft_context_instance_init (FtContext * self,
                          gpointer klass)
{
	self->priv = ft_context_get_instance_private (self);
	self->priv->json = NULL;
	self->ref_count = 1;
}

static void
ft_context_finalize (FtContext * obj)
{
	FtContext * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_CONTEXT, FtContext);
	g_signal_handlers_destroy (self);
	_g_free0 (self->event_source);
	_g_object_unref0 (self->time_block);
	_g_object_unref0 (self->session);
	_g_free0 (self->priv->json);
}

/**
     * Snapshot of timer/session state at a given time.
     */
static GType
ft_context_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { ft_value_context_init, ft_value_context_free_value, ft_value_context_copy_value, ft_value_context_peek_pointer, "p", ft_value_context_collect_value, "p", ft_value_context_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (FtContextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_context_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtContext), 0, (GInstanceInitFunc) ft_context_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 ft_context_type_id;
	ft_context_type_id = g_type_register_fundamental (g_type_fundamental_next (), "FtContext", &g_define_type_info, &g_define_type_fundamental_info, 0);
	FtContext_private_offset = g_type_add_instance_private (ft_context_type_id, sizeof (FtContextPrivate));
	return ft_context_type_id;
}

GType
ft_context_get_type (void)
{
	static volatile gsize ft_context_type_id__once = 0;
	if (g_once_init_enter (&ft_context_type_id__once)) {
		GType ft_context_type_id;
		ft_context_type_id = ft_context_get_type_once ();
		g_once_init_leave (&ft_context_type_id__once, ft_context_type_id);
	}
	return ft_context_type_id__once;
}

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

void
ft_context_unref (gpointer instance)
{
	FtContext * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		FT_CONTEXT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

