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

/*
 * Copyright (C) 2010  Antonio Ospite <ospite@studenti.unina.it>
 *
 * 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 <stdlib.h>
#include <string.h>
#include <fsogsm.h>
#include <gee.h>
#include <fsobasics.h>
#include <fsotransport.h>
#include <fsoframework.h>


#define FREESCALE_NEPTUNE_TYPE_MODEM (freescale_neptune_modem_get_type ())
#define FREESCALE_NEPTUNE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FREESCALE_NEPTUNE_TYPE_MODEM, FreescaleNeptuneModem))
#define FREESCALE_NEPTUNE_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FREESCALE_NEPTUNE_TYPE_MODEM, FreescaleNeptuneModemClass))
#define FREESCALE_NEPTUNE_IS_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FREESCALE_NEPTUNE_TYPE_MODEM))
#define FREESCALE_NEPTUNE_IS_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FREESCALE_NEPTUNE_TYPE_MODEM))
#define FREESCALE_NEPTUNE_MODEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FREESCALE_NEPTUNE_TYPE_MODEM, FreescaleNeptuneModemClass))

typedef struct _FreescaleNeptuneModem FreescaleNeptuneModem;
typedef struct _FreescaleNeptuneModemClass FreescaleNeptuneModemClass;
typedef struct _FreescaleNeptuneModemPrivate FreescaleNeptuneModemPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _fso_gsm_at_command_sequence_unref0(var) ((var == NULL) ? NULL : (var = (fso_gsm_at_command_sequence_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER (freescale_neptune_unsolicited_response_handler_get_type ())
#define FREESCALE_NEPTUNE_UNSOLICITED_RESPONSE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER, FreescaleNeptuneUnsolicitedResponseHandler))
#define FREESCALE_NEPTUNE_UNSOLICITED_RESPONSE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER, FreescaleNeptuneUnsolicitedResponseHandlerClass))
#define FREESCALE_NEPTUNE_IS_UNSOLICITED_RESPONSE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER))
#define FREESCALE_NEPTUNE_IS_UNSOLICITED_RESPONSE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER))
#define FREESCALE_NEPTUNE_UNSOLICITED_RESPONSE_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FREESCALE_NEPTUNE_TYPE_UNSOLICITED_RESPONSE_HANDLER, FreescaleNeptuneUnsolicitedResponseHandlerClass))

typedef struct _FreescaleNeptuneUnsolicitedResponseHandler FreescaleNeptuneUnsolicitedResponseHandler;
typedef struct _FreescaleNeptuneUnsolicitedResponseHandlerClass FreescaleNeptuneUnsolicitedResponseHandlerClass;

struct _FreescaleNeptuneModem {
	FsoGsmAbstractModem parent_instance;
	FreescaleNeptuneModemPrivate * priv;
};

struct _FreescaleNeptuneModemClass {
	FsoGsmAbstractModemClass parent_class;
};

struct _FreescaleNeptuneModemPrivate {
	gchar* _revision;
	guint8* _bdaddr;
	gint _bdaddr_length1;
	gint __bdaddr_size_;
};


static gpointer freescale_neptune_modem_parent_class = NULL;
static GType freescale_neptune_modem_type_id = 0;

#define FREESCALE_NEPTUNE_MODULE_NAME "fsogsm.modem_freescale_neptune"
GType freescale_neptune_modem_get_type (void) G_GNUC_CONST;
GType freescale_neptune_modem_register_type (GTypeModule * module);
#define FREESCALE_NEPTUNE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FREESCALE_NEPTUNE_TYPE_MODEM, FreescaleNeptuneModemPrivate))
enum  {
	FREESCALE_NEPTUNE_MODEM_DUMMY_PROPERTY,
	FREESCALE_NEPTUNE_MODEM_REVISION
};
static gchar* freescale_neptune_modem_real_repr (FsoFrameworkAbstractObject* base);
static void freescale_neptune_modem_real_configureData (FsoGsmAbstractModem* base);
static void freescale_neptune_modem_real_createChannels (FsoGsmAbstractModem* base);
static void freescale_neptune_modem_real_registerCustomMediators (FsoGsmAbstractModem* base, GeeHashMap* mediators);
void freescale_neptune_registerNeptuneMediators (GeeHashMap* table);
static FsoGsmUnsolicitedResponseHandler* freescale_neptune_modem_real_createUnsolicitedHandler (FsoGsmAbstractModem* base);
FreescaleNeptuneUnsolicitedResponseHandler* freescale_neptune_unsolicited_response_handler_new (void);
FreescaleNeptuneUnsolicitedResponseHandler* freescale_neptune_unsolicited_response_handler_construct (GType object_type);
GType freescale_neptune_unsolicited_response_handler_get_type (void) G_GNUC_CONST;
GType freescale_neptune_unsolicited_response_handler_register_type (GTypeModule * module);
static FsoGsmChannel* freescale_neptune_modem_real_channelForCommand (FsoGsmAbstractModem* base, FsoGsmAtCommand* command, const gchar* query);
FreescaleNeptuneModem* freescale_neptune_modem_new (void);
FreescaleNeptuneModem* freescale_neptune_modem_construct (GType object_type);
const gchar* freescale_neptune_modem_get_revision (FreescaleNeptuneModem* self);
void freescale_neptune_modem_set_revision (FreescaleNeptuneModem* self, const gchar* value);
guint8* freescale_neptune_modem_get_bdaddr (FreescaleNeptuneModem* self, int* result_length1);
void freescale_neptune_modem_set_bdaddr (FreescaleNeptuneModem* self, guint8* value, int value_length1);
static guint8* _vala_array_dup1 (guint8* self, int length);
static GObject * freescale_neptune_modem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void freescale_neptune_modem_finalize (GObject* obj);
static void _vala_freescale_neptune_modem_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_freescale_neptune_modem_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error);
void fso_register_function (GTypeModule* module);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);

const gchar* FREESCALE_NEPTUNE_CHANNEL_NAMES[4] = {"main", "sms", "sim", "misc"};

static gchar* freescale_neptune_modem_real_repr (FsoFrameworkAbstractObject* base) {
	FreescaleNeptuneModem * self;
	gchar* result = NULL;
	GeeHashMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_;
	self = (FreescaleNeptuneModem*) base;
	_tmp0_ = ((FsoGsmAbstractModem*) self)->channels;
	_tmp1_ = gee_abstract_map_get_size ((GeeMap*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("%i", _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat ("<", _tmp4_, "C>", NULL);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	result = _tmp6_;
	return result;
}


static void freescale_neptune_modem_real_configureData (FsoGsmAbstractModem* base) {
	FreescaleNeptuneModem * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_;
	gint _tmp3__length1;
	FsoGsmAtCommandSequence* _tmp4_;
	FsoGsmAtCommandSequence* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar** _tmp17_ = NULL;
	gchar** _tmp18_;
	gint _tmp18__length1;
	FsoGsmAtCommandSequence* _tmp19_;
	FsoGsmAtCommandSequence* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar** _tmp24_ = NULL;
	gchar** _tmp25_;
	gint _tmp25__length1;
	FsoGsmAtCommandSequence* _tmp26_;
	FsoGsmAtCommandSequence* _tmp27_;
	gchar* _tmp28_;
	gchar** _tmp29_ = NULL;
	gchar** _tmp30_;
	gint _tmp30__length1;
	FsoGsmAtCommandSequence* _tmp31_;
	FsoGsmAtCommandSequence* _tmp32_;
	self = (FreescaleNeptuneModem*) base;
	_tmp0_ = g_strdup ("+EPOM=1,0");
	_tmp1_ = g_strdup ("+EAPF=12,1,0");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	_tmp4_ = fso_gsm_at_command_sequence_new (_tmp3_, 2);
	_tmp5_ = _tmp4_;
	fso_gsm_modem_registerAtCommandSequence ((FsoGsmModem*) self, "MODEM", "init", _tmp5_);
	_fso_gsm_at_command_sequence_unref0 (_tmp5_);
	_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
	_tmp6_ = g_strdup ("+CRC=1");
	_tmp7_ = g_strdup ("+CLIP=1");
	_tmp8_ = g_strdup ("+COLP=1");
	_tmp9_ = g_strdup ("+CCWA=1");
	_tmp10_ = g_strdup ("+CSSN=1,1");
	_tmp11_ = g_strdup ("+CTZU=1");
	_tmp12_ = g_strdup ("+CTZR=1");
	_tmp13_ = g_strdup ("+CREG=2");
	_tmp14_ = g_strdup ("+CAOC=2");
	_tmp15_ = g_strdup ("+CGEREP=2,1");
	_tmp16_ = g_strdup ("+CGREG=2");
	_tmp17_ = g_new0 (gchar*, 11 + 1);
	_tmp17_[0] = _tmp6_;
	_tmp17_[1] = _tmp7_;
	_tmp17_[2] = _tmp8_;
	_tmp17_[3] = _tmp9_;
	_tmp17_[4] = _tmp10_;
	_tmp17_[5] = _tmp11_;
	_tmp17_[6] = _tmp12_;
	_tmp17_[7] = _tmp13_;
	_tmp17_[8] = _tmp14_;
	_tmp17_[9] = _tmp15_;
	_tmp17_[10] = _tmp16_;
	_tmp18_ = _tmp17_;
	_tmp18__length1 = 11;
	_tmp19_ = fso_gsm_at_command_sequence_new (_tmp18_, 11);
	_tmp20_ = _tmp19_;
	fso_gsm_modem_registerAtCommandSequence ((FsoGsmModem*) self, "main", "init", _tmp20_);
	_fso_gsm_at_command_sequence_unref0 (_tmp20_);
	_tmp18_ = (_vala_array_free (_tmp18_, _tmp18__length1, (GDestroyNotify) g_free), NULL);
	_tmp21_ = g_strdup ("+CRRM");
	_tmp22_ = g_strdup ("+EPMS?");
	_tmp23_ = g_strdup ("+EMGL=4");
	_tmp24_ = g_new0 (gchar*, 3 + 1);
	_tmp24_[0] = _tmp21_;
	_tmp24_[1] = _tmp22_;
	_tmp24_[2] = _tmp23_;
	_tmp25_ = _tmp24_;
	_tmp25__length1 = 3;
	_tmp26_ = fso_gsm_at_command_sequence_new (_tmp25_, 3);
	_tmp27_ = _tmp26_;
	fso_gsm_modem_registerAtCommandSequence ((FsoGsmModem*) self, "sms", "unlocked", _tmp27_);
	_fso_gsm_at_command_sequence_unref0 (_tmp27_);
	_tmp25_ = (_vala_array_free (_tmp25_, _tmp25__length1, (GDestroyNotify) g_free), NULL);
	_tmp28_ = g_strdup ("+USBSTAT=255,1");
	_tmp29_ = g_new0 (gchar*, 1 + 1);
	_tmp29_[0] = _tmp28_;
	_tmp30_ = _tmp29_;
	_tmp30__length1 = 1;
	_tmp31_ = fso_gsm_at_command_sequence_new (_tmp30_, 1);
	_tmp32_ = _tmp31_;
	fso_gsm_modem_registerAtCommandSequence ((FsoGsmModem*) self, "misc", "init", _tmp32_);
	_fso_gsm_at_command_sequence_unref0 (_tmp32_);
	_tmp30_ = (_vala_array_free (_tmp30_, _tmp30__length1, (GDestroyNotify) g_free), NULL);
}


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 freescale_neptune_modem_real_createChannels (FsoGsmAbstractModem* base) {
	FreescaleNeptuneModem * self;
	FsoFrameworkLogger* _tmp0_;
	FsoFrameworkTransportSpec* _tmp1_;
	FsoFrameworkTransportSpec* _tmp2_;
	const gchar* _tmp3_;
	self = (FreescaleNeptuneModem*) base;
	_tmp0_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp0_, "Create Freescale Neptune channels");
	_tmp1_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->type;
	if (g_strcmp0 (_tmp3_, "serial") == 0) {
		FsoFrameworkSmartKeyFile* _tmp4_;
		gchar* _tmp5_ = NULL;
		gchar* muxnode_prefix;
		_tmp4_ = ((FsoFrameworkAbstractObject*) self)->config;
		_tmp5_ = fso_framework_smart_key_file_stringValue (_tmp4_, FREESCALE_NEPTUNE_MODULE_NAME, "muxnode_prefix", "");
		muxnode_prefix = _tmp5_;
		{
			gint i;
			i = 0;
			{
				gboolean _tmp6_;
				_tmp6_ = TRUE;
				while (TRUE) {
					gboolean _tmp7_;
					gint _tmp9_;
					gint _tmp10_;
					const gchar* _tmp11_;
					gchar* _tmp12_;
					gchar* channel;
					FsoFrameworkSmartKeyFile* _tmp13_;
					const gchar* _tmp14_;
					const gchar* _tmp15_ = NULL;
					gchar* _tmp16_ = NULL;
					gchar* _tmp17_;
					gchar* _tmp18_ = NULL;
					gchar* _tmp19_;
					gchar* dlci;
					const gchar* _tmp20_;
					_tmp7_ = _tmp6_;
					if (!_tmp7_) {
						gint _tmp8_;
						_tmp8_ = i;
						i = _tmp8_ + 1;
					}
					_tmp6_ = FALSE;
					_tmp9_ = i;
					if (!(_tmp9_ < G_N_ELEMENTS (FREESCALE_NEPTUNE_CHANNEL_NAMES))) {
						break;
					}
					_tmp10_ = i;
					_tmp11_ = FREESCALE_NEPTUNE_CHANNEL_NAMES[_tmp10_];
					_tmp12_ = g_strdup (_tmp11_);
					channel = _tmp12_;
					_tmp13_ = ((FsoFrameworkAbstractObject*) self)->config;
					_tmp14_ = channel;
					_tmp15_ = string_to_string (_tmp14_);
					_tmp16_ = g_strconcat ("dlci_", _tmp15_, NULL);
					_tmp17_ = _tmp16_;
					_tmp18_ = fso_framework_smart_key_file_stringValue (_tmp13_, FREESCALE_NEPTUNE_MODULE_NAME, _tmp17_, "");
					_tmp19_ = _tmp18_;
					_g_free0 (_tmp17_);
					dlci = _tmp19_;
					_tmp20_ = dlci;
					if (g_strcmp0 (_tmp20_, "") != 0) {
						const gchar* _tmp21_;
						const gchar* _tmp22_ = NULL;
						const gchar* _tmp23_;
						const gchar* _tmp24_ = NULL;
						gchar* _tmp25_ = NULL;
						gchar* muxnode;
						FsoFrameworkTransportSpec* _tmp26_;
						FsoFrameworkTransportSpec* _tmp27_;
						const gchar* _tmp28_;
						const gchar* _tmp29_;
						FsoFrameworkTransportSpec* _tmp30_;
						FsoFrameworkTransportSpec* _tmp31_;
						guint _tmp32_;
						FsoFrameworkTransport* _tmp33_ = NULL;
						FsoFrameworkTransport* transport;
						const gchar* _tmp34_;
						FsoFrameworkTransport* _tmp35_;
						FsoGsmStateBasedAtParser* _tmp36_;
						FsoGsmStateBasedAtParser* _tmp37_;
						FsoGsmAtChannel* _tmp38_;
						FsoGsmAtChannel* _tmp39_;
						_tmp21_ = muxnode_prefix;
						_tmp22_ = string_to_string (_tmp21_);
						_tmp23_ = dlci;
						_tmp24_ = string_to_string (_tmp23_);
						_tmp25_ = g_strconcat (_tmp22_, _tmp24_, NULL);
						muxnode = _tmp25_;
						_tmp26_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
						_tmp27_ = _tmp26_;
						_tmp28_ = _tmp27_->name;
						_tmp29_ = muxnode;
						_tmp30_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
						_tmp31_ = _tmp30_;
						_tmp32_ = _tmp31_->speed;
						_tmp33_ = fso_framework_transport_create (_tmp28_, _tmp29_, _tmp32_, TRUE, TRUE);
						transport = _tmp33_;
						_tmp34_ = channel;
						_tmp35_ = transport;
						_tmp36_ = fso_gsm_state_based_at_parser_new ();
						_tmp37_ = _tmp36_;
						_tmp38_ = fso_gsm_at_channel_new (_tmp34_, _tmp35_, (FsoFrameworkParser*) _tmp37_);
						_tmp39_ = _tmp38_;
						_g_object_unref0 (_tmp39_);
						_g_object_unref0 (_tmp37_);
						_g_object_unref0 (transport);
						_g_free0 (muxnode);
					} else {
						FsoFrameworkLogger* _tmp40_;
						const gchar* _tmp41_;
						const gchar* _tmp42_ = NULL;
						gchar* _tmp43_ = NULL;
						gchar* _tmp44_;
						_tmp40_ = ((FsoFrameworkAbstractObject*) self)->logger;
						_tmp41_ = channel;
						_tmp42_ = string_to_string (_tmp41_);
						_tmp43_ = g_strconcat ("No dlci for channel '", _tmp42_, "'", NULL);
						_tmp44_ = _tmp43_;
						fso_framework_logger_warning (_tmp40_, _tmp44_);
						_g_free0 (_tmp44_);
					}
					_g_free0 (dlci);
					_g_free0 (channel);
				}
			}
		}
		_g_free0 (muxnode_prefix);
	} else {
		FsoFrameworkTransportSpec* _tmp45_;
		FsoFrameworkTransportSpec* _tmp46_;
		const gchar* _tmp47_;
		_tmp45_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
		_tmp46_ = _tmp45_;
		_tmp47_ = _tmp46_->type;
		if (g_strcmp0 (_tmp47_, "tcp") == 0) {
			{
				gint i;
				i = 0;
				{
					gboolean _tmp48_;
					_tmp48_ = TRUE;
					while (TRUE) {
						gboolean _tmp49_;
						gint _tmp51_;
						gint _tmp52_;
						const gchar* _tmp53_;
						gchar* _tmp54_;
						gchar* channel;
						FsoFrameworkSmartKeyFile* _tmp55_;
						const gchar* _tmp56_;
						const gchar* _tmp57_ = NULL;
						gchar* _tmp58_ = NULL;
						gchar* _tmp59_;
						gint _tmp60_ = 0;
						gint _tmp61_;
						gint dlci;
						gint _tmp62_;
						_tmp49_ = _tmp48_;
						if (!_tmp49_) {
							gint _tmp50_;
							_tmp50_ = i;
							i = _tmp50_ + 1;
						}
						_tmp48_ = FALSE;
						_tmp51_ = i;
						if (!(_tmp51_ < G_N_ELEMENTS (FREESCALE_NEPTUNE_CHANNEL_NAMES))) {
							break;
						}
						_tmp52_ = i;
						_tmp53_ = FREESCALE_NEPTUNE_CHANNEL_NAMES[_tmp52_];
						_tmp54_ = g_strdup (_tmp53_);
						channel = _tmp54_;
						_tmp55_ = ((FsoFrameworkAbstractObject*) self)->config;
						_tmp56_ = channel;
						_tmp57_ = string_to_string (_tmp56_);
						_tmp58_ = g_strconcat ("dlci_", _tmp57_, NULL);
						_tmp59_ = _tmp58_;
						_tmp60_ = fso_framework_smart_key_file_intValue (_tmp55_, FREESCALE_NEPTUNE_MODULE_NAME, _tmp59_, 0);
						_tmp61_ = _tmp60_;
						_g_free0 (_tmp59_);
						dlci = _tmp61_;
						_tmp62_ = dlci;
						if (_tmp62_ > 0) {
							FsoFrameworkTransportSpec* _tmp63_;
							FsoFrameworkTransportSpec* _tmp64_;
							const gchar* _tmp65_;
							FsoFrameworkTransportSpec* _tmp66_;
							FsoFrameworkTransportSpec* _tmp67_;
							const gchar* _tmp68_;
							FsoFrameworkTransportSpec* _tmp69_;
							FsoFrameworkTransportSpec* _tmp70_;
							guint _tmp71_;
							gint _tmp72_;
							FsoFrameworkTransport* _tmp73_ = NULL;
							FsoFrameworkTransport* transport;
							const gchar* _tmp74_;
							FsoFrameworkTransport* _tmp75_;
							FsoGsmStateBasedAtParser* _tmp76_;
							FsoGsmStateBasedAtParser* _tmp77_;
							FsoGsmAtChannel* _tmp78_;
							FsoGsmAtChannel* _tmp79_;
							_tmp63_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
							_tmp64_ = _tmp63_;
							_tmp65_ = _tmp64_->type;
							_tmp66_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
							_tmp67_ = _tmp66_;
							_tmp68_ = _tmp67_->name;
							_tmp69_ = fso_gsm_abstract_modem_get_modem_transport_spec ((FsoGsmAbstractModem*) self);
							_tmp70_ = _tmp69_;
							_tmp71_ = _tmp70_->speed;
							_tmp72_ = dlci;
							_tmp73_ = fso_framework_transport_create (_tmp65_, _tmp68_, _tmp71_ + _tmp72_, TRUE, TRUE);
							transport = _tmp73_;
							_tmp74_ = channel;
							_tmp75_ = transport;
							_tmp76_ = fso_gsm_state_based_at_parser_new ();
							_tmp77_ = _tmp76_;
							_tmp78_ = fso_gsm_at_channel_new (_tmp74_, _tmp75_, (FsoFrameworkParser*) _tmp77_);
							_tmp79_ = _tmp78_;
							_g_object_unref0 (_tmp79_);
							_g_object_unref0 (_tmp77_);
							_g_object_unref0 (transport);
						} else {
							FsoFrameworkLogger* _tmp80_;
							const gchar* _tmp81_;
							const gchar* _tmp82_ = NULL;
							gchar* _tmp83_ = NULL;
							gchar* _tmp84_;
							_tmp80_ = ((FsoFrameworkAbstractObject*) self)->logger;
							_tmp81_ = channel;
							_tmp82_ = string_to_string (_tmp81_);
							_tmp83_ = g_strconcat ("No dlci for channel '", _tmp82_, "'", NULL);
							_tmp84_ = _tmp83_;
							fso_framework_logger_warning (_tmp80_, _tmp84_);
							_g_free0 (_tmp84_);
						}
						_g_free0 (channel);
					}
				}
			}
		} else {
			FsoFrameworkLogger* _tmp85_;
			_tmp85_ = ((FsoFrameworkAbstractObject*) self)->logger;
			fso_framework_logger_error (_tmp85_, "This modem only supports serial or TCP transports");
		}
	}
}


static void freescale_neptune_modem_real_registerCustomMediators (FsoGsmAbstractModem* base, GeeHashMap* mediators) {
	FreescaleNeptuneModem * self;
	FsoFrameworkLogger* _tmp0_;
	GeeHashMap* _tmp1_;
	self = (FreescaleNeptuneModem*) base;
	g_return_if_fail (mediators != NULL);
	_tmp0_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp0_, "Register Neptune mediators");
	_tmp1_ = mediators;
	freescale_neptune_registerNeptuneMediators (_tmp1_);
}


static FsoGsmUnsolicitedResponseHandler* freescale_neptune_modem_real_createUnsolicitedHandler (FsoGsmAbstractModem* base) {
	FreescaleNeptuneModem * self;
	FsoGsmUnsolicitedResponseHandler* result = NULL;
	FreescaleNeptuneUnsolicitedResponseHandler* _tmp0_;
	self = (FreescaleNeptuneModem*) base;
	_tmp0_ = freescale_neptune_unsolicited_response_handler_new ();
	result = (FsoGsmUnsolicitedResponseHandler*) _tmp0_;
	return result;
}


static FsoGsmChannel* freescale_neptune_modem_real_channelForCommand (FsoGsmAbstractModem* base, FsoGsmAtCommand* command, const gchar* query) {
	FreescaleNeptuneModem * self;
	FsoGsmChannel* result = NULL;
	GeeHashMap* _tmp0_;
	gpointer _tmp1_ = NULL;
	self = (FreescaleNeptuneModem*) base;
	g_return_val_if_fail (command != NULL, NULL);
	g_return_val_if_fail (query != NULL, NULL);
	_tmp0_ = ((FsoGsmAbstractModem*) self)->channels;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, "main");
	result = (FsoGsmChannel*) _tmp1_;
	return result;
}


FreescaleNeptuneModem* freescale_neptune_modem_construct (GType object_type) {
	FreescaleNeptuneModem * self = NULL;
	self = (FreescaleNeptuneModem*) fso_gsm_abstract_modem_construct (object_type);
	return self;
}


FreescaleNeptuneModem* freescale_neptune_modem_new (void) {
	return freescale_neptune_modem_construct (FREESCALE_NEPTUNE_TYPE_MODEM);
}


const gchar* freescale_neptune_modem_get_revision (FreescaleNeptuneModem* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_revision;
	result = _tmp0_;
	return result;
}


void freescale_neptune_modem_set_revision (FreescaleNeptuneModem* self, const gchar* value) {
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_revision);
	self->priv->_revision = _tmp1_;
	g_object_notify ((GObject *) self, "revision");
}


guint8* freescale_neptune_modem_get_bdaddr (FreescaleNeptuneModem* self, int* result_length1) {
	guint8* result;
	guint8* _tmp0_;
	gint _tmp0__length1;
	guint8* _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_bdaddr;
	_tmp0__length1 = self->priv->_bdaddr_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}


static guint8* _vala_array_dup1 (guint8* self, int length) {
	return g_memdup (self, length * sizeof (guint8));
}


void freescale_neptune_modem_set_bdaddr (FreescaleNeptuneModem* self, guint8* value, int value_length1) {
	guint8* _tmp0_;
	gint _tmp0__length1;
	guint8* _tmp1_;
	gint _tmp1__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp0__length1 = value_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__length1;
	self->priv->_bdaddr = (g_free (self->priv->_bdaddr), NULL);
	self->priv->_bdaddr = _tmp1_;
	self->priv->_bdaddr_length1 = _tmp1__length1;
	self->priv->__bdaddr_size_ = self->priv->_bdaddr_length1;
}


static GObject * freescale_neptune_modem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	FreescaleNeptuneModem * self;
	FsoFrameworkLogger* _tmp0_;
	parent_class = G_OBJECT_CLASS (freescale_neptune_modem_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = FREESCALE_NEPTUNE_MODEM (obj);
	_tmp0_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp0_, "Called FreescaleNeptune.Modem construct");
	return obj;
}


static void freescale_neptune_modem_class_init (FreescaleNeptuneModemClass * klass) {
	freescale_neptune_modem_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FreescaleNeptuneModemPrivate));
	FSO_FRAMEWORK_ABSTRACT_OBJECT_CLASS (klass)->repr = freescale_neptune_modem_real_repr;
	FSO_GSM_ABSTRACT_MODEM_CLASS (klass)->configureData = freescale_neptune_modem_real_configureData;
	FSO_GSM_ABSTRACT_MODEM_CLASS (klass)->createChannels = freescale_neptune_modem_real_createChannels;
	FSO_GSM_ABSTRACT_MODEM_CLASS (klass)->registerCustomMediators = freescale_neptune_modem_real_registerCustomMediators;
	FSO_GSM_ABSTRACT_MODEM_CLASS (klass)->createUnsolicitedHandler = freescale_neptune_modem_real_createUnsolicitedHandler;
	FSO_GSM_ABSTRACT_MODEM_CLASS (klass)->channelForCommand = freescale_neptune_modem_real_channelForCommand;
	G_OBJECT_CLASS (klass)->get_property = _vala_freescale_neptune_modem_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_freescale_neptune_modem_set_property;
	G_OBJECT_CLASS (klass)->constructor = freescale_neptune_modem_constructor;
	G_OBJECT_CLASS (klass)->finalize = freescale_neptune_modem_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FREESCALE_NEPTUNE_MODEM_REVISION, g_param_spec_string ("revision", "revision", "revision", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void freescale_neptune_modem_instance_init (FreescaleNeptuneModem * self) {
	gchar* _tmp0_;
	guint8* _tmp1_ = NULL;
	self->priv = FREESCALE_NEPTUNE_MODEM_GET_PRIVATE (self);
	_tmp0_ = g_strdup ("unknown");
	self->priv->_revision = _tmp0_;
	_tmp1_ = g_new0 (guint8, 6);
	_tmp1_[0] = (guint8) 0;
	_tmp1_[1] = (guint8) 0;
	_tmp1_[2] = (guint8) 0;
	_tmp1_[3] = (guint8) 0;
	_tmp1_[4] = (guint8) 0;
	_tmp1_[5] = (guint8) 0;
	self->priv->_bdaddr = _tmp1_;
	self->priv->_bdaddr_length1 = 6;
	self->priv->__bdaddr_size_ = self->priv->_bdaddr_length1;
}


static void freescale_neptune_modem_finalize (GObject* obj) {
	FreescaleNeptuneModem * self;
	self = FREESCALE_NEPTUNE_MODEM (obj);
	_g_free0 (self->priv->_revision);
	self->priv->_bdaddr = (g_free (self->priv->_bdaddr), NULL);
	G_OBJECT_CLASS (freescale_neptune_modem_parent_class)->finalize (obj);
}


/**
 * @class FreescaleNeptune.Modem
 *
 * This modem plugin supports the Freescale neptune chipset used on Motorola EzX
 * phones.
 **/
