39 #include <satcat5/coap_connection.h>
40 #include <satcat5/coap_endpoint.h>
52 constexpr
explicit Resource(
const char* uri_path)
67 {
return (uri[0] ==
'/') ? (uri + 1) : (uri); }
74 {
return !(*
this == other); }
CoAP request/response handling for a single client-server connection.
bool error_response(satcat5::coap::Code code, const char *why=0)
If able, return an error in response to an incoming request from a remote client.
Variant of coap::Connection for UDP connections.
Variant for a UDP client or server with multiple active connections.
satcat5::udp::Dispatch * udp() const
Pointer to the parent's network interface.
Base-class for parsing CoAP message headers and options.
Resource that echos back any incoming payload.
bool request_get(Connection *obj, Reader *msg) override
GET requests respond with the payload from the request.
constexpr ResourceEcho(const char *uri_path)
Constructor (user calls add_resource).
ResourceEcho(ResourceServer *server, const char *uri_path)
Constructor (parent class calls add_resource).
Resource that returns a fixed status code for all requests.
constexpr ResourceError(const char *uri_path, Code errcode)
Constructor (user calls add_resource).
const satcat5::coap::Code m_errcode
All request types respond with the specified error code.
bool request_delete(Connection *obj, Reader *msg) override
All request types respond with the specified error code.
bool request_put(Connection *obj, Reader *msg) override
All request types respond with the specified error code.
bool request_post(Connection *obj, Reader *msg) override
All request types respond with the specified error code.
ResourceError(ResourceServer *server, const char *uri_path, Code errcode)
Constructor (parent class calls add_resource).
bool request_get(Connection *obj, Reader *msg) override
All request types respond with the specified error code.
Define a single CoAP resource.
virtual bool request_delete(Connection *obj, Reader *msg)
Event handlers for GET, POST, PUT, and DELETE queries.
virtual bool request_put(Connection *obj, Reader *msg)
Event handlers for GET, POST, PUT, and DELETE queries.
const char *const m_uri_path
URI-Path for this resource.
bool operator==(const Resource &other) const
Comparison operators for comparing two URI-paths.
virtual bool request_post(Connection *obj, Reader *msg)
Event handlers for GET, POST, PUT, and DELETE queries.
static constexpr const char * normalize_uri(const char *uri)
Remove leading slash from a user-provided path.
satcat5::ip::Dispatch * ip() const
Pointer to the parent's network interface.
~Resource() SATCAT5_OPTIONAL_DTOR
Destructor is only accessible to the child object.
constexpr Resource(const char *uri_path)
Simple constructor sets the URI path for the resource.
bool operator!=(const Resource &other) const
Comparison operators for comparing two URI-paths.
virtual bool request_get(Connection *obj, Reader *msg)
Event handlers for GET, POST, PUT, and DELETE queries.
ResourceServer *const m_server
Optional pointer to the server object.
satcat5::udp::Dispatch * udp() const
Pointer to the parent's network interface.
Resource that creates a log::Log entry.
constexpr ResourceLog(const char *uri_path, s8 priority)
Constructor (user calls add_resource).
s8 m_priority
Priority for created log messages.
bool request_post(Connection *obj, Reader *msg) override
POST requests create a log::Log entry.
ResourceLog(ResourceServer *server, const char *uri_path, s8 priority)
Constructor (parent class calls add_resource).
The NullResource does not implement GET, POST, PUT, or DELETE.
Manager for several Resource objects available on an Endpoint.
ResourceServer(satcat5::udp::Dispatch *udp, satcat5::udp::Port port=satcat5::udp::PORT_COAP)
Constructor. By default, bind this server to port 5683.
void coap_request(Connection *obj, Reader *msg) override
Handler for an incoming request.
satcat5::coap::ConnectionUdp m_connection
Single UDP connection.
void remove_resource(Resource *resource)
Remove a Resource from the linked list.
satcat5::util::List< Resource > m_resources
List of resources.
void add_resource(Resource *resource)
Add a Resource to the linked list.
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Dispatcher sorts incoming UDP messages by port index.
Helper functions for manipulating singly-linked lists.
Templated linked-list class.
constexpr Code CODE_BAD_METHOD(4, 5)
< 4.04 Not Found
CoAP message header CODE field (Section 12.1).
UDP and TCP ports are both 16-bit unsigned integers.
Miscellaneous mathematical utility functions.