summaryrefslogtreecommitdiffstats
path: root/unit/test-mux.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-10-09 17:17:03 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-10-15 16:15:16 -0500
commitb1ff21f0592c10bda20fdb1c8d35a3d6bc60625c (patch)
tree842c88f9d66c5cd5343637daebc4a1e998229dac /unit/test-mux.c
parent4734ebcb46100e623994c00a95c9cebd4d04784b (diff)
downloadofono-b1ff21f0592c10bda20fdb1c8d35a3d6bc60625c.tar.bz2
Fixup unit test to the new API
Diffstat (limited to 'unit/test-mux.c')
-rw-r--r--unit/test-mux.c75
1 files changed, 47 insertions, 28 deletions
diff --git a/unit/test-mux.c b/unit/test-mux.c
index 77903f81..8349fa2f 100644
--- a/unit/test-mux.c
+++ b/unit/test-mux.c
@@ -59,15 +59,17 @@ static int do_connect(const char *address, unsigned short port)
}
static GMainLoop *mainloop;
+static GAtMux *mux;
static gboolean cleanup_callback(gpointer data)
{
GAtChat *chat = data;
g_at_chat_shutdown(chat);
-
g_at_chat_unref(chat);
+ g_at_mux_unref(mux);
+
g_main_loop_quit(mainloop);
return FALSE;
@@ -91,37 +93,54 @@ static void mux_debug(const char *str, void *data)
g_print("%s: %s\n", (char *) data, str);
}
-static gboolean idle_callback(gpointer data)
+static void mux_setup(GAtMux *mux, gpointer data)
{
- GAtMux *mux = data;
- GAtChat *chat;
+ GAtChat *chat = data;
+ GIOChannel *io;
GAtSyntax *syntax;
- g_print("idle: callback\n");
-
- syntax = g_at_syntax_new_gsmv1();
- chat = g_at_mux_create_chat(mux, syntax);
- g_at_syntax_unref(syntax);
+ g_print("mux_setup: %p\n", mux);
- if (!chat) {
- g_printerr("chat failed\n");
+ if (mux == NULL) {
+ g_at_chat_unref(chat);
g_main_loop_quit(mainloop);
- return FALSE;
+ return;
}
- g_at_chat_set_debug(chat, mux_debug, "CHAT");
+ g_at_mux_start(mux);
- g_at_chat_send(chat, "AT+CGMI", NULL, NULL, NULL, NULL);
+ io = g_at_mux_create_channel(mux);
+ syntax = g_at_syntax_new_gsm_permissive();
+ chat = g_at_chat_new(io, syntax);
+ g_at_syntax_unref(syntax);
+ g_io_channel_unref(io);
+ g_at_chat_set_debug(chat, mux_debug, "CHAT");
+ g_at_chat_set_wakeup_command(chat, "\r", 1000, 5000);
+ g_at_chat_send(chat, "AT+CGMI", NULL, NULL, NULL, NULL);
g_at_chat_send(chat, "AT+CGMR", NULL, chat_callback, chat, NULL);
+}
- return FALSE;
+static void mux_init(gboolean ok, GAtResult *result, gpointer data)
+{
+ GAtChat *chat = data;
+
+ g_print("mux_init: %d\n", ok);
+
+ if (ok == FALSE) {
+ g_at_chat_unref(chat);
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ g_at_mux_setup_gsm0710(chat, mux_setup, chat, NULL);
}
static void test_mux(void)
{
GIOChannel *io;
- GAtMux *mux;
+ GAtChat *chat;
+ GAtSyntax *syntax;
int sk;
sk= do_connect("192.168.0.202", 2000);
@@ -130,28 +149,28 @@ static void test_mux(void)
return;
}
+ mux = NULL;
io = g_io_channel_unix_new(sk);
- mux = g_at_mux_new(io);
+ g_io_channel_set_close_on_unref(io, TRUE);
+
+ syntax = g_at_syntax_new_gsm_permissive();
+ chat = g_at_chat_new(io, syntax);
+ g_at_syntax_unref(syntax);
+
g_io_channel_unref(io);
- if (!mux) {
- g_printerr("mux failed\n");
- close(sk);
+ if (!chat) {
+ g_printerr("Chat creation failed\n");
return;
}
- g_at_mux_set_debug(mux, mux_debug, "MUX");
-
- g_io_channel_set_close_on_unref(io, TRUE);
+ g_at_chat_set_debug(chat, mux_debug, "MUX");
+ g_at_chat_set_wakeup_command(chat, "\r", 1000, 5000);
+ g_at_chat_send(chat, "ATE0", NULL, mux_init, chat, NULL);
mainloop = g_main_loop_new(NULL, FALSE);
- g_idle_add(idle_callback, mux);
-
g_main_loop_run(mainloop);
-
- g_at_mux_unref(mux);
-
g_main_loop_unref(mainloop);
}