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 /* As soon as we get the primary AT port, we initialize the
* modem */ * modem */
MM_BASE_MODEM_GET_CLASS (self)->initialize (self, MM_BASE_MODEM_GET_CLASS (self)->initialize (self,
MM_AT_SERIAL_PORT (port),
NULL, /* TODO: cancellable */ NULL, /* TODO: cancellable */
(GAsyncReadyCallback)initialize_ready, (GAsyncReadyCallback)initialize_ready,
NULL); NULL);
@@ -707,4 +708,3 @@ mm_base_modem_class_init (MMBaseModemClass *klass)
G_PARAM_READWRITE); G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONNECTION, properties[PROP_CONNECTION]); g_object_class_install_property (object_class, PROP_CONNECTION, properties[PROP_CONNECTION]);
} }

View File

@@ -59,6 +59,7 @@ struct _MMBaseModemClass {
/* Modem initialization. /* Modem initialization.
* Whenever the primary AT port is grabbed, this method gets called */ * Whenever the primary AT port is grabbed, this method gets called */
void (* initialize) (MMBaseModem *self, void (* initialize) (MMBaseModem *self,
MMAtSerialPort *port,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); 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); guint mm_base_modem_get_product_id (MMBaseModem *self);
#endif /* MM_BASE_MODEM_H */ #endif /* MM_BASE_MODEM_H */

View File

@@ -1208,6 +1208,8 @@ typedef struct {
MMBroadbandModem *self; MMBroadbandModem *self;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
InitializeStep step; InitializeStep step;
MMAtSerialPort *port;
gboolean close_port;
} InitializeContext; } InitializeContext;
static void initialize_step (InitializeContext *ctx); 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_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (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_object_unref (ctx->self);
g_free (ctx); g_free (ctx);
} }
@@ -1259,13 +1265,28 @@ static void
initialize_step (InitializeContext *ctx) initialize_step (InitializeContext *ctx)
{ {
switch (ctx->step) { 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 */ /* Fall down to next step */
ctx->step++; ctx->step++;
}
case INITIALIZE_STEP_IFACE_MODEM: case INITIALIZE_STEP_IFACE_MODEM:
/* Initialize the Modem interface */ /* Initialize the Modem interface */
mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self), mm_iface_modem_initialize (MM_IFACE_MODEM (ctx->self),
ctx->port,
(GAsyncReadyCallback)iface_modem_initialize_ready, (GAsyncReadyCallback)iface_modem_initialize_ready,
ctx); ctx);
return; return;
@@ -1321,6 +1342,7 @@ initialize_step (InitializeContext *ctx)
static void static void
initialize (MMBaseModem *self, initialize (MMBaseModem *self,
MMAtSerialPort *port,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
@@ -1329,6 +1351,7 @@ initialize (MMBaseModem *self,
ctx = g_new0 (InitializeContext, 1); ctx = g_new0 (InitializeContext, 1);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->port = g_object_ref (port);
ctx->result = g_simple_async_result_new (G_OBJECT (self), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,

View File

@@ -650,7 +650,10 @@ unlock_check_context_free (UnlockCheckContext *ctx)
static gboolean static gboolean
restart_initialize_idle (MMIfaceModem *self) 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; return FALSE;
} }
@@ -1457,6 +1460,7 @@ struct _InitializationContext {
static InitializationContext * static InitializationContext *
initialization_context_new (MMIfaceModem *self, initialization_context_new (MMIfaceModem *self,
MMAtSerialPort *port,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
@@ -1464,7 +1468,7 @@ initialization_context_new (MMIfaceModem *self,
ctx = g_new0 (InitializationContext, 1); ctx = g_new0 (InitializationContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -1939,7 +1943,6 @@ interface_initialization_step (InitializationContext *ctx)
/* We are done without errors! */ /* We are done without errors! */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
mm_serial_port_close (MM_SERIAL_PORT (ctx->port));
initialization_context_free (ctx); initialization_context_free (ctx);
return; return;
} }
@@ -1949,27 +1952,14 @@ interface_initialization_step (InitializationContext *ctx)
static void static void
interface_initialization (MMIfaceModem *self, interface_initialization (MMIfaceModem *self,
MMAtSerialPort *port,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
InitializationContext *ctx; interface_initialization_step (initialization_context_new (self,
GError *error = NULL; port,
callback,
ctx = initialization_context_new (self, callback, user_data); 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);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -2056,6 +2046,7 @@ interface_initialization_ready (MMIfaceModem *self,
void void
mm_iface_modem_initialize (MMIfaceModem *self, mm_iface_modem_initialize (MMIfaceModem *self,
MMAtSerialPort *port,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
@@ -2120,6 +2111,7 @@ mm_iface_modem_initialize (MMIfaceModem *self,
/* Perform async initialization here */ /* Perform async initialization here */
interface_initialization (self, interface_initialization (self,
port,
(GAsyncReadyCallback)interface_initialization_ready, (GAsyncReadyCallback)interface_initialization_ready,
result); result);
g_object_unref (skeleton); g_object_unref (skeleton);

View File

@@ -20,6 +20,7 @@
#include <gio/gio.h> #include <gio/gio.h>
#include "mm-charsets.h" #include "mm-charsets.h"
#include "mm-at-serial-port.h"
#define MM_TYPE_IFACE_MODEM (mm_iface_modem_get_type ()) #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)) #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) */ /* Initialize Modem interface (async) */
void mm_iface_modem_initialize (MMIfaceModem *self, void mm_iface_modem_initialize (MMIfaceModem *self,
MMAtSerialPort *port,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self, gboolean mm_iface_modem_initialize_finish (MMIfaceModem *self,