~ubuntu-branches/ubuntu/oneiric/modemmanager/oneiric

« back to all changes in this revision

Viewing changes to src/mm-plugin-base.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl, Thomas Bechtold, Mathieu Trudel-Lapierre
  • Date: 2011-05-04 13:17:33 UTC
  • mfrom: (1.1.10 upstream) (9.1.6 natty)
  • Revision ID: james.westby@ubuntu.com-20110504131733-4xn3f3il1cn3krc3
Tags: 0.4+git.20110429t103114.863dbca-1
[ Thomas Bechtold ]
* debian/rules, debian/control: migrate from CDBS to using dh

[ Mathieu Trudel-Lapierre ]
* upstream snapshot 2011-04-29 10:31:14 (GMT)
  + 863dbca63132b820fca6c48a9c212f852752ee16
* debian/README.source: add instructions for using this packaging branch and
  how to build from it; adapted from the NetworkManager package.
* debian/rules, debian/control: update control and rules to use dh-autoreconf
  rather than just autoreconf.
* debian/control: bump Standards-Version to 3.9.2.
* debian/rules: re-add DEB_* variables which got dropped from the dh
  migration, since we no longer include buildvars.mk.
* debian/patches/git-backport-e208c52-to-0c4b944.patch,
  debian/patches/git-backport-verbose-cmee-errors-7d20acc.patch: dropped,
  applied upstream.
* debian/control: bump debhelper Build-Depends to 8.
* debian/compat: bump to compat level 8, according to the debhelper update.
* debian/rules: cleanup extra files left behind by intltoolize.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
#define MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_BASE_SUPPORTS_TASK, MMPluginBaseSupportsTaskPrivate))
94
94
 
95
95
typedef struct {
 
96
    char *command;
 
97
    guint32 tries;
 
98
    guint32 delay_seconds;
 
99
    MMBaseSupportsTaskCustomInitResultFunc callback;
 
100
    gpointer callback_data;
 
101
} CustomInit;
 
102
 
 
103
typedef struct {
96
104
    MMPluginBase *plugin;
97
105
    GUdevDevice *port;
98
106
    char *physdev_path;
110
118
    char *probe_resp;
111
119
    GError *probe_error;
112
120
 
113
 
    char *custom_init;
114
 
    guint32 custom_init_max_tries;
115
 
    guint32 custom_init_tries;
116
 
    guint32 custom_init_delay_seconds;
117
 
    gboolean custom_init_fail_if_timeout;
 
121
    /* Custom init commands plugins might want */
 
122
    GSList *custom;
 
123
    GSList *cur_custom; /* Pointer to current custom init command */
118
124
 
119
125
    MMSupportsPortResultFunc callback;
120
126
    gpointer callback_data;
225
231
}
226
232
 
227
233
void
228
 
mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask *task,
 
234
mm_plugin_base_supports_task_add_custom_init_command (MMPluginBaseSupportsTask *task,
229
235
                                                      const char *cmd,
230
236
                                                      guint32 delay_seconds,
231
 
                                                      guint32 max_tries,
232
 
                                                      gboolean fail_if_timeout)
 
237
                                                      MMBaseSupportsTaskCustomInitResultFunc callback,
 
238
                                                      gpointer callback_data)
233
239
{
234
240
    MMPluginBaseSupportsTaskPrivate *priv;
 
241
    CustomInit *custom;
235
242
 
236
243
    g_return_if_fail (task != NULL);
237
244
    g_return_if_fail (MM_IS_PLUGIN_BASE_SUPPORTS_TASK (task));
 
245
    g_return_if_fail (callback != NULL);
238
246
 
239
247
    priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
240
248
 
241
 
    g_free (priv->custom_init);
242
 
    priv->custom_init = g_strdup (cmd);
243
 
    priv->custom_init_max_tries = max_tries;
244
 
    priv->custom_init_delay_seconds = delay_seconds;
245
 
    priv->custom_init_fail_if_timeout = fail_if_timeout;
 
249
    custom = g_malloc0 (sizeof (*custom));
 
250
    custom->command = g_strdup (cmd);
 
251
    custom->delay_seconds = delay_seconds ? delay_seconds : 3;
 
252
    custom->callback = callback;
 
253
    custom->callback_data = callback_data;
 
254
 
 
255
    priv->custom = g_slist_append (priv->custom, custom);
246
256
}
247
257
 
248
258
static void
254
264
supports_task_dispose (GObject *object)
255
265
{
256
266
    MMPluginBaseSupportsTaskPrivate *priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (object);
 
267
    GSList *iter;
257
268
 
258
269
    if (MM_IS_SERIAL_PORT (priv->probe_port))
259
270
        mm_serial_port_flash_cancel (MM_SERIAL_PORT (priv->probe_port));
263
274
    g_free (priv->driver);
264
275
    g_free (priv->probe_resp);
265
276
    g_clear_error (&(priv->probe_error));
266
 
    g_free (priv->custom_init);
 
277
 
 
278
    for (iter = priv->custom; iter; iter = g_slist_next (iter)) {
 
279
        CustomInit *custom = iter->data;
 
280
 
 
281
        g_free (custom->command);
 
282
        memset (custom, 0, sizeof (*custom));
 
283
        g_free (custom);
 
284
    }
267
285
 
268
286
    if (priv->open_id)
269
287
        g_source_remove (priv->open_id);
721
739
    task_priv->probe_id = g_idle_add (handle_probe_response, task);
722
740
}
723
741
 
 
742
static void
 
