Upgrade ofono to 1.2
[profile/ivi/ofono.git] / gatchat / gatserver.h
1 /*
2  *
3  *  AT Server 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 __GATSERVER_H
23 #define __GATSERVER_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include "gatresult.h"
30 #include "gatutil.h"
31 #include "gatio.h"
32
33 struct _GAtServer;
34
35 typedef struct _GAtServer GAtServer;
36
37 /* V.250 Table 1/V.250 Result codes */
38 enum _GAtServerResult {
39         G_AT_SERVER_RESULT_OK = 0,
40         G_AT_SERVER_RESULT_CONNECT = 1,
41         G_AT_SERVER_RESULT_RING = 2,
42         G_AT_SERVER_RESULT_NO_CARRIER = 3,
43         G_AT_SERVER_RESULT_ERROR = 4,
44         G_AT_SERVER_RESULT_NO_DIALTONE = 6,
45         G_AT_SERVER_RESULT_BUSY = 7,
46         G_AT_SERVER_RESULT_NO_ANSWER = 8,
47         G_AT_SERVER_RESULT_EXT_ERROR = 256,
48 };
49
50 typedef enum _GAtServerResult GAtServerResult;
51
52 /* Types of AT command:
53  * COMMAND_ONLY: command without any sub-parameters, e.g. ATA, AT+CLCC
54  * QUERY: command followed by '?', e.g. AT+CPIN?
55  * SUPPORT: command followed by '=?', e.g. AT+CSMS=?
56  * SET: command followed by '=', e.g. AT+CLIP=1
57  *      or, basic command followed with sub-parameters, e.g. ATD12345;
58  */
59 enum _GAtServerRequestType {
60         G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY,
61         G_AT_SERVER_REQUEST_TYPE_QUERY,
62         G_AT_SERVER_REQUEST_TYPE_SUPPORT,
63         G_AT_SERVER_REQUEST_TYPE_SET,
64 };
65
66 typedef enum _GAtServerRequestType GAtServerRequestType;
67
68 typedef void (*GAtServerNotifyFunc)(GAtServer *server,
69                                         GAtServerRequestType type,
70                                         GAtResult *result, gpointer user_data);
71
72 typedef void (*GAtServerFinishFunc)(GAtServer *server, gpointer user_data);
73
74 GAtServer *g_at_server_new(GIOChannel *io);
75 GIOChannel *g_at_server_get_channel(GAtServer *server);
76 GAtIO *g_at_server_get_io(GAtServer *server);
77
78 GAtServer *g_at_server_ref(GAtServer *server);
79 void g_at_server_suspend(GAtServer *server);
80 void g_at_server_resume(GAtServer *server);
81 void g_at_server_unref(GAtServer *server);
82
83 gboolean g_at_server_shutdown(GAtServer *server);
84
85 gboolean g_at_server_set_echo(GAtServer *server, gboolean echo);
86 gboolean g_at_server_set_disconnect_function(GAtServer *server,
87                                         GAtDisconnectFunc disconnect,
88                                         gpointer user_data);
89 gboolean g_at_server_set_debug(GAtServer *server,
90                                         GAtDebugFunc func,
91                                         gpointer user_data);
92
93 gboolean g_at_server_register(GAtServer *server, const char *prefix,
94                                         GAtServerNotifyFunc notify,
95                                         gpointer user_data,
96                                         GDestroyNotify destroy_notify);
97 gboolean g_at_server_unregister(GAtServer *server, const char *prefix);
98
99 /* Send a final result code. E.g. G_AT_SERVER_RESULT_NO_DIALTONE */
100 void g_at_server_send_final(GAtServer *server, GAtServerResult result);
101
102 /* Send an extended final result code. E.g. +CME ERROR: SIM failure. */
103 void g_at_server_send_ext_final(GAtServer *server, const char *result);
104
105 /* Send an intermediate result code to report the progress. E.g. CONNECT */
106 void g_at_server_send_intermediate(GAtServer *server, const char *result);
107
108 /* Send an unsolicited result code. E.g. RING */
109 void g_at_server_send_unsolicited(GAtServer *server, const char *result);
110
111 /*
112  * Send a single response line for the command.  The line should be no longer
113  * than 2048 characters.  If the response contains multiple lines, use
114  * FALSE for the 'last' parameter for lines 1 .. n -1, and 'TRUE' for the last
115  * line.  This is required for formatting of 27.007 compliant multi-line
116  * responses.
117  */
118 void g_at_server_send_info(GAtServer *server, const char *line, gboolean last);
119
120 gboolean g_at_server_set_finish_callback(GAtServer *server,
121                                                 GAtServerFinishFunc finishf,
122                                                 gpointer user_data);
123 gboolean g_at_server_command_pending(GAtServer *server);
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif /* __GATSERVER_H */