/[svn]/linuxsampler/trunk/src/network/lscpparser.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/network/lscpparser.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 135 - (show annotations) (download) (as text)
Sun Jun 20 16:01:50 2004 UTC (19 years, 10 months ago) by senkov
File MIME type: text/x-c++hdr
File size: 5460 byte(s)
* Update parser to comply with the latest spec

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 #ifndef __LSCPPARSER_H__
24 #define __LSCPPARSER_H__
25
26 #include <sys/types.h>
27 #include <sys/socket.h>
28
29 #include <stdlib.h>
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33
34 #include "../common/global.h"
35 #include "../Sampler.h"
36
37 /// Will be returned by the parser in case of syntax errors.
38 #define LSCP_SYNTAX_ERROR -69
39
40 using namespace LinuxSampler;
41
42 /**
43 * How the fill states of disk stream buffers should be reflected.
44 */
45 enum fill_response_t {
46 fill_response_bytes, ///< The returned values are meant in bytes.
47 fill_response_percentage ///< The returned values are meant in percentage.
48 };
49
50 /**
51 * Event types
52 */
53 enum event_t {
54 event_channels,
55 event_voice_count,
56 event_stream_count,
57 event_channel_buffer_fill,
58 event_channel_info,
59 event_misc
60 };
61
62 /**
63 * Semantic value of the lookahead symbol.
64 *
65 * Structure that is used by the parser to process and return values from the
66 * input text. The lexical analyzer for example returns a number for
67 * recognized number strings in the input text and the parser might return a
68 * value for each of it's rules.
69 */
70 struct YYSTYPE {
71 union {
72 char Char;
73 unsigned int Number;
74 double Dotnum;
75 fill_response_t FillResponse;
76 event_t Event;
77 };
78 std::string String;
79 std::map<std::string,std::string> KeyValList;
80 };
81 #define yystype YYSTYPE ///< For backward compatibility.
82 #define YYSTYPE_IS_DECLARED ///< We tell the lexer / parser that we use our own data structure as defined above.
83
84 // just symbol prototyping
85 class LSCPServer;
86
87 // pointer to an (reentrant) scanner / lexical analyzer
88 typedef void* yyscan_t;
89
90 /**
91 * Parameters given to the parser on every yyparse() call.
92 */
93 struct yyparse_param_t {
94 LSCPServer* pServer;
95 yyscan_t pScanner;
96 };
97 #define YYPARSE_PARAM yyparse_param
98
99 /**
100 * Prototype of the main scanner function (lexical analyzer).
101 */
102 #define YY_DECL int yylex(YYSTYPE* yylval, yyscan_t yyscanner)
103
104 /**
105 * Override lex's input function which just reads from stdin by default.
106 * We read from a socket instead.
107 */
108 #define YY_INPUT(buf,result,max_size) \
109 errno=0; \
110 while ( (result = recv(hSession, buf, max_size, 0)) < 0 ) \
111 { \
112 if(errno != EINTR) \
113 { \
114 switch(errno) { \
115 case EBADF: \
116 dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); \
117 break; \
118 case ECONNREFUSED: \
119 dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); \
120 break; \
121 case ENOTCONN: \
122 dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); \
123 break; \
124 case ENOTSOCK: \
125 dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); \
126 break; \
127 case EAGAIN: \
128 dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); \
129 break; \
130 case EINTR: \
131 dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); \
132 break; \
133 case EFAULT: \
134 dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); \
135 break; \
136 case EINVAL: \
137 dmsg(2,("LSCPScanner: Invalid argument passed.\n")); \
138 break; \
139 case ENOMEM: \
140 dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); \
141 break; \
142 default: \
143 dmsg(2,("LSCPScanner: Unknown recv() error.\n")); \
144 break; \
145 } \
146 YY_FATAL_ERROR( "input in flex scanner failed" ); \
147 break; \
148 } \
149 errno=0; \
150 clearerr(yyin); \
151 }\
152
153
154 #endif // __LSCPPARSER_H__

  ViewVC Help
Powered by ViewVC