mirror of git://git.sysmocom.de/ofono
Add server at command data structure
This commit is contained in:
parent
c7828602d4
commit
8850d3dc9e
|
@ -88,6 +88,13 @@ struct v250_settings {
|
|||
unsigned int c108; /* set by &D<val> */
|
||||
};
|
||||
|
||||
/* AT command set that server supported */
|
||||
struct at_command {
|
||||
GAtServerNotifyFunc notify;
|
||||
gpointer user_data;
|
||||
GDestroyNotify destroy_notify;
|
||||
};
|
||||
|
||||
struct _GAtServer {
|
||||
gint ref_count; /* Ref count */
|
||||
struct v250_settings v250; /* V.250 command setting */
|
||||
|
@ -99,6 +106,7 @@ struct _GAtServer {
|
|||
gpointer user_disconnect_data; /* User disconnect data */
|
||||
GAtDebugFunc debugf; /* Debugging output function */
|
||||
gpointer debug_data; /* Data to pass to debug func */
|
||||
GHashTable *command_list; /* List of AT commands */
|
||||
struct ring_buffer *read_buf; /* Current read buffer */
|
||||
GQueue *write_queue; /* Write buffer queue */
|
||||
guint max_read_attempts; /* Max reads per select */
|
||||
|
@ -651,6 +659,9 @@ static void g_at_server_cleanup(GAtServer *server)
|
|||
/* Cleanup pending data to write */
|
||||
write_queue_free(server->write_queue);
|
||||
|
||||
g_hash_table_destroy(server->command_list);
|
||||
server->command_list = NULL;
|
||||
|
||||
server->channel = NULL;
|
||||
}
|
||||
|
||||
|
@ -696,6 +707,16 @@ static void v250_settings_create(struct v250_settings *v250)
|
|||
v250->c108 = 0;
|
||||
}
|
||||
|
||||
static void at_notify_node_destroy(gpointer data)
|
||||
{
|
||||
struct at_command *node = data;
|
||||
|
||||
if (node->destroy_notify)
|
||||
node->destroy_notify(node->user_data);
|
||||
|
||||
g_free(node);
|
||||
}
|
||||
|
||||
GAtServer *g_at_server_new(GIOChannel *io)
|
||||
{
|
||||
GAtServer *server;
|
||||
|
@ -710,6 +731,9 @@ GAtServer *g_at_server_new(GIOChannel *io)
|
|||
server->ref_count = 1;
|
||||
v250_settings_create(&server->v250);
|
||||
server->channel = io;
|
||||
server->command_list = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
at_notify_node_destroy);
|
||||
server->read_buf = ring_buffer_new(BUF_SIZE);
|
||||
if (!server->read_buf)
|
||||
goto error;
|
||||
|
@ -734,6 +758,9 @@ GAtServer *g_at_server_new(GIOChannel *io)
|
|||
return server;
|
||||
|
||||
error:
|
||||
if (server->command_list)
|
||||
g_hash_table_destroy(server->command_list);
|
||||
|
||||
if (server->read_buf)
|
||||
ring_buffer_free(server->read_buf);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "gatresult.h"
|
||||
#include "gatutil.h"
|
||||
|
||||
struct _GAtServer;
|
||||
|
@ -46,6 +47,27 @@ enum _GAtServerResult {
|
|||
|
||||
typedef enum _GAtServerResult GAtServerResult;
|
||||
|
||||
/* Types of AT command:
|
||||
* COMMAND_ONLY: command without any sub-parameters, e.g. ATA, AT+CLCC
|
||||
* QUERY: command followed by '?', e.g. AT+CPIN?
|
||||
* SUPPORT: command followed by '=?', e.g. AT+CSMS=?
|
||||
* SET: command followed by '=', e.g. AT+CLIP=1
|
||||
* or, basic command followed with sub-parameters, e.g. ATD12345;
|
||||
*/
|
||||
enum _GAtServerRequestType {
|
||||
G_AT_SERVER_REQUEST_TYPE_ERROR,
|
||||
G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY,
|
||||
G_AT_SERVER_REQUEST_TYPE_QUERY,
|
||||
G_AT_SERVER_REQUEST_TYPE_SUPPORT,
|
||||
G_AT_SERVER_REQUEST_TYPE_SET,
|
||||
};
|
||||
|
||||
typedef enum _GAtServerRequestType GAtServerRequestType;
|
||||
|
||||
typedef GAtServerResult (*GAtServerNotifyFunc)(GAtServerRequestType type,
|
||||
GAtResult *result,
|
||||
gpointer user_data);
|
||||
|
||||
GAtServer *g_at_server_new(GIOChannel *io);
|
||||
|
||||
GAtServer *g_at_server_ref(GAtServer *server);
|
||||
|
|
Loading…
Reference in New Issue