/* * SPDX-License-Identifier: AGPL-3.0-only * Copyright (c) Camden Dixie O'Brien */ #ifndef PROTOCOL_INTERFACE_H #define PROTOCOL_INTERFACE_H #include "protocol_messages.h" typedef ResponseStatus (*CommandHandler)( const Message *command, Message *response_out); /** * Initialize the protocol interface and start listening for commands. */ void protocol_interface_init(void); /** * Set the handler for commands with a given intruction. * * The handler will be invoked when/if a command with the specified * instruction is received. The response status should be returned, * and upon success the response should be populated. Strings in the * response must be allocated with alloc_message_string(); these will * be freed by the interface when the response has been sent. * * Only a single handler can be set for a given instruction; if * multiple are added then only the one added last will be used. */ void set_command_handler( CommandInstruction instruction, CommandHandler handler); /** * Allocate a buffer for a string with the given length (in bytes), * returning a pointer to it or NULL if space has ran out. * * The actual space allocated will be length + 1 bytes, and the last * byte in this buffer will be set to the null character. */ char *alloc_message_string(unsigned length); #endif