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

/*
 * Copyright (C) 2009-2011 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 */

#include <glib.h>
#include <glib-object.h>
#include <fsogsm.h>
#include <stdlib.h>
#include <string.h>
#include <fsobasics.h>
#include <freesmartphone.h>


#define TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER (ti_calypso_unsolicited_response_handler_get_type ())
#define TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER, TiCalypsoUnsolicitedResponseHandler))
#define TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER, TiCalypsoUnsolicitedResponseHandlerClass))
#define TI_CALYPSO_IS_UNSOLICITED_RESPONSE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER))
#define TI_CALYPSO_IS_UNSOLICITED_RESPONSE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER))
#define TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER, TiCalypsoUnsolicitedResponseHandlerClass))

typedef struct _TiCalypsoUnsolicitedResponseHandler TiCalypsoUnsolicitedResponseHandler;
typedef struct _TiCalypsoUnsolicitedResponseHandlerClass TiCalypsoUnsolicitedResponseHandlerClass;
typedef struct _TiCalypsoUnsolicitedResponseHandlerPrivate TiCalypsoUnsolicitedResponseHandlerPrivate;

#define TI_CALYPSO_TYPE_MODEM (ti_calypso_modem_get_type ())
#define TI_CALYPSO_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TI_CALYPSO_TYPE_MODEM, TiCalypsoModem))
#define TI_CALYPSO_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TI_CALYPSO_TYPE_MODEM, TiCalypsoModemClass))
#define TI_CALYPSO_IS_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TI_CALYPSO_TYPE_MODEM))
#define TI_CALYPSO_IS_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TI_CALYPSO_TYPE_MODEM))
#define TI_CALYPSO_MODEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TI_CALYPSO_TYPE_MODEM, TiCalypsoModemClass))

typedef struct _TiCalypsoModem TiCalypsoModem;
typedef struct _TiCalypsoModemClass TiCalypsoModemClass;
typedef struct _TiCalypsoModemPrivate TiCalypsoModemPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TI_CALYPSO_TYPE_PERCENT_CPRI (ti_calypso_percent_cpri_get_type ())
#define TI_CALYPSO_PERCENT_CPRI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TI_CALYPSO_TYPE_PERCENT_CPRI, TiCalypsoPercentCPRI))
#define TI_CALYPSO_PERCENT_CPRI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TI_CALYPSO_TYPE_PERCENT_CPRI, TiCalypsoPercentCPRIClass))
#define TI_CALYPSO_IS_PERCENT_CPRI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TI_CALYPSO_TYPE_PERCENT_CPRI))
#define TI_CALYPSO_IS_PERCENT_CPRI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TI_CALYPSO_TYPE_PERCENT_CPRI))
#define TI_CALYPSO_PERCENT_CPRI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TI_CALYPSO_TYPE_PERCENT_CPRI, TiCalypsoPercentCPRIClass))

typedef struct _TiCalypsoPercentCPRI TiCalypsoPercentCPRI;
typedef struct _TiCalypsoPercentCPRIClass TiCalypsoPercentCPRIClass;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _TiCalypsoPercentCPRIPrivate TiCalypsoPercentCPRIPrivate;

#define TI_CALYPSO_PERCENT_CPRI_TYPE_STATUS (ti_calypso_percent_cpri_status_get_type ())

#define TI_CALYPSO_TYPE_PERCENT_CSTAT (ti_calypso_percent_cstat_get_type ())
#define TI_CALYPSO_PERCENT_CSTAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TI_CALYPSO_TYPE_PERCENT_CSTAT, TiCalypsoPercentCSTAT))
#define TI_CALYPSO_PERCENT_CSTAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TI_CALYPSO_TYPE_PERCENT_CSTAT, TiCalypsoPercentCSTATClass))
#define TI_CALYPSO_IS_PERCENT_CSTAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TI_CALYPSO_TYPE_PERCENT_CSTAT))
#define TI_CALYPSO_IS_PERCENT_CSTAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TI_CALYPSO_TYPE_PERCENT_CSTAT))
#define TI_CALYPSO_PERCENT_CSTAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TI_CALYPSO_TYPE_PERCENT_CSTAT, TiCalypsoPercentCSTATClass))

