Generic SmartRest library
Dependents: SmartRestUnitTest MbedSmartRest MbedSmartRestStreaming
AbstractClient.h
00001 /* 00002 * AbstractClient.h 00003 * 00004 * Created on: Nov 1, 2013 00005 * * Authors: Vincent Wochnik <v.wochnik@gmail.com> 00006 * 00007 * Copyright (c) 2013 Cumulocity GmbH 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining 00010 * a copy of this software and associated documentation files (the 00011 * "Software"), to deal in the Software without restriction, including 00012 * without limitation the rights to use, copy, modify, merge, publish, 00013 * distribute, sublicense, and/or sell copies of the Software, and to 00014 * permit persons to whom the Software is furnished to do so, subject to 00015 * the following conditions: 00016 * 00017 * The above copyright notice and this permission notice shall be 00018 * included in all copies or substantial portions of the Software. 00019 * 00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00021 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00022 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00023 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00024 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00025 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00026 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00027 */ 00028 00029 /** 00030 * @file AbstractClient.h 00031 * An abstraction layer for the SmartREST http client. 00032 */ 00033 00034 #ifndef ABSTRACTCLIENT_H 00035 #define ABSTRACTCLIENT_H 00036 00037 #ifdef HAVE_CONFIG_H 00038 #include <config.h> 00039 #endif 00040 00041 #include "DataGenerator.h" 00042 #include "AbstractDataSource.h" 00043 #include "AbstractDataSink.h" 00044 00045 /** Return value indicating that the operation has been successful. */ 00046 #define CLIENT_OK 0 00047 /** Return value indicating that there has been a connection error. */ 00048 #define CLIENT_CONNECTION_ERROR 1 00049 /** Return value indicating that an internal error occurred. */ 00050 #define CLIENT_INTERNAL_ERROR 2 00051 00052 /* 00053 * An abstraction layer for the SmartREST http client. 00054 * 00055 * All methods have to be called in the following order: 00056 * - beginRequest() 00057 * - sendIdentifier() (optional) 00058 * - sendData() (optional) 00059 * - endRequest() 00060 * - awaitResponse() 00061 * - receiveData() (optional) 00062 * - stop() 00063 * 00064 * Additionally, stop() can be called at any time to reset the state of 00065 * this instance. 00066 */ 00067 class AbstractClient 00068 { 00069 public: 00070 virtual ~AbstractClient() { }; 00071 00072 /** 00073 * Begins a new request. This method has to be the first call for 00074 * any request. A connection to the server will be established 00075 * and the start of a HTTP post request will be sent over the 00076 * connection including Host and Authorization headers. 00077 */ 00078 virtual uint8_t beginRequest() = 0; 00079 00080 /** 00081 * Sends the X-Id device identifier header. 00082 * @param identifier the identifier to be sent. The value has to remain 00083 * valid for the entire request. 00084 */ 00085 virtual uint8_t sendIdentifier(const char*) = 0; 00086 00087 /** 00088 * Sends POST data over the connection. Before the data is sent, 00089 * a Content-Length header is also sent over the connection. if the 00090 * estimated length does not match the actual conten length, 00091 * unexpected behavior will occur. 00092 * @param generator the data generator for the data to be sent 00093 */ 00094 virtual uint8_t sendData(DataGenerator& generator) = 0; 00095 00096 /** 00097 * Finishes the request. In case no data has been sent over the 00098 * connection, this method will send twice carriage-return new-line. 00099 */ 00100 virtual uint8_t endRequest() = 0; 00101 00102 /** 00103 * Blocks until the start of a response has been received. 00104 */ 00105 virtual uint8_t awaitResponse() = 0; 00106 00107 /** 00108 * Returns a data source for reading data. 00109 * When no data can be read for whatever reason, 00110 * a data source with an error state may be returned. 00111 * @return the data source to read from 00112 */ 00113 virtual AbstractDataSource& receiveData() = 0; 00114 00115 /** 00116 * Resets the connection. This method can be called at any time 00117 * and resets the state of this instance. 00118 */ 00119 virtual void stop() = 0; 00120 }; 00121 00122 #endif
Generated on Wed Jul 13 2022 09:53:06 by 1.7.2