/[svn]/linuxsampler/trunk/src/network/lscpresultset.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/network/lscpresultset.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (show annotations) (download)
Tue Jun 8 00:48:20 2004 UTC (19 years, 10 months ago) by senkov
File size: 3657 byte(s)
Added comments

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * 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"
39 #include "../common/LinuxSamplerException.h"
40
41 //Construct an empty resultset
42 LSCPResultSet::LSCPResultSet(void) {
43 count = 0;
44 storage = "";
45 }
46
47 //Construct a resultset with a single line
48 LSCPResultSet::LSCPResultSet(String Value) {
49 count = 1;
50 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) {
56 if (count == -1)
57 throw LinuxSamplerException("Attempting to change already produced resultset");
58 storage = storage + Label + ": " + Value + "\r\n";
59 count++;
60 }
61
62 void LSCPResultSet::Add(String Label, int Value) {
63 char temp[16];
64 snprintf(temp, sizeof(temp), "%i", Value);
65 Add(Label, temp);
66 }
67
68 void LSCPResultSet::Add(String Label, float Value) {
69 char temp[16];
70 snprintf(temp, sizeof(temp), "%10.4f", Value);
71 Add(Label, temp);
72 }
73
74 //Add a single string to the resultset
75 void LSCPResultSet::Add(String Value) {
76 if (count == -1)
77 throw LinuxSamplerException("Attempting to change already produced resultset");
78 if (count != 0)
79 throw LinuxSamplerException("Attempting to create illegal resultset");
80 storage = Value + "\r\n";
81 count = 1;
82 }
83
84 //Produce resultset
85 String LSCPResultSet::Produce(void) {
86 if (count == 0) //When there is nothing in the resultset we just send "OK" to ack the request
87 return "OK\r\n";
88 if (count == 1) //Single line results are just that, single line
89 return storage;
90 //Multiline results MUST end with a line with a single dot
91 return storage + ".\r\n";
92 }

  ViewVC Help
Powered by ViewVC