typedef struct _TiCalypsoPercentCSTAT TiCalypsoPercentCSTAT;
typedef struct _TiCalypsoPercentCSTATClass TiCalypsoPercentCSTATClass;
typedef struct _TiCalypsoPercentCSTATPrivate TiCalypsoPercentCSTATPrivate;

#define TI_CALYPSO_TYPE_PERCENT_CSQ (ti_calypso_percent_csq_get_type ())
#define TI_CALYPSO_PERCENT_CSQ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TI_CALYPSO_TYPE_PERCENT_CSQ, TiCalypsoPercentCSQ))
#define TI_CALYPSO_PERCENT_CSQ_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TI_CALYPSO_TYPE_PERCENT_CSQ, TiCalypsoPercentCSQClass))
#define TI_CALYPSO_IS_PERCENT_CSQ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TI_CALYPSO_TYPE_PERCENT_CSQ))
#define TI_CALYPSO_IS_PERCENT_CSQ_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TI_CALYPSO_TYPE_PERCENT_CSQ))
#define TI_CALYPSO_PERCENT_CSQ_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TI_CALYPSO_TYPE_PERCENT_CSQ, TiCalypsoPercentCSQClass))

typedef struct _TiCalypsoPercentCSQ TiCalypsoPercentCSQ;
typedef struct _TiCalypsoPercentCSQClass TiCalypsoPercentCSQClass;
typedef struct _TiCalypsoPercentCSQPrivate TiCalypsoPercentCSQPrivate;

struct _TiCalypsoUnsolicitedResponseHandler {
	FsoGsmAtUnsolicitedResponseHandler parent_instance;
	TiCalypsoUnsolicitedResponseHandlerPrivate * priv;
};

