core: always pass open port to interface initializations

When the first AT port is grabbed, modem initialization is launched, using that
specific port. This port is also passed to all interface initialization methods.
This commit is contained in:
Aleksander Morgado
2011-11-28 12:53:30 +01:00
parent 1d495c58e6
commit acc3e3f6da
5 changed files with 41 additions and 24 deletions

View File

@@ -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]);
}

View File

@@ -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 */

View File

@@ -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,

View File

@@ -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);

View File

@@ -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,