Share loudgame_send code to reduce duplication.
authorCarl Worth <cworth@cworth.org>
Tue, 15 Jan 2008 04:51:21 +0000 (20:51 -0800)
committerCarl Worth <cworth@cworth.org>
Tue, 15 Jan 2008 04:51:21 +0000 (20:51 -0800)
lg-echo.c
loudgame.c
loudgame.h

index b6a48e8bf6aa018e2788013f5a4049ee3cd212b0..c153472bb84f78ce8e1613086d0f90f0f3dcbaa9 100644 (file)
--- a/lg-echo.c
+++ b/lg-echo.c
@@ -27,21 +27,7 @@ echo_handle_message (loudgame_t *lg,
                     const char *peer,
                     const char *message)
 {
-    LmMessage *reply;
-    gboolean result;
-    GError *error = NULL;
-
-    reply = lm_message_new (peer, LM_MESSAGE_TYPE_MESSAGE);
-
-    lm_message_node_add_child (reply->node, "body", message);
-
-    result = lm_connection_send (lg->connection, reply, &error);
-    lm_message_unref (reply);
-
-    if (! result) {
-       g_error ("lm_connection_send failed: error->message");
-       loudgame_quit (lg, 1);
-    }
+    loudgame_send (lg, peer, message);
 }
 
 int
index 53b392b1b0d9440f97da8162b204cae85b8e3123..e2f0af2d5b751968725dfdd427b2e08b93e8f059 100644 (file)
@@ -70,11 +70,10 @@ connection_open_cb (LmConnection *connection, gboolean result, loudgame_t *lg)
                                authentication_cb, lg, FALSE,  NULL);
 }
 
-static void
-send_reply (LmConnection       *connection,
-           const char          *peer,
-           const char          *message,
-           loudgame_t          *lg)
+void
+loudgame_send (loudgame_t      *lg,
+              const char       *peer,
+              const char       *message)
 {
     LmMessage *reply;
     gboolean result;
@@ -84,11 +83,12 @@ send_reply (LmConnection    *connection,
 
     lm_message_node_add_child (reply->node, "body", message);
 
-    result = lm_connection_send (connection, reply, &error);
+    result = lm_connection_send (lg->connection, reply, &error);
     lm_message_unref (reply);
 
     if (! result) {
-       g_error ("lm_connection_send failed: error->message");
+       g_error ("lm_connection_send failed: %s\n",
+                error->message);
        loudgame_quit (lg, 1);
     }
 }
@@ -107,7 +107,7 @@ handle_command (LmConnection        *connection,
     }
 
     error = g_strdup_printf ("Unknown command: '%s'", command);
-    send_reply (connection, peer, error, lg);
+    loudgame_send (lg, peer, error);
     free (error);
 }
  
index 726394bf26b0ddb1f599b2710e74999c4388a9c0..a65f5dd6aa38fce3dc546bd3d3af0e6710edf355 100644 (file)
@@ -46,6 +46,11 @@ loudgame_init (loudgame_t *lg, int argc, char **argv);
 int
 loudgame_run (loudgame_t *lg);
 
+void
+loudgame_send (loudgame_t      *lg,
+              const char       *peer,
+              const char       *message);
+
 void
 loudgame_quit (loudgame_t *lg, int return_value);