struct _TiCalypsoUnsolicitedResponseHandlerClass {
	FsoGsmAtUnsolicitedResponseHandlerClass parent_class;
	void (*channelReady) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
	void (*percentCPI) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
	void (*percentCPRI) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
	void (*percentCSSN) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
	void (*percentCSTAT) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
	void (*percentCSQ) (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
};

struct _TiCalypsoUnsolicitedResponseHandlerPrivate {
	gboolean phbReady;
	gboolean smsReady;
	gboolean fullReady;
};

struct _TiCalypsoModem {
	FsoGsmAbstractModem parent_instance;
	TiCalypsoModemPrivate * priv;
	gchar* dspCommand;
};

struct _TiCalypsoModemClass {
	FsoGsmAbstractModemClass parent_class;
};

typedef enum  {
	TI_CALYPSO_PERCENT_CPRI_STATUS_DISABLED = 0,
	TI_CALYPSO_PERCENT_CPRI_STATUS_ENABLED = 1,
	TI_CALYPSO_PERCENT_CPRI_STATUS_UNKNOWN = 2
} TiCalypsoPercentCPRIStatus;

struct _TiCalypsoPercentCPRI {
	FsoGsmAbstractAtCommand parent_instance;
	TiCalypsoPercentCPRIPrivate * priv;
	TiCalypsoPercentCPRIStatus telcipher;
	TiCalypsoPercentCPRIStatus pdpcipher;
};

struct _TiCalypsoPercentCPRIClass {
	FsoGsmAbstractAtCommandClass parent_class;
};

struct _TiCalypsoPercentCSTAT {
	FsoGsmAbstractAtCommand parent_instance;
	TiCalypsoPercentCSTATPrivate * priv;
	gchar* subsystem;
	gboolean ready;
};

struct _TiCalypsoPercentCSTATClass {
	FsoGsmAbstractAtCommandClass parent_class;
};

struct _TiCalypsoPercentCSQ {
	FsoGsmAbstractAtCommand parent_instance;
	TiCalypsoPercentCSQPrivate * priv;
	gint strength;
};

struct _TiCalypsoPercentCSQClass {
	FsoGsmAbstractAtCommandClass parent_class;
};


static gpointer ti_calypso_unsolicited_response_handler_parent_class = NULL;
static GType ti_calypso_unsolicited_response_handler_type_id = 0;

GType ti_calypso_unsolicited_response_handler_get_type (void) G_GNUC_CONST;
GType ti_calypso_unsolicited_response_handler_register_type (GTypeModule * module);
#define TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER, TiCalypsoUnsolicitedResponseHandlerPrivate))
enum  {
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_DUMMY_PROPERTY
};
static void ti_calypso_unsolicited_response_handler_updateReadyness (TiCalypsoUnsolicitedResponseHandler* self);
TiCalypsoUnsolicitedResponseHandler* ti_calypso_unsolicited_response_handler_new (void);
TiCalypsoUnsolicitedResponseHandler* ti_calypso_unsolicited_response_handler_construct (GType object_type);
void ti_calypso_unsolicited_response_handler_channelReady (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_channelReady_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
void ti_calypso_unsolicited_response_handler_percentCPI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_percentCPI_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
void ti_calypso_unsolicited_response_handler_percentCPRI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_percentCPRI_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
void ti_calypso_unsolicited_response_handler_percentCSSN (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_percentCSSN_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
void ti_calypso_unsolicited_response_handler_percentCSTAT (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_percentCSTAT_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
void ti_calypso_unsolicited_response_handler_percentCSQ (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void _ti_calypso_unsolicited_response_handler_percentCSQ_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self);
static void ti_calypso_unsolicited_response_handler_real_channelReady (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void ti_calypso_unsolicited_response_handler_real_percentCPI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
GType ti_calypso_modem_get_type (void) G_GNUC_CONST;
GType ti_calypso_modem_register_type (GTypeModule * module);
static void ti_calypso_unsolicited_response_handler_real_percentCPRI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
GType ti_calypso_percent_cpri_get_type (void) G_GNUC_CONST;
GType ti_calypso_percent_cpri_register_type (GTypeModule * module);
GType ti_calypso_percent_cpri_status_get_type (void) G_GNUC_CONST;
static void ti_calypso_unsolicited_response_handler_real_percentCSSN (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
static void ti_calypso_unsolicited_response_handler_real_percentCSTAT (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
GType ti_calypso_percent_cstat_get_type (void) G_GNUC_CONST;
GType ti_calypso_percent_cstat_register_type (GTypeModule * module);
static void ti_calypso_unsolicited_response_handler_real_percentCSQ (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs);
GType ti_calypso_percent_csq_get_type (void) G_GNUC_CONST;
GType ti_calypso_percent_csq_register_type (GTypeModule * module);
static void ti_calypso_unsolicited_response_handler_finalize (GObject* obj);


static void ti_calypso_unsolicited_response_handler_updateReadyness (TiCalypsoUnsolicitedResponseHandler* self) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp3_;
	gboolean newFullReady;
	gboolean _tmp4_;
	gboolean _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->phbReady;
	if (_tmp1_) {
		gboolean _tmp2_;
		_tmp2_ = self->priv->smsReady;
		_tmp0_ = _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp3_ = _tmp0_;
	newFullReady = _tmp3_;
	_tmp4_ = newFullReady;
	_tmp5_ = self->priv->fullReady;
	if (_tmp4_ != _tmp5_) {
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp6_ = newFullReady;
		self->priv->fullReady = _tmp6_;
		_tmp7_ = self->priv->fullReady;
		if (_tmp7_) {
			FsoGsmModem* _tmp8_;
			FsoFrameworkLogger* _tmp9_;
			FsoGsmModem* _tmp10_;
			_tmp8_ = fso_gsm_theModem;
			_tmp9_ = ((FsoFrameworkAbstractObject*) _tmp8_)->logger;
			fso_framework_logger_info (_tmp9_, "TI Calypso SIM now ready");
			_tmp10_ = fso_gsm_theModem;
			fso_gsm_modem_advanceToState (_tmp10_, FSO_GSM_MODEM_STATUS_ALIVE_SIM_READY, FALSE);
		}
	}
}


static void _ti_calypso_unsolicited_response_handler_channelReady_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_channelReady (self, prefix, rhs);
}


static void _ti_calypso_unsolicited_response_handler_percentCPI_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_percentCPI (self, prefix, rhs);
}


static void _ti_calypso_unsolicited_response_handler_percentCPRI_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_percentCPRI (self, prefix, rhs);
}


static void _ti_calypso_unsolicited_response_handler_percentCSSN_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_percentCSSN (self, prefix, rhs);
}


static void _ti_calypso_unsolicited_response_handler_percentCSTAT_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_percentCSTAT (self, prefix, rhs);
}


static void _ti_calypso_unsolicited_response_handler_percentCSQ_unsolicited_response_handler_func (const gchar* prefix, const gchar* rhs, gpointer self) {
	ti_calypso_unsolicited_response_handler_percentCSQ (self, prefix, rhs);
}


TiCalypsoUnsolicitedResponseHandler* ti_calypso_unsolicited_response_handler_construct (GType object_type) {
	TiCalypsoUnsolicitedResponseHandler * self = NULL;
	self = (TiCalypsoUnsolicitedResponseHandler*) fso_gsm_at_unsolicited_response_handler_construct (object_type);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "AT-Command Interpreter ready", _ti_calypso_unsolicited_response_handler_channelReady_unsolicited_response_handler_func, self);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "%CPI", _ti_calypso_unsolicited_response_handler_percentCPI_unsolicited_response_handler_func, self);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "%CPRI", _ti_calypso_unsolicited_response_handler_percentCPRI_unsolicited_response_handler_func, self);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "%CSSN", _ti_calypso_unsolicited_response_handler_percentCSSN_unsolicited_response_handler_func, self);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "%CSTAT", _ti_calypso_unsolicited_response_handler_percentCSTAT_unsolicited_response_handler_func, self);
	fso_gsm_base_unsolicited_response_handler_registerUrc ((FsoGsmBaseUnsolicitedResponseHandler*) self, "%CSQ", _ti_calypso_unsolicited_response_handler_percentCSQ_unsolicited_response_handler_func, self);
	return self;
}


