… | |
… | |
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 |
|
|
81 | { |
68 | cmd_queue.push_back (command ( |
82 | cmd_queue.push_back (command ()); |
69 | stamp, handler, (char *)salloc (datalen, data), datalen |
83 | command &cmd = cmd_queue.back (); |
70 | )); |
84 | cmd.stamp = stamp; |
|
|
85 | cmd.handler = handler; |
|
|
86 | cmd.data = (char *)salloc (datalen + 1, data); |
|
|
87 | cmd.datalen = datalen; |
|
|
88 | } |
71 | } |
89 | } |
72 | |
90 | |
73 | bool |
91 | bool |
74 | client::handle_command () |
92 | client::handle_command () |
75 | { |
93 | { |
… | |
… | |
80 | return false; |
98 | return false; |
81 | |
99 | |
82 | command &cmd = cmd_queue.front (); |
100 | command &cmd = cmd_queue.front (); |
83 | |
101 | |
84 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
102 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
85 | //TODO: do fire_stop and other things that might be necessary |
103 | { |
|
|
104 | reset_state (); |
86 | send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); |
105 | send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); |
|
|
106 | } |
87 | else |
107 | else |
88 | execute (cmd.handler, cmd.data, cmd.datalen); |
108 | execute (cmd.handler, cmd.data, cmd.datalen); |
89 | |
109 | |
90 | sfree (cmd.data, cmd.datalen); |
|
|
91 | cmd_queue.pop_front (); |
110 | cmd_queue.pop_front (); |
92 | |
111 | |
93 | return true; |
112 | return true; |
94 | } |
113 | } |
95 | |
114 | |