1c87c5fbaSopenharmony_ci/* 2c87c5fbaSopenharmony_ci * coap_async.h -- state management for asynchronous messages 3c87c5fbaSopenharmony_ci * 4c87c5fbaSopenharmony_ci * Copyright (C) 2010-2023 Olaf Bergmann <bergmann@tzi.org> 5c87c5fbaSopenharmony_ci * 6c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 7c87c5fbaSopenharmony_ci * 8c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see README for terms 9c87c5fbaSopenharmony_ci * of use. 10c87c5fbaSopenharmony_ci */ 11c87c5fbaSopenharmony_ci 12c87c5fbaSopenharmony_ci/** 13c87c5fbaSopenharmony_ci * @file coap_async.h 14c87c5fbaSopenharmony_ci * @brief State management for asynchronous messages 15c87c5fbaSopenharmony_ci */ 16c87c5fbaSopenharmony_ci 17c87c5fbaSopenharmony_ci#ifndef COAP_ASYNC_H_ 18c87c5fbaSopenharmony_ci#define COAP_ASYNC_H_ 19c87c5fbaSopenharmony_ci 20c87c5fbaSopenharmony_ci#include "coap_net.h" 21c87c5fbaSopenharmony_ci 22c87c5fbaSopenharmony_ci/** 23c87c5fbaSopenharmony_ci * @ingroup application_api 24c87c5fbaSopenharmony_ci * @defgroup coap_async Asynchronous Messaging 25c87c5fbaSopenharmony_ci * @{ 26c87c5fbaSopenharmony_ci * API for delayed "separate" messages. 27c87c5fbaSopenharmony_ci * A coap_context_t object holds a list of coap_async_t objects that can 28c87c5fbaSopenharmony_ci * be used to generate a separate response in the case a result of a request 29c87c5fbaSopenharmony_ci * cannot be delivered immediately. 30c87c5fbaSopenharmony_ci */ 31c87c5fbaSopenharmony_ci 32c87c5fbaSopenharmony_ci/** 33c87c5fbaSopenharmony_ci * Returns @c 1 if libcoap was built with separate messages enabled, 34c87c5fbaSopenharmony_ci * @c 0 otherwise. 35c87c5fbaSopenharmony_ci */ 36c87c5fbaSopenharmony_ciint coap_async_is_supported(void); 37c87c5fbaSopenharmony_ci 38c87c5fbaSopenharmony_ci/** 39c87c5fbaSopenharmony_ci * Allocates a new coap_async_t object and fills its fields according to 40c87c5fbaSopenharmony_ci * the given @p request. This function returns a pointer to the registered 41c87c5fbaSopenharmony_ci * coap_async_t object or @c NULL on error. Note that this function will 42c87c5fbaSopenharmony_ci * return @c NULL in case that an object with the same identifier is already 43c87c5fbaSopenharmony_ci * registered. 44c87c5fbaSopenharmony_ci * 45c87c5fbaSopenharmony_ci * When the delay expires, a copy of the @p request will get sent to the 46c87c5fbaSopenharmony_ci * appropriate request handler. 47c87c5fbaSopenharmony_ci * 48c87c5fbaSopenharmony_ci * @param session The session that is used for asynchronous transmissions. 49c87c5fbaSopenharmony_ci * @param request The request that is handled asynchronously. 50c87c5fbaSopenharmony_ci * @param delay The amount of time to delay before sending response, 0 means 51c87c5fbaSopenharmony_ci * wait forever. 52c87c5fbaSopenharmony_ci * 53c87c5fbaSopenharmony_ci * @return A pointer to the registered coap_async_t object or @c 54c87c5fbaSopenharmony_ci * NULL in case of an error. 55c87c5fbaSopenharmony_ci */ 56c87c5fbaSopenharmony_cicoap_async_t *coap_register_async(coap_session_t *session, 57c87c5fbaSopenharmony_ci const coap_pdu_t *request, 58c87c5fbaSopenharmony_ci coap_tick_t delay); 59c87c5fbaSopenharmony_ci 60c87c5fbaSopenharmony_ci/** 61c87c5fbaSopenharmony_ci * Update the delay timeout, so changing when the registered @p async triggers. 62c87c5fbaSopenharmony_ci * 63c87c5fbaSopenharmony_ci * When the new delay expires, a copy of the original request will get sent to 64c87c5fbaSopenharmony_ci * the appropriate request handler. 65c87c5fbaSopenharmony_ci * 66c87c5fbaSopenharmony_ci * @param async The object to update. 67c87c5fbaSopenharmony_ci * @param delay The amount of time to delay before sending response, 0 means 68c87c5fbaSopenharmony_ci * wait forever. 69c87c5fbaSopenharmony_ci */ 70c87c5fbaSopenharmony_civoid coap_async_set_delay(coap_async_t *async, coap_tick_t delay); 71c87c5fbaSopenharmony_ci 72c87c5fbaSopenharmony_ci/** 73c87c5fbaSopenharmony_ci * Trigger the registered @p async. 74c87c5fbaSopenharmony_ci * 75c87c5fbaSopenharmony_ci * A copy of the original request will get sent to the appropriate request 76c87c5fbaSopenharmony_ci * handler. 77c87c5fbaSopenharmony_ci * 78c87c5fbaSopenharmony_ci * @param async The async object to trigger. 79c87c5fbaSopenharmony_ci */ 80c87c5fbaSopenharmony_civoid coap_async_trigger(coap_async_t *async); 81c87c5fbaSopenharmony_ci 82c87c5fbaSopenharmony_ci/** 83c87c5fbaSopenharmony_ci * Releases the memory that was allocated by coap_register_async() for the 84c87c5fbaSopenharmony_ci * object @p async. 85c87c5fbaSopenharmony_ci * 86c87c5fbaSopenharmony_ci * @param session The session to use. 87c87c5fbaSopenharmony_ci * @param async The object to delete. 88c87c5fbaSopenharmony_ci */ 89c87c5fbaSopenharmony_civoid coap_free_async(coap_session_t *session, coap_async_t *async); 90c87c5fbaSopenharmony_ci 91c87c5fbaSopenharmony_ci/** 92c87c5fbaSopenharmony_ci * Retrieves the object identified by @p token from the list of asynchronous 93c87c5fbaSopenharmony_ci * transactions that are registered with @p context. This function returns a 94c87c5fbaSopenharmony_ci * pointer to that object or @c NULL if not found. 95c87c5fbaSopenharmony_ci * 96c87c5fbaSopenharmony_ci * @param session The session that is used for asynchronous transmissions. 97c87c5fbaSopenharmony_ci * @param token The PDU's token of the object to retrieve. 98c87c5fbaSopenharmony_ci * 99c87c5fbaSopenharmony_ci * @return A pointer to the object identified by @p token or @c NULL if 100c87c5fbaSopenharmony_ci * not found. 101c87c5fbaSopenharmony_ci */ 102c87c5fbaSopenharmony_cicoap_async_t *coap_find_async(coap_session_t *session, coap_bin_const_t token); 103c87c5fbaSopenharmony_ci 104c87c5fbaSopenharmony_ci/** 105c87c5fbaSopenharmony_ci * Set the application data pointer held in @p async. This overwrites any 106c87c5fbaSopenharmony_ci * existing data pointer. 107c87c5fbaSopenharmony_ci * 108c87c5fbaSopenharmony_ci * @param async The async state object. 109c87c5fbaSopenharmony_ci * @param app_data The pointer to the data. 110c87c5fbaSopenharmony_ci */ 111c87c5fbaSopenharmony_civoid coap_async_set_app_data(coap_async_t *async, void *app_data); 112c87c5fbaSopenharmony_ci 113c87c5fbaSopenharmony_ci/** 114c87c5fbaSopenharmony_ci * Gets the application data pointer held in @p async. 115c87c5fbaSopenharmony_ci * 116c87c5fbaSopenharmony_ci * @param async The async state object. 117c87c5fbaSopenharmony_ci * 118c87c5fbaSopenharmony_ci * @return The applicaton data pointer. 119c87c5fbaSopenharmony_ci */ 120c87c5fbaSopenharmony_civoid *coap_async_get_app_data(const coap_async_t *async); 121c87c5fbaSopenharmony_ci 122c87c5fbaSopenharmony_ci/** @} */ 123c87c5fbaSopenharmony_ci 124c87c5fbaSopenharmony_ci#endif /* COAP_ASYNC_H_ */ 125