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/
HTTPFile.h@0:1855a008f28e, 2012-08-16 (annotated)
- Committer:
- togayan
- Date:
- Thu Aug 16 15:49:19 2012 +0000
- Revision:
- 0:1855a008f28e
- Child:
- 4:ab3092d15121
First revision of mpod_nhk_english.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:1855a008f28e | 28 | /** Read a piece of data to be transmitted |
togayan | 0:1855a008f28e | 29 | * @param buf Pointer to the buffer on which to copy the data |
togayan | 0:1855a008f28e | 30 | * @param len Length of the buffer |
togayan | 0:1855a008f28e | 31 | * @param pReadLen Pointer to the variable on which the actual copied data length will be stored |
togayan | 0:1855a008f28e | 32 | */ |
togayan | 0:1855a008f28e | 33 | virtual int read(char* buf, size_t len, size_t* pReadLen); |
togayan | 0:1855a008f28e | 34 | |
togayan | 0:1855a008f28e | 35 | /** Write a piece of data transmitted by the server |
togayan | 0:1855a008f28e | 36 | * @param buf Pointer to the buffer from which to copy the data |
togayan | 0:1855a008f28e | 37 | * @param len Length of the buffer |
togayan | 0:1855a008f28e | 38 | */ |
togayan | 0:1855a008f28e | 39 | virtual int write(const char* buf, size_t len); |
togayan | 0:1855a008f28e | 40 | |
togayan | 0:1855a008f28e | 41 | /** Get MIME type |
togayan | 0:1855a008f28e | 42 | * @param type Internet media type from Content-Type header |
togayan | 0:1855a008f28e | 43 | */ |
togayan | 0:1855a008f28e | 44 | virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header |
togayan | 0:1855a008f28e | 45 | |
togayan | 0:1855a008f28e | 46 | /** Set MIME type |
togayan | 0:1855a008f28e | 47 | * @param type Internet media type from Content-Type header |
togayan | 0:1855a008f28e | 48 | */ |
togayan | 0:1855a008f28e | 49 | virtual void setDataType(const char* type); |
togayan | 0:1855a008f28e | 50 | |
togayan | 0:1855a008f28e | 51 | /** Determine whether the HTTP client should chunk the data |
togayan | 0:1855a008f28e | 52 | * Used for Transfer-Encoding header |
togayan | 0:1855a008f28e | 53 | */ |
togayan | 0:1855a008f28e | 54 | virtual bool getIsChunked(); |
togayan | 0:1855a008f28e | 55 | |
togayan | 0:1855a008f28e | 56 | /** Determine whether the data is chunked |
togayan | 0:1855a008f28e | 57 | * Recovered from Transfer-Encoding header |
togayan | 0:1855a008f28e | 58 | */ |
togayan | 0:1855a008f28e | 59 | virtual void setIsChunked(bool chunked); |
togayan | 0:1855a008f28e | 60 | |
togayan | 0:1855a008f28e | 61 | /** If the data is not chunked, get its size |
togayan | 0:1855a008f28e | 62 | * Used for Content-Length header |
togayan | 0:1855a008f28e | 63 | */ |
togayan | 0:1855a008f28e | 64 | virtual size_t getDataLen(); |
togayan | 0:1855a008f28e | 65 | |
togayan | 0:1855a008f28e | 66 | /** If the data is not chunked, set its size |
togayan | 0:1855a008f28e | 67 | * From Content-Length header |
togayan | 0:1855a008f28e | 68 | */ |
togayan | 0:1855a008f28e | 69 | virtual void setDataLen(size_t len); |
togayan | 0:1855a008f28e | 70 | |
togayan | 0:1855a008f28e | 71 | private: |
togayan | 0:1855a008f28e | 72 | bool openFile(const char* mode); //true on success, false otherwise |
togayan | 0:1855a008f28e | 73 | void closeFile(); |
togayan | 0:1855a008f28e | 74 | |
togayan | 0:1855a008f28e | 75 | FILE* m_fp; |
togayan | 0:1855a008f28e | 76 | string m_path; |
togayan | 0:1855a008f28e | 77 | size_t m_len; |
togayan | 0:1855a008f28e | 78 | bool m_chunked; |
togayan | 0:1855a008f28e | 79 | }; |
togayan | 0:1855a008f28e | 80 | |
togayan | 0:1855a008f28e | 81 | #endif /* HTTPFILE_H_ */ |