743
start_generic_probing (MMPluginBaseSupportsTask *task, MMAtSerialPort *port)
 
744
{
 
745
    mm_at_serial_port_queue_command (port, "+GCAP", 3, parse_response, task);
 
746
}
 
747
 
724
748
static void flash_done (MMSerialPort *port, GError *error, gpointer user_data);
725
749
 
726
750
static void
731
755
{
732
756
    MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data);
733
757
    MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
734
 
 
735
 
    if (error) {
736
 
        task_priv->custom_init_tries++;
737
 
        if (task_priv->custom_init_tries < task_priv->custom_init_max_tries) {
738
 
            /* Try the custom command again */
739
 
            flash_done (MM_SERIAL_PORT (port), NULL, user_data);
740
 
            return;
741
 
        } else if (task_priv->custom_init_fail_if_timeout) {
742
 
            /* Fail the probe if the plugin wanted it and the command timed out */
743
 
            if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
744
 
                probe_complete (task);
745
 
                return;
746
 
            }
747
 
        }
748
 
    }
749
 
 
750
 
    /* Otherwise proceed to probing */
751
 
    mm_at_serial_port_queue_command (port, "+GCAP", 3, parse_response, user_data);
 
758
    CustomInit *custom = task_priv->cur_custom->data;
 
759
    gboolean retry = FALSE;
 
760
    gboolean fail = FALSE;
 
761
    guint32 level = 0;
 
762
 
 
763
    custom->tries++;
 
764
    retry = custom->callback (task, response, error, custom->tries, &fail, &level, custom->callback_data);
 
765
 
 
766
    if (fail) {
 
767
        /* Plugin said to fail the probe */
 
768
        probe_complete (task);
 
769
        return;
 
770
    }
 
771
 
 
772
    if (level > 0) {
 
773
        /* Plugin supports the modem */
 
774
        task_priv->probed_caps = level;
 
775
        probe_complete (task);
 
776
        return;
 
777
    }
 
778
 
 
779
    if (retry) {
 
780
        /* Try the custom command again */
 
781
        flash_done (MM_SERIAL_PORT (port), NULL, task);
 
782
        return;
 
783
    }
 
784
 
 
785
    /* Any more custom init commands? */
 
786
    task_priv->cur_custom = g_slist_next (task_priv->cur_custom);
 
787
    if (task_priv->cur_custom) {
 
788
        /* There are more custom init commands */
 
789
        flash_done (MM_SERIAL_PORT (port), NULL, task);
 
790
        return;
 
791
    }
 
792
 
 
793
    /* Otherwise continue with generic probing */
 
794
    start_generic_probing (task, port);
752
795
}
753
796
 
754
797
static void
756
799
{
757
800
    MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data);
758
801
    MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
759
 
    guint32 delay_secs = task_priv->custom_init_delay_seconds;
760
802
 
761
803
    /* Send the custom init command if any */
762
 
    if (task_priv->custom_init) {
763
 
        if (!delay_secs)
764
 
            delay_secs = 3;
 
804
    if (task_priv->cur_custom) {
 
805
        CustomInit *custom = task_priv->cur_custom->data;
 
806
 
765
807
        mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port),
766
 
                                         task_priv->custom_init,
767
 
                                         delay_secs,
 
808
                                         custom->command,
 
809
                                         custom->delay_seconds,
768
810
                                         custom_init_response,
769
 
                                         user_data);
 
811
                                         task);
770
812
    } else {
771
813
        /* Otherwise start normal probing */
772
 
        custom_init_response (MM_AT_SERIAL_PORT (port), NULL, NULL, user_data);
 
814
        start_generic_probing (task, MM_AT_SERIAL_PORT (port));
773
815
    }
774
816
}
775
817
 
820
862
gboolean
821
863
mm_plugin_base_probe_port (MMPluginBase *self,
822
864
                           MMPluginBaseSupportsTask *task,
 
865
                           guint64 send_delay_us,
823
866
                           GError **error)
824
867
{
825
868
    MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
844
887
    }
845
888
 
846
889
    g_object_set (serial,
847
 
                  MM_SERIAL_PORT_SEND_DELAY, (guint64) 100000,
 
890
                  MM_SERIAL_PORT_SEND_DELAY, send_delay_us,
848
891
                  MM_PORT_CARRIER_DETECT, FALSE,
 
892
                  MM_SERIAL_PORT_SPEW_CONTROL, TRUE,
849
893
                  NULL);
850
894
 
851
895
    mm_at_serial_port_set_response_parser (serial,
855
899
 
856
900
    /* Open the port */
857
901
    task_priv->probe_port = serial;
 
902
    task_priv->cur_custom = task_priv->custom;
858
903
    task_priv->open_id = g_idle_add (try_open, task);
859
904
    return TRUE;
860
905
}
933
978
                pid = g_udev_device_get_sysfs_attr (parent, "card_id");
934
979
                if (!vid || !pid)
935
980
                    goto out;
 
981
            } else if (!strcmp (parent_subsys, "platform")) {
 
982
                /* Platform devices don't usually have a VID/PID */
 
983
                success = TRUE;
 
984
                goto out;
936
985
            }
937
986
        }
938
987
    }