This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.
Dependencies: mbed DebugLibrary
NetServices/services/http/client/data/HTTPText.h@1:995212d326ca, 2011-02-11 (annotated)
- Committer:
- Yann
- Date:
- Fri Feb 11 10:17:20 2011 +0000
- Revision:
- 1:995212d326ca
- Parent:
- 0:f30e2135b0db
V0.0.0.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 0:f30e2135b0db | 1 | |
Yann | 0:f30e2135b0db | 2 | /* |
Yann | 0:f30e2135b0db | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
Yann | 0:f30e2135b0db | 4 | |
Yann | 0:f30e2135b0db | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Yann | 0:f30e2135b0db | 6 | of this software and associated documentation files (the "Software"), to deal |
Yann | 0:f30e2135b0db | 7 | in the Software without restriction, including without limitation the rights |
Yann | 0:f30e2135b0db | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Yann | 0:f30e2135b0db | 9 | copies of the Software, and to permit persons to whom the Software is |
Yann | 0:f30e2135b0db | 10 | furnished to do so, subject to the following conditions: |
Yann | 0:f30e2135b0db | 11 | |
Yann | 0:f30e2135b0db | 12 | The above copyright notice and this permission notice shall be included in |
Yann | 0:f30e2135b0db | 13 | all copies or substantial portions of the Software. |
Yann | 0:f30e2135b0db | 14 | |
Yann | 0:f30e2135b0db | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Yann | 0:f30e2135b0db | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Yann | 0:f30e2135b0db | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Yann | 0:f30e2135b0db | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Yann | 0:f30e2135b0db | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Yann | 0:f30e2135b0db | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Yann | 0:f30e2135b0db | 21 | THE SOFTWARE. |
Yann | 0:f30e2135b0db | 22 | */ |
Yann | 0:f30e2135b0db | 23 | |
Yann | 0:f30e2135b0db | 24 | /** \file |
Yann | 0:f30e2135b0db | 25 | HTTP Text data source/sink header file |
Yann | 0:f30e2135b0db | 26 | */ |
Yann | 0:f30e2135b0db | 27 | |
Yann | 0:f30e2135b0db | 28 | #ifndef HTTP_TEXT_H |
Yann | 0:f30e2135b0db | 29 | #define HTTP_TEXT_H |
Yann | 0:f30e2135b0db | 30 | |
Yann | 0:f30e2135b0db | 31 | #include "../HTTPData.h" |
Yann | 0:f30e2135b0db | 32 | #include "mbed.h" |
Yann | 0:f30e2135b0db | 33 | |
Yann | 0:f30e2135b0db | 34 | #define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems |
Yann | 0:f30e2135b0db | 35 | |
Yann | 0:f30e2135b0db | 36 | ///HTTP Client data container for text |
Yann | 0:f30e2135b0db | 37 | /** |
Yann | 0:f30e2135b0db | 38 | This is a simple "Text" data repository for HTTP requests. |
Yann | 0:f30e2135b0db | 39 | */ |
Yann | 0:f30e2135b0db | 40 | class HTTPText : public HTTPData //Simple Text I/O |
Yann | 0:f30e2135b0db | 41 | { |
Yann | 0:f30e2135b0db | 42 | public: |
Yann | 0:f30e2135b0db | 43 | ///Instantiates the object. |
Yann | 0:f30e2135b0db | 44 | /** |
Yann | 0:f30e2135b0db | 45 | @param encoding encoding of the data, it defaults to text/html. |
Yann | 0:f30e2135b0db | 46 | @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes. |
Yann | 0:f30e2135b0db | 47 | */ |
Yann | 0:f30e2135b0db | 48 | HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC); |
Yann | 0:f30e2135b0db | 49 | virtual ~HTTPText(); |
Yann | 0:f30e2135b0db | 50 | |
Yann | 0:f30e2135b0db | 51 | ///Gets text |
Yann | 0:f30e2135b0db | 52 | /** |
Yann | 0:f30e2135b0db | 53 | Returns the text in the container as a zero-terminated char*. |
Yann | 0:f30e2135b0db | 54 | The array returned points to the internal buffer of the object and remains owned by the object. |
Yann | 0:f30e2135b0db | 55 | */ |
Yann | 0:f30e2135b0db | 56 | const char* gets() const; |
Yann | 0:f30e2135b0db | 57 | |
Yann | 0:f30e2135b0db | 58 | //Puts text |
Yann | 0:f30e2135b0db | 59 | /** |
Yann | 0:f30e2135b0db | 60 | Sets the text in the container using a zero-terminated char*. |
Yann | 0:f30e2135b0db | 61 | */ |
Yann | 0:f30e2135b0db | 62 | void puts(const char* str); |
Yann | 0:f30e2135b0db | 63 | |
Yann | 0:f30e2135b0db | 64 | ///Gets text |
Yann | 0:f30e2135b0db | 65 | /** |
Yann | 0:f30e2135b0db | 66 | Returns the text in the container as string. |
Yann | 0:f30e2135b0db | 67 | */ |
Yann | 0:f30e2135b0db | 68 | string& get(); |
Yann | 0:f30e2135b0db | 69 | |
Yann | 0:f30e2135b0db | 70 | ///Puts text |
Yann | 0:f30e2135b0db | 71 | /** |
Yann | 0:f30e2135b0db | 72 | Sets the text in the container as string. |
Yann | 0:f30e2135b0db | 73 | */ |
Yann | 0:f30e2135b0db | 74 | void set(const string& str); |
Yann | 0:f30e2135b0db | 75 | |
Yann | 0:f30e2135b0db | 76 | ///Clears the content. |
Yann | 0:f30e2135b0db | 77 | /** |
Yann | 0:f30e2135b0db | 78 | If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request. |
Yann | 0:f30e2135b0db | 79 | */ |
Yann | 0:f30e2135b0db | 80 | virtual void clear(); |
Yann | 0:f30e2135b0db | 81 | |
Yann | 0:f30e2135b0db | 82 | protected: |
Yann | 0:f30e2135b0db | 83 | virtual int read(char* buf, int len); |
Yann | 0:f30e2135b0db | 84 | virtual int write(const char* buf, int len); |
Yann | 0:f30e2135b0db | 85 | |
Yann | 0:f30e2135b0db | 86 | virtual string getDataType(); //Internet media type for Content-Type header |
Yann | 0:f30e2135b0db | 87 | virtual void setDataType(const string& type); //Internet media type from Content-Type header |
Yann | 0:f30e2135b0db | 88 | |
Yann | 0:f30e2135b0db | 89 | virtual bool getIsChunked(); //For Transfer-Encoding header |
Yann | 0:f30e2135b0db | 90 | virtual void setIsChunked(bool chunked); //From Transfer-Encoding header |
Yann | 0:f30e2135b0db | 91 | |
Yann | 0:f30e2135b0db | 92 | virtual int getDataLen(); //For Content-Length header |
Yann | 0:f30e2135b0db | 93 | virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length |
Yann | 0:f30e2135b0db | 94 | |
Yann | 0:f30e2135b0db | 95 | private: |
Yann | 0:f30e2135b0db | 96 | string m_buf; |
Yann | 0:f30e2135b0db | 97 | string m_encoding; |
Yann | 0:f30e2135b0db | 98 | int m_maxSize; |
Yann | 0:f30e2135b0db | 99 | }; |
Yann | 0:f30e2135b0db | 100 | |
Yann | 0:f30e2135b0db | 101 | #endif |