summaryrefslogtreecommitdiffstats
path: root/gatchat/gatsyntax.h
blob: d76cf6fadf63c75ceef042faca841e20eb0d3e31 (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
/*
 *
 *  AT chat library with GLib integration
 *
 *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __GATSYNTAX_H
#define __GATSYNTAX_H

#ifdef __cplusplus
extern "C" {
#endif

enum _GAtSyntaxExpectHint {
	G_AT_SYNTAX_EXPECT_PDU,
	G_AT_SYNTAX_EXPECT_MULTILINE,
	G_AT_SYNTAX_EXPECT_PROMPT
};

typedef enum _GAtSyntaxExpectHint GAtSyntaxExpectHint;

enum _GAtSyntaxResult {
	G_AT_SYNTAX_RESULT_UNRECOGNIZED,
	G_AT_SYNTAX_RESULT_UNSURE,
	G_AT_SYNTAX_RESULT_LINE,
	G_AT_SYNTAX_RESULT_MULTILINE,
	G_AT_SYNTAX_RESULT_PDU,
	G_AT_SYNTAX_RESULT_PROMPT,
};

typedef enum _GAtSyntaxResult GAtSyntaxResult;

typedef struct _GAtSyntax GAtSyntax;

typedef void (*GAtSyntaxSetHintFunc)(GAtSyntax *syntax,
					GAtSyntaxExpectHint hint);
typedef GAtSyntaxResult (*GAtSyntaxFeedFunc)(GAtSyntax *syntax,
						const char *bytes, gsize *len);

struct _GAtSyntax {
	gint ref_count;
	int state;
	GAtSyntaxSetHintFunc set_hint;
	GAtSyntaxFeedFunc feed;
};


GAtSyntax *g_at_syntax_new_full(GAtSyntaxFeedFunc feed,
					GAtSyntaxSetHintFunc hint,
					int initial_state);

/* This syntax implements very strict checking of 27.007 standard, which means
 * it might not work with a majority of modems.  However, it does handle echo
 * properly and can be used to detect a modem's deviations from the relevant
 * standards.
 */
GAtSyntax *g_at_syntax_new_gsmv1();

/* This syntax implements an extremely lax parser that can handle a variety
 * of modems.  Unfortunately it does not deal with echo at all, so echo must
 * be explicitly turned off before using the parser
 */
GAtSyntax *g_at_syntax_new_gsm_permissive();

GAtSyntax *g_at_syntax_ref(GAtSyntax *syntax);
void g_at_syntax_unref(GAtSyntax *syntax);

#ifdef __cplusplus
}
#endif

#endif /* __GATSYNTAX_H */