A Port of TI's Webserver for the CC3000

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HttpDynamic.h Source File

HttpDynamic.h

00001 /*****************************************************************************
00002 *
00003 *  HttpDynamic.h
00004 *  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
00005 *
00006 *  Redistribution and use in source and binary forms, with or without
00007 *  modification, are permitted provided that the following conditions
00008 *  are met:
00009 *
00010 *    Redistributions of source code must retain the above copyright
00011 *    notice, this list of conditions and the following disclaimer.
00012 *
00013 *    Redistributions in binary form must reproduce the above copyright
00014 *    notice, this list of conditions and the following disclaimer in the
00015 *    documentation and/or other materials provided with the   
00016 *    distribution.
00017 *
00018 *    Neither the name of Texas Instruments Incorporated nor the names of
00019 *    its contributors may be used to endorse or promote products derived
00020 *    from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00026 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 *
00034 *****************************************************************************/
00035 #ifndef _HTTP_DYNAMIC_H_
00036 #define _HTTP_DYNAMIC_H_
00037 
00038 #include "HttpConfig.h"
00039 
00040 #ifdef HTTP_CORE_ENABLE_DYNAMIC
00041 
00042 /** 
00043  * @defgroup HttpDynamic Dynamic request handler module
00044  * This module implements dynamic content processing for HTTP requests.
00045  * All requests are handled by C code functions, and the response contents is returned via HttpResopnse routines
00046  * Note this module is only compiled if HTTP_CORE_ENABLE_DYNAMIC is defined in HttpConfig.h
00047  *
00048  * @{
00049  */
00050 
00051 #include "HttpRequest.h"
00052 
00053 #define HTTP_DYNAMIC_NUM_OF_RESOURCES       2
00054 #define HTTP_DYNAMIC_MAX_RESOURCE_LEN       14
00055 #define HTTP_DYNAMIC_LED_NUM_LEN            4
00056 #define HTTP_DYNAMIC_LED_ACTION_LEN         7
00057 #define HTTP_DYNAMIC_TEMPR_UNIT_LEN         5
00058 #define HTTP_DYNAMIC_CONF_PROTO_LEN         6
00059 #define HTTP_DYNAMIC_CONTENT_BODY_LEN       17
00060 
00061 
00062 enum HttpDynamicNumOfResources
00063 {
00064     LED,
00065     WHEEL,
00066 };
00067 
00068 enum HttpDynamicLedNumber
00069 {
00070     NOLED,
00071     LED_1,
00072     LED_2,
00073     LED_3,
00074     LED_4,
00075     //LED_5,
00076     //LED_6,
00077     //LED_7,
00078     //LED_8
00079 };
00080 
00081 enum HttpDynamicLedAction
00082 {
00083     OFF,
00084     ON,
00085     toggle,
00086 };
00087 
00088 enum HttpDynamicWheelAction
00089 {
00090     NONE,
00091    GETSTATUS
00092 };
00093 
00094 
00095 /* input params structure */
00096 struct HttpDynamicLedInParam
00097 {
00098     enum HttpDynamicLedNumber   uLedNumber;
00099     enum HttpDynamicLedAction       uLedAction;
00100 };
00101 
00102 struct HttpDynamicWheelInParam
00103 {
00104     enum HttpDynamicWheelAction uWheelAction;
00105 };
00106 
00107 
00108 typedef union
00109 {
00110     struct HttpDynamicLedInParam        uLedParam;
00111     struct HttpDynamicWheelInParam          uWheelParam;
00112 }inputParams;
00113 
00114 struct HttpDynamicLedOutParam
00115 {
00116     uint8   uLedDummyOut;
00117 };
00118 
00119 struct HttpDynamicWheelOutParam
00120 {
00121         uint8   uLedDummyOut;
00122         uint8   uWheelPosition;
00123     uint16  uWheelValue;
00124 };
00125 
00126 
00127 typedef union
00128 {
00129     struct HttpDynamicLedOutParam       uLedParam;
00130     struct HttpDynamicWheelOutParam sWheelParam;
00131 }outputParams;
00132 
00133 typedef struct 
00134 {
00135     inputParams dynamicHandlerInParam;
00136     outputParams    dynamicHandlerOutParam;
00137     enum HttpDynamicNumOfResources  resourceType;
00138     void (*pDynamicHandler)(inputParams,  outputParams*);
00139 }PerConnDynamicContent;
00140 
00141 
00142 /**
00143  * Initialize HttpDynamic module state for a new request, and identify the request
00144  * This function must examine the specified resource string and determine whether it can commit to process this request
00145  * Also, if the resource string includes any information that this module needs in order to process the request (such as the contents of the query string)
00146  * then it is the responsibility of this function to parse this information and store it in a connection-specific struct.
00147  * If this function returns nonzero, then the core will call HttpDynamic_ProcessRequest() with the rest of the request details.
00148  * @param uConnection The number of the connection. This value is guaranteed to satisfy: 0 <= uConnection < HTTP_CORE_MAX_CONNECTIONS
00149  * @param resource The resource part of the URL, as specified by the browser in the request, including any query string (and hash)
00150  *                 Note: The resource string exists ONLY during the call to this function. The string pointer should not be copied by this function.
00151  * @return nonzero if request is to be handled by this module. zero if not.
00152  */
00153 int HttpDynamic_InitRequest(uint16 uConnection, struct HttpBlob resource);
00154 
00155 /**
00156  * Process a dynamic-content HTTP request
00157  * This function is only be called by the core, if HttpDynamic_InitRequest() returns nonzero.
00158  * This function processes the specified HTTP request, and send the response on the connection specified by request->uConnection.
00159  * This function must call the HttpResponse_*() functions in order to send data back to the browser.
00160  * Please refer to HttpResponse.h for more information.
00161  * @param request Pointer to all data available about the request
00162  */
00163 void HttpDynamic_ProcessRequest(struct HttpRequest* request);
00164 
00165 /// @}
00166 
00167 #endif // HTTP_CORE_ENABLE_DYNAMIC
00168 
00169 #endif // _HTTP_DYNAMIC_H_
00170