diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/protocol.h | 58 | ||||
-rw-r--r-- | include/utils.h | 8 |
2 files changed, 47 insertions, 19 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 */ diff --git a/include/utils.h b/include/utils.h index f92e0fa..c769917 100644 --- a/include/utils.h +++ b/include/utils.h @@ -14,9 +14,9 @@ int cmp_uuid(uuid_t *first, uuid_t *second); */ typedef int fpi1_t; -fpi1_t add(fpi1_t a, fpi1_t b); -fpi1_t sub(fpi1_t a, fpi1_t b); -fpi1_t mul(fpi1_t a, fpi1_t b); -fpi1_t div(fpi1_t a, fpi1_t b); +fpi1_t fpi1_add(fpi1_t a, fpi1_t b); +fpi1_t fpi1_sub(fpi1_t a, fpi1_t b); +fpi1_t fpi1_mul(fpi1_t a, fpi1_t b); +fpi1_t fpi1_div(fpi1_t a, fpi1_t b); #endif /* PROJECT_UTILS_H */ |