diff options
author | Denis Kenzior <denis.kenzior@intel.com> | 2009-05-06 14:33:17 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel.holtmann@intel.com> | 2009-05-06 14:42:54 -0700 |
commit | 64c42764736de15544e58666bdf97de088f7a7b5 (patch) | |
tree | 8f496fa6822a15acc593bd8ee66007ed0925efd3 /gatchat/gatchat.h | |
parent | 4ea27466bf3a5a3309d5ee689a1470c20c483ef9 (diff) | |
download | ofono-64c42764736de15544e58666bdf97de088f7a7b5.tar.bz2 |
Add AT chat library implementation
Diffstat (limited to 'gatchat/gatchat.h')
-rw-r--r-- | gatchat/gatchat.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h new file mode 100644 index 00000000..58ca9114 --- /dev/null +++ b/gatchat/gatchat.h @@ -0,0 +1,105 @@ +/* + * + * AT chat library with GLib integration + * + * Copyright (C) 2008-2009 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 __GATCHAT_H +#define __GATCHAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "gatresult.h" + +struct _GAtChat; + +typedef struct _GAtChat GAtChat; + +typedef void (*GAtResultFunc)(gboolean success, GAtResult *result, + gpointer user_data); +typedef void (*GAtNotifyFunc)(GAtResult *result, gpointer user_data); +typedef void (*GAtDisconnectFunc)(gpointer user_data); + +enum _GAtChatFlags { + G_AT_CHAT_FLAG_NO_LEADING_CRLF = 1, /* Some emulators are broken */ +}; + +typedef enum _GAtChatFlags GAtChatFlags; + +GAtChat *g_at_chat_new(GIOChannel *channel, int flags); + +GAtChat *g_at_chat_ref(GAtChat *chat); +void g_at_chat_unref(GAtChat *chat); + +gboolean g_at_chat_shutdown(GAtChat *chat); + +gboolean g_at_chat_set_disconnect_function(GAtChat *chat, + GAtDisconnectFunc disconnect, gpointer user_data); + +/*! + * Queue an AT command for execution. The command contents are given + * in cmd. Once the command executes, the callback function given by + * func is called with user provided data in user_data. + * + * Returns an id of the queued command which can be canceled using + * g_at_chat_cancel. If an error occurred, an id of 0 is returned. + * + * This function can be used in three ways: + * - Send a simple command such as g_at_chat_send(p, "AT+CGMI?", ... + * + * - Send a compound command: g_at_chat_send(p, "AT+CMD1;+CMD2", ... + * + * - Send a command requiring a prompt. The command up to '\r' is sent + * after which time a '> ' prompt is expected from the modem. Further + * contents of the command are sent until a '\r' or end of string is + * encountered. If end of string is encountered, the Ctrl-Z character + * is sent automatically. There is no need to include the Ctrl-Z + * by the caller. + * + * The valid_resp field can be used to send an array of strings which will + * be accepted as a valid response for this command. This is treated as a + * simple prefix match. If a response line comes in from the modem and it + * does not match any of the prefixes in valid_resp, it is treated as an + * unsolicited notification. If valid_resp is NULL, then all response + * lines after command submission and final response line are treated as + * part of the command response. This can be used to get around broken + * modems which send unsolicited notifications during command processing. + */ +guint g_at_chat_send(GAtChat *chat, const char *cmd, + const char **valid_resp, GAtResultFunc func, + gpointer user_data, GDestroyNotify notify); + +gboolean g_at_chat_cancel(GAtChat *chat, guint id); + +guint g_at_chat_register(GAtChat *chat, const char *prefix, + GAtNotifyFunc func, gboolean expect_pdu, + gpointer user_data, GDestroyNotify notify); + +gboolean g_at_chat_unregister(GAtChat *chat, guint id); + +gboolean g_at_chat_set_wakeup_command(GAtChat *chat, const char *cmd, + guint timeout, guint msec); + + +#ifdef __cplusplus +} +#endif + +#endif /* __GATCHAT_H */ |