Prefix control event constants by namespace
This will avoid conflicts with future device events.
This commit is contained in:
parent
999c964689
commit
b08dada6c1
4 changed files with 16 additions and 16 deletions
|
@ -25,9 +25,9 @@ control_event_serialize(const struct control_event *event, unsigned char *buf) {
|
|||
case CONTROL_EVENT_TYPE_TEXT: {
|
||||
// write length (2 bytes) + string (non nul-terminated)
|
||||
size_t len = strlen(event->text_event.text);
|
||||
if (len > TEXT_MAX_LENGTH) {
|
||||
if (len > CONTROL_EVENT_TEXT_MAX_LENGTH) {
|
||||
// injecting a text takes time, so limit the text length
|
||||
len = TEXT_MAX_LENGTH;
|
||||
len = CONTROL_EVENT_TEXT_MAX_LENGTH;
|
||||
}
|
||||
buffer_write16be(&buf[1], (uint16_t) len);
|
||||
memcpy(&buf[3], event->text_event.text, len);
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include "common.h"
|
||||
|
||||
#define CONTROL_EVENT_QUEUE_SIZE 64
|
||||
#define TEXT_MAX_LENGTH 300
|
||||
#define SERIALIZED_EVENT_MAX_SIZE (3 + TEXT_MAX_LENGTH)
|
||||
#define CONTROL_EVENT_TEXT_MAX_LENGTH 300
|
||||
#define CONTROL_EVENT_SERIALIZED_MAX_SIZE (3 + CONTROL_EVENT_TEXT_MAX_LENGTH)
|
||||
|
||||
enum control_event_type {
|
||||
CONTROL_EVENT_TYPE_KEYCODE,
|
||||
|
@ -59,7 +59,7 @@ struct control_event_queue {
|
|||
int tail;
|
||||
};
|
||||
|
||||
// buf size must be at least SERIALIZED_EVENT_MAX_SIZE
|
||||
// buf size must be at least CONTROL_EVENT_SERIALIZED_MAX_SIZE
|
||||
int
|
||||
control_event_serialize(const struct control_event *event, unsigned char *buf);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ controller_push_event(struct controller *controller,
|
|||
static bool
|
||||
process_event(struct controller *controller,
|
||||
const struct control_event *event) {
|
||||
unsigned char serialized_event[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char serialized_event[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int length = control_event_serialize(event, serialized_event);
|
||||
if (!length) {
|
||||
return false;
|
||||
|
|
|
@ -13,7 +13,7 @@ static void test_serialize_keycode_event(void) {
|
|||
},
|
||||
};
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 10);
|
||||
|
||||
|
@ -34,7 +34,7 @@ static void test_serialize_text_event(void) {
|
|||
},
|
||||
};
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 16);
|
||||
|
||||
|
@ -49,20 +49,20 @@ static void test_serialize_text_event(void) {
|
|||
static void test_serialize_long_text_event(void) {
|
||||
struct control_event event;
|
||||
event.type = CONTROL_EVENT_TYPE_TEXT;
|
||||
char text[TEXT_MAX_LENGTH + 1];
|
||||
char text[CONTROL_EVENT_TEXT_MAX_LENGTH + 1];
|
||||
memset(text, 'a', sizeof(text));
|
||||
text[TEXT_MAX_LENGTH] = '\0';
|
||||
text[CONTROL_EVENT_TEXT_MAX_LENGTH] = '\0';
|
||||
event.text_event.text = text;
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 3 + TEXT_MAX_LENGTH);
|
||||
assert(size == 3 + CONTROL_EVENT_TEXT_MAX_LENGTH);
|
||||
|
||||
unsigned char expected[3 + TEXT_MAX_LENGTH];
|
||||
unsigned char expected[3 + CONTROL_EVENT_TEXT_MAX_LENGTH];
|
||||
expected[0] = 0x01; // CONTROL_EVENT_TYPE_KEYCODE
|
||||
expected[1] = 0x01;
|
||||
expected[2] = 0x2c; // text length (16 bits)
|
||||
memset(&expected[3], 'a', TEXT_MAX_LENGTH);
|
||||
memset(&expected[3], 'a', CONTROL_EVENT_TEXT_MAX_LENGTH);
|
||||
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ static void test_serialize_mouse_event(void) {
|
|||
},
|
||||
};
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 18);
|
||||
|
||||
|
@ -119,7 +119,7 @@ static void test_serialize_scroll_event(void) {
|
|||
},
|
||||
};
|
||||
|
||||
unsigned char buf[SERIALIZED_EVENT_MAX_SIZE];
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 21);
|
||||
|
||||
|
|
Loading…
Reference in a new issue