GType freescale_neptune_modem_get_type (void) {
	return freescale_neptune_modem_type_id;
}


GType freescale_neptune_modem_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (FreescaleNeptuneModemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) freescale_neptune_modem_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FreescaleNeptuneModem), 0, (GInstanceInitFunc) freescale_neptune_modem_instance_init, NULL };
	freescale_neptune_modem_type_id = g_type_module_register_type (module, FSO_GSM_TYPE_ABSTRACT_MODEM, "FreescaleNeptuneModem", &g_define_type_info, 0);
	return freescale_neptune_modem_type_id;
}


static void _vala_freescale_neptune_modem_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	FreescaleNeptuneModem * self;
	self = FREESCALE_NEPTUNE_MODEM (object);
	switch (property_id) {
		case FREESCALE_NEPTUNE_MODEM_REVISION:
		g_value_set_string (value, freescale_neptune_modem_get_revision (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_freescale_neptune_modem_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	FreescaleNeptuneModem * self;
	self = FREESCALE_NEPTUNE_MODEM (object);
	switch (property_id) {
		case FREESCALE_NEPTUNE_MODEM_REVISION:
		freescale_neptune_modem_set_revision (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


/**
 * This function gets called on plugin initialization time.
 * @return the name of your plugin here
 * @note that it needs to be a name in the format <subsystem>.<plugin>
 * else your module will be unloaded immediately.
 **/
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error) {
	gchar* result = NULL;
	FsoFrameworkLogger* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	_tmp0_ = fso_framework_theLogger;
	fso_framework_logger_debug (_tmp0_, "fsogsm.freescale_neptune fso_factory_function");
	_tmp1_ = g_strdup (FREESCALE_NEPTUNE_MODULE_NAME);
	result = _tmp1_;
	return result;
}


void fso_register_function (GTypeModule* module) {
	g_return_if_fail (module != NULL);
	freescale_neptune_modem_register_type (module);
	freescale_neptune_neptune_plus_cpin_register_type (module);
	freescale_neptune_neptune_device_get_information_register_type (module);
	freescale_neptune_neptune_sim_send_auth_code_register_type (module);
	freescale_neptune_neptune_network_register_register_type (module);
	freescale_neptune_neptune_network_unregister_register_type (module);
	freescale_neptune_neptune_call_list_calls_register_type (module);
	freescale_neptune_unsolicited_response_handler_register_type (module);
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