TiCalypsoUnsolicitedResponseHandler* ti_calypso_unsolicited_response_handler_new (void) {
	return ti_calypso_unsolicited_response_handler_construct (TI_CALYPSO_TYPE_UNSOLICITED_RESPONSE_HANDLER);
}


static void ti_calypso_unsolicited_response_handler_real_channelReady (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	FsoGsmModem* _tmp0_;
	FsoFrameworkLogger* _tmp1_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
	_tmp0_ = fso_gsm_theModem;
	_tmp1_ = ((FsoFrameworkAbstractObject*) _tmp0_)->logger;
	_tmp2_ = fso_framework_logger_debug (_tmp1_, "Congratulations Madam, it's a channel!");
	g_assert (_tmp2_);
}


void ti_calypso_unsolicited_response_handler_channelReady (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->channelReady (self, prefix, rhs);
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_;
	gchar _tmp1_;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


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


static void ti_calypso_unsolicited_response_handler_real_percentCPI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	const gchar* _tmp0_;
	gchar _tmp1_ = '\0';
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
	_tmp0_ = rhs;
	_tmp1_ = string_get (_tmp0_, (glong) 2);
	switch (_tmp1_) {
		case '0':
		case '9':
		{
			FsoGsmModem* _tmp2_;
			TiCalypsoModem* _tmp3_;
			TiCalypsoModem* calypso;
			FsoGsmCustomAtCommand* _tmp4_;
			FsoGsmCustomAtCommand* cmd;
			FsoGsmModem* _tmp5_;
			FsoGsmCustomAtCommand* _tmp6_;
			TiCalypsoModem* _tmp7_;
			const gchar* _tmp8_;
			_tmp2_ = fso_gsm_theModem;
			_tmp3_ = _g_object_ref0 (TI_CALYPSO_MODEM (_tmp2_));
			calypso = _tmp3_;
			_tmp4_ = fso_gsm_custom_at_command_new ("", FALSE);
			cmd = _tmp4_;
			_tmp5_ = fso_gsm_theModem;
			_tmp6_ = cmd;
			_tmp7_ = calypso;
			_tmp8_ = _tmp7_->dspCommand;
			fso_gsm_modem_processAtCommandAsync (_tmp5_, (FsoGsmAtCommand*) _tmp6_, _tmp8_, FSO_GSM_MODEM_DEFAULT_RETRIES, NULL, NULL);
			_g_object_unref0 (cmd);
			_g_object_unref0 (calypso);
			break;
		}
		default:
		{
			break;
		}
	}
}


