]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/xively/XivelyDatastream.h
first commit
[arduino] / books / pdummies / Libraries / xively / XivelyDatastream.h
1 #ifndef XIVELY_DATASTREAM_H
2 #define XIVELY_DATASTREAM_H
3
4 #include <Stream.h>
5 #include <Printable.h>
6
7 #define DATASTREAM_STRING 0
8 #define DATASTREAM_BUFFER 1
9 #define DATASTREAM_INT 2
10 #define DATASTREAM_FLOAT 3
11
12 class XivelyDatastream : public Printable {
13   friend class XivelyClient;
14
15   typedef struct {
16     char* _buffer;
17     int _bufferSize;
18   } tBuffer;
19 public:
20
21   XivelyDatastream(String& aId, int aType);
22   XivelyDatastream(char* aIdBuffer, int aIdBufferLength, int aType);
23   XivelyDatastream(char* aIdBuffer, int aIdBufferLength, int aType, char* aValueBuffer, int aValueBufferLength);
24   int updateValue(Stream& aStream);
25   void setInt(int aValue);
26   void setFloat(float aValue);
27   void setString(String& aValue);
28   void setBuffer(const char* aValue);
29   String& getString();
30   int getInt();
31   float getFloat();
32   char* getBuffer();
33   virtual size_t printTo(Print&) const;
34 protected:
35   int idLength() { return (_idType == DATASTREAM_STRING ? _idString.length() : strlen(_idBuffer._buffer)); };
36   char idChar(int idx) { return (_idType == DATASTREAM_STRING ? _idString[idx] : (idx > strlen(_idBuffer._buffer) ? '\0' : _idBuffer._buffer[idx])); };
37   // FIXME Only needed until readStringUntil is available in core
38   int timedRead(Stream& aStream);
39
40   int _idType;
41   String _idString;
42   tBuffer _idBuffer;
43   int _valueType;
44   String _valueString;
45   union {
46     tBuffer _valueBuffer;
47     int _valueInt;
48     float _valueFloat;
49   } _value;
50 };
51
52 #endif