1c87c5fbaSopenharmony_ci/*
2c87c5fbaSopenharmony_ci * coap_async_internal.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_internal.h
14c87c5fbaSopenharmony_ci * @brief CoAP async internal information
15c87c5fbaSopenharmony_ci */
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci#ifndef COAP_ASYNC_INTERNAL_H_
18c87c5fbaSopenharmony_ci#define COAP_ASYNC_INTERNAL_H_
19c87c5fbaSopenharmony_ci
20c87c5fbaSopenharmony_ci#include "coap_internal.h"
21c87c5fbaSopenharmony_ci#include "coap_net.h"
22c87c5fbaSopenharmony_ci
23c87c5fbaSopenharmony_ci/* Note that if COAP_SERVER_SUPPORT is not set, then COAP_ASYNC_SUPPORT undefined */
24c87c5fbaSopenharmony_ci#if COAP_ASYNC_SUPPORT
25c87c5fbaSopenharmony_ci
26c87c5fbaSopenharmony_ci/**
27c87c5fbaSopenharmony_ci * @ingroup internal_api
28c87c5fbaSopenharmony_ci * @defgroup coap_async_internal Asynchronous Messaging
29c87c5fbaSopenharmony_ci * @{
30c87c5fbaSopenharmony_ci * Internal API for CoAP Asynchronous processing.
31c87c5fbaSopenharmony_ci * A coap_context_t object holds a list of coap_async_t objects that can be
32c87c5fbaSopenharmony_ci * used to generate a separate response in the case a result of a request cannot
33c87c5fbaSopenharmony_ci * be delivered immediately.
34c87c5fbaSopenharmony_ci */
35c87c5fbaSopenharmony_cistruct coap_async_t {
36c87c5fbaSopenharmony_ci  struct coap_async_t *next; /**< internally used for linking */
37c87c5fbaSopenharmony_ci  coap_tick_t delay;    /**< When to delay to before triggering the response
38c87c5fbaSopenharmony_ci                             0 indicates never trigger */
39c87c5fbaSopenharmony_ci  coap_session_t *session;         /**< transaction session */
40c87c5fbaSopenharmony_ci  coap_pdu_t *pdu;                 /**< copy of request pdu */
41c87c5fbaSopenharmony_ci  void *appdata;                   /**< User definable data pointer */
42c87c5fbaSopenharmony_ci};
43c87c5fbaSopenharmony_ci
44c87c5fbaSopenharmony_ci/**
45c87c5fbaSopenharmony_ci * Checks if there are any pending Async requests - if so, send them off.
46c87c5fbaSopenharmony_ci * Otherewise return the time remaining for the next Async to be triggered
47c87c5fbaSopenharmony_ci * or 0 if nothing to do.
48c87c5fbaSopenharmony_ci *
49c87c5fbaSopenharmony_ci * @param context The current context.
50c87c5fbaSopenharmony_ci * @param now     The current time in ticks.
51c87c5fbaSopenharmony_ci *
52c87c5fbaSopenharmony_ci * @return The tick time before the next Async needs to go, else 0 if
53c87c5fbaSopenharmony_ci *         nothing to do.
54c87c5fbaSopenharmony_ci */
55c87c5fbaSopenharmony_cicoap_tick_t coap_check_async(coap_context_t *context, coap_tick_t now);
56c87c5fbaSopenharmony_ci
57c87c5fbaSopenharmony_ci/**
58c87c5fbaSopenharmony_ci * Removes and frees off all of the async entries for the given context.
59c87c5fbaSopenharmony_ci *
60c87c5fbaSopenharmony_ci * @param context The context to remove all async entries from.
61c87c5fbaSopenharmony_ci */
62c87c5fbaSopenharmony_civoid coap_delete_all_async(coap_context_t *context);
63c87c5fbaSopenharmony_ci
64c87c5fbaSopenharmony_ci/** @} */
65c87c5fbaSopenharmony_ci
66c87c5fbaSopenharmony_ci#endif /* COAP_ASYNC_SUPPORT */
67c87c5fbaSopenharmony_ci
68c87c5fbaSopenharmony_ci#endif /* COAP_ASYNC_INTERNAL_H_ */
69