Simple IoT Board用のライブラリです。 ESP8266ライブラリの軽量化 送信のみのソフトシリアルライブラリを含んでいます。

Dependents:   SITB_HttpGetSample SITB_IFTTTSample SITB_INA226PRC AmbientExampleSITB ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IHTTPData.h Source File

IHTTPData.h

00001 /* IHTTPData.h */
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 
00020 #ifndef IHTTPDATA_H
00021 #define IHTTPDATA_H
00022 
00023 #include <cstring>
00024 
00025 using std::size_t;
00026 
00027 class IHTTPData
00028 {
00029   protected:
00030   /** Get a specific header
00031   *
00032   */
00033   virtual bool getHeader(char* header, size_t maxHeaderLen) { return false; }
00034 };
00035 
00036 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
00037 class IHTTPDataOut : public IHTTPData
00038 {
00039 protected:
00040   friend class HTTPClient;
00041   
00042   /** Reset stream to its beginning 
00043    * Called by the HTTPClient on each new request
00044    */
00045   virtual void readReset() = 0;
00046 
00047   /** Read a piece of data to be transmitted
00048    * @param buf Pointer to the buffer on which to copy the data
00049    * @param len Length of the buffer
00050    * @param pReadLen Pointer to the variable on which the actual copied data length will be stored
00051    */
00052   virtual int read(char* buf, size_t len, size_t* pReadLen) = 0;
00053   
00054   /** Get MIME type
00055    * @param type Internet media type from Content-Type header
00056    */
00057   virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header
00058   
00059   /** Determine whether the HTTP client should chunk the data
00060    *  Used for Transfer-Encoding header
00061    */
00062   virtual bool getIsChunked() = 0;
00063   
00064   /** If the data is not chunked, get its size
00065    *  Used for Content-Length header
00066    */
00067   virtual size_t getDataLen() = 0;
00068 
00069 };
00070 
00071 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
00072 class IHTTPDataIn : public IHTTPData
00073 {
00074 protected:
00075   friend class HTTPClient;
00076 
00077   /** Reset stream to its beginning 
00078    * Called by the HTTPClient on each new request
00079    */
00080   virtual void writeReset() = 0;
00081 
00082   /** Write a piece of data transmitted by the server
00083    * @param buf Pointer to the buffer from which to copy the data
00084    * @param len Length of the buffer
00085    */
00086   virtual int write(const char* buf, size_t len) = 0;
00087 
00088   /** Set MIME type
00089    * @param type Internet media type from Content-Type header
00090    */
00091   virtual void setDataType(const char* type) = 0;
00092 
00093   /** Determine whether the data is chunked
00094    *  Recovered from Transfer-Encoding header
00095    */
00096   virtual void setIsChunked(bool chunked) = 0;
00097   
00098   /** If the data is not chunked, set its size
00099    * From Content-Length header
00100    */
00101   virtual void setDataLen(size_t len) = 0;
00102 
00103 };
00104 
00105 #endif