Embedded C project:18/12/2014

Dependencies:   DS1307 TextLCD mbed

Committer:
ninoderkinderen
Date:
Thu Dec 18 09:35:49 2014 +0000
Revision:
0:8d87bc453349
Programma embedded C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ninoderkinderen 0:8d87bc453349 1
ninoderkinderen 0:8d87bc453349 2 /*
ninoderkinderen 0:8d87bc453349 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
ninoderkinderen 0:8d87bc453349 4
ninoderkinderen 0:8d87bc453349 5 Permission is hereby granted, free of charge, to any person obtaining a copy
ninoderkinderen 0:8d87bc453349 6 of this software and associated documentation files (the "Software"), to deal
ninoderkinderen 0:8d87bc453349 7 in the Software without restriction, including without limitation the rights
ninoderkinderen 0:8d87bc453349 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ninoderkinderen 0:8d87bc453349 9 copies of the Software, and to permit persons to whom the Software is
ninoderkinderen 0:8d87bc453349 10 furnished to do so, subject to the following conditions:
ninoderkinderen 0:8d87bc453349 11
ninoderkinderen 0:8d87bc453349 12 The above copyright notice and this permission notice shall be included in
ninoderkinderen 0:8d87bc453349 13 all copies or substantial portions of the Software.
ninoderkinderen 0:8d87bc453349 14
ninoderkinderen 0:8d87bc453349 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ninoderkinderen 0:8d87bc453349 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ninoderkinderen 0:8d87bc453349 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ninoderkinderen 0:8d87bc453349 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ninoderkinderen 0:8d87bc453349 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ninoderkinderen 0:8d87bc453349 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ninoderkinderen 0:8d87bc453349 21 THE SOFTWARE.
ninoderkinderen 0:8d87bc453349 22 */
ninoderkinderen 0:8d87bc453349 23
ninoderkinderen 0:8d87bc453349 24 /** \file
ninoderkinderen 0:8d87bc453349 25 HTTP File data source/sink header file
ninoderkinderen 0:8d87bc453349 26 */
ninoderkinderen 0:8d87bc453349 27
ninoderkinderen 0:8d87bc453349 28 #ifndef HTTP_FILE_H
ninoderkinderen 0:8d87bc453349 29 #define HTTP_FILE_H
ninoderkinderen 0:8d87bc453349 30
ninoderkinderen 0:8d87bc453349 31 #include "../HTTPData.h"
ninoderkinderen 0:8d87bc453349 32 #include "mbed.h"
ninoderkinderen 0:8d87bc453349 33
ninoderkinderen 0:8d87bc453349 34 ///HTTP Client data container for files
ninoderkinderen 0:8d87bc453349 35 /**
ninoderkinderen 0:8d87bc453349 36 This class provides file access/storage for HTTP requests and responses' data payloads.
ninoderkinderen 0:8d87bc453349 37
ninoderkinderen 0:8d87bc453349 38
ninoderkinderen 0:8d87bc453349 39 */
ninoderkinderen 0:8d87bc453349 40 class HTTPFile : public HTTPData //Read or Write data from a file
ninoderkinderen 0:8d87bc453349 41 {
ninoderkinderen 0:8d87bc453349 42 public:
ninoderkinderen 0:8d87bc453349 43 ///Instantiates data source/sink with file in param.
ninoderkinderen 0:8d87bc453349 44 /**
ninoderkinderen 0:8d87bc453349 45 Uses file at path @a path.
ninoderkinderen 0:8d87bc453349 46 It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance.
ninoderkinderen 0:8d87bc453349 47 Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing.
ninoderkinderen 0:8d87bc453349 48
ninoderkinderen 0:8d87bc453349 49 @note
ninoderkinderen 0:8d87bc453349 50 Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem).
ninoderkinderen 0:8d87bc453349 51 */
ninoderkinderen 0:8d87bc453349 52 HTTPFile(const char* path);
ninoderkinderen 0:8d87bc453349 53 virtual ~HTTPFile();
ninoderkinderen 0:8d87bc453349 54
ninoderkinderen 0:8d87bc453349 55 ///Forces file closure
ninoderkinderen 0:8d87bc453349 56 virtual void clear();
ninoderkinderen 0:8d87bc453349 57
ninoderkinderen 0:8d87bc453349 58 protected:
ninoderkinderen 0:8d87bc453349 59 virtual int read(char* buf, int len);
ninoderkinderen 0:8d87bc453349 60 virtual int write(const char* buf, int len);
ninoderkinderen 0:8d87bc453349 61
ninoderkinderen 0:8d87bc453349 62 virtual string getDataType(); //Internet media type for Content-Type header
ninoderkinderen 0:8d87bc453349 63 virtual void setDataType(const string& type); //Internet media type from Content-Type header
ninoderkinderen 0:8d87bc453349 64
ninoderkinderen 0:8d87bc453349 65 virtual bool getIsChunked(); //For Transfer-Encoding header
ninoderkinderen 0:8d87bc453349 66 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header virtual
ninoderkinderen 0:8d87bc453349 67
ninoderkinderen 0:8d87bc453349 68 virtual int getDataLen(); //For Content-Length header
ninoderkinderen 0:8d87bc453349 69 virtual void setDataLen(int len); //From Content-Length header
ninoderkinderen 0:8d87bc453349 70
ninoderkinderen 0:8d87bc453349 71 private:
ninoderkinderen 0:8d87bc453349 72 bool openFile(const char* mode); //true on success, false otherwise
ninoderkinderen 0:8d87bc453349 73 void closeFile();
ninoderkinderen 0:8d87bc453349 74
ninoderkinderen 0:8d87bc453349 75 FILE* m_fp;
ninoderkinderen 0:8d87bc453349 76 string m_path;
ninoderkinderen 0:8d87bc453349 77 int m_len;
ninoderkinderen 0:8d87bc453349 78 bool m_chunked;
ninoderkinderen 0:8d87bc453349 79 };
ninoderkinderen 0:8d87bc453349 80
ninoderkinderen 0:8d87bc453349 81 #endif