mbed.org implementation of the abstract SmartREST library for the Cumulocity Platform SmartREST protocol.
Dependents: MbedSmartRestMain MbedSmartRestMain
Revision 13:aba98ad2ac1b, committed 2014-11-15
- Comitter:
- Cumulocity
- Date:
- Sat Nov 15 12:21:41 2014 +0100
- Parent:
- 12:6634f9814235
- Commit message:
- Updated from revision 0b898f0efc6d
Changed in this revision
diff -r 6634f9814235 -r aba98ad2ac1b AbstractSmartRest.h --- a/AbstractSmartRest.h Sat Nov 15 11:37:14 2014 +0100 +++ b/AbstractSmartRest.h Sat Nov 15 12:21:41 2014 +0100 @@ -109,7 +109,6 @@ */ virtual uint8_t bootstrap(const DataGenerator&) = 0; -#ifndef SMARTREST_TRANSACTIONAL /** * Sends a smart request. * @param generator the generator which will generate the data to be @@ -123,6 +122,18 @@ virtual uint8_t send(const DataGenerator&, const char* = NULL) = 0; /** + * Starts a SmartRest stream. + * @param uri the stream endpoint URI + * @param record the record which will be sent to the endpoint + * @param overrideIdentifier a device identifier which gets sent instead + * of the identifier specified in the + * constructor. If an empty string is + * specified, no identifier is sent at all. + * @return a non-zero value if and only if an error occured + */ + virtual uint8_t stream(const char*, const Record&, const char* = NULL) = 0; + + /** * Tries to receive a parsed response row. * When the function succeeds, but the row pointer is NULL, there are * no more rows to be read. @@ -135,7 +146,6 @@ * Closes the connection. */ virtual void stop() = 0; -#endif /* * Retrieves the template identifier.
diff -r 6634f9814235 -r aba98ad2ac1b SmartRest.cpp --- a/SmartRest.cpp Sat Nov 15 11:37:14 2014 +0100 +++ b/SmartRest.cpp Sat Nov 15 12:21:41 2014 +0100 @@ -95,7 +95,7 @@ ParsedRecord record; int8_t ret; - ret = beginRequest(NULL); + ret = beginRequest(NULL, NULL); if (ret != SMARTREST_SUCCESS) return ret; ret = awaitResponse(); @@ -134,7 +134,7 @@ { uint8_t res; - res = beginRequest(overrideIdentifier); + res = beginRequest(NULL, overrideIdentifier); if (res != SMARTREST_SUCCESS) return res; @@ -142,6 +142,18 @@ return awaitResponse(); } /*-------------------------------------------------------------------------*/ +uint8_t SmartRest::stream(const char *uri, const Record& record, const char *overrideIdentifier) +{ + uint8_t res; + + res = beginRequest(uri, overrideIdentifier); + if (res != SMARTREST_SUCCESS) + return res; + + _client.sendData(record); + return awaitResponse(); +} +/*-------------------------------------------------------------------------*/ uint8_t SmartRest::receive(ParsedRecord& record) { uint8_t res; @@ -176,11 +188,19 @@ return _identifier; } /*-------------------------------------------------------------------------*/ -uint8_t SmartRest::beginRequest(const char *overrideIdentifier) +uint8_t SmartRest::beginRequest(const char *uri, const char *overrideIdentifier) { int res; - res = _client.beginRequest(); + if (uri != NULL) + { + res = _client.beginStream(uri); + } + else + { + res = _client.beginRequest(); + } + if (res == CLIENT_CONNECTION_ERROR) { return SMARTREST_CONNECTION_FAILED;
diff -r 6634f9814235 -r aba98ad2ac1b SmartRest.h --- a/SmartRest.h Sat Nov 15 11:37:14 2014 +0100 +++ b/SmartRest.h Sat Nov 15 12:21:41 2014 +0100 @@ -61,20 +61,14 @@ uint8_t request(const DataGenerator&, Aggregator&, const char* = NULL); #endif uint8_t bootstrap(const DataGenerator&); -#ifndef SMARTREST_TRANSACTIONAL uint8_t send(const DataGenerator&, const char* = NULL); + uint8_t stream(const char*, const Record&, const char* = NULL); uint8_t receive(ParsedRecord&); void stop(); -#endif const char * getIdentifier(); protected: -#ifdef SMARTREST_TRANSACTIONAL - uint8_t send(const DataGenerator&, const char*); - uint8_t receive(ParsedRecord&); - void stop(); -#endif - uint8_t beginRequest(const char*); + uint8_t beginRequest(const char*, const char*); uint8_t awaitResponse(); bool setMoGid(ParsedRecord&);