2. libpcp
2.1 Main server section
2.1.1 Server setup
2.1.1.1 e_pcpa_t pcpaInitStream(pcpa_t *stream)
Initialise a pcp stream, allocating memory as needed.
2.1.1.2 e_pcpa_t pcpaSetCallbackFuncBuffer(pcpa_t *stream, pcpa_cb_table_t *callback_table, uint callbacks_max)
Assign a callback table to the stream in preperation for callback registration.
2.1.1.3 e_pcpa_t pcpaSetCallbackFunc(pcpa_t *stream, char *keyword, pcpa_callback *callback, void *data)
Register a callback. If a command is received where the first keyword matches keyword
, callback
is called to process it. The stream is passed as the first argument to the callback, and data
as the second.
2.1.1.4 e_pcpa_t pcpaOpenServerWithBinary(pcpa_t *stream, int open_mode, u_short port, u_short binary_port, undefined4 param_5)
Open the pcp server on port
, and prepare to use binary_port
for data transfer.
Binds to 0.0.0.0
if open_mode
is 0
, 127.0.0.1
if it is 1
.
param_5
is currently unknown. Pass 300000
for now; I think it’s some sort of timeout.
2.1.1.5 void pcpaClose(pcpa_t *stream)
Close a pcp stream
2.1.2 Server mainloop
2.1.2.1 e_pcpa_t pcpaServer(pcpa_t *stream, timeout_t timeout_ms)
Perform one tick of the server. If no events occure within timeout_ms
, this returns.
2.2 Within callbacks
2.2.1 Reading commands
2.2.1.1 char* pcpaGetCommand(pcpa_t* pcpa, char* command)
Fetch the value for a given key. Returns NULL
if the key is not found.
2.2.1.2 char* pcpaGetKeyword(pcpa_t* stream, uint keyword_num)
Request the keyword at a given index. Useful for fetching the 0-index keyword when the same callback is registered to multiple keywords.
2.2.2 Sending responses
2.2.2.1 pcp_send_data_t *pcpaSetSendPacket(pcpa_t *stream, char *keyword, char *value)
Begin a response, setting the initial key-value pair.
2.2.2.2 pcp_send_data_t *pcpaAddSendPacket(pcpa_t *stream, char *keyword, char *value)
Add an additional key-value pair onto the packet being generated.
2.2.2.3 e_pcpa_t pcpaSetBinaryMode(pcpa_t *stream, binary_mode_t binary_mode)
Set the binary mode to either disabled, receiving, or transmitting data.
2.2.2.4 e_pcpa_t pcpaSetBeforeBinaryModeCallBackFunc(pcpa_t *stream, pcpa_callback *callback, void *data)
Register a callback to be called before a data transfer commences.
2.2.2.5 e_pcpa_t pcpaSetSendBinaryBuffer(pcpa_t *stream, byte *send_buffer, size_t len)
Set the buffer to transmit from when performing a server->consumer data transfer. Should usually be called in the before callback.
2.2.2.6 e_pcpa_t pcpaSetRecvBinaryBuffer(pcpa_t *stream, byte *recv_buffer, size_t len)
Set the buffer to receive into when performing a consumer->server data transfer. Should usually be called in the before callback.
2.2.2.7 e_pcpa_t pcpaSetAfterBinaryModeCallBackFunc(pcpa_t *stream, pcpa_callback *callback, void *data)
Register a callback to be called after a data transfer completes.