aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mm-base-modem.c2
-rw-r--r--src/mm-base-modem.h2
-rw-r--r--src/mm-broadband-modem.c25
-rw-r--r--src/mm-iface-modem.c34
-rw-r--r--src/mm-iface-modem.h2
5 files changed, 41 insertions, 24 deletions
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index 2fa424d6..6a10053a 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -266,6 +266,7 @@ mm_base_modem_grab_port (MMBaseModem *self,
/* As soon as we get the primary AT port, we initialize the
* modem */
MM_BASE_MODEM_GET_CLASS (self)->initialize (self,
+ MM_AT_SERIAL_PORT (port),
NULL, /* TODO: cancellable */
(GAsyncReadyCallback)initialize_ready,
NULL);
@@ -707,4 +708,3 @@ mm_base_modem_class_init (MMBaseModemClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONNECTION, properties[PROP_CONNECTION]);
}
-
diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h
index cd2999ad..f37bf6fe 100644
--- a/src/mm-base-modem.h
+++ b/src/mm-base-modem.h
@@ -59,6 +59,7 @@ struct _MMBaseModemClass {
/* Modem initialization.
* Whenever the primary AT port is grabbed, this method gets called */
void (* initialize) (MMBaseModem *self,
+ MMAtSerialPort *port,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -130,4 +131,3 @@ guint mm_base_modem_get_vendor_id (MMBaseModem *self);
guint mm_base_modem_get_product_id (MMBaseModem *self);
#endif /* MM_BASE_MODEM_H */
-
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index 192c32c1..5a11678d 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -1208,6 +1208,8 @@ typedef struct {
MMBroadbandModem *self;
GSimpleAsyncResult *result;
InitializeStep step;
+ MMAtSerialPort *port;
+ gboolean close_port;
} InitializeContext;
static void initialize_step (InitializeContext *ctx);
@@ -1217,6 +1219,10 @@ initialize_context_complete_and_free (InitializeContext *ctx)
{
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->result);
+ /* balance open/close count */
+ if (ctx->close_port)
+ mm_serial_port_close (MM_SERIAL_PORT (ctx->port));
+ g_object_unref (ctx->port);
g_object_unref (ctx->self);
g_free (ctx);
}
@@ -1259,13 +1265,28 @@ static void
initialize_step (InitializeContext *ctx)
{
switch (ctx->step) {
- case INITIALIZE_STEP_FIRST:
+ case INITIALIZE_STEP_FIRST: {
+ GError *error = NULL;
+
+ /* Open and send first commands to the serial port */
+ if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) {
+ g_simple_async_result_take_error (ctx->result, error);
+ initialize_context_complete_and_free (ctx);
+ return;
+ }
+ ctx->close_port = TRUE;
+ /* Try to disable echo */
+ mm_at_serial_port_queue_command (ctx->port, "E0", 3, NULL, NULL);
+ /* Try to get extended errors */
+ mm_at_serial_port_queue_command (ctx->port, "+CMEE=1", 2, NULL, NULL);
/* Fall down to next step */
ctx->step++;
+ }
case INITIALIZE_STEP_IFACE_MODEM:
/* Initialize the Modem interface */
mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self),
+ ctx->port,
(GAsyncReadyCallback)iface_modem_initialize_ready,
ctx);
return;
@@ -1321,6 +1342,7 @@ initialize_step (InitializeContext *ctx)
static void
initialize (MMBaseModem *self,
+ MMAtSerialPort *port,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -1329,6 +1351,7 @@ initialize (MMBaseModem *self,
ctx = g_new0 (InitializeContext, 1);
ctx->self = g_object_ref (self);
+ ctx->port = g_object_ref (port);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index 2e11e432..ff7d0c78 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -650,7 +650,10 @@ unlock_check_context_free (UnlockCheckContext *ctx)
static gboolean
restart_initialize_idle (MMIfaceModem *self)
{
- mm_iface_modem_initialize (self, NULL, NULL);
+ mm_iface_modem_initialize (self,
+ mm_base_modem_get_port_primary (MM_BASE_MODEM (self)),
+ NULL,
+ NULL);
return FALSE;
}
@@ -1457,6 +1460,7 @@ struct _InitializationContext {
static InitializationContext *
initialization_context_new (MMIfaceModem *self,
+ MMAtSerialPort *port,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1464,7 +1468,7 @@ initialization_context_new (MMIfaceModem *self,
ctx = g_new0 (InitializationContext, 1);
ctx->self = g_object_ref (self);
- ctx->port = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self)));
+ ctx->port = g_object_ref (port);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
@@ -1939,7 +1943,6 @@ interface_initialization_step (InitializationContext *ctx)
/* We are done without errors! */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
g_simple_async_result_complete_in_idle (ctx->result);
- mm_serial_port_close (MM_SERIAL_PORT (ctx->port));
initialization_context_free (ctx);
return;
}
@@ -1949,27 +1952,14 @@ interface_initialization_step (InitializationContext *ctx)
static void
interface_initialization (MMIfaceModem *self,
+ MMAtSerialPort *port,
GAsyncReadyCallback callback,
gpointer user_data)
{
- InitializationContext *ctx;
- GError *error = NULL;
-
- ctx = initialization_context_new (self, callback, user_data);
-
- if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) {
- g_simple_async_result_take_error (ctx->result, error);
- g_simple_async_result_complete_in_idle (ctx->result);
- initialization_context_free (ctx);
- return;
- }
-
- /* Try to disable echo */
- mm_at_serial_port_queue_command (ctx->port, "E0", 3, NULL, NULL);
- /* Try to get extended errors */
- mm_at_serial_port_queue_command (ctx->port, "+CMEE=1", 2, NULL, NULL);
-
- interface_initialization_step (ctx);
+ interface_initialization_step (initialization_context_new (self,
+ port,
+ callback,
+ user_data));
}
/*****************************************************************************/
@@ -2056,6 +2046,7 @@ interface_initialization_ready (MMIfaceModem *self,
void
mm_iface_modem_initialize (MMIfaceModem *self,
+ MMAtSerialPort *port,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -2120,6 +2111,7 @@ mm_iface_modem_initialize (MMIfaceModem *self,
/* Perform async initialization here */
interface_initialization (self,
+ port,
(GAsyncReadyCallback)interface_initialization_ready,
result);
g_object_unref (skeleton);
diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h
index b743faa9..7d4f8ada 100644
--- a/src/mm-iface-modem.h
+++ b/src/mm-iface-modem.h
@@ -20,6 +20,7 @@
#include <gio/gio.h>
#include "mm-charsets.h"
+#include "mm-at-serial-port.h"
#define MM_TYPE_IFACE_MODEM (mm_iface_modem_get_type ())
#define MM_IFACE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_IFACE_MODEM, MMIfaceModem))
@@ -248,6 +249,7 @@ GType mm_iface_modem_get_type (void);
/* Initialize Modem interface (async) */
void mm_iface_modem_initialize (MMIfaceModem *self,
+ MMAtSerialPort *port,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self,