aboutsummaryrefslogtreecommitdiff
path: root/src/espik_net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/espik_net.c')
-rw-r--r--src/espik_net.c54
1 files changed, 22 insertions, 32 deletions
diff --git a/src/espik_net.c b/src/espik_net.c
index 87aaf30..8970f05 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -1,5 +1,7 @@
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <Ecore.h>
#include <Ecore_Con.h>
@@ -8,15 +10,13 @@
#include "espik_net.h"
#include "espik_common_handler.h"
#include "espik_error.h"
+#include "espik_debug.h"
#include "espik.h"
-#include <unistd.h>
-#include <stdlib.h>
-
-typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
+typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
-static int ret; /* For debug */
-static char connected = 0;
+static int ret; /* For debug */
+static char connected = 0;
Ecore_Con_Server* con_sock;
@@ -26,36 +26,34 @@ void espik_con_init (t_info serv_info)
nb_launch = ecore_con_init ();
-#if _ESPIK_DEBUG_
-/* printf ("espik_con_init: nb_launch = %d\n", nb_launch); */
-#endif
+/* espik_debug_printf ("nb_launch = %d", nb_launch); */
con_sock = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
- serv_info.server->host, (int)serv_info.server->port, NULL);
+ serv_info.server->host, (int)serv_info.server->port, NULL);
if (!con_sock)
{
- fprintf (stderr, "ecore_con_server_connect failed (ECORE_CON_REMOTE_SYSTEM)\n");
+ espik_debug_print ("ecore_con_server_connect failed (ECORE_CON_REMOTE_SYSTEM)");
exit (-1);
}
if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
- (Handler_Func) server_data, NULL)))
+ (Handler_Func) server_data, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA) failed at %s\n", __FUNCTION__);
+ espik_debug_print ("ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA)");
exit (-1);
}
if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
- (Handler_Func) espik_con_up, NULL)))
+ (Handler_Func) espik_con_up, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD) failed at %s\n", __FUNCTION__);
+ espik_debug_print ("ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD)");
exit (-1);
}
if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
- (Handler_Func) espik_con_shutdown, NULL)))
+ (Handler_Func) espik_con_shutdown, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL) failed at %s\n", __FUNCTION__);
+ espik_debug_print ("ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL)");
exit (-1);
}
}
@@ -63,30 +61,26 @@ void espik_con_init (t_info serv_info)
void espik_con_up()
{
printf ("Connected\n");
- connected = 1;
+ connected++;
}
void espik_con_shutdown ()
{
-#if _ESPIK_DEBUG_
-/* printf ("> espik_con_shutdown\n"); */
-#endif
+/* espik_debug_print ("> espik_con_shutdown"); */
if (!connected)
- fprintf (stderr, "Unable to connect to server\n");
+ espik_debug_print ("Unable to connect to server");
ecore_con_server_del (con_sock);
ecore_con_shutdown ();
-#if _ESPIK_DEBUG_
-/* printf ("< espik_con_shutdown\n"); */
-#endif
+/* espik_debug_print ("< espik_con_shutdown"); */
ecore_main_loop_quit ();
}
void espik_raw_send (char *msg)
{
- int len;
+ int len;
char* out;
len = strlen (msg) + 3;
@@ -95,9 +89,7 @@ void espik_raw_send (char *msg)
snprintf (out, len, "%s\r\n", msg);
-#if _ESPIK_DEBUG_
- printf ("espik_raw_send:\nmsg: %s\nout: %s\n", msg, out);
-#endif
+ espik_debug_print ("msg: %s\nout: %s", msg, out);
/*
printf ("out[len-3]: 0x%X\n", out[len - 3]);
printf ("out[len-2]: 0x%X\n", out[len - 2]);
@@ -106,9 +98,7 @@ void espik_raw_send (char *msg)
ret = ecore_con_server_send (con_sock, out, strlen (out));
-#if _ESPIK_DEBUG_
-/* printf ("ecore_con_server_send: %d\n", ret); */
-#endif
+/* espik_debug_print ("%d", ret); */
free (out);
}