Themes
[xdock.git] / src / server / command.c
blob3dfb3898aba324c232bbd54e6db0b9cad8041e21
1 #include "command.h"
2 #include "network.h"
3 #include "widget.h"
4 #include "event.h"
6 #include <stdio.h>
8 int check_parameters(unsigned char* command, int bytes, int correct_min, int correct_max)
10 if(bytes-1 < correct_min || bytes-1 > correct_max)
12 int i;
14 fprintf(stderr, "Incorrect protocol command:");
15 for(i=0; i<bytes; i++)
16 fprintf(stderr, " %02X", command[i]);
17 fprintf(stderr, "\n");
18 return 0;
20 else
21 return -1;
24 int run_command(client_t* client, unsigned char* command, int bytes)
26 switch(command[0])
28 case 0x0: // NOP
29 if(check_parameters(command, bytes, 0, 0))
30 draw_update(client);
31 break;
33 case 0x1: // draw pixel
34 if(check_parameters(command, bytes, 3, 3))
35 draw_pixel(client, command[1], command[2], command[3]);
36 break;
38 case 0x2: // draw line
39 if(check_parameters(command, bytes, 5, 5))
40 draw_line(client, command[1], command[2], command[3], command[4], command[5]);
41 break;
43 case 0x8: // draw rectangle
44 if(check_parameters(command, bytes, 5, 5))
45 draw_rectangle(client, command[1], command[2], command[3], command[4], command[5]);
46 break;
48 case 0x9: // draw box
49 if(check_parameters(command, bytes, 6, 6))
50 draw_box(client, command[1], command[2], command[3], command[4], command[5], command[6]);
51 break;
53 case 0x3: // move box
54 if(check_parameters(command, bytes, 7, 7))
55 move_box(client, command[1], command[2], command[3], command[4], command[5], command[6], command[7]);
56 break;
58 case 0x7: // set color
59 if(check_parameters(command, bytes, 4, 4))
60 set_color(client, command[1], command[2], command[3], command[4]);
61 break;
63 case 0x4: // write
64 command[bytes] = 0; // I don't know why
65 // printf("command -> %s\n", &command[4]);
66 if(check_parameters(command, bytes, 6, 100))
67 write_text(client, command[1], command[2], command[3], command[4], &command[5]);
68 break;
70 case 0x5: // new XPM
71 if(check_parameters(command, bytes, 3, 100000))
72 new_pixmap(client, command[1], bytes - 2, &command[2]);
73 break;
75 case 0x6: // draw image
76 if(check_parameters(command, bytes, 3, 3))
77 draw_image(client, command[1], command[2], command[3]);
78 break;
80 case 0x0A: // grab events
81 if(check_parameters(command, bytes, 5, 5))
82 grab_events(client, command[1], command[2], command[3], command[4], command[5]);
83 break;
85 case 0xA0: // draw 3D box (DEPRECATED)
86 if(check_parameters(command, bytes, 4, 4))
87 draw_led_panel(client, command[1], command[2], command[3], command[4]);
88 break;
90 case 0xA1: // draw 3D box
91 if(check_parameters(command, bytes, 5, 5))
92 draw_panel(client, command[1], command[2], command[3], command[4], command[5]);
93 break;
95 default:
96 check_parameters(command, bytes, 2, 1);
97 return 0;
100 return 1;