Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DebugLib EthernetInterface cantcoap mbed-rtos
Fork of yeswecancoap by
request.h
00001 #pragma once 00002 00003 #include "cantcoap.h" 00004 00005 00006 /** Coap Request class 00007 * This class contains the coap request. It let's all the information from the request to process a response. 00008 */ 00009 class Request : protected CoapPDU 00010 { 00011 public: 00012 /** Memory-managed constructor. Buffer for PDU is dynamically sized and allocated by the object. 00013 * When using this constructor, the CoapPDU class will allocate space for the PDU. 00014 * Contrast this with the parameterized constructors, which allow the use of an external buffer. 00015 * 00016 * Note, the PDU container and space can be reused by issuing a CoapPDU::reset(). If the new PDU exceeds the 00017 * space of the previously allocated memory, then further memory will be dynamically allocated. 00018 * 00019 * Deleting the object will free the Object container and all dynamically allocated memory. 00020 * 00021 * \note It would have been nice to use something like UDP_CORK or MSG_MORE, to allow separate buffers 00022 * for token, options, and payload but these FLAGS aren't implemented for UDP in LwIP so stuck with one buffer for now. 00023 * 00024 * CoAP version defaults to 1. 00025 * 00026 * \sa Request::Request(uint8_t *pdu, int pduLength), Request::Request::(uint8_t *buffer, int bufferLength, int pduLength), 00027 * Request:Request()~ 00028 * 00029 */ 00030 Request(); 00031 00032 /** Memory-managed constructor. Buffer for PDU is dynamically sized and allocated by the object. 00033 * When using this constructor, the CoapPDU class will allocate space for the PDU. 00034 * Contrast this with the parameterized constructors, which allow the use of an external buffer. 00035 * 00036 * Note, the PDU container and space can be reused by issuing a CoapPDU::reset(). If the new PDU exceeds the 00037 * space of the previously allocated memory, then further memory will be dynamically allocated. 00038 * 00039 * Deleting the object will free the Object container and all dynamically allocated memory. 00040 * 00041 * \note It would have been nice to use something like UDP_CORK or MSG_MORE, to allow separate buffers 00042 * for token, options, and payload but these FLAGS aren't implemented for UDP in LwIP so stuck with one buffer for now. 00043 * 00044 * CoAP version defaults to 1. 00045 * 00046 * \sa Request::Request(uint8_t *pdu, int pduLength), Request::Request::(uint8_t *buffer, int bufferLength, int pduLength), 00047 * Request:Request()~ 00048 * 00049 */ 00050 Request(uint8_t *pdu, int pduLength); 00051 00052 /** Construct a PDU using an external buffer. No copy of the buffer is made. 00053 * This differs from CoapPDU::CoapPDU(uint8_t *pdu, int pduLength) in that the buffer may be larger 00054 * than the actual CoAP PDU contained int the buffer. This is typically used when a large buffer is reused 00055 * multiple times. Note that \b pduLength can be 0. 00056 * 00057 * If an actual CoAP PDU is passed in the buffer, \b pduLength should match its length. CoapPDU::validate() must 00058 * be called to initiate the object before member functions can be used. 00059 * 00060 * A PDU constructed in this manner must be validated with CoapPDU::validate() before the member variables will be accessible. 00061 * 00062 * \warning The validation call parses the PDU structure to set some internal parameters. If you do 00063 * not validate the PDU, then the behaviour of member access functions will be undefined. 00064 * 00065 * The buffer can be reused by issuing a CoapPDU::reset() but the class will not change the size of the buffer. If the 00066 * newly constructed PDU exceeds the size of the buffer, the function called (for example CoapPDU::addOption) will fail. 00067 * 00068 * Deleting this object will only delete the Object container and will not delete the PDU buffer. 00069 * 00070 * \param buffer A buffer which either contains a CoAP PDU or is intended to be used to construct one. 00071 * \param bufferLength The length of the buffer 00072 * \param pduLength If the buffer contains a CoAP PDU, this specifies the length of the PDU within the buffer. 00073 * 00074 * \sa Request::Request(), Request::Request(uint8_t *pdu, int pduLength) 00075 */ 00076 Request(uint8_t *buffer, int bufferLength, int pduLength); 00077 00078 using CoapPDU::Type; 00079 using CoapPDU::Code; 00080 00081 using CoapPDU::getType; 00082 using CoapPDU::getCode; 00083 00084 /** Get the payload content send with the request 00085 * @return Pointer to the content 00086 */ 00087 char* getContent(); 00088 00089 /** Get the lenght of the content 00090 * @code 00091 * void get_hello(Request* req, Response* res) 00092 * { 00093 * if(req->hasContent()){ 00094 * printf("Content: %s\r\n", req->getContent()); 00095 * } 00096 * } 00097 * @endcode 00098 * @return integer containing the length of the content 00099 */ 00100 int getContentLength(); 00101 00102 /** Check if the request has content 00103 * @return boolean value depending on if the request contains any content 00104 */ 00105 int hasContent(); 00106 00107 /* 00108 int getMessageId(); 00109 int getToken();*/ 00110 00111 //using getContentFormat(); 00112 00113 //getOptions(); 00114 00115 00116 };
Generated on Wed Jul 13 2022 18:09:57 by
1.7.2
