Generic SmartRest library
Dependents: SmartRestUnitTest MbedSmartRest MbedSmartRestStreaming
AbstractDataSink.h@1:3e7b4c9e0821, 2014-04-16 (annotated)
- Committer:
- vwochnik
- Date:
- Wed Apr 16 08:30:49 2014 +0000
- Revision:
- 1:3e7b4c9e0821
- Parent:
- 0:744801d5734d
fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vwochnik | 0:744801d5734d | 1 | /* |
vwochnik | 0:744801d5734d | 2 | * AbstractDataSink.h |
vwochnik | 0:744801d5734d | 3 | * |
vwochnik | 0:744801d5734d | 4 | * Created on: Nov 1, 2013 |
vwochnik | 0:744801d5734d | 5 | * * Authors: Vincent Wochnik <v.wochnik@gmail.com> |
vwochnik | 0:744801d5734d | 6 | * |
vwochnik | 0:744801d5734d | 7 | * Copyright (c) 2013 Cumulocity GmbH |
vwochnik | 0:744801d5734d | 8 | * |
vwochnik | 0:744801d5734d | 9 | * Permission is hereby granted, free of charge, to any person obtaining |
vwochnik | 0:744801d5734d | 10 | * a copy of this software and associated documentation files (the |
vwochnik | 0:744801d5734d | 11 | * "Software"), to deal in the Software without restriction, including |
vwochnik | 0:744801d5734d | 12 | * without limitation the rights to use, copy, modify, merge, publish, |
vwochnik | 0:744801d5734d | 13 | * distribute, sublicense, and/or sell copies of the Software, and to |
vwochnik | 0:744801d5734d | 14 | * permit persons to whom the Software is furnished to do so, subject to |
vwochnik | 0:744801d5734d | 15 | * the following conditions: |
vwochnik | 0:744801d5734d | 16 | * |
vwochnik | 0:744801d5734d | 17 | * The above copyright notice and this permission notice shall be |
vwochnik | 0:744801d5734d | 18 | * included in all copies or substantial portions of the Software. |
vwochnik | 0:744801d5734d | 19 | * |
vwochnik | 0:744801d5734d | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
vwochnik | 0:744801d5734d | 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
vwochnik | 0:744801d5734d | 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
vwochnik | 0:744801d5734d | 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
vwochnik | 0:744801d5734d | 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
vwochnik | 0:744801d5734d | 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
vwochnik | 0:744801d5734d | 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
vwochnik | 0:744801d5734d | 27 | */ |
vwochnik | 0:744801d5734d | 28 | |
vwochnik | 0:744801d5734d | 29 | /** |
vwochnik | 0:744801d5734d | 30 | * @file AbstractDataSink.h |
vwochnik | 0:744801d5734d | 31 | * An abstraction for a data sink which can be used to send data |
vwochnik | 0:744801d5734d | 32 | * over a connection. |
vwochnik | 0:744801d5734d | 33 | * |
vwochnik | 0:744801d5734d | 34 | * Following write actions are supported: |
vwochnik | 0:744801d5734d | 35 | * - write a character |
vwochnik | 0:744801d5734d | 36 | * - write a buffer of certain length |
vwochnik | 0:744801d5734d | 37 | * - write a character string |
vwochnik | 0:744801d5734d | 38 | * - write an unsigned number |
vwochnik | 0:744801d5734d | 39 | */ |
vwochnik | 0:744801d5734d | 40 | |
vwochnik | 0:744801d5734d | 41 | #ifndef ABSTRACTDATASINK_H |
vwochnik | 0:744801d5734d | 42 | #define ABSTRACTDATASINK_H |
vwochnik | 0:744801d5734d | 43 | |
vwochnik | 0:744801d5734d | 44 | #ifdef HAVE_CONFIG_H |
vwochnik | 0:744801d5734d | 45 | #include <config.h> |
vwochnik | 0:744801d5734d | 46 | #endif |
vwochnik | 0:744801d5734d | 47 | |
vwochnik | 0:744801d5734d | 48 | #include <stddef.h> |
vwochnik | 0:744801d5734d | 49 | |
vwochnik | 0:744801d5734d | 50 | /* |
vwochnik | 0:744801d5734d | 51 | * The AbstractDataSink class provides a way to write data to a |
vwochnik | 0:744801d5734d | 52 | * connection. |
vwochnik | 0:744801d5734d | 53 | */ |
vwochnik | 0:744801d5734d | 54 | class AbstractDataSink |
vwochnik | 0:744801d5734d | 55 | { |
vwochnik | 0:744801d5734d | 56 | public: |
vwochnik | 0:744801d5734d | 57 | virtual ~AbstractDataSink() { }; |
vwochnik | 0:744801d5734d | 58 | |
vwochnik | 0:744801d5734d | 59 | /** |
vwochnik | 0:744801d5734d | 60 | * Writes a single character. |
vwochnik | 0:744801d5734d | 61 | * @param c the character to write |
vwochnik | 0:744801d5734d | 62 | * @return the number of characters written, in this case 1 or 0 |
vwochnik | 0:744801d5734d | 63 | */ |
vwochnik | 0:744801d5734d | 64 | virtual size_t write(char c) = 0; |
vwochnik | 0:744801d5734d | 65 | |
vwochnik | 0:744801d5734d | 66 | /** |
vwochnik | 0:744801d5734d | 67 | * Writes a buffer. |
vwochnik | 0:744801d5734d | 68 | * @param buf the buffer to write |
vwochnik | 0:744801d5734d | 69 | * @param length the length of the buffer in bytes |
vwochnik | 0:744801d5734d | 70 | * @return the number of characters written |
vwochnik | 0:744801d5734d | 71 | */ |
vwochnik | 0:744801d5734d | 72 | virtual size_t write(void *buf, size_t length) = 0; |
vwochnik | 0:744801d5734d | 73 | |
vwochnik | 0:744801d5734d | 74 | /** |
vwochnik | 0:744801d5734d | 75 | * Writes a character string. |
vwochnik | 0:744801d5734d | 76 | * @param str the string to write |
vwochnik | 0:744801d5734d | 77 | * @return the number of characters written |
vwochnik | 0:744801d5734d | 78 | */ |
vwochnik | 0:744801d5734d | 79 | virtual size_t write(const char *str) = 0; |
vwochnik | 0:744801d5734d | 80 | |
vwochnik | 0:744801d5734d | 81 | /** |
vwochnik | 0:744801d5734d | 82 | * Writes a number with base 10. |
vwochnik | 0:744801d5734d | 83 | * @param number the number to write |
vwochnik | 0:744801d5734d | 84 | * @return the number of digits written |
vwochnik | 0:744801d5734d | 85 | */ |
vwochnik | 0:744801d5734d | 86 | virtual size_t write(unsigned long number) = 0; |
vwochnik | 0:744801d5734d | 87 | }; |
vwochnik | 0:744801d5734d | 88 | |
vwochnik | 0:744801d5734d | 89 | #endif |