summaryrefslogtreecommitdiff
path: root/src/mm-port-probe-at.h
blob: d180be4f69b71f7437b698b76bc522bd7f216ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details:
 *
 * Copyright (C) 2011 - 2012 Aleksander Morgado <aleksander@gnu.org>
 * Copyright (C) 2012 Google, Inc.
 */

#ifndef MM_PORT_PROBE_AT_H
#define MM_PORT_PROBE_AT_H

#include <glib.h>

/* The response processor. The expected result depends on the
 * probing type:
 *  - AT             --> Boolean
 *  - Vendor         --> String
 *  - Product        --> String
 *
 * TRUE must be returned when the operation is to be considered successful,
 * and a result may be given.
 *
 * FALSE must be returned when:
 *  - A GError is propagated into result_error, which will be treated as a
 *    critical error and therefore the operation will be aborted.
 *  - When no result_error is given, to instruct the operation to go on with
 *    the next scheduled command.
 *
 * A special case to consider is the initialization commands, used by
 * some plugins. In this case, there is no expected result, but plugins may
 * set an optional boolean result, specifying whether the port is an AT port
 * or not.
 *  - Initialization --> None or Boolean
 * When the initialization is considered enough, TRUE is returned, and
 * FALSE otherwise.
 */
typedef gboolean (* MMPortProbeAtResponseProcessor) (const gchar *command,
                                                     const gchar *response,
                                                     gboolean last_command,
                                                     const GError *error,
                                                     GVariant **result,
                                                     GError **result_error);

/* Struct to configure port probing commands */
typedef struct {
    /* The AT command */
    gchar *command;
    /* Timeout of the command, in seconds */
    guint timeout;
    /* The response processor */
    MMPortProbeAtResponseProcessor response_processor;
} MMPortProbeAtCommand;

/* Common helper response processors */

/* Every string received as response, will be set as result */
gboolean mm_port_probe_response_processor_string (const gchar *command,
                                                  const gchar *response,
                                                  gboolean last_command,
                                                  const GError *error,
                                                  GVariant **result,
                                                  GError **result_error);
/* Generic response parser for AT probing, useful also in custom init commands */
gboolean mm_port_probe_response_processor_is_at (const gchar *command,
                                                 const gchar *response,
                                                 gboolean last_command,
                                                 const GError *error,
                                                 GVariant **result,
                                                 GError **result_error);
/* Generic response parser which returns TRUE if no error  */
gboolean mm_port_probe_response_processor_no_error (const gchar *command,
                                                    const gchar *response,
                                                    gboolean last_command,
                                                    const GError *error,
                                                    GVariant **result,
                                                    GError **result_error);


#endif /* MM_PORT_PROBE_AT_H */