Do not call __connman_service_put() twice
[framework/connectivity/connman.git] / gatchat / gatsyntax.h
1 /*
2  *
3  *  AT chat library with GLib integration
4  *
5  *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program 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
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __GATSYNTAX_H
23 #define __GATSYNTAX_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 enum _GAtSyntaxExpectHint {
30         G_AT_SYNTAX_EXPECT_PDU,
31         G_AT_SYNTAX_EXPECT_MULTILINE,
32         G_AT_SYNTAX_EXPECT_PROMPT
33 };
34
35 typedef enum _GAtSyntaxExpectHint GAtSyntaxExpectHint;
36
37 enum _GAtSyntaxResult {
38         G_AT_SYNTAX_RESULT_UNRECOGNIZED,
39         G_AT_SYNTAX_RESULT_UNSURE,
40         G_AT_SYNTAX_RESULT_LINE,
41         G_AT_SYNTAX_RESULT_MULTILINE,
42         G_AT_SYNTAX_RESULT_PDU,
43         G_AT_SYNTAX_RESULT_PROMPT,
44 };
45
46 typedef enum _GAtSyntaxResult GAtSyntaxResult;
47
48 typedef struct _GAtSyntax GAtSyntax;
49
50 typedef void (*GAtSyntaxSetHintFunc)(GAtSyntax *syntax,
51                                         GAtSyntaxExpectHint hint);
52 typedef GAtSyntaxResult (*GAtSyntaxFeedFunc)(GAtSyntax *syntax,
53                                                 const char *bytes, gsize *len);
54
55 struct _GAtSyntax {
56         gint ref_count;
57         int state;
58         GAtSyntaxSetHintFunc set_hint;
59         GAtSyntaxFeedFunc feed;
60 };
61
62
63 GAtSyntax *g_at_syntax_new_full(GAtSyntaxFeedFunc feed,
64                                         GAtSyntaxSetHintFunc hint,
65                                         int initial_state);
66
67 /* This syntax implements very strict checking of 27.007 standard, which means
68  * it might not work with a majority of modems.  However, it does handle echo
69  * properly and can be used to detect a modem's deviations from the relevant
70  * standards.
71  */
72 GAtSyntax *g_at_syntax_new_gsmv1();
73
74 /* This syntax implements an extremely lax parser that can handle a variety
75  * of modems.  Unfortunately it does not deal with echo at all, so echo must
76  * be explicitly turned off before using the parser
77  */
78 GAtSyntax *g_at_syntax_new_gsm_permissive();
79
80 GAtSyntax *g_at_syntax_ref(GAtSyntax *syntax);
81 void g_at_syntax_unref(GAtSyntax *syntax);
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif /* __GATSYNTAX_H */