http://http://diytec.web.fc2.com/mark2r2/

Dependencies:   EthernetNetIf NTPClient_NetServices mbed ConfigFile

Committer:
mark2r2
Date:
Tue Sep 20 12:46:26 2011 +0000
Revision:
0:08a4d61cd84c
V1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mark2r2 0:08a4d61cd84c 1
mark2r2 0:08a4d61cd84c 2 /*
mark2r2 0:08a4d61cd84c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mark2r2 0:08a4d61cd84c 4
mark2r2 0:08a4d61cd84c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mark2r2 0:08a4d61cd84c 6 of this software and associated documentation files (the "Software"), to deal
mark2r2 0:08a4d61cd84c 7 in the Software without restriction, including without limitation the rights
mark2r2 0:08a4d61cd84c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mark2r2 0:08a4d61cd84c 9 copies of the Software, and to permit persons to whom the Software is
mark2r2 0:08a4d61cd84c 10 furnished to do so, subject to the following conditions:
mark2r2 0:08a4d61cd84c 11
mark2r2 0:08a4d61cd84c 12 The above copyright notice and this permission notice shall be included in
mark2r2 0:08a4d61cd84c 13 all copies or substantial portions of the Software.
mark2r2 0:08a4d61cd84c 14
mark2r2 0:08a4d61cd84c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mark2r2 0:08a4d61cd84c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mark2r2 0:08a4d61cd84c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mark2r2 0:08a4d61cd84c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mark2r2 0:08a4d61cd84c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mark2r2 0:08a4d61cd84c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mark2r2 0:08a4d61cd84c 21 THE SOFTWARE.
mark2r2 0:08a4d61cd84c 22 */
mark2r2 0:08a4d61cd84c 23
mark2r2 0:08a4d61cd84c 24 #ifndef HTTP_STREAM_H
mark2r2 0:08a4d61cd84c 25 #define HTTP_STREAM_H
mark2r2 0:08a4d61cd84c 26
mark2r2 0:08a4d61cd84c 27 #include "../HTTPData.h"
mark2r2 0:08a4d61cd84c 28 #include "mbed.h"
mark2r2 0:08a4d61cd84c 29
mark2r2 0:08a4d61cd84c 30 /** \file
mark2r2 0:08a4d61cd84c 31 HTTP Stream data source/sink header file
mark2r2 0:08a4d61cd84c 32 */
mark2r2 0:08a4d61cd84c 33
mark2r2 0:08a4d61cd84c 34 typedef uint8_t byte;
mark2r2 0:08a4d61cd84c 35
mark2r2 0:08a4d61cd84c 36 ///HTTP Client Streaming tool
mark2r2 0:08a4d61cd84c 37 /**
mark2r2 0:08a4d61cd84c 38 This class allows you to stream data from the web using a persisting HTTP connection.
mark2r2 0:08a4d61cd84c 39 To use it properly you must use a non-blocking HTTPClient method.
mark2r2 0:08a4d61cd84c 40 */
mark2r2 0:08a4d61cd84c 41 class HTTPStream : public HTTPData //Streaming buf
mark2r2 0:08a4d61cd84c 42 {
mark2r2 0:08a4d61cd84c 43 public:
mark2r2 0:08a4d61cd84c 44 ///Instantiates the object
mark2r2 0:08a4d61cd84c 45 HTTPStream();
mark2r2 0:08a4d61cd84c 46 virtual ~HTTPStream();
mark2r2 0:08a4d61cd84c 47
mark2r2 0:08a4d61cd84c 48 ///Starts to read into buffer
mark2r2 0:08a4d61cd84c 49 /**
mark2r2 0:08a4d61cd84c 50 Passes a buffer of address @a buf and size @a size to the instance.
mark2r2 0:08a4d61cd84c 51 When it receives data it will be stored in this buffer.
mark2r2 0:08a4d61cd84c 52 When the buffer is full it throttles the client until this function is called again.
mark2r2 0:08a4d61cd84c 53 */
mark2r2 0:08a4d61cd84c 54 void readNext(byte* buf, int size);
mark2r2 0:08a4d61cd84c 55
mark2r2 0:08a4d61cd84c 56 ///Returns whether there is data available to read
mark2r2 0:08a4d61cd84c 57 bool readable();
mark2r2 0:08a4d61cd84c 58
mark2r2 0:08a4d61cd84c 59 ///Returns the actual length of the payload written in the buffer
mark2r2 0:08a4d61cd84c 60 int readLen();
mark2r2 0:08a4d61cd84c 61
mark2r2 0:08a4d61cd84c 62 virtual void clear();
mark2r2 0:08a4d61cd84c 63
mark2r2 0:08a4d61cd84c 64 protected:
mark2r2 0:08a4d61cd84c 65 virtual int read(char* buf, int len);
mark2r2 0:08a4d61cd84c 66 virtual int write(const char* buf, int len);
mark2r2 0:08a4d61cd84c 67
mark2r2 0:08a4d61cd84c 68 virtual string getDataType(); //Internet media type for Content-Type header
mark2r2 0:08a4d61cd84c 69 virtual void setDataType(const string& type); //Internet media type from Content-Type header
mark2r2 0:08a4d61cd84c 70
mark2r2 0:08a4d61cd84c 71 virtual bool getIsChunked(); //For Transfer-Encoding header
mark2r2 0:08a4d61cd84c 72 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
mark2r2 0:08a4d61cd84c 73
mark2r2 0:08a4d61cd84c 74 virtual int getDataLen(); //For Content-Length header
mark2r2 0:08a4d61cd84c 75 virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length
mark2r2 0:08a4d61cd84c 76
mark2r2 0:08a4d61cd84c 77 private:
mark2r2 0:08a4d61cd84c 78 byte* m_buf;
mark2r2 0:08a4d61cd84c 79 int m_size; //Capacity
mark2r2 0:08a4d61cd84c 80 int m_len; //Length
mark2r2 0:08a4d61cd84c 81 };
mark2r2 0:08a4d61cd84c 82
mark2r2 0:08a4d61cd84c 83 #endif