locking: Simplify maintenance / debugging /documentation

Update the Public API equivalent of the libcoap functions that need to be
called when locked with a name suffix of _lkd.

Move matching Public API functions out of coap_threadsafe.c to be coded
just ahead of the newly renamed _lkd function.

Properly define the _lkd function in the appropriate _internal.h file for
documentation, removing the #defines from coap_threadsafe_internal.h.

Tag all the Public API functions that have a _lkd function with COAP_API.
COAP_API can then be defined as to what should be done for that function.

Check libcoap library does not call the original Public API function when
it should be calling the _lkd function by marking the Public API not _lkd
functions as deprecated during the libcoap library build.
[Done by the new COAP_API being defined as __attribute__((deprecated)).]

Work in progress for all the functions that need to be multi-thread safe.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2024-05-22 11:40:44 +01:00
1 parent e8e44bf6aa
commit 91d8fad663
30 files changed
+874 -523

No files matched your search

+6 -6
View File
@@ -53,9 +53,9 @@ int coap_async_is_supported(void);
* @return A pointer to the registered coap_async_t object or @c
* NULL in case of an error.
*/
coap_async_t *coap_register_async(coap_session_t *session,
const coap_pdu_t *request,
coap_tick_t delay);
COAP_API coap_async_t *coap_register_async(coap_session_t *session,
const coap_pdu_t *request,
coap_tick_t delay);
/**
* Update the delay timeout, so changing when the registered @p async triggers.
@@ -67,7 +67,7 @@ coap_async_t *coap_register_async(coap_session_t *session,
* @param delay The amount of time to delay before sending response, 0 means
* wait forever.
*/
void coap_async_set_delay(coap_async_t *async, coap_tick_t delay);
COAP_API void coap_async_set_delay(coap_async_t *async, coap_tick_t delay);
/**
* Trigger the registered @p async.
@@ -77,7 +77,7 @@ void coap_async_set_delay(coap_async_t *async, coap_tick_t delay);
*
* @param async The async object to trigger.
*/
void coap_async_trigger(coap_async_t *async);
COAP_API void coap_async_trigger(coap_async_t *async);
/**
* Releases the memory that was allocated by coap_register_async() for the
@@ -99,7 +99,7 @@ void coap_free_async(coap_session_t *session, coap_async_t *async);
* @return A pointer to the object identified by @p token or @c NULL if
* not found.
*/
coap_async_t *coap_find_async(coap_session_t *session, coap_bin_const_t token);
COAP_API coap_async_t *coap_find_async(coap_session_t *session, coap_bin_const_t token);
/**
* Set the application data pointer held in @p async. This overwrites any
+76
View File
@@ -41,6 +41,30 @@ struct coap_async_t {
void *appdata; /**< User definable data pointer */
};
/**
* Allocates a new coap_async_t object and fills its fields according to
* the given @p request. This function returns a pointer to the registered
* coap_async_t object or @c NULL on error. Note that this function will
* return @c NULL in case that an object with the same identifier is already
* registered.
*
* When the delay expires, a copy of the @p request will get sent to the
* appropriate request handler.
*
* Note: This function must be called in the locked state.
*
* @param session The session that is used for asynchronous transmissions.
* @param request The request that is handled asynchronously.
* @param delay The amount of time to delay before sending response, 0 means
* wait forever.
*
* @return A pointer to the registered coap_async_t object or @c
* NULL in case of an error.
*/
coap_async_t *coap_register_async_lkd(coap_session_t *session,
const coap_pdu_t *request,
coap_tick_t delay);
/**
* Checks if there are any pending Async requests - if so, send them off.
* Otherewise return the time remaining for the next Async to be triggered
@@ -54,6 +78,58 @@ struct coap_async_t {
*/
coap_tick_t coap_check_async(coap_context_t *context, coap_tick_t now);
/**
* Retrieves the object identified by @p token from the list of asynchronous
* transactions that are registered with @p context. This function returns a
* pointer to that object or @c NULL if not found.
*
* Note: This function must be called in the locked state.
*
* @param session The session that is used for asynchronous transmissions.
* @param token The PDU's token of the object to retrieve.
*
* @return A pointer to the object identified by @p token or @c NULL if
* not found.
*/
coap_async_t *coap_find_async_lkd(coap_session_t *session, coap_bin_const_t token);
/**
* Trigger the registered @p async.
*
* A copy of the original request will get sent to the appropriate request
* handler.
*
* Note: This function must be called in the locked state.
*
* @param async The async object to trigger.
*/
void coap_async_trigger_lkd(coap_async_t *async);
/**
* Update the delay timeout, so changing when the registered @p async triggers.
*
* When the new delay expires, a copy of the original request will get sent to
* the appropriate request handler.
*
* Note: This function must be called in the locked state.
*
* @param async The object to update.
* @param delay The amount of time to delay before sending response, 0 means
* wait forever.
*/
void coap_async_set_delay_lkd(coap_async_t *async, coap_tick_t delay);
/**
* Releases the memory that was allocated by coap_register_async() for the
* object @p async.
*
* Note: This function must be called in the locked state.
*
* @param session The session to use.
* @param async The object to delete.
*/
void coap_free_async_lkd(coap_session_t *session, coap_async_t *async);
/**
* Removes and frees off all of the async entries for the given context.
*
+18 -18
View File
@@ -335,12 +335,12 @@ typedef void (*coap_release_large_data_t)(coap_session_t *session,
*
* @return @c 1 if addition is successful, else @c 0.
*/
int coap_add_data_large_request(coap_session_t *session,
coap_pdu_t *pdu,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
COAP_API int coap_add_data_large_request(coap_session_t *session,
coap_pdu_t *pdu,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
/**
* Associates given data with the @p response pdu that is passed as fourth
@@ -392,18 +392,18 @@ int coap_add_data_large_request(coap_session_t *session,
*
* @return @c 1 if addition is successful, else @c 0.
*/
int coap_add_data_large_response(coap_resource_t *resource,
coap_session_t *session,
const coap_pdu_t *request,
coap_pdu_t *response,
const coap_string_t *query,
uint16_t media_type,
int maxage,
uint64_t etag,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
COAP_API int coap_add_data_large_response(coap_resource_t *resource,
coap_session_t *session,
const coap_pdu_t *request,
coap_pdu_t *response,
const coap_string_t *query,
uint16_t media_type,
int maxage,
uint64_t etag,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
/**
* Set the context level CoAP block handling bits for handling RFC7959.
+118 -1
View File
@@ -305,6 +305,72 @@ coap_lg_xmit_t *coap_find_lg_xmit_response(const coap_session_t *session,
const coap_pdu_t *request,
const coap_resource_t *resource,
const coap_string_t *query);
/**
* Associates given data with the @p response pdu that is passed as fourth
* parameter.
*
* This function will fail if data has already been added to the @p pdu.
*
* If all the data can be transmitted in a single PDU, this is functionally
* the same as coap_add_data() except @p release_func (if not NULL) will get
* invoked after data transmission. The Content-Format, Max-Age and ETag
* options may be added in as appropriate.
*
* Used by a server request handler to create the response.
*
* If the data spans multiple PDUs, then the data will get transmitted using
* (Q-)Block2 (response) option with the addition of the Size2 and ETag
* options. The underlying library will handle the transmission of the
* individual blocks. Once the body of data has been transmitted (or a
* failure occurred), then @p release_func (if not NULL) will get called so the
* application can de-allocate the @p data based on @p app_data. It is the
* responsibility of the application not to change the contents of @p data
* until the data transfer has completed.
*
* There is no need for the application to include the (Q-)Block2 option in the
* @p pdu.
*
* coap_add_data_large_response_lkd() (or the alternative coap_add_data_large_*()
* functions) must be called only once per PDU and must be the last PDU update
* before returning from the request handler function.
*
* Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
* for libcoap to work correctly when using this function.
*
* Note: This function must be called in the locked state.
*
* @param resource The resource the data is associated with.
* @param session The coap session.
* @param request The requesting pdu.
* @param response The response pdu.
* @param query The query taken from the (original) requesting pdu.
* @param media_type The content format of the data.
* @param maxage The maxmimum life of the data. If @c -1, then there
* is no maxage.
* @param etag ETag to use if not 0.
* @param length The total length of the data.
* @param data The entire data block to transmit.
* @param release_func The function to call to de-allocate @p data or NULL if
* the function is not required.
* @param app_ptr A Pointer that the application can provide for when
* release_func() is called.
*
* @return @c 1 if addition is successful, else @c 0.
*/
int coap_add_data_large_response_lkd(coap_resource_t *resource,
coap_session_t *session,
const coap_pdu_t *request,
coap_pdu_t *response,
const coap_string_t *query,
uint16_t media_type,
int maxage,
uint64_t etag,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
@@ -339,7 +405,7 @@ int coap_block_drop_resp_q_block2_crcv(coap_session_t *session,
/**
* The function checks that the code in a newly formed lg_xmit created by
* coap_add_data_large_response() is updated.
* coap_add_data_large_response_lkd() is updated.
*
* @param session The session.
* @param request The request PDU to to check.
@@ -354,6 +420,57 @@ void coap_check_code_lg_xmit(const coap_session_t *session,
const coap_string_t *query);
#if COAP_CLIENT_SUPPORT
/**
* Associates given data with the @p pdu that is passed as second parameter.
*
* This function will fail if data has already been added to the @p pdu.
*
* If all the data can be transmitted in a single PDU, this is functionally
* the same as coap_add_data_lkd() except @p release_func (if not NULL) will get
* invoked after data transmission.
*
* Used for a client request.
*
* If the data spans multiple PDUs, then the data will get transmitted using
* (Q-)Block1 option with the addition of the Size1 and Request-Tag options.
* The underlying library will handle the transmission of the individual blocks.
* Once the body of data has been transmitted (or a failure occurred), then
* @p release_func (if not NULL) will get called so the application can
* de-allocate the @p data based on @p app_data. It is the responsibility of
* the application not to change the contents of @p data until the data
* transfer has completed.
*
* There is no need for the application to include the (Q-)Block1 option in the
* @p pdu.
*
* coap_add_data_large_request_lkd() (or the alternative coap_add_data_large_*()
* functions) must be called only once per PDU and must be the last PDU update
* before the PDU is transmitted. The (potentially) initial data will get
* transmitted when coap_send() is invoked.
*
* Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
* for libcoap to work correctly when using this function.
*
* Note: This function must be called in the locked state.
*
* @param session The session to associate the data with.
* @param pdu The PDU to associate the data with.
* @param length The length of data to transmit.
* @param data The data to transmit.
* @param release_func The function to call to de-allocate @p data or @c NULL
* if the function is not required.
* @param app_ptr A Pointer that the application can provide for when
* release_func() is called.
*
* @return @c 1 if addition is successful, else @c 0.
*/
int coap_add_data_large_request_lkd(coap_session_t *session,
coap_pdu_t *pdu,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
/**
* The function checks if the token needs to be updated before PDU is
* presented to the application (only relevant to clients).
+12 -12
View File
@@ -123,8 +123,8 @@ void coap_delete_cache_key(coap_cache_key_t *cache_key);
*
* @return @return @c 1 if successful, else @c 0.
*/
int coap_cache_ignore_options(coap_context_t *context,
const uint16_t *options, size_t count);
COAP_API int coap_cache_ignore_options(coap_context_t *context,
const uint16_t *options, size_t count);
/**
* Create a new cache-entry hash keyed by cache-key derived from the PDU.
@@ -149,11 +149,11 @@ int coap_cache_ignore_options(coap_context_t *context,
*
* @return The returned cache-key or @c NULL if failure.
*/
coap_cache_entry_t *coap_new_cache_entry(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_time);
COAP_API coap_cache_entry_t *coap_new_cache_entry(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_time);
/**
* Remove a cache-entry from the hash list and free off all the appropriate
@@ -175,8 +175,8 @@ void coap_delete_cache_entry(coap_context_t *context,
*
* @return The cache-entry for @p cache_key or @c NULL if not found.
*/
coap_cache_entry_t *coap_cache_get_by_key(coap_context_t *context,
const coap_cache_key_t *cache_key);
COAP_API coap_cache_entry_t *coap_cache_get_by_key(coap_context_t *context,
const coap_cache_key_t *cache_key);
/**
* Searches for a cache-entry corresponding to @p pdu. This
@@ -190,9 +190,9 @@ coap_cache_entry_t *coap_cache_get_by_key(coap_context_t *context,
*
* @return The cache-entry for @p request or @c NULL if not found.
*/
coap_cache_entry_t *coap_cache_get_by_pdu(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_session_based_t session_based);
COAP_API coap_cache_entry_t *coap_cache_get_by_pdu(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_session_based_t session_based);
/**
* Returns the PDU information stored in the @p coap_cache entry.
+81
View File
@@ -58,6 +58,87 @@ struct coap_cache_entry_t {
*/
void coap_expire_cache_entries(coap_context_t *context);
/**
* Searches for a cache-entry identified by @p cache_key. This
* function returns the corresponding cache-entry or @c NULL
* if not found.
*
* Note: This function must be called in the locked state.
*
* @param context The context to use.
* @param cache_key The cache-key to get the hashed coap-entry.
*
* @return The cache-entry for @p cache_key or @c NULL if not found.
*/
coap_cache_entry_t *coap_cache_get_by_key_lkd(coap_context_t *context,
const coap_cache_key_t *cache_key);
/**
* Searches for a cache-entry corresponding to @p pdu. This
* function returns the corresponding cache-entry or @c NULL if not
* found.
*
* Note: This function must be called in the locked state.
*
* @param session The session to use.
* @param pdu The CoAP request to search for.
* @param session_based COAP_CACHE_IS_SESSION_BASED if session based
* cache-key to be used, else COAP_CACHE_NOT_SESSION_BASED.
*
* @return The cache-entry for @p request or @c NULL if not found.
*/
coap_cache_entry_t *coap_cache_get_by_pdu_lkd(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_session_based_t session_based);
/**
* Define the CoAP options that are not to be included when calculating
* the cache-key. Options that are defined as Non-Cache and the Observe
* option are always ignored.
*
* Note: This function must be called in the locked state.
*
* @param context The context to save the ignored options information in.
* @param options The array of options to ignore.
* @param count The number of options to ignore. Use 0 to reset the
* options matching.
*
* @return @return @c 1 if successful, else @c 0.
*/
int coap_cache_ignore_options_lkd(coap_context_t *context,
const uint16_t *options, size_t count);
/**
* Create a new cache-entry hash keyed by cache-key derived from the PDU.
*
* If @p session_based is set, then this cache-entry will get deleted when
* the session is freed off.
* If @p record_pdu is set, then the copied PDU will get freed off when
* this cache-entry is deleted.
*
* The cache-entry is maintained on a context hash list.
*
* Note: This function must be called in the locked state.
*
* @param session The session to use to derive the context from.
* @param pdu The pdu to use to generate the cache-key.
* @param record_pdu COAP_CACHE_RECORD_PDU if to take a copy of the PDU for
* later use, else COAP_CACHE_NOT_RECORD_PDU.
* @param session_based COAP_CACHE_IS_SESSION_BASED if to associate this
* cache-entry with the the session (which is embedded
* in the cache-entry), else COAP_CACHE_NOT_SESSION_BASED.
* @param idle_time Idle time in seconds before cache-entry is expired.
* If set to 0, it does not expire (but will get
* deleted if the session is deleted and it is session_based).
*
* @return The returned cache-key or @c NULL if failure.
*/
coap_cache_entry_t *coap_new_cache_entry_lkd(coap_session_t *session,
const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_time);
typedef void coap_digest_ctx_t;
/**
+4 -4
View File
@@ -528,9 +528,9 @@ coap_mid_t coap_send(coap_session_t *session, coap_pdu_t *pdu);
* @return The result from the associated event handler or 0 if none was
* registered.
*/
int coap_handle_event(coap_context_t *context,
coap_event_t event,
coap_session_t *session);
COAP_API int coap_handle_event(coap_context_t *context,
coap_event_t event,
coap_session_t *session);
/**
* Returns 1 if there are no messages to send or to dispatch in the context's
* queues.
@@ -541,7 +541,7 @@ int coap_handle_event(coap_context_t *context,
* queued for transmission. Note that @c 0 does not mean there has
* been a response to a transmitted request.
*/
int coap_can_exit(coap_context_t *context);
COAP_API int coap_can_exit(coap_context_t *context);
/**
* Returns the current value of an internal tick counter. The counter counts \c
+40 -9
View File
@@ -180,9 +180,9 @@ struct coap_context_t {
#else /* ! COAP_EPOLL_SUPPORT */
#if !defined(RIOT_VERSION) && !defined(WITH_CONTIKI)
fd_set readfds, writefds, exceptfds; /**< Used for select call
in coap_io_process_with_fds() */
in coap_io_process_with_fds_lkd() */
coap_socket_t *sockets[64]; /**< Track different socket information
in coap_io_process_with_fds */
in coap_io_process_with_fds_lkd() */
unsigned int num_sockets; /**< Number of sockets being tracked */
#endif /* ! RIOT_VERSION && ! WITH_CONTIKI */
#endif /* ! COAP_EPOLL_SUPPORT */
@@ -458,6 +458,36 @@ int coap_client_delay_first(coap_session_t *session);
*/
void coap_free_context_lkd(coap_context_t *context);
/**
* Invokes the event handler of @p context for the given @p event and
* @p data.
*
* Note: This function must be called in the locked state.
*
* @param context The CoAP context whose event handler is to be called.
* @param event The event to deliver.
* @param session The session related to @p event.
* @return The result from the associated event handler or 0 if none was
* registered.
*/
int coap_handle_event_lkd(coap_context_t *context,
coap_event_t event,
coap_session_t *session);
/**
* Returns 1 if there are no messages to send or to dispatch in the context's
* queues.
*
* Note: This function must be called in the locked state.
*
* @param context The CoAP context to check.
*
* @return @c 0 if there are still pending transmits else @c 1 if nothing
* queued for transmission. Note that @c 0 does not mean there has
* been a response to a transmitted request.
*/
int coap_can_exit_lkd(coap_context_t *context);
/** @} */
/**
@@ -505,7 +535,7 @@ void coap_io_do_epoll_lkd(coap_context_t *ctx, struct epoll_event *events,
*
* Note: This function must be called in the locked state.
*
* coap_io_process() is called internally to try to send outstanding
* coap_io_process_lkd() is called internally to try to send outstanding
* data as well as process any packets just received.
*
* @param context The CoAP context.
@@ -579,14 +609,15 @@ unsigned int coap_io_prepare_io_lkd(coap_context_t *ctx,
* The main I/O processing function. All pending network I/O is completed,
* and then optionally waits for the next input packet.
*
* This internally calls coap_io_prepare_io(), then select() for the appropriate
* sockets, updates COAP_SOCKET_CAN_xxx where appropriate and then calls
* coap_io_do_io() before returning with the time spent in the function.
* This internally calls coap_io_prepare_io_lkd(), then select() for the
* appropriate sockets, updates COAP_SOCKET_CAN_xxx where appropriate and then
* calls coap_io_do_io_lkd() before returning with the time spent in the
* function.
*
* Alternatively, if libcoap is compiled with epoll support, this internally
* calls coap_io_prepare_epoll(), then epoll_wait() for waiting for any file
* calls coap_io_prepare_epoll_lkd(), then epoll_wait() for waiting for any file
* descriptors that have (internally) been set up with epoll_ctl() and
* finally coap_io_do_epoll() before returning with the time spent in the
* finally coap_io_do_epoll_lkd() before returning with the time spent in the
* function.
*
* Note: This function must be called in the locked state.
@@ -633,7 +664,7 @@ int coap_io_process_lkd(coap_context_t *ctx, uint32_t timeout_ms);
* or NULL if not required.
*
*
* @return Number of milliseconds spent in coap_io_process_with_fds, or @c -1
* @return Number of milliseconds spent in coap_io_process_with_fds_lkd, or @c -1
* if there was an error. If defined, readfds, writefds, exceptfds
* are updated as returned by the internal select() call.
*/
+6 -6
View File
@@ -288,8 +288,8 @@ coap_resource_t *coap_resource_proxy_uri_init2(coap_method_handler_t handler,
*
* @return A pointer to the resource or @c NULL if not found.
*/
coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
coap_str_const_t *uri_path);
COAP_API coap_resource_t *coap_get_resource_from_uri_path(coap_context_t *context,
coap_str_const_t *uri_path);
/**
* Get the uri_path from a @p resource.
@@ -354,7 +354,7 @@ void coap_resource_release_userdata_handler(coap_context_t *context,
* @param context The context to use.
* @param resource The resource to store.
*/
void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
COAP_API void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
/**
* Deletes a resource identified by @p resource. The storage allocated for that
@@ -367,7 +367,7 @@ void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
* @return @c 1 if the resource was found (and destroyed),
* @c 0 otherwise.
*/
int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
COAP_API int coap_delete_resource(coap_context_t *context, coap_resource_t *resource);
/**
* Registers the specified @p handler as message handler for the request type
@@ -499,7 +499,7 @@ coap_print_status_t coap_print_link(const coap_resource_t *resource,
/**
* @deprecated use coap_resource_notify_observers() instead.
*/
COAP_DEPRECATED int coap_resource_set_dirty(coap_resource_t *r,
const coap_string_t *query);
COAP_DEPRECATED COAP_API int coap_resource_set_dirty(coap_resource_t *r,
const coap_string_t *query);
#endif /* COAP_RESOURCE_H_ */
+41
View File
@@ -111,6 +111,33 @@ struct coap_resource_t {
};
/**
* Registers the given @p resource for @p context. The resource must have been
* created by coap_resource_init() or coap_resource_unknown_init(), the
* storage allocated for the resource will be released by coap_delete_resource_lkd().
*
* Note: This function must be called in the locked state.
*
* @param context The context to use.
* @param resource The resource to store.
*/
void coap_add_resource_lkd(coap_context_t *context, coap_resource_t *resource);
/**
* Deletes a resource identified by @p resource. The storage allocated for that
* resource is freed, and removed from the context.
*
* Note: This function must be called in the locked state.
*
* @param context This parameter is ignored, but kept for backward
* compatibility.
* @param resource The resource to delete.
*
* @return @c 1 if the resource was found (and destroyed),
* @c 0 otherwise.
*/
int coap_delete_resource_lkd(coap_context_t *context, coap_resource_t *resource);
/**
* Deletes all resources from given @p context and frees their storage.
*
@@ -132,6 +159,20 @@ void coap_delete_all_resources(coap_context_t *context);
HASH_FIND(hh, (r), (k)->s, (k)->length, (res)); \
}
/**
* Returns the resource identified by the unique string @p uri_path. If no
* resource was found, this function returns @c NULL.
*
* Note: This function must be called in the locked state.
*
* @param context The context to look for this resource.
* @param uri_path The unique string uri of the resource.
*
* @return A pointer to the resource or @c NULL if not found.
*/
coap_resource_t *coap_get_resource_from_uri_path_lkd(coap_context_t *context,
coap_str_const_t *uri_path);
/**
* Deletes an attribute.
* Note: This is for internal use only, as it is not deleted from its chain.
+5 -5
View File
@@ -60,8 +60,8 @@ void coap_resource_set_get_observable(coap_resource_t *resource, int mode);
*
* @return @c 1 if the Observe has been triggered, @c 0 otherwise.
*/
int coap_resource_notify_observers(coap_resource_t *resource,
const coap_string_t *query);
COAP_API int coap_resource_notify_observers(coap_resource_t *resource,
const coap_string_t *query);
/**
* Checks all known resources to see if they are dirty and then notifies
@@ -69,7 +69,7 @@ int coap_resource_notify_observers(coap_resource_t *resource,
*
* @param context The context to check for dirty resources.
*/
void coap_check_notify(coap_context_t *context);
COAP_API void coap_check_notify(coap_context_t *context);
/**
* Callback handler definition called when a new observe has been set up,
@@ -279,8 +279,8 @@ void coap_persist_set_observe_num(coap_resource_t *resource,
* @return @c 1 if observe cancel transmission initiation is successful,
* else @c 0.
*/
int coap_cancel_observe(coap_session_t *session, coap_binary_t *token,
coap_pdu_type_t message_type);
COAP_API int coap_cancel_observe(coap_session_t *session, coap_binary_t *token,
coap_pdu_type_t message_type);
/** @} */
+48 -2
View File
@@ -147,6 +147,30 @@ int coap_delete_observer(coap_resource_t *resource,
*/
void coap_delete_observers(coap_context_t *context, coap_session_t *session);
/**
* Initiate the sending of an Observe packet for all observers of @p resource,
* optionally matching @p query if not NULL
*
* Note: This function must be called in the locked state.
*
* @param resource The CoAP resource to use.
* @param query The Query to match against or NULL
*
* @return @c 1 if the Observe has been triggered, @c 0 otherwise.
*/
int coap_resource_notify_observers_lkd(coap_resource_t *resource,
const coap_string_t *query);
/**
* Checks all known resources to see if they are dirty and then notifies
* subscribed observers.
*
* Note: This function must be called in the locked state.
*
* @param context The context to check for dirty resources.
*/
void coap_check_notify_lkd(coap_context_t *context);
/**
* Close down persist tracking, releasing any memory used.
*
@@ -154,7 +178,29 @@ void coap_delete_observers(coap_context_t *context, coap_session_t *session);
*/
void coap_persist_cleanup(coap_context_t *context);
/** @} */
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
/**
* Cancel an observe that is being tracked by the client large receive logic.
* (coap_context_set_block_mode() has to be called)
* This will trigger the sending of an observe cancel pdu to the server.
*
* Note: This function must be called in the locked state.
*
* @param session The session that is being used for the observe.
* @param token The original token used to initiate the observation.
* @param message_type The COAP_MESSAGE_ type (NON or CON) to send the observe
* cancel pdu as.
*
* @return @c 1 if observe cancel transmission initiation is successful,
* else @c 0.
*/
int coap_cancel_observe_lkd(coap_session_t *session, coap_binary_t *token,
coap_pdu_type_t message_type);
#endif /* COAP_CLIENT_SUPPORT */
/** @} */
#endif /* COAP_SUBSCRIBE_INTERNAL_H_ */
-63
View File
@@ -22,17 +22,6 @@
/* *INDENT-OFF* */
#ifndef COAP_THREAD_IGNORE_LOCKED_MAPPING
#define coap_add_data_large_request(a,b,c,d,e,f) coap_add_data_large_request_locked(a,b,c,d,e,f)
#define coap_add_data_large_response(a,b,c,d,e,f,g,h,i,j,k,l) coap_add_data_large_response_locked(a,b,c,d,e,f,g,h,i,j,k,l)
#define coap_add_resource(c,r) coap_add_resource_locked(c,r)
#define coap_async_trigger(a) coap_async_trigger_locked(a)
#define coap_async_set_delay(a,d) coap_async_set_delay_locked(a,d)
#define coap_cache_get_by_key(s,c) coap_cache_get_by_key_locked(s,c)
#define coap_cache_get_by_pdu(s,r,b) coap_cache_get_by_pdu_locked(s,r,b)
#define coap_cache_ignore_options(c,o,n) coap_cache_ignore_options_locked(c,o,n)
#define coap_can_exit(c) coap_can_exit_locked(c)
#define coap_cancel_observe(s,t,v) coap_cancel_observe_locked(s,t,v)
#define coap_check_notify(s) coap_check_notify_locked(s)
#define coap_context_oscore_server(c,o) coap_context_oscore_server_locked(c,o)
#define coap_context_set_block_mode(c,b) coap_context_set_block_mode_locked(c,b)
#define coap_context_set_max_block_size(c,m) coap_context_set_max_block_size_locked(c,m)
@@ -40,13 +29,9 @@
#define coap_context_set_pki_root_cas(c,f,d) coap_context_set_pki_root_cas_locked(c,f,d)
#define coap_context_set_psk(c,h,k,l) coap_context_set_psk_locked(c,h,k,l)
#define coap_context_set_psk2(c,s) coap_context_set_psk2_locked(c,s)
#define coap_find_async(s,t) coap_find_async_locked(s,t)
#define coap_delete_oscore_recipient(s,r) coap_delete_oscore_recipient_locked(s,r)
#define coap_delete_resource(c,r) coap_delete_resource_locked(c,r)
#define coap_free_endpoint(e) coap_free_endpoint_locked(e)
#define coap_get_resource_from_uri_path(c,u) coap_get_resource_from_uri_path_locked(c,u)
#define coap_join_mcast_group_intf(c,g,i) coap_join_mcast_group_intf_locked(c,g,i)
#define coap_new_cache_entry(s,p,r,b,i) coap_new_cache_entry_locked(s,p,r,b,i)
#define coap_new_client_session(c,l,s,p) coap_new_client_session_locked(c,l,s,p)
#define coap_new_client_session_oscore(c,l,s,p,o) coap_new_client_session_oscore_locked(c,l,s,p,o)
#define coap_new_client_session_oscore_pki(c,l,s,p,d,o) coap_new_client_session_oscore_pki_locked(c,l,s,p,d,o)
@@ -62,10 +47,7 @@
#define coap_persist_startup(c,d,o,m,s) coap_persist_startup_locked(c,d,o,m,s)
#define coap_persist_stop(c) coap_persist_stop_locked(c)
#define coap_pdu_duplicate(o,s,l,t,d) coap_pdu_duplicate_locked(o,s,l,t,d)
#define coap_register_async(s,r,d) coap_register_async_locked(s,r,d)
#define coap_register_option(c,t) coap_register_option_locked(c,t)
#define coap_resource_notify_observers(r,q) coap_resource_notify_observers_locked(r,q)
#define coap_resource_set_dirty(r,q) coap_resource_set_dirty_locked(r,q)
#define coap_send(s,p) coap_send_locked(s,p)
#define coap_send_ack(s,r) coap_send_ack_locked(s,r)
#define coap_send_error(s,r,c,o) coap_send_error_locked(s,r,c,o)
@@ -81,39 +63,6 @@
/* Locked equivalend functions */
int coap_add_data_large_request_locked(coap_session_t *session,
coap_pdu_t *pdu,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
int coap_add_data_large_response_locked(coap_resource_t *resource,
coap_session_t *session,
const coap_pdu_t *request,
coap_pdu_t *response,
const coap_string_t *query,
uint16_t media_type,
int maxage,
uint64_t etag,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
void coap_add_resource_locked(coap_context_t *context, coap_resource_t *resource);
void coap_async_trigger_locked(coap_async_t *async);
void coap_async_set_delay_locked(coap_async_t *async, coap_tick_t delay);
coap_cache_entry_t *coap_cache_get_by_key_locked(coap_context_t *context,
const coap_cache_key_t *cache_key);
coap_cache_entry_t *coap_cache_get_by_pdu_locked(coap_session_t *session,
const coap_pdu_t *request,
coap_cache_session_based_t session_based);
int coap_cache_ignore_options_locked(coap_context_t *ctx,
const uint16_t *options,
size_t count);
int coap_can_exit_locked(coap_context_t *context);
int coap_cancel_observe_locked(coap_session_t *session, coap_binary_t *token,
coap_pdu_type_t type);
void coap_check_notify_locked(coap_context_t *context);
int coap_context_oscore_server_locked(coap_context_t *context,
coap_oscore_conf_t *oscore_conf);
void coap_context_set_block_mode_locked(coap_context_t *context,
@@ -130,11 +79,7 @@ int coap_context_set_psk2_locked(coap_context_t *ctx,
coap_dtls_spsk_t *setup_data);
int coap_delete_oscore_recipient_locked(coap_context_t *context,
coap_bin_const_t *recipient_id);
int coap_delete_resource_locked(coap_context_t *context, coap_resource_t *resource);
coap_async_t *coap_find_async_locked(coap_session_t *session, coap_bin_const_t token);
void coap_free_endpoint_locked(coap_endpoint_t *ep);
coap_resource_t *coap_get_resource_from_uri_path_locked(coap_context_t *context,
coap_str_const_t *uri_path);
int coap_join_mcast_group_intf_locked(coap_context_t *ctx, const char *group_name,
const char *ifname);
coap_subscription_t *coap_persist_observe_add_locked(coap_context_t *context,
@@ -149,13 +94,7 @@ int coap_persist_startup_locked(coap_context_t *context,
const char *obs_cnt_save_file,
uint32_t save_freq);
void coap_persist_stop_locked(coap_context_t *context);
coap_async_t *coap_register_async_locked(coap_session_t *session, const coap_pdu_t *request,
coap_tick_t delay);
size_t coap_session_max_pdu_size_locked(const coap_session_t *session);
coap_cache_entry_t *coap_new_cache_entry_locked(coap_session_t *session, const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_timeout);
coap_session_t *coap_new_client_session_locked(coap_context_t *ctx,
const coap_address_t *local_if,
const coap_address_t *server,
@@ -206,8 +145,6 @@ coap_pdu_t *coap_pdu_duplicate_locked(const coap_pdu_t *old_pdu,
const uint8_t *token,
coap_opt_filter_t *drop_options);
void coap_register_option_locked(coap_context_t *ctx, uint16_t type);
int coap_resource_notify_observers_locked(coap_resource_t *r,
const coap_string_t *query);
int coap_resource_set_dirty_locked(coap_resource_t *r,
const coap_string_t *query);
coap_mid_t coap_send_locked(coap_session_t *session, coap_pdu_t *pdu);