]> git.cworth.org Git - loudgame/blob - lg-echo.c
Separate common code into loudgame.c and demonstrate with separate lg-test and lg...
[loudgame] / lg-echo.c
1 /*
2  * Copyright (C) 2008 Carl Worth
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see http://www.gnu.org/licenses/ .
16  *
17  * Author: Carl Worth <cworth@cworth.org>
18  */
19
20 #include "loudgame.h"
21
22 #include <string.h>
23 #include <stdlib.h>
24
25 static void
26 echo_handle_message (loudgame_t *lg,
27                      const char *peer,
28                      const char *message)
29 {
30     LmMessage *reply;
31     gboolean result;
32     GError *error = NULL;
33
34     reply = lm_message_new (peer, LM_MESSAGE_TYPE_MESSAGE);
35
36     lm_message_node_add_child (reply->node, "body", message);
37
38     result = lm_connection_send (lg->connection, reply, &error);
39     lm_message_unref (reply);
40
41     if (! result) {
42         g_error ("lm_connection_send failed: error->message");
43         loudgame_quit (lg, 1);
44     }
45 }
46
47 int
48 main (int argc, char **argv)
49 {
50     loudgame_t lg;
51
52     loudgame_init (&lg, argc, argv);
53
54     lg.handle_message = echo_handle_message;
55
56     return loudgame_run (&lg);
57 }