Debian Codegraph @

src/libqmi-glib/qmi-endpoint.h

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3 /*
4 * libqmi-glib -- GLib/GIO based library to control QMI devices
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
20 *
21 * Copyright (C) 2019 Eric Caruso <[email protected]>
22 */
23
24 #ifndef _LIBQMI_GLIB_QMI_ENDPOINT_H_
25 #define _LIBQMI_GLIB_QMI_ENDPOINT_H_
26
27 #include <glib-object.h>
28 #include <gio/gio.h>
29
30 #include "qmi-ctl.h"
31 #include "qmi-file.h"
32 #include "qmi-message.h"
33
34 /* Constants for allocating/releasing clients */
35 #define QMI_MESSAGE_CTL_ALLOCATE_CID 0x0022
36 #define QMI_MESSAGE_CTL_RELEASE_CID 0x0023
37 #define QMI_MESSAGE_CTL_INTERNAL_ALLOCATE_CID_QRTR 0xFF22
38 #define QMI_MESSAGE_CTL_INTERNAL_RELEASE_CID_QRTR 0xFF23
39
40 typedef void (*QmiMessageHandler) (QmiMessage *message,
41 gpointer user_data);
42
43 #define QMI_TYPE_ENDPOINT (qmi_endpoint_get_type ())
44 #define QMI_ENDPOINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QMI_TYPE_ENDPOINT, QmiEndpoint))
45 #define QMI_ENDPOINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QMI_TYPE_ENDPOINT, QmiEndpointClass))
46 #define QMI_IS_ENDPOINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QMI_TYPE_ENDPOINT))
47 #define QMI_IS_ENDPOINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QMI_TYPE_ENDPOINT))
48 #define QMI_ENDPOINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QMI_TYPE_ENDPOINT, QmiEndpointClass))
49
50 typedef struct _QmiEndpoint QmiEndpoint;
51 typedef struct _QmiEndpointClass QmiEndpointClass;
52 typedef struct _QmiEndpointPrivate QmiEndpointPrivate;
53
54 #define QMI_ENDPOINT_FILE "endpoint-file"
55 #define QMI_ENDPOINT_SIGNAL_NEW_DATA "new-data"
56 #define QMI_ENDPOINT_SIGNAL_HANGUP "hangup"
57
58 struct _QmiEndpoint {
59 /*< private >*/
60 GObject parent;
61 QmiEndpointPrivate *priv;
62 };
63
64 struct _QmiEndpointClass {
65 /*< private >*/
66 GObjectClass parent;
67
68 /* low level I/O primitives */
69 void (* open) (QmiEndpoint *self,
70 gboolean use_proxy,
71 guint timeout,
72 GCancellable *cancellable,
73 GAsyncReadyCallback callback,
74 gpointer user_data);
75 gboolean (* open_finish) (QmiEndpoint *self,
76 GAsyncResult *res,
77 GError **error);
78
79 gboolean (* is_open) (QmiEndpoint *self);
80
81 void (* setup_indications) (QmiEndpoint *self,
82 guint timeout,
83 GCancellable *cancellable,
84 GAsyncReadyCallback callback,
85 gpointer user_data);
86 gboolean (* setup_indications_finish) (QmiEndpoint *self,
87 GAsyncResult *res,
88 GError **error);
89
90 gboolean (* send) (QmiEndpoint *self,
91 QmiMessage *message,
92 guint timeout,
93 GCancellable *cancellable,
94 GError **error);
95
96 void (* close) (QmiEndpoint *self,
97 guint timeout,
98 GCancellable *cancellable,
99 GAsyncReadyCallback callback,
100 gpointer user_data);
101 gboolean (* close_finish) (QmiEndpoint *self,
102 GAsyncResult *res,
103 GError **error);
104 };
105
106 GType qmi_endpoint_get_type (void);
107 G_DEFINE_AUTOPTR_CLEANUP_FUNC (QmiEndpoint, g_object_unref)
108
109 const gchar *qmi_endpoint_get_name (QmiEndpoint *self);
110
111 void qmi_endpoint_open (QmiEndpoint *self,
112 gboolean use_proxy,
113 guint timeout,
114 GCancellable *cancellable,
115 GAsyncReadyCallback callback,
116 gpointer user_data);
117 gboolean qmi_endpoint_open_finish (QmiEndpoint *self,
118 GAsyncResult *res,
119 GError **error);
120
121 gboolean qmi_endpoint_is_open (QmiEndpoint *self);
122
123 void qmi_endpoint_setup_indications (QmiEndpoint *self,
124 guint timeout,
125 GCancellable *cancellable,
126 GAsyncReadyCallback callback,
127 gpointer user_data);
128 gboolean qmi_endpoint_setup_indications_finish (QmiEndpoint *self,
129 GAsyncResult *res,
130 GError **error);
131
132 gboolean qmi_endpoint_send (QmiEndpoint *self,
133 QmiMessage *message,
134 guint timeout,
135 GCancellable *cancellable,
136 GError **error);
137
138 void qmi_endpoint_close (QmiEndpoint *self,
139 guint timeout,
140 GCancellable *cancellable,
141 GAsyncReadyCallback callback,
142 gpointer user_data);
143 gboolean qmi_endpoint_close_finish (QmiEndpoint *self,
144 GAsyncResult *res,
145 GError **error);
146
147 /*
148 * Parse all messages, calling @handler on each one while also passing
149 * along @user_data.
150 *
151 * If it hits an unrecoverable error such as a framing issue, returns
152 * false and sets @error. Otherwise, returns true.
153 */
154 gboolean qmi_endpoint_parse_buffer (QmiEndpoint *self,
155 QmiMessageHandler handler,
156 gpointer user_data,
157 GError **error);
158
159 /*
160 * Adds the message in @buf to the buffer.
161 *
162 * This function should only be called by subclasses when they receive
163 * something on the underlying transport.
164 */
165 void qmi_endpoint_add_message (QmiEndpoint *self,
166 const guint8 *buf,
167 guint len);
168
169 #endif /* _LIBQMI_GLIB_QMI_ENDPOINT_H_ */