equal
deleted
inserted
replaced
1 #include "frontlib.h" |
|
2 #include "logging.h" |
|
3 #include "nonblocksockets.h" |
|
4 #include "ipcconn.h" |
|
5 |
|
6 #include <SDL.h> |
|
7 #include <SDL_net.h> |
|
8 #include <stdio.h> |
|
9 #include <stdint.h> |
|
10 #include <stdlib.h> |
|
11 |
|
12 static int flib_initflags; |
|
13 |
|
14 int flib_init(int flags) { |
|
15 flib_initflags = flags; |
|
16 |
|
17 if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) { |
|
18 if(SDL_Init(0)==-1) { |
|
19 flib_log_e("Error in SDL_Init: %s", SDL_GetError()); |
|
20 return -1; |
|
21 } |
|
22 } |
|
23 |
|
24 if(SDLNet_Init()==-1) { |
|
25 flib_log_e("Error in SDLNet_Init: %s", SDLNet_GetError()); |
|
26 if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) { |
|
27 SDL_Quit(); |
|
28 } |
|
29 return -1; |
|
30 } |
|
31 |
|
32 flib_ipcconn_init(); |
|
33 return 0; |
|
34 } |
|
35 |
|
36 void flib_quit() { |
|
37 flib_ipcconn_quit(); |
|
38 |
|
39 SDLNet_Quit(); |
|
40 if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) { |
|
41 SDL_Quit(); |
|
42 } |
|
43 } |
|
44 |
|
45 int main(int argc, char *argv[]) { |
|
46 flib_init(0); |
|
47 int port = flib_ipcconn_listen(); |
|
48 printf("%i\n", port); |
|
49 fflush(stdout); |
|
50 char data[256]; |
|
51 while(flib_ipcconn_state() != IPC_NOT_CONNECTED) { |
|
52 flib_ipcconn_tick(); |
|
53 int size = flib_ipcconn_recv_message(data); |
|
54 if(size>0) { |
|
55 data[size]=0; |
|
56 flib_log_i("IPC IN: %s", data); |
|
57 if(data[0]=='?') { |
|
58 flib_log_i("IPC OUT: !"); |
|
59 flib_ipcconn_send_message("!", 1); |
|
60 } |
|
61 } |
|
62 } |
|
63 flib_log_i("IPC connection lost."); |
|
64 return 0; |
|
65 } |
|