20 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
***************************************************************************/ |
22 |
|
|
23 |
|
/********************************************************* |
24 |
|
* This class helps to constuct valid resultsets per |
25 |
|
* LSCP protocol specification |
26 |
|
* |
27 |
|
* Valid results include: |
28 |
|
* OK - to ack the request |
29 |
|
* Single line to ack the requests and give status |
30 |
|
* Several lines of information in the following format: |
31 |
|
* LABEL0: VALUE0 |
32 |
|
* LABEL1: VALUE1 |
33 |
|
* VALELx: VALUEx |
34 |
|
* . |
35 |
|
* |
36 |
|
* ******************************************************/ |
37 |
|
|
38 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
39 |
#include "../common/LinuxSamplerException.h" |
#include "../common/LinuxSamplerException.h" |
40 |
|
|
41 |
|
//Construct an empty resultset |
42 |
LSCPResultSet::LSCPResultSet(void) { |
LSCPResultSet::LSCPResultSet(void) { |
43 |
count = 0; |
count = 0; |
44 |
storage = ""; |
storage = ""; |
45 |
} |
} |
46 |
|
|
47 |
|
//Construct a resultset with a single line |
48 |
LSCPResultSet::LSCPResultSet(String Value) { |
LSCPResultSet::LSCPResultSet(String Value) { |
49 |
count = 1; |
count = 1; |
50 |
storage = Value + "\r\n"; |
storage = Value + "\r\n"; |
51 |
} |
} |
52 |
|
|
53 |
|
//Add a label/value pair to the resultset |
54 |
|
//Values could be of different types for now supports String, int and float. |
55 |
void LSCPResultSet::Add(String Label, String Value) { |
void LSCPResultSet::Add(String Label, String Value) { |
56 |
if (count == -1) |
if (count == -1) |
57 |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
71 |
Add(Label, temp); |
Add(Label, temp); |
72 |
} |
} |
73 |
|
|
74 |
|
//Add a single string to the resultset |
75 |
void LSCPResultSet::Add(String Value) { |
void LSCPResultSet::Add(String Value) { |
76 |
if (count == -1) |
if (count == -1) |
77 |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
81 |
count = 1; |
count = 1; |
82 |
} |
} |
83 |
|
|
84 |
|
//Produce resultset |
85 |
String LSCPResultSet::Produce(void) { |
String LSCPResultSet::Produce(void) { |
86 |
if (count == 0) |
if (count == 0) //When there is nothing in the resultset we just send "OK" to ack the request |
87 |
return "OK\r\n"; |
return "OK\r\n"; |
88 |
if (count == 1) |
if (count == 1) //Single line results are just that, single line |
89 |
return storage; |
return storage; |
90 |
|
//Multiline results MUST end with a line with a single dot |
91 |
return storage + ".\r\n"; |
return storage + ".\r\n"; |
92 |
} |
} |