1 | #include <stdlib.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <string.h> |
---|
4 | #include <signal.h> |
---|
5 | #include <unistd.h> |
---|
6 | |
---|
7 | // For debugging purposes... |
---|
8 | // ... should not be defined in a release. |
---|
9 | // (defaults to 13666) |
---|
10 | //#define LCDPORT 13667 |
---|
11 | |
---|
12 | #include "../server/drivers/lcd.h" |
---|
13 | #include "../server/sock.h" |
---|
14 | #include "../server/clients.h" |
---|
15 | #include "../server/screenlist.h" |
---|
16 | #include "../server/screen.h" |
---|
17 | #include "../server/parse.h" |
---|
18 | #include "../server/render.h" |
---|
19 | #include "../server/serverscreens.h" |
---|
20 | |
---|
21 | |
---|
22 | void exit_program(int val); |
---|
23 | |
---|
24 | |
---|
25 | int main() |
---|
26 | { |
---|
27 | char string[1024]; |
---|
28 | int sock; |
---|
29 | screen *s; |
---|
30 | int timer=0; |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | // Ctrl-C will cause a clean exit... |
---|
35 | signal(SIGINT, exit_program); |
---|
36 | // and "kill"... |
---|
37 | signal(SIGTERM, exit_program); |
---|
38 | // and "kill -HUP" (hangup)... |
---|
39 | signal(SIGHUP, exit_program); |
---|
40 | // and just in case, "kill -KILL" (which cannot be trapped; but oh well) |
---|
41 | signal(SIGKILL, exit_program); |
---|
42 | |
---|
43 | |
---|
44 | memset(string, 0, 1024); |
---|
45 | |
---|
46 | lcd_init(""); |
---|
47 | |
---|
48 | // Feel free to add as many drivers as you like... :) |
---|
49 | //lcd_add_driver("joy", ""); |
---|
50 | //lcd_add_driver("curses", "Booger"); |
---|
51 | lcd_add_driver("MtxOrb", ""); |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | sock = sock_create_server(); |
---|
56 | |
---|
57 | if(sock <= 0) |
---|
58 | { |
---|
59 | printf("Error opening socket.\n"); |
---|
60 | return 1; |
---|
61 | } |
---|
62 | |
---|
63 | if(client_init() < 0) |
---|
64 | { |
---|
65 | printf("Error initializing client list\n"); |
---|
66 | return 1; |
---|
67 | } |
---|
68 | |
---|
69 | if(screenlist_init() < 0) |
---|
70 | { |
---|
71 | printf("Error initializing screen list\n"); |
---|
72 | return 1; |
---|
73 | } |
---|
74 | |
---|
75 | // Make sure the server screen shows up every once in a while.. |
---|
76 | server_screen_init(); |
---|
77 | |
---|
78 | // Main loop... |
---|
79 | while(1) |
---|
80 | { |
---|
81 | sock_poll_clients(); |
---|
82 | parse_all_client_messages(); |
---|
83 | // TODO: Check for and handle keypresses here... |
---|
84 | //handle_input(); |
---|
85 | |
---|
86 | timer++; |
---|
87 | if(timer >= 32) |
---|
88 | { |
---|
89 | timer = 0; |
---|
90 | // TODO: Notify clients of "listen" and "ignore" |
---|
91 | s = screenlist_next(); |
---|
92 | if(s) |
---|
93 | { |
---|
94 | printf("Screen: %s\n", s->id); |
---|
95 | } |
---|
96 | } |
---|
97 | draw_server_screen(timer); |
---|
98 | s = screenlist_current(); |
---|
99 | if(s) |
---|
100 | { |
---|
101 | // render something here... |
---|
102 | draw_screen(s, timer); |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | no_screen_screen(timer); |
---|
107 | } |
---|
108 | |
---|
109 | usleep(125000); |
---|
110 | } |
---|
111 | |
---|
112 | // Say goodbye! |
---|
113 | goodbye_screen(); |
---|
114 | |
---|
115 | // Can go anywhere... |
---|
116 | lcd_shutdown(); |
---|
117 | // Must come before screenlist_shutdown |
---|
118 | client_shutdown(); |
---|
119 | // Must come after client_shutdown |
---|
120 | screenlist_shutdown(); |
---|
121 | // Should come after client_shutdown |
---|
122 | sock_close_all(); |
---|
123 | |
---|
124 | return 0; |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | void exit_program(int val) |
---|
129 | { |
---|
130 | // Say goodbye! |
---|
131 | goodbye_screen(); |
---|
132 | |
---|
133 | // Can go anywhere... |
---|
134 | lcd_shutdown(); |
---|
135 | // Must come before screenlist_shutdown |
---|
136 | client_shutdown(); |
---|
137 | // Must come after client_shutdown |
---|
138 | screenlist_shutdown(); |
---|
139 | // Should come after client_shutdown |
---|
140 | sock_close_all(); |
---|
141 | |
---|
142 | exit(0); |
---|
143 | |
---|
144 | } |
---|