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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (hide annotations) (download)
Sun Aug 22 14:46:47 2004 UTC (19 years, 8 months ago) by schoenebeck
File size: 6091 byte(s)
* set default volume to 1.0 in Gigasampler engine (was 0.0)
* implemented "SET CHANNEL AUDIO_OUTPUT_CHANNEL" LSCP command
* fixed "GET ENGINE INFO" LSCP command
* fixed "GET CHANNEL INFO" LSCP command
* src/network/lscp.y: fixed 'stringval' rule (returned string with formal
  apostrophes), fixed 'dotnum' rule (ignored position after decimal point)

1 senkov 113 /***************************************************************************
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 senkov 116 /*********************************************************
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 senkov 113 #include "lscpresultset.h"
39    
40 senkov 116 //Construct an empty resultset
41 senkov 120 //Default index is -1 meaning the resultset doesn't have an index
42     LSCPResultSet::LSCPResultSet(int index) {
43     result_index = index;
44 senkov 113 count = 0;
45     storage = "";
46 senkov 120 result_type = result_type_success;
47 senkov 113 }
48    
49 senkov 116 //Construct a resultset with a single line
50 senkov 120 //Default index is -1 meaning the resultset doesn't have an index
51     LSCPResultSet::LSCPResultSet(String Value, int index) {
52     result_index = index;
53 senkov 113 count = 1;
54     storage = Value + "\r\n";
55 senkov 120 result_type = result_type_success;
56 senkov 113 }
57    
58 senkov 116 //Add a label/value pair to the resultset
59     //Values could be of different types for now supports String, int and float.
60 senkov 113 void LSCPResultSet::Add(String Label, String Value) {
61     if (count == -1)
62     throw LinuxSamplerException("Attempting to change already produced resultset");
63 senkov 120 if (result_type != result_type_success)
64     throw LinuxSamplerException("Attempting to create illegal resultset");
65 senkov 113 storage = storage + Label + ": " + Value + "\r\n";
66     count++;
67     }
68    
69 schoenebeck 225 void LSCPResultSet::Add(String Label, const char* pValue) {
70     Add(Label, String(pValue));
71     }
72    
73 senkov 120 void LSCPResultSet::Add(int Value) {
74     Add(ToString(Value));
75     }
76    
77 senkov 113 void LSCPResultSet::Add(String Label, int Value) {
78 senkov 120 Add(Label, ToString(Value));
79 senkov 113 }
80    
81     void LSCPResultSet::Add(String Label, float Value) {
82 schoenebeck 225 char s[1024];
83     snprintf(s, 1023, "%.3f", Value);
84     Add(Label, String(s));
85 senkov 113 }
86    
87 schoenebeck 223 void LSCPResultSet::Add(String Label, bool Value) {
88     String s = (Value) ? "true" : "false";
89     Add(Label, s);
90     }
91    
92 senkov 116 //Add a single string to the resultset
93 senkov 113 void LSCPResultSet::Add(String Value) {
94 senkov 120 if (result_type != result_type_success)
95     throw LinuxSamplerException("Attempting to create illegal resultset");
96 senkov 113 if (count == -1)
97     throw LinuxSamplerException("Attempting to change already produced resultset");
98     if (count != 0)
99     throw LinuxSamplerException("Attempting to create illegal resultset");
100     storage = Value + "\r\n";
101     count = 1;
102     }
103    
104 senkov 120 //Generate an error result set from an exception.
105     //Per LSCP spec, error result is a sinle line in the following format:
106     //ERR:<CODE>:Message text\r\n
107     //This method will be used to generate unknown errors only (code 0)
108     //To generate errors with other codes as well as warnings use other methods (below).
109     //Because this is an unknown error, this method will also print message to the stderr.
110     void LSCPResultSet::Error(LinuxSamplerException e) {
111     e.PrintMessage();
112     Error(e.Message());
113     }
114    
115     //This will construct an error with a string and error code
116     //code has a default of 0
117     //String has a default of "Undefined Error"
118     void LSCPResultSet::Error (String message, int code) {
119     //Even though this is must be a single line resultset we won't throw
120     //anything here because this is already part of exception handling.
121     //We'll just 'forget' all previous results (if any) from this resultset.
122     result_type = result_type_error;
123     storage = "ERR:" + ToString(code) + ":" + message + "\r\n";
124     count = 1;
125     }
126    
127     //This will construct a warning with a string and error code
128     //code has a default of 0
129     //String has a default of "Undefined Error"
130     void LSCPResultSet::Warning (String message, int code) {
131     //FIXME: DO we want warnings as part of the resultset or
132     //do we want them to work like errors??? For now, make them work like errors.
133     result_type = result_type_warning;
134     if (result_index == -1)
135     storage = "WRN:" + ToString(code) + ":" + message + "\r\n";
136     else
137     storage = "WRN[" + ToString(result_index) + "]:" + ToString(code) + ":" + message + "\r\n";
138     count = 1;
139     }
140    
141 senkov 116 //Produce resultset
142 senkov 113 String LSCPResultSet::Produce(void) {
143 senkov 120 //FIXME: I'm assuming that only a sinle like "OK" can have index
144 senkov 116 if (count == 0) //When there is nothing in the resultset we just send "OK" to ack the request
145 senkov 120 if (result_index == -1)
146     return "OK\r\n";
147     else
148     return "OK[" + ToString(result_index) + "]\r\n";
149 senkov 116 if (count == 1) //Single line results are just that, single line
150 senkov 113 return storage;
151 senkov 116 //Multiline results MUST end with a line with a single dot
152 senkov 113 return storage + ".\r\n";
153     }

  ViewVC Help
Powered by ViewVC