… | |
… | |
47 | #include <arpa/inet.h> |
47 | #include <arpa/inet.h> |
48 | |
48 | |
49 | #include <loader.h> |
49 | #include <loader.h> |
50 | |
50 | |
51 | #define MAX_QUEUE_DEPTH 500 //TODO |
51 | #define MAX_QUEUE_DEPTH 500 //TODO |
52 | |
|
|
53 | //TODO: cannot use this, as it might ignore vital commands such as fire_stop |
|
|
54 | #define MAX_QUEUE_BACKLOG 1e99 //TODO |
52 | #define MAX_QUEUE_BACKLOG 5. //TODO |
|
|
53 | |
|
|
54 | void |
|
|
55 | client::reset_state () |
|
|
56 | { |
|
|
57 | if (!pl) |
|
|
58 | return; |
|
|
59 | |
|
|
60 | pl->run_on = 0; |
|
|
61 | pl->fire_on = 0; |
|
|
62 | } |
55 | |
63 | |
56 | void |
64 | void |
57 | client::queue_command (packet_type *handler, char *data, int datalen) |
65 | client::queue_command (packet_type *handler, char *data, int datalen) |
58 | { |
66 | { |
59 | tstamp stamp = now (); |
67 | tstamp stamp = now (); |
60 | |
68 | |
61 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
69 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
|
|
70 | { |
62 | //TODO: just disconnect here? |
71 | //TODO: just disconnect here? |
|
|
72 | reset_state (); |
63 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
73 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
|
|
74 | } |
64 | else if (!cmd_queue.empty () && cmd_queue.front ().stamp + MAX_QUEUE_BACKLOG < stamp) |
75 | else if (!cmd_queue.empty () && cmd_queue.front ().stamp + MAX_QUEUE_BACKLOG < stamp) |
65 | //TODO: do fire_stop and other things that might be necessary |
76 | { |
|
|
77 | reset_state (); |
66 | send_packet_printf ("drawinfo %d too many commands in queue, ignoring.", NDI_RED); |
78 | send_packet_printf ("drawinfo %d too many commands in queue, ignoring.", NDI_RED); |
|
|
79 | } |
67 | else |
80 | else |
68 | cmd_queue.push_back (command ( |
81 | cmd_queue.push_back (command ( |
69 | stamp, handler, (char *)salloc (datalen, data), datalen |
82 | stamp, handler, (char *)salloc (datalen + 1, data), datalen |
70 | )); |
83 | )); |
71 | } |
84 | } |
72 | |
85 | |
73 | bool |
86 | bool |
74 | client::handle_command () |
87 | client::handle_command () |
… | |
… | |
80 | return false; |
93 | return false; |
81 | |
94 | |
82 | command &cmd = cmd_queue.front (); |
95 | command &cmd = cmd_queue.front (); |
83 | |
96 | |
84 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
97 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
85 | //TODO: do fire_stop and other things that might be necessary |
98 | { |
|
|
99 | reset_state (); |
86 | send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); |
100 | send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); |
|
|
101 | } |
87 | else |
102 | else |
88 | execute (cmd.handler, cmd.data, cmd.datalen); |
103 | execute (cmd.handler, cmd.data, cmd.datalen); |
89 | |
104 | |
90 | sfree (cmd.data, cmd.datalen); |
105 | sfree (cmd.data, cmd.datalen); |
91 | cmd_queue.pop_front (); |
106 | cmd_queue.pop_front (); |