Download NHK English news podcast automatically. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/

Dependencies:   BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem mbed-rtos mbed

Download NHK English news podcast automatically. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/

Committer:
togayan
Date:
Sat Sep 01 04:12:37 2012 +0000
Revision:
4:ab3092d15121
Parent:
0:1855a008f28e
HTTPFile was changed to follow the latest HTTPClient library.; BlinkLed was isolated as a library.; Change LED port from LED1,2 to LED3,4 for the specification of pwmout.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
togayan 0:1855a008f28e 1 /* HTTPFile.h */
togayan 0:1855a008f28e 2 #ifndef HTTPFILE_H_
togayan 0:1855a008f28e 3 #define HTTPFILE_H_
togayan 0:1855a008f28e 4
togayan 0:1855a008f28e 5 #include "IHTTPData.h"
togayan 0:1855a008f28e 6 #include "FATFileSystem.h"
togayan 0:1855a008f28e 7 #include <string>
togayan 0:1855a008f28e 8
togayan 0:1855a008f28e 9 using std::string;
togayan 0:1855a008f28e 10
togayan 0:1855a008f28e 11 /** A data endpoint to store file
togayan 0:1855a008f28e 12 */
togayan 0:1855a008f28e 13 class HTTPFile : public IHTTPDataIn, public IHTTPDataOut
togayan 0:1855a008f28e 14 {
togayan 0:1855a008f28e 15 public:
togayan 0:1855a008f28e 16 /** Create an HTTPFile instance for input
togayan 0:1855a008f28e 17 * @param path Path of file to store the incoming string
togayan 0:1855a008f28e 18 */
togayan 0:1855a008f28e 19 HTTPFile(const char* path);
togayan 0:1855a008f28e 20
togayan 0:1855a008f28e 21 ~HTTPFile();
togayan 0:1855a008f28e 22
togayan 0:1855a008f28e 23 /** Forces file closure
togayan 0:1855a008f28e 24 */
togayan 0:1855a008f28e 25 void clear();
togayan 0:1855a008f28e 26
togayan 0:1855a008f28e 27 protected:
togayan 4:ab3092d15121 28 /** Reset stream to its beginning
togayan 4:ab3092d15121 29 * Called by the HTTPClient on each new request
togayan 4:ab3092d15121 30 */
togayan 4:ab3092d15121 31 virtual void readReset();
togayan 4:ab3092d15121 32
togayan 0:1855a008f28e 33 /** Read a piece of data to be transmitted
togayan 0:1855a008f28e 34 * @param buf Pointer to the buffer on which to copy the data
togayan 0:1855a008f28e 35 * @param len Length of the buffer
togayan 0:1855a008f28e 36 * @param pReadLen Pointer to the variable on which the actual copied data length will be stored
togayan 0:1855a008f28e 37 */
togayan 0:1855a008f28e 38 virtual int read(char* buf, size_t len, size_t* pReadLen);
togayan 0:1855a008f28e 39
togayan 4:ab3092d15121 40 /** Reset stream to its beginning
togayan 4:ab3092d15121 41 * Called by the HTTPClient on each new request
togayan 4:ab3092d15121 42 */
togayan 4:ab3092d15121 43 virtual void writeReset();
togayan 4:ab3092d15121 44
togayan 0:1855a008f28e 45 /** Write a piece of data transmitted by the server
togayan 0:1855a008f28e 46 * @param buf Pointer to the buffer from which to copy the data
togayan 0:1855a008f28e 47 * @param len Length of the buffer
togayan 0:1855a008f28e 48 */
togayan 0:1855a008f28e 49 virtual int write(const char* buf, size_t len);
togayan 0:1855a008f28e 50
togayan 0:1855a008f28e 51 /** Get MIME type
togayan 0:1855a008f28e 52 * @param type Internet media type from Content-Type header
togayan 0:1855a008f28e 53 */
togayan 0:1855a008f28e 54 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
togayan 0:1855a008f28e 55
togayan 0:1855a008f28e 56 /** Set MIME type
togayan 0:1855a008f28e 57 * @param type Internet media type from Content-Type header
togayan 0:1855a008f28e 58 */
togayan 0:1855a008f28e 59 virtual void setDataType(const char* type);
togayan 0:1855a008f28e 60
togayan 0:1855a008f28e 61 /** Determine whether the HTTP client should chunk the data
togayan 0:1855a008f28e 62 * Used for Transfer-Encoding header
togayan 0:1855a008f28e 63 */
togayan 0:1855a008f28e 64 virtual bool getIsChunked();
togayan 0:1855a008f28e 65
togayan 0:1855a008f28e 66 /** Determine whether the data is chunked
togayan 0:1855a008f28e 67 * Recovered from Transfer-Encoding header
togayan 0:1855a008f28e 68 */
togayan 0:1855a008f28e 69 virtual void setIsChunked(bool chunked);
togayan 0:1855a008f28e 70
togayan 0:1855a008f28e 71 /** If the data is not chunked, get its size
togayan 0:1855a008f28e 72 * Used for Content-Length header
togayan 0:1855a008f28e 73 */
togayan 0:1855a008f28e 74 virtual size_t getDataLen();
togayan 0:1855a008f28e 75
togayan 0:1855a008f28e 76 /** If the data is not chunked, set its size
togayan 0:1855a008f28e 77 * From Content-Length header
togayan 0:1855a008f28e 78 */
togayan 0:1855a008f28e 79 virtual void setDataLen(size_t len);
togayan 0:1855a008f28e 80
togayan 0:1855a008f28e 81 private:
togayan 0:1855a008f28e 82 bool openFile(const char* mode); //true on success, false otherwise
togayan 0:1855a008f28e 83 void closeFile();
togayan 0:1855a008f28e 84
togayan 0:1855a008f28e 85 FILE* m_fp;
togayan 0:1855a008f28e 86 string m_path;
togayan 0:1855a008f28e 87 size_t m_len;
togayan 0:1855a008f28e 88 bool m_chunked;
togayan 0:1855a008f28e 89 };
togayan 0:1855a008f28e 90
togayan 0:1855a008f28e 91 #endif /* HTTPFILE_H_ */