From 794804e27f73de40710c1e208440a5f1d603e441 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 5 Mar 2024 21:17:20 -0500 Subject: [PATCH] A few more .h file docs. --- src/packetstream.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/serialize.h | 19 ++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/packetstream.h b/src/packetstream.h index 0c5fe0e4..89df51a2 100644 --- a/src/packetstream.h +++ b/src/packetstream.h @@ -8,19 +8,67 @@ #include +/** A handle to a UNIX-style pipe. */ typedef struct uv_pipe_s uv_pipe_t; +/** A packet stream instance. */ typedef struct _tf_packetstream_t tf_packetstream_t; +/** +** A function called when a packet is received. +** @param packet_type The type of the packet as specified by the sender. +** @param begin The beginning of the data. +** @param length The length of the data. +** @param user_data User data. +*/ typedef void(tf_packetstream_onreceive_t)(int packet_type, const char* begin, size_t length, void* user_data); +/** +** Create a packet stream. +** @return The packet stream. +*/ tf_packetstream_t* tf_packetstream_create(); + +/** +** Destroy a packet stream. +** @param stream The packet stream. +*/ void tf_packetstream_destroy(tf_packetstream_t* stream); +/** +** Start a packet stream receiving. +** @param stream The packet stream. +*/ void tf_packetstream_start(tf_packetstream_t* stream); + +/** +** Send a discrete packet over a packet stream. +** @param stream The packet stream. +** @param packet_type The type of the packet. +** @param begin The start of the packet data. +** @param length The length of the packet data. +*/ void tf_packetstream_send(tf_packetstream_t* stream, int packet_type, const char* begin, size_t length); + +/** +** Register the callback to be called when a message is received. +** @param stream The packet stream. +** @param callback The callback function. +** @param user_data User data to pass to the callback. +*/ void tf_packetstream_set_on_receive(tf_packetstream_t* stream, tf_packetstream_onreceive_t* callback, void* user_data); + +/** +** Close a packet stream. +** @param stream The packet stream. +*/ void tf_packetstream_close(tf_packetstream_t* stream); + +/** +** Get the internal pipe object from a packet stream. +** @param stream The packet stream. +** @return The pipe. +*/ uv_pipe_t* tf_packetstream_get_pipe(tf_packetstream_t* stream); /** @} */ diff --git a/src/serialize.h b/src/serialize.h index 768581fc..740a7ea3 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -9,10 +9,29 @@ #include "quickjs.h" +/** A task. */ typedef struct _tf_task_t tf_task_t; +/** A handle to a remote task. */ typedef struct _tf_taskstub_t tf_taskstub_t; +/** +** Store JS data in a binary blob. +** @param task The calling task. +** @param to The handle to the task to which the data will be sent. +** @param[out] out_buffer Populated with the stored data. +** @param[out] out_size Populated with the size of out_data. +** @param value The JS value to store. +*/ void tf_serialize_store(tf_task_t* task, tf_taskstub_t* to, void** out_buffer, size_t* out_size, JSValue value); + +/** +** Retrieve JS data from a binary blob. +** @param task The calling task. +** @param from The handle to the task from which the data was received. +** @param buffer The data. +** @param size The size of the data. +** @return The received JS data. +*/ JSValue tf_serialize_load(tf_task_t* task, tf_taskstub_t* from, const char* buffer, size_t size); /** @} */