mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-28 07:51:19 +01:00
net/gcoap: allow to pass user context to requests
This commit is contained in:
parent
75397a2be1
commit
3fd8357071
@ -647,7 +647,6 @@ typedef struct gcoap_listener {
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of the request memo type
|
||||
*
|
||||
*/
|
||||
typedef struct gcoap_request_memo gcoap_request_memo_t;
|
||||
|
||||
@ -684,6 +683,7 @@ struct gcoap_request_memo {
|
||||
supports resending message */
|
||||
sock_udp_ep_t remote_ep; /**< Remote endpoint */
|
||||
gcoap_resp_handler_t resp_handler; /**< Callback for the response */
|
||||
void *context; /**< ptr to user defined context data */
|
||||
xtimer_t response_timer; /**< Limits wait for response */
|
||||
msg_t timeout_msg; /**< For response timer */
|
||||
};
|
||||
@ -782,13 +782,14 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
* @param[in] len Length of the buffer
|
||||
* @param[in] remote Destination for the packet
|
||||
* @param[in] resp_handler Callback when response received, may be NULL
|
||||
* @param[in] context User defined context passed to the response handler
|
||||
*
|
||||
* @return length of the packet
|
||||
* @return 0 if cannot send
|
||||
*/
|
||||
size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
const sock_udp_ep_t *remote,
|
||||
gcoap_resp_handler_t resp_handler);
|
||||
gcoap_resp_handler_t resp_handler, void *context);
|
||||
|
||||
/**
|
||||
* @brief Sends a buffer containing a CoAP request to the provided endpoint
|
||||
@ -800,15 +801,17 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
* @param[in] len Length of the buffer
|
||||
* @param[in] remote Destination for the packet
|
||||
* @param[in] resp_handler Callback when response received, may be NULL
|
||||
* @param[in] context User defined context passed to the response handler
|
||||
*
|
||||
* @return length of the packet
|
||||
* @return 0 if cannot send
|
||||
*/
|
||||
static inline size_t gcoap_req_send2(const uint8_t *buf, size_t len,
|
||||
const sock_udp_ep_t *remote,
|
||||
gcoap_resp_handler_t resp_handler)
|
||||
gcoap_resp_handler_t resp_handler,
|
||||
void *context)
|
||||
{
|
||||
return gcoap_req_send(buf, len, remote, resp_handler);
|
||||
return gcoap_req_send(buf, len, remote, resp_handler, context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2017 Ken Bannister. All rights reserved.
|
||||
* 2019 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -16,6 +17,7 @@
|
||||
* Runs a thread (_pid) to manage request/response messaging.
|
||||
*
|
||||
* @author Ken Bannister <kb2ma@runbox.com>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@ -721,7 +723,7 @@ ssize_t gcoap_finish(coap_pkt_t *pdu, size_t payload_len, unsigned format)
|
||||
|
||||
size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
const sock_udp_ep_t *remote,
|
||||
gcoap_resp_handler_t resp_handler)
|
||||
gcoap_resp_handler_t resp_handler, void *context)
|
||||
{
|
||||
gcoap_request_memo_t *memo = NULL;
|
||||
unsigned msg_type = (*buf & 0x30) >> 4;
|
||||
@ -748,6 +750,7 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
}
|
||||
|
||||
memo->resp_handler = resp_handler;
|
||||
memo->context = context;
|
||||
memcpy(&memo->remote_ep, remote, sizeof(sock_udp_ep_t));
|
||||
|
||||
switch (msg_type) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user