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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download) (as text)
Fri Mar 5 13:46:15 2004 UTC (20 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5316 byte(s)
* implemented parser for the LinuxSampler control protocol (LSCP) by using
  flex / bison (where src/network/lscp.l is the input file for lex / flex
  and src/network/lscp.y is the input file for yacc / bison), parser and
  scanner can be regenerated by 'make parser'
* implemented LSCP network server (only single threaded so far), LSCP
  server will be launched if LinuxSampler was started with "--server" flag,
  implemented the following LSCP commands so far: "LOAD INSTRUMENT", "GET
  CHANNEL VOICE_COUNT", "GET CHANNEL STREAM_COUNT", "GET CHANNEL
  BUFFER_FILL", "SET CHANNEL VOLUME" and "RESET CHANNEL"
* disk thread now started within the engine

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

  ViewVC Help
Powered by ViewVC