void ti_calypso_unsolicited_response_handler_percentCPI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->percentCPI (self, prefix, rhs);
}


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


static void ti_calypso_unsolicited_response_handler_real_percentCPRI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	FsoGsmModem* _tmp0_;
	gpointer _tmp1_ = NULL;
	TiCalypsoPercentCPRI* cpri;
	TiCalypsoPercentCPRI* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	FsoGsmConstantsAtResponse _tmp9_ = 0;
	gboolean _tmp10_;
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
	_tmp0_ = fso_gsm_theModem;
	_tmp1_ = fso_gsm_modem_createAtCommand (_tmp0_, TI_CALYPSO_TYPE_PERCENT_CPRI, (GBoxedCopyFunc) g_object_ref, g_object_unref, "%CPRI");
	cpri = (TiCalypsoPercentCPRI*) _tmp1_;
	_tmp2_ = cpri;
	_tmp3_ = prefix;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = rhs;
	_tmp6_ = string_to_string (_tmp5_);
	_tmp7_ = g_strconcat (_tmp4_, ": ", _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = fso_gsm_abstract_at_command_validateUrc ((FsoGsmAbstractAtCommand*) _tmp2_, _tmp8_);
	_tmp10_ = _tmp9_ == FSO_GSM_CONSTANTS_AT_RESPONSE_VALID;
	_g_free0 (_tmp8_);
	if (_tmp10_) {
		FsoGsmModem* _tmp11_;
		gpointer _tmp12_ = NULL;
		FreeSmartphoneGSMNetwork* obj;
		FreeSmartphoneGSMNetwork* _tmp13_;
		TiCalypsoPercentCPRI* _tmp14_;
		TiCalypsoPercentCPRIStatus _tmp15_;
		TiCalypsoPercentCPRI* _tmp16_;
		TiCalypsoPercentCPRIStatus _tmp17_;
		_tmp11_ = fso_gsm_theModem;
		_tmp12_ = fso_gsm_modem_theDevice (_tmp11_, FREE_SMARTPHONE_GSM_TYPE_NETWORK, (GBoxedCopyFunc) g_object_ref, g_object_unref);
		obj = (FreeSmartphoneGSMNetwork*) _tmp12_;
		_tmp13_ = obj;
		_tmp14_ = cpri;
		_tmp15_ = _tmp14_->telcipher;
		_tmp16_ = cpri;
		_tmp17_ = _tmp16_->pdpcipher;
		g_signal_emit_by_name (_tmp13_, "cipher-status", (FreeSmartphoneGSMCipherStatus) _tmp15_, (FreeSmartphoneGSMCipherStatus) _tmp17_);
		_g_object_unref0 (obj);
	}
	_g_object_unref0 (cpri);
}


void ti_calypso_unsolicited_response_handler_percentCPRI (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->percentCPRI (self, prefix, rhs);
}


static void ti_calypso_unsolicited_response_handler_real_percentCSSN (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
}


void ti_calypso_unsolicited_response_handler_percentCSSN (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->percentCSSN (self, prefix, rhs);
}


/**
     * TI Calypso subsystem status report:
     *
     * %CSTAT: PHB,0
     * %CSTAT: SMS,0
     * %CSTAT: RDY,1
     * %CSTAT: EONS,1
     *
     * PHB is phonebook, SMS is messagebook. RDY is supposed to be sent, after
     * PHB and SMS both being 1, however it's not sent on all devices.
     * EONS is completely undocumented, but likely the reading of the operator
     * table elementary files from the SIM. Not that it would matter anyways, since
     * these may be corrupt, hence this signal is very unreliable.
     *
     * Due to RDY being unreliable as well, we wait for PHB and SMS sending availability
     * and then synthesize a global SimReady signal.
     **/
static void ti_calypso_unsolicited_response_handler_real_percentCSTAT (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	FsoGsmModem* _tmp0_;
	gpointer _tmp1_ = NULL;
	TiCalypsoPercentCSTAT* cstat;
	TiCalypsoPercentCSTAT* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	FsoGsmConstantsAtResponse _tmp9_ = 0;
	gboolean _tmp10_;
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
	_tmp0_ = fso_gsm_theModem;
	_tmp1_ = fso_gsm_modem_createAtCommand (_tmp0_, TI_CALYPSO_TYPE_PERCENT_CSTAT, (GBoxedCopyFunc) g_object_ref, g_object_unref, "%CSTAT");
	cstat = (TiCalypsoPercentCSTAT*) _tmp1_;
	_tmp2_ = cstat;
	_tmp3_ = prefix;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = rhs;
	_tmp6_ = string_to_string (_tmp5_);
	_tmp7_ = g_strconcat (_tmp4_, ": ", _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = fso_gsm_abstract_at_command_validateUrc ((FsoGsmAbstractAtCommand*) _tmp2_, _tmp8_);
	_tmp10_ = _tmp9_ == FSO_GSM_CONSTANTS_AT_RESPONSE_VALID;
	_g_free0 (_tmp8_);
	if (_tmp10_) {
		TiCalypsoPercentCSTAT* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		GQuark _tmp15_ = 0U;
		static GQuark _tmp14_label0 = 0;
		static GQuark _tmp14_label1 = 0;
		_tmp11_ = cstat;
		_tmp12_ = _tmp11_->subsystem;
		_tmp13_ = _tmp12_;
		_tmp15_ = (NULL == _tmp13_) ? 0 : g_quark_from_string (_tmp13_);
		if (_tmp15_ == ((0 != _tmp14_label0) ? _tmp14_label0 : (_tmp14_label0 = g_quark_from_static_string ("PHB")))) {
			switch (0) {
				default:
				{
					TiCalypsoPercentCSTAT* _tmp16_;
					gboolean _tmp17_;
					_tmp16_ = cstat;
					_tmp17_ = _tmp16_->ready;
					self->priv->phbReady = _tmp17_;
					ti_calypso_unsolicited_response_handler_updateReadyness (self);
					break;
				}
			}
		} else if (_tmp15_ == ((0 != _tmp14_label1) ? _tmp14_label1 : (_tmp14_label1 = g_quark_from_static_string ("SMS")))) {
			switch (0) {
				default:
				{
					TiCalypsoPercentCSTAT* _tmp18_;
					gboolean _tmp19_;
					_tmp18_ = cstat;
					_tmp19_ = _tmp18_->ready;
					self->priv->smsReady = _tmp19_;
					ti_calypso_unsolicited_response_handler_updateReadyness (self);
					break;
				}
			}
		} else {
			switch (0) {
				default:
				{
					break;
				}
			}
		}
	}
	_g_object_unref0 (cstat);
}


void ti_calypso_unsolicited_response_handler_percentCSTAT (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->percentCSTAT (self, prefix, rhs);
}


static void ti_calypso_unsolicited_response_handler_real_percentCSQ (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	FsoGsmModem* _tmp0_;
	gpointer _tmp1_ = NULL;
	TiCalypsoPercentCSQ* csq;
	TiCalypsoPercentCSQ* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	FsoGsmConstantsAtResponse _tmp9_ = 0;
	gboolean _tmp10_;
	g_return_if_fail (prefix != NULL);
	g_return_if_fail (rhs != NULL);
	_tmp0_ = fso_gsm_theModem;
	_tmp1_ = fso_gsm_modem_createAtCommand (_tmp0_, TI_CALYPSO_TYPE_PERCENT_CSQ, (GBoxedCopyFunc) g_object_ref, g_object_unref, "%CSQ");
	csq = (TiCalypsoPercentCSQ*) _tmp1_;
	_tmp2_ = csq;
	_tmp3_ = prefix;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = rhs;
	_tmp6_ = string_to_string (_tmp5_);
	_tmp7_ = g_strconcat (_tmp4_, ": ", _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = fso_gsm_abstract_at_command_validateUrc ((FsoGsmAbstractAtCommand*) _tmp2_, _tmp8_);
	_tmp10_ = _tmp9_ == FSO_GSM_CONSTANTS_AT_RESPONSE_VALID;
	_g_free0 (_tmp8_);
	if (_tmp10_) {
		FsoGsmModem* _tmp11_;
		gpointer _tmp12_ = NULL;
		FreeSmartphoneGSMNetwork* obj;
		FreeSmartphoneGSMNetwork* _tmp13_;
		TiCalypsoPercentCSQ* _tmp14_;
		gint _tmp15_;
		_tmp11_ = fso_gsm_theModem;
		_tmp12_ = fso_gsm_modem_theDevice (_tmp11_, FREE_SMARTPHONE_GSM_TYPE_NETWORK, (GBoxedCopyFunc) g_object_ref, g_object_unref);
		obj = (FreeSmartphoneGSMNetwork*) _tmp12_;
		_tmp13_ = obj;
		_tmp14_ = csq;
		_tmp15_ = _tmp14_->strength;
		g_signal_emit_by_name (_tmp13_, "signal-strength", _tmp15_);
		_g_object_unref0 (obj);
	}
	_g_object_unref0 (csq);
}


void ti_calypso_unsolicited_response_handler_percentCSQ (TiCalypsoUnsolicitedResponseHandler* self, const gchar* prefix, const gchar* rhs) {
	g_return_if_fail (self != NULL);
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS (self)->percentCSQ (self, prefix, rhs);
}


static void ti_calypso_unsolicited_response_handler_class_init (TiCalypsoUnsolicitedResponseHandlerClass * klass) {
	ti_calypso_unsolicited_response_handler_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TiCalypsoUnsolicitedResponseHandlerPrivate));
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->channelReady = ti_calypso_unsolicited_response_handler_real_channelReady;
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->percentCPI = ti_calypso_unsolicited_response_handler_real_percentCPI;
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->percentCPRI = ti_calypso_unsolicited_response_handler_real_percentCPRI;
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->percentCSSN = ti_calypso_unsolicited_response_handler_real_percentCSSN;
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->percentCSTAT = ti_calypso_unsolicited_response_handler_real_percentCSTAT;
	TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_CLASS (klass)->percentCSQ = ti_calypso_unsolicited_response_handler_real_percentCSQ;
	G_OBJECT_CLASS (klass)->finalize = ti_calypso_unsolicited_response_handler_finalize;
}


static void ti_calypso_unsolicited_response_handler_instance_init (TiCalypsoUnsolicitedResponseHandler * self) {
	self->priv = TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER_GET_PRIVATE (self);
}


static void ti_calypso_unsolicited_response_handler_finalize (GObject* obj) {
	TiCalypsoUnsolicitedResponseHandler * self;
	self = TI_CALYPSO_UNSOLICITED_RESPONSE_HANDLER (obj);
	G_OBJECT_CLASS (ti_calypso_unsolicited_response_handler_parent_class)->finalize (obj);
}


GType ti_calypso_unsolicited_response_handler_get_type (void) {
	return ti_calypso_unsolicited_response_handler_type_id;
}


GType ti_calypso_unsolicited_response_handler_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (TiCalypsoUnsolicitedResponseHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ti_calypso_unsolicited_response_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TiCalypsoUnsolicitedResponseHandler), 0, (GInstanceInitFunc) ti_calypso_unsolicited_response_handler_instance_init, NULL };
	ti_calypso_unsolicited_response_handler_type_id = g_type_module_register_type (module, FSO_GSM_TYPE_AT_UNSOLICITED_RESPONSE_HANDLER, "TiCalypsoUnsolicitedResponseHandler", &g_define_type_info, 0);
	return ti_calypso_unsolicited_response_handler_type_id;
}



