aboutsummaryrefslogtreecommitdiff
path: root/src/mm-port-probe.h
blob: dfce77a8629bde2c2b2445f91a56e1b138325984 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* -*- 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 Aleksander Morgado <aleksander@gnu.org>
 */

#ifndef MM_PORT_PROBE_H
#define MM_PORT_PROBE_H

#include "config.h"

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gudev/gudev.h>

#include "mm-private-boxed-types.h"
#include "mm-port-probe-at.h"
#include "mm-at-serial-port.h"
#include "mm-device.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))
#define MM_IS_PORT_PROBE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PORT_PROBE))
#define MM_IS_PORT_PROBE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  MM_TYPE_PORT_PROBE))
#define MM_PORT_PROBE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  MM_TYPE_PORT_PROBE, MMPortProbeClass))

/* Flags to request port probing */
typedef enum { /*< underscore_name=mm_port_probe_flag >*/
    MM_PORT_PROBE_NONE       = 0,
    MM_PORT_PROBE_AT         = 1 << 0,
    MM_PORT_PROBE_AT_VENDOR  = 1 << 1,
    MM_PORT_PROBE_AT_PRODUCT = 1 << 2,
    MM_PORT_PROBE_AT_ICERA   = 1 << 3,
    MM_PORT_PROBE_QCDM       = 1 << 4,
    MM_PORT_PROBE_QMI        = 1 << 5
} MMPortProbeFlag;

typedef struct _MMPortProbe MMPortProbe;
typedef struct _MMPortProbeClass MMPortProbeClass;
typedef struct _MMPortProbePrivate MMPortProbePrivate;

#define MM_PORT_PROBE_DEVICE "device"
#define MM_PORT_PROBE_PORT   "port"

struct _MMPortProbe {
    GObject parent;
    MMPortProbePrivate *priv;
};

struct _MMPortProbeClass {
    GObjectClass parent;
};

/* Custom AT probing initialization setup.
 * Plugins can use this to configure how AT ports need to get initialized.
 * It also helps to implement plugin-specific checks, as plugins can set
 * their own probing results on the 'probe' object. */
typedef void     (* MMPortProbeAtCustomInit)       (MMPortProbe *probe,
                                                    MMAtSerialPort *port,
                                                    GCancellable *cancellable,
                                                    GAsyncReadyCallback callback,
                                                    gpointer user_data);
typedef gboolean (* MMPortProbeAtCustomInitFinish) (MMPortProbe *probe,
                                                    GAsyncResult *result,
                                                    GError **error);

GType mm_port_probe_get_type (void);

MMPortProbe *mm_port_probe_new (MMDevice *device,
                                GUdevDevice *port);

MMDevice    *mm_port_probe_peek_device      (MMPortProbe *self);
MMDevice    *mm_port_probe_get_device       (MMPortProbe *self);
GUdevDevice *mm_port_probe_peek_port        (MMPortProbe *self);
GUdevDevice *mm_port_probe_get_port         (MMPortProbe *self);
const gchar *mm_port_probe_get_port_name    (MMPortProbe *self);
const gchar *mm_port_probe_get_port_subsys  (MMPortProbe *self);

/* Probing result setters */
void mm_port_probe_set_result_at         (MMPortProbe *self,
                                          gboolean at);
void mm_port_probe_set_result_at_vendor  (MMPortProbe *self,
                                          const gchar *at_vendor);
void mm_port_probe_set_result_at_product (MMPortProbe *self,
                                          const gchar *at_product);
void mm_port_probe_set_result_at_icera   (MMPortProbe *self,
                                          gboolean is_icera);
void mm_port_probe_set_result_qcdm       (MMPortProbe *self,
                                          gboolean qcdm);
void mm_port_probe_set_result_qmi        (MMPortProbe *self,
                                          gboolean qmi);

/* Run probing */
void     mm_port_probe_run        (MMPortProbe *self,
                                   MMPortProbeFlag flags,
                                   guint64 at_send_delay,
                                   gboolean at_remove_echo,
                                   gboolean at_send_lf,
                                   const MMPortProbeAtCommand *at_custom_probe,
                                   const MMAsyncMethod *at_custom_init,
                                   GAsyncReadyCallback callback,
                                   gpointer user_data);
gboolean mm_port_probe_run_finish (MMPortProbe *self,
                                   GAsyncResult *result,
                                   GError **error);
gboolean mm_port_probe_run_cancel (MMPortProbe *self);

gboolean mm_port_probe_run_cancel_at_probing (MMPortProbe *self);

/* Probing result getters */
MMPortType    mm_port_probe_get_port_type    (MMPortProbe *self);
gboolean      mm_port_probe_is_at            (MMPortProbe *self);
gboolean      mm_port_probe_is_qcdm          (MMPortProbe *self);
gboolean      mm_port_probe_is_qmi           (MMPortProbe *self);
const gchar  *mm_port_probe_get_vendor       (MMPortProbe *self);
const gchar  *mm_port_probe_get_product      (MMPortProbe *self);
gboolean      mm_port_probe_is_icera         (MMPortProbe *self);

/* Additional helpers */
gboolean mm_port_probe_list_has_at_port  (GList *list);
gboolean mm_port_probe_list_has_qmi_port (GList *list);
gboolean mm_port_probe_list_is_icera     (GList *list);

#endif /* MM_PORT_PROBE_H */