Yes We Can / yeswecancoap

Dependencies:   DebugLib EthernetInterface cantcoap mbed-rtos

Dependents:   COAP coap

Fork of yeswecancoap by Sille Van Landschoot

Embed: (wiki syntax)

« Back to documentation index

Request Class Reference

Request Class Reference

Coap Request class This class contains the coap request. More...

#include <request.h>

Public Member Functions

 Request ()
 Memory-managed constructor.
 Request (uint8_t *pdu, int pduLength)
 Memory-managed constructor.
 Request (uint8_t *buffer, int bufferLength, int pduLength)
 Construct a PDU using an external buffer.
char * getContent ()
 Get the payload content send with the request.
int getContentLength ()
 Get the lenght of the content.
int hasContent ()
 Check if the request has content.

Detailed Description

Coap Request class This class contains the coap request.

It let's all the information from the request to process a response.

Definition at line 9 of file request.h.


Constructor & Destructor Documentation

Request (  )

Memory-managed constructor.

Buffer for PDU is dynamically sized and allocated by the object. When using this constructor, the CoapPDU class will allocate space for the PDU. Contrast this with the parameterized constructors, which allow the use of an external buffer.

Note, the PDU container and space can be reused by issuing a CoapPDU::reset(). If the new PDU exceeds the space of the previously allocated memory, then further memory will be dynamically allocated.

Deleting the object will free the Object container and all dynamically allocated memory.

Note:
It would have been nice to use something like UDP_CORK or MSG_MORE, to allow separate buffers for token, options, and payload but these FLAGS aren't implemented for UDP in LwIP so stuck with one buffer for now.

CoAP version defaults to 1.

See also:
Request::Request(uint8_t *pdu, int pduLength), Request::Request::(uint8_t *buffer, int bufferLength, int pduLength), Request:Request()~

Definition at line 3 of file request.cpp.

Request ( uint8_t *  pdu,
int  pduLength 
)

Memory-managed constructor.

Buffer for PDU is dynamically sized and allocated by the object. When using this constructor, the CoapPDU class will allocate space for the PDU. Contrast this with the parameterized constructors, which allow the use of an external buffer.

Note, the PDU container and space can be reused by issuing a CoapPDU::reset(). If the new PDU exceeds the space of the previously allocated memory, then further memory will be dynamically allocated.

Deleting the object will free the Object container and all dynamically allocated memory.

Note:
It would have been nice to use something like UDP_CORK or MSG_MORE, to allow separate buffers for token, options, and payload but these FLAGS aren't implemented for UDP in LwIP so stuck with one buffer for now.

CoAP version defaults to 1.

See also:
Request::Request(uint8_t *pdu, int pduLength), Request::Request::(uint8_t *buffer, int bufferLength, int pduLength), Request:Request()~

Definition at line 8 of file request.cpp.

Request ( uint8_t *  buffer,
int  bufferLength,
int  pduLength 
)

Construct a PDU using an external buffer.

No copy of the buffer is made. This differs from CoapPDU::CoapPDU(uint8_t *pdu, int pduLength) in that the buffer may be larger than the actual CoAP PDU contained int the buffer. This is typically used when a large buffer is reused multiple times. Note that pduLength can be 0.

If an actual CoAP PDU is passed in the buffer, pduLength should match its length. CoapPDU::validate() must be called to initiate the object before member functions can be used.

A PDU constructed in this manner must be validated with CoapPDU::validate() before the member variables will be accessible.

Warning:
The validation call parses the PDU structure to set some internal parameters. If you do not validate the PDU, then the behaviour of member access functions will be undefined.

The buffer can be reused by issuing a CoapPDU::reset() but the class will not change the size of the buffer. If the newly constructed PDU exceeds the size of the buffer, the function called (for example CoapPDU::addOption) will fail.

Deleting this object will only delete the Object container and will not delete the PDU buffer.

Parameters:
bufferA buffer which either contains a CoAP PDU or is intended to be used to construct one.
bufferLengthThe length of the buffer
pduLengthIf the buffer contains a CoAP PDU, this specifies the length of the PDU within the buffer.
See also:
Request::Request(), Request::Request(uint8_t *pdu, int pduLength)

Definition at line 13 of file request.cpp.


Member Function Documentation

char * getContent (  )

Get the payload content send with the request.

Returns:
Pointer to the content

Definition at line 18 of file request.cpp.

int getContentLength (  )

Get the lenght of the content.

  void get_hello(Request* req, Response* res)
  {
       if(req->hasContent()){
          printf("Content: %s\r\n", req->getContent());
       }
  }
Returns:
integer containing the length of the content

Definition at line 23 of file request.cpp.

int hasContent (  )

Check if the request has content.

Returns:
boolean value depending on if the request contains any content

Definition at line 28 of file request.cpp.