2022-04-13 05:59:01 +08:00
|
|
|
#ifndef SC_DEVICEMSG_H
|
|
|
|
#define SC_DEVICEMSG_H
|
2019-05-31 20:55:11 +08:00
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2020-06-05 05:23:09 +08:00
|
|
|
#define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k
|
2020-06-05 03:42:09 +08:00
|
|
|
// type: 1 byte; length: 4 bytes
|
|
|
|
#define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5)
|
2019-05-31 20:55:11 +08:00
|
|
|
|
|
|
|
enum device_msg_type {
|
|
|
|
DEVICE_MSG_TYPE_CLIPBOARD,
|
2021-11-20 19:10:09 +08:00
|
|
|
DEVICE_MSG_TYPE_ACK_CLIPBOARD,
|
2019-05-31 20:55:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct device_msg {
|
|
|
|
enum device_msg_type type;
|
|
|
|
union {
|
|
|
|
struct {
|
2021-01-24 22:14:53 +08:00
|
|
|
char *text; // owned, to be freed by free()
|
2019-05-31 20:55:11 +08:00
|
|
|
} clipboard;
|
2021-11-20 19:10:09 +08:00
|
|
|
struct {
|
|
|
|
uint64_t sequence;
|
|
|
|
} ack_clipboard;
|
2019-05-31 20:55:11 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// return the number of bytes consumed (0 for no msg available, -1 on error)
|
|
|
|
ssize_t
|
|
|
|
device_msg_deserialize(const unsigned char *buf, size_t len,
|
|
|
|
struct device_msg *msg);
|
|
|
|
|
|
|
|
void
|
|
|
|
device_msg_destroy(struct device_msg *msg);
|
|
|
|
|
|
|
|
#endif
|