diff options
author | 2019-05-21 17:41:21 +0300 | |
---|---|---|
committer | 2019-05-21 17:41:21 +0300 | |
commit | cabb90c1240015ee5cd17d91573588527bcc2482 (patch) | |
tree | 0e3b07fa887ca25a12e32f5c126407d149483a21 /include/protocol.h | |
parent | bb70fccb66f55e9cc2b9ed0bf366479828f41346 (diff) | |
download | usurpation-cabb90c1240015ee5cd17d91573588527bcc2482.tar.gz usurpation-cabb90c1240015ee5cd17d91573588527bcc2482.tar.bz2 usurpation-cabb90c1240015ee5cd17d91573588527bcc2482.zip |
Protocol: changes to interface and some re-implementation.
Most functions exposed in protocol.h take a connection descriptor
(cd_t) as first argument. This allows for multiple connections. Device
gets only one connection which means that cd_t is effectively 0 all
the time.
Additionaly, any function that actually does anything with a
connection descriptor instead of just passing it to another function
must be implemented separately in device and daemon.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'include/protocol.h')
-rw-r--r-- | include/protocol.h | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/include/protocol.h b/include/protocol.h index ac83154..60d31ea 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,9 +23,17 @@ #include <errno.h> -#define E_TLV_OVERFLOW (1 << 0) -#define E_UNKNOWN_TYPE (1 << 1) +#define E_TLV_OVERFLOW (1 << 0) +#define E_UNKNOWN_TYPE (1 << 1) +#define E_IVALID_DESCRIPTOR (1 << 2) +/** + * Regular packets contain tlv's defined by tlv_type. + * + * Hearbeat packet tell daemon that device is still alive and listening. + * + * Discovery packets are used for what they say. + */ enum packet_type { REGURAL, HEARTBEAT, @@ -33,6 +41,11 @@ enum packet_type { }; /** + * Connection descriptor. + */ +typedef unsigned int cd_t; + +/** * Message sequence number since beggining of sesssion. * * Mainly used for identifying lost messages. @@ -40,13 +53,16 @@ enum packet_type { typedef unsigned int msg_idx_t; enum tlv_type { - /** NULL-terminated string. */ + /** + * NULL-terminated string. To be put in a queue to display on the + * screen. + */ TEXT, /** Fixed point. 1 decimal digit of precision. */ FPI1, - /** Literally time_t*/ + /** Literally time_t */ TIMESTAMP, /** Represents a request for lost message. Data is unsigned integer @@ -54,51 +70,63 @@ enum tlv_type { */ REQUEST, - /** Response to request. Begins with unsigned integer that represents + /** + * Response to request. Begins with unsigned integer that represents * which message is being repeated and the actual null-terminated * message after that. */ REPLY, - /** UUID that represents a particular device. + /** + * UUID that represents a particular device. */ UUID }; +/** + * Packet data itself is a special type of tlv. A packet is either regular, + * hearbeat or discovery. + */ struct packet_data { enum packet_type type; size_t packet_size; char *data; /* Bytes representing tlv's */ }; +/** + * Literally type-length-value + * */ struct tlv { enum tlv_type type; size_t length; void *data; }; -/* +/** * Reads last packets received, parses and stores them to be later retreived * via get_tlv. * */ -void get_last_data(void); +void get_last_data(cd_t connection); -/* Returns tlv's parsed by get_last_data. Returned tlv is only valid until +/** Returns tlv's parsed by get_last_data. Returned tlv is only valid until * next call to get_tlv. * */ struct tlv * get_tlv(void); -/* Any modifications made to the pending outgoing packet are nullified. +/** + * Any modifications made to the pending outgoing packet are nullified. * */ -void clear_data(void); +void clear_data(cd_t connection); -/* Appends data to the next packet to be sent. Type of data is determined by +/** + * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -int push_data(const char *data, enum tlv_type); +int push_data(cd_t connection, const char *data, enum tlv_type); -/* Sends packet towards the other end. +/** + * Sends packet towards the other end. * */ -void flush_data(void); +void flush_data(cd_t connection); #endif /* PROTOCOL_H_INCLUDED */ |