aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-09-10 18:17:06 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:20 +0100
commitfa3fa38e0db3475d6f4c0273d6855fce375d1be0 (patch)
tree3fa15561504805fec6b53c9770f6b6e3a98bb473
parent610bffc4e817fa04dcde19d31584b194038fdde6 (diff)
port-probe: allow providing custom initialization AT commands
-rw-r--r--src/mm-port-probe.c38
-rw-r--r--src/mm-port-probe.h3
2 files changed, 37 insertions, 4 deletions
diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c
index ec425f64..8fae68d5 100644
--- a/src/mm-port-probe.c
+++ b/src/mm-port-probe.c
@@ -46,6 +46,8 @@ typedef struct {
guint64 at_send_delay;
/* Number of times we tried to open the AT port */
guint at_open_tries;
+ /* Custom initialization commands for the AT port */
+ const MMPortProbeAtCommand *at_custom_init;
/* Current group of AT commands to be sent */
const MMPortProbeAtCommand *at_commands;
/* Current AT Result processor */
@@ -367,6 +369,21 @@ serial_probe_at_result_processor (MMPortProbe *self,
}
static void
+serial_probe_at_custom_init_result_processor (MMPortProbe *self,
+ GValue *result)
+{
+ PortProbeRunTask *task = self->priv->task;
+
+ /* No result is really expected here, but we could get a boolean to indicate
+ * AT support */
+ if (G_VALUE_HOLDS_BOOLEAN (result))
+ serial_probe_at_result_processor (self, result);
+
+ /* Reset so that it doesn't get scheduled again */
+ task->at_custom_init = NULL;
+}
+
+static void
serial_probe_at_parse_response (MMAtSerialPort *port,
GString *response,
GError *error,
@@ -415,8 +432,13 @@ serial_probe_at_parse_response (MMAtSerialPort *port,
}
/* Got some processed result */
- task->at_result_processor (self, &result);
- g_value_unset (&result);
+ if (G_IS_VALUE (&result)) {
+ task->at_result_processor (self, &result);
+ g_value_unset (&result);
+ } else {
+ /* Custom init commands are allowed to not return anything */
+ task->at_result_processor (self, NULL);
+ }
/* Reschedule probing */
serial_probe_schedule (self);
@@ -455,9 +477,15 @@ serial_probe_schedule (MMPortProbe *self)
task->at_result_processor = NULL;
task->at_commands = NULL;
+ /* If we got some custom initialization commands requested, go on with them
+ * first. */
+ if (task->at_custom_init) {
+ task->at_result_processor = serial_probe_at_custom_init_result_processor;
+ task->at_commands = task->at_custom_init;
+ }
/* AT check requested and not already probed? */
- if ((task->flags & MM_PORT_PROBE_AT) &&
- !(self->priv->flags & MM_PORT_PROBE_AT)) {
+ else if ((task->flags & MM_PORT_PROBE_AT) &&
+ !(self->priv->flags & MM_PORT_PROBE_AT)) {
/* Prepare AT probing */
task->at_result_processor = serial_probe_at_result_processor;
task->at_commands = mm_port_probe_at_command_get_probing ();
@@ -701,6 +729,7 @@ void
mm_port_probe_run (MMPortProbe *self,
guint32 flags,
guint64 at_send_delay,
+ const MMPortProbeAtCommand *at_custom_init,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -717,6 +746,7 @@ mm_port_probe_run (MMPortProbe *self,
task = g_new0 (PortProbeRunTask, 1);
task->at_send_delay = at_send_delay;
task->flags = 0;
+ task->at_custom_init = at_custom_init;
task->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
diff --git a/src/mm-port-probe.h b/src/mm-port-probe.h
index 0b14c34b..98f66363 100644
--- a/src/mm-port-probe.h
+++ b/src/mm-port-probe.h
@@ -23,6 +23,8 @@
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
#include <gudev/gudev.h>
+#include "mm-port-probe-at-command.h"
+
#define MM_TYPE_PORT_PROBE (mm_port_probe_get_type ())
#define MM_PORT_PROBE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PORT_PROBE, MMPortProbe))
#define MM_PORT_PROBE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PORT_PROBE, MMPortProbeClass))
@@ -88,6 +90,7 @@ const gchar *mm_port_probe_get_port_driver (MMPortProbe *self);
void mm_port_probe_run (MMPortProbe *self,
guint32 flags,
guint64 at_send_delay,
+ const MMPortProbeAtCommand *at_custom_init,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_port_probe_run_finish (MMPortProbe *self,