Upgrade ofono to 1.2
[profile/ivi/ofono.git] / gatchat / gatsyntax.h
1 /*
2  *
3  *  AT chat library with GLib integration
4  *
5  *  Copyright (C) 2008-2011  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         G_AT_SYNTAX_EXPECT_SHORT_PROMPT
34 };
35
36 typedef enum _GAtSyntaxExpectHint GAtSyntaxExpectHint;
37
38 enum _GAtSyntaxResult {
39         G_AT_SYNTAX_RESULT_UNRECOGNIZED,
40         G_AT_SYNTAX_RESULT_UNSURE,
41         G_AT_SYNTAX_RESULT_LINE,
42         G_AT_SYNTAX_RESULT_MULTILINE,
43         G_AT_SYNTAX_RESULT_PDU,
44         G_AT_SYNTAX_RESULT_PROMPT,
45 };
46
47 typedef enum _GAtSyntaxResult GAtSyntaxResult;
48
49 typedef struct _GAtSyntax GAtSyntax;
50
51 typedef void (*GAtSyntaxSetHintFunc)(GAtSyntax *syntax,
52                                         GAtSyntaxExpectHint hint);
53 typedef GAtSyntaxResult (*GAtSyntaxFeedFunc)(GAtSyntax *syntax,
54                                                 const char *bytes, gsize *len);
55
56 struct _GAtSyntax {
57         gint ref_count;
58         int state;
59         GAtSyntaxSetHintFunc set_hint;
60         GAtSyntaxFeedFunc feed;
61 };
62
63
64 GAtSyntax *g_at_syntax_new_full(GAtSyntaxFeedFunc feed,
65                                         GAtSyntaxSetHintFunc hint,
66                                         int initial_state);
67
68 /* This syntax implements very strict checking of 27.007 standard, which means
69  * it might not work with a majority of modems.  However, it does handle echo
70  * properly and can be used to detect a modem's deviations from the relevant
71  * standards.
72  */
73 GAtSyntax *g_at_syntax_new_gsmv1(void);
74
75 /* This syntax implements an extremely lax parser that can handle a variety
76  * of modems.  Unfortunately it does not deal with echo at all, so echo must
77  * be explicitly turned off before using the parser
78  */
79 GAtSyntax *g_at_syntax_new_gsm_permissive(void);
80
81 GAtSyntax *g_at_syntax_ref(GAtSyntax *syntax);
82 void g_at_syntax_unref(GAtSyntax *syntax);
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif /* __GATSYNTAX_H */