X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Finclude%2Finternal%2Focserverrequest.h;h=565c6e18f8e244c1c6138a03045be17c01bdc5e3;hb=53427ddcd8a79536638ce85e61a6630a9e6b3139;hp=e96ed511fd30775d8ed0ab14bf6f1f0d28468ce6;hpb=1e0a58c84d416bab6fdfbc2cf6175c2c7b150e09;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/include/internal/ocserverrequest.h b/resource/csdk/stack/include/internal/ocserverrequest.h index e96ed51..565c6e1 100644 --- a/resource/csdk/stack/include/internal/ocserverrequest.h +++ b/resource/csdk/stack/include/internal/ocserverrequest.h @@ -18,93 +18,251 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +/** + * @file + * + * This file contains the definition, types and interfaces for server request + * + */ + #ifndef OC_SERVER_REQUEST_H #define OC_SERVER_REQUEST_H -#include "occoap.h" +#include "cacommon.h" +#include "cainterface.h" /** * The signature of the internal call back functions to handle responses from entity handler */ typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse); -OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse); -OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse); -// following structure will be created in occoap and passed up the stack on the server side -typedef struct OCServerRequest { - // the REST method retrieved from received request PDU +/** + * following structure will be created in occoap and passed up the stack on the server side. + */ +typedef struct OCServerRequest +{ + /** The REST method retrieved from received request PDU.*/ OCMethod method; - // resourceUrl will be filled in occoap using the path options in received request PDU - unsigned char resourceUrl[MAX_URI_LENGTH]; - // resource query send by client - unsigned char query[MAX_QUERY_LENGTH]; - // qos is indicating if the request is CON or NON + /** Accept format retrieved from the received request PDU. */ + OCPayloadFormat acceptFormat; + + /** resourceUrl will be filled in occoap using the path options in received request PDU.*/ + char resourceUrl[MAX_URI_LENGTH]; + + /** resource query send by client.*/ + char query[MAX_QUERY_LENGTH]; + + /** qos is indicating if the request is CON or NON.*/ OCQualityOfService qos; - // Observe option field + + /** Observe option field.*/ uint32_t observationOption; + + /** Observe Result field.*/ OCStackResult observeResult; + + /** number of Responses.*/ uint8_t numResponses; + + /** Response Entity Handler .*/ OCEHResponseHandler ehResponseHandler; - ////////////////////////////////////////////////////////// - // IP address & port of client registered for observe //These - OCDevAddr requesterAddr; //Members - // CoAP token for the observe request //Might - OCCoAPToken requestToken; //Be - // The ID of CoAP pdu //Kept in - uint16_t coapID; //CoAP + + /** Remote endpoint address **/ + OCDevAddr devAddr; + + /** The ID of server request*/ + uint32_t requestId; + + /** Token for the request.*/ + CAToken_t requestToken; + + /** token length the request.*/ + uint8_t tokenLength; + + /** The ID of CoAP pdu (Kept in CoAp).*/ + uint16_t coapID; + + /** For Delayed Response.*/ uint8_t delayedResNeeded; - uint8_t secured; - ////////////////////////////////////////////////////////// - // An array of the received vendor specific header options + + /** Number of vendor specific header options.*/ uint8_t numRcvdVendorSpecificHeaderOptions; - OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS]; + + /** An Array of received vendor specific header options.*/ + OCHeaderOption *rcvdVendorSpecificHeaderOptions; + + /** Request to complete.*/ uint8_t requestComplete; + + /** Linked list; for multiple server request.*/ struct OCServerRequest * next; - // Flag indicating slow response + + /** Flag indicating slow response.*/ uint8_t slowFlag; + + /** Flag indicating notification.*/ uint8_t notificationFlag; - // reqJSON is retrieved from the payload of the received request PDU - unsigned char reqJSONPayload[1]; + + /** Payload Size.*/ + size_t payloadSize; + + /** payload is retrieved from the payload of the received request PDU.*/ + uint8_t payload[1]; + + // WARNING: Do NOT add attributes after payload as they get overwritten + // when payload content gets copied over! + } OCServerRequest; -// following structure will be created in ocstack to aggregate responses (in future: for block transfer) +/** + * Following structure will be created in ocstack to aggregate responses + * (in future: for block transfer). + */ typedef struct OCServerResponse { + + /** Linked list; for multiple server response.*/ struct OCServerResponse * next; - // this is the pointer to server payload data to be transferred - unsigned char *payload; + + /** this is the pointer to server payload data to be transferred.*/ + OCPayload* payload; + + /** Remaining size of the payload data to be transferred.*/ uint16_t remainingPayloadSize; + + /** Requests to handle.*/ OCRequestHandle requestHandle; } OCServerResponse; -OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token); +/** + * Handler function for sending a response from a single resource + * + * @param ehResponse Pointer to the response from the resource. + * + * @return + * ::OCStackResult + */ +OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse); -OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle); +/** + * Handler function for sending a response from multiple resources, such as a collection. + * Aggregates responses from multiple resource until all responses are received then sends the + * concatenated response + * + * TODO: Need to add a timeout in case a (remote?) resource does not respond + * + * @param ehResponse Pointer to the response from the resource. + * + * @return + * ::OCStackResult + */ +OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse); -OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle); +/** + * Get a server request from the server request list using the specified token. + * + * @param token Token of server request. + * @param tokenLength Length of token. + * + * @return + * OCServerRequest* + */ +OCServerRequest * GetServerRequestUsingToken (const CAToken_t token, uint8_t tokenLength); +/** + * Get a server request from the server request list using the specified handle + * + * @param handle Handle of server request. + * @return + * OCServerRequest* + */ +OCServerRequest * GetServerRequestUsingHandle (const OCRequestHandle handle); + +/** + * Get a server response from the server response list using the specified handle + * + * @param handle handle of server response. + * + * @return + * OCServerResponse* + */ +OCServerResponse * GetServerResponseUsingHandle (const OCRequestHandle handle); + +/** + * Add a server request to the server request list + * + * @param request Initialized server request that is created by this function. + * @param coapID ID of CoAP pdu. + * @param delayedResNeeded Delayed response required 0=no 1=yes. + * @param notificationFlag TODO: remove - does not appear to be used any longer. + * @param method RESTful method. + * @param numRcvdVendorSpecificHeaderOptions Number of received vendor specific header options. + * @param observationOption Value of observation option. + * @param qos Request QOS. + * @param query Request query. + * @param rcvdVendorSpecificHeaderOptions Received vendor specific header options. + * @param reqJSONPayload Request JSON payload. + * @param requestToken Request token. + * @param tokenLength Request token length. + * @param resourceUrl URL of resource. + * @param reqTotalSize Total size of the request. + * @param acceptFormat The format requested for the payload encoding. + * @param devAddr Device Address. + * + * @return + * ::OCStackResult + */ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID, - uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method, + uint8_t delayedResNeeded, uint8_t notificationFlag, OCMethod method, uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption, - OCQualityOfService qos, unsigned char * query, + OCQualityOfService qos, char * query, OCHeaderOption * rcvdVendorSpecificHeaderOptions, - unsigned char * reqJSONPayload, OCCoAPToken * requestToken, - OCDevAddr * requesterAddr, unsigned char * resourceUrl, uint32_t reqTotalSize); + uint8_t * payload, CAToken_t requestToken, + uint8_t tokenLength, + char * resourceUrl, size_t reqTotalSize, + OCPayloadFormat acceptFormat, + const OCDevAddr *devAddr); -OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle); - -// Internal function to create OCEntityHandlerRequest at the server from a received coap pdu -OCStackResult FormOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest, OCRequestHandle request, - OCMethod method, OCResourceHandle resource, unsigned char * queryBuf, unsigned char * bufReqPayload, - uint8_t numVendorOptions, OCHeaderOption * vendorOptions, OCObserveAction observeAction, - OCObservationId observeID); +/** + * Form the OCEntityHandlerRequest struct that is passed to a resource's entity handler + * + * @param entityHandlerRequest pointer to the OCEntityHandlerRequest struct that is created. + * @param request Request handle. + * @param method RESTful method. + * @param resource Resource handle. + * @param queryBuf Resource query of request. + * @param bufReqPayload JSON payload of request. + * @param numVendorOptions Number of vendor options. + * @param vendorOptions Vendor options. + * @param observeAction Observe action flag. + * @param observeID Observe ID. + * + * @return + * OCStackResult + */ +OCStackResult FormOCEntityHandlerRequest( + OCEntityHandlerRequest * entityHandlerRequest, + OCRequestHandle request, + OCMethod method, + OCDevAddr *endpoint, + OCResourceHandle resource, + char * queryBuf, + OCPayloadType payloadType, + uint8_t * payload, + size_t payloadSize, + uint8_t numVendorOptions, + OCHeaderOption * vendorOptions, + OCObserveAction observeAction, + OCObservationId observeID, + uint16_t messageID); +/** + * Find a server request in the server request list and delete + * + * @param serverRequest server request to find and delete. + */ void FindAndDeleteServerRequest(OCServerRequest * serverRequest); -void DeleteServerRequest(OCServerRequest * serverRequest); - -void FindAndDeleteServerResponse(OCServerResponse * serverResponse); - -void DeleteServerResponse(OCServerResponse * serverResponse); - #endif //OC_SERVER_REQUEST_H +