2022-04-12 23:59:01 +02:00
|
|
|
#ifndef SC_DEVICEMSG_H
|
|
|
|
#define SC_DEVICEMSG_H
|
2019-05-31 14:55:11 +02:00
|
|
|
|
2021-01-08 19:24:51 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-05-31 14:55:11 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2020-06-04 23:23:09 +02:00
|
|
|
#define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k
|
2020-06-04 21:42:09 +02:00
|
|
|
// type: 1 byte; length: 4 bytes
|
|
|
|
#define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5)
|
2019-05-31 14:55:11 +02:00
|
|
|
|
2024-02-23 20:05:12 +01:00
|
|
|
enum sc_device_msg_type {
|
2019-05-31 14:55:11 +02:00
|
|
|
DEVICE_MSG_TYPE_CLIPBOARD,
|
2021-11-20 12:10:09 +01:00
|
|
|
DEVICE_MSG_TYPE_ACK_CLIPBOARD,
|
2024-01-12 23:32:30 +08:00
|
|
|
DEVICE_MSG_TYPE_UHID_OUTPUT,
|
2019-05-31 14:55:11 +02:00
|
|
|
};
|
|
|
|
|
2024-02-23 20:05:12 +01:00
|
|
|
struct sc_device_msg {
|
|
|
|
enum sc_device_msg_type type;
|
2019-05-31 14:55:11 +02:00
|
|
|
union {
|
|
|
|
struct {
|
2021-01-24 15:14:53 +01:00
|
|
|
char *text; // owned, to be freed by free()
|
2019-05-31 14:55:11 +02:00
|
|
|
} clipboard;
|
2021-11-20 12:10:09 +01:00
|
|
|
struct {
|
|
|
|
uint64_t sequence;
|
|
|
|
} ack_clipboard;
|
2024-01-12 23:32:30 +08:00
|
|
|
struct {
|
|
|
|
uint16_t id;
|
|
|
|
uint16_t size;
|
|
|
|
uint8_t *data; // owned, to be freed by free()
|
|
|
|
} uhid_output;
|
2019-05-31 14:55:11 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// return the number of bytes consumed (0 for no msg available, -1 on error)
|
|
|
|
ssize_t
|
2024-02-23 20:05:12 +01:00
|
|
|
sc_device_msg_deserialize(const uint8_t *buf, size_t len,
|
|
|
|
struct sc_device_msg *msg);
|
2019-05-31 14:55:11 +02:00
|
|
|
|
|
|
|
void
|
2024-02-23 20:05:12 +01:00
|
|
|
sc_device_msg_destroy(struct sc_device_msg *msg);
|
2019-05-31 14:55:11 +02:00
|
|
|
|
|
|
|
#endif
|