aboutsummaryrefslogtreecommitdiff
path: root/src/espik_net.c
blob: 510ead1d58690f29130ebc304b634a58223d38e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <string.h>
#include <stdio.h>

#include <Ecore.h>
#include <Ecore_Con.h>

#include "espik_global.h"
#include "espik_net.h"
#include "espik_common_handler.h"
#include "espik_error.h"
#include "espik.h"

#include <unistd.h>
#include <stdlib.h>

typedef int			(*Handler_Func) (void* data, int ev_type, void* ev);

Ecore_Con_Server*	con_sock;

void	espik_con_init (t_info serv_info)
{
	ecore_con_init ();

	con_sock = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
			serv_info.server->host, (int)serv_info.server->port, NULL);
	if (!con_sock)
	{
		fprintf (stderr, "ecore_con_server_connect failed\n");
		exit (-1);
	}

	ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
			(Handler_Func) server_data, NULL);
}

void	espik_con_shutdown ()
{
#if _ESPIK_DEBUG_
	printf ("> espik_con_shutdown\n");
#endif
	ecore_con_server_del (con_sock);
	ecore_con_shutdown ();

#if _ESPIK_DEBUG_
	printf ("< espik_con_shutdown\n");
#endif
	/*	ecore_main_loop_quit ();	*/
}

void	espik_raw_send (char *msg)
{
	int		len;
	char*	out;

	len = strlen (msg) + 3;

    out = malloc (sizeof (char) * len);

	snprintf (out, len, "%s\r\n", msg);

#if _ESPIK_DEBUG_
	printf ("espik_raw_send:\nmsg: %s\nout: %s\n", msg, out);
#endif
	/*
		printf ("out[len-3]: 0x%X\n", out[len - 3]);
		printf ("out[len-2]: 0x%X\n", out[len - 2]);
		printf ("out[len-1]: 0x%X\n", out[len - 1]);
	*/

#if _ESPIK_DEBUG_
	printf ("ecore_con_server_send: %d\n", ecore_con_server_send (con_sock,
					out, strlen (out)));
#endif

	free (out);
}