Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_FringeServer.cc
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* -------------------------------------------------------------------- */
36  /* Code to talk to a running fringe. */
37  /* */
38  /*************************************************************************/
39 
40 #include "EST_system.h"
41 #include "EST_socket.h"
42 #include <csignal>
43 #include "EST_unix.h"
44 #include "EST_TKVL.h"
45 #include "EST_ServiceTable.h"
46 #include "EST_FringeServer.h"
47 #include "EST_Pathname.h"
48 #include "EST_error.h"
49 #include "EST_Token.h"
50 #include <iomanip>
51 #include <iostream>
52 
53 static EST_Regex ipnum("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
54 
55 
56 EST_FringeServer::ResultHandler::ResultHandler()
57 {
58 }
59 
60 EST_FringeServer::ResultHandler::~ResultHandler()
61 {
62 }
63 
64 void EST_FringeServer::ResultHandler::process(void)
65 {
66 }
67 
69  : EST_Server(name, "fringe", trace)
70 {
71 }
72 
74  : EST_Server(name, "fringe")
75 {
76 }
77 
78 EST_FringeServer::EST_FringeServer(EST_String hostname, int port, ostream *trace)
79  : EST_Server(hostname, port, trace)
80 {
81 }
82 
84  : EST_Server(hostname, port)
85 {
86 }
87 
89 {
90 }
91 
92 static void setup_command_tokenstream(EST_TokenStream &toks)
93 {
94  toks.set_SingleCharSymbols("(){}[]=");
95  toks.set_PunctuationSymbols("");
97  toks.set_quotes('"', '\\');
98 }
99 
100 bool EST_FringeServer::parse_command(const EST_String command,
101  EST_String &package,
102  EST_String &operation,
103  EST_FringeServer::Args &arguments)
104 {
105  EST_TokenStream toks;
106  EST_Token tok;
107  int i;
108 
109  toks.open_string(command);
110 
111  setup_command_tokenstream(toks);
112 
113  if (toks.eof())
114  return FALSE;
115 
116  tok=toks.get();
117 
118  EST_String op = tok.String();
119  if ((i = op.index(".", -1)) >= 0)
120  {
121  package = op.before(i,1);
122  operation = op.after(i,1);
123  }
124  else
125  {
126  package = "";
127  operation = op;
128  }
129 
130  while (!toks.eof())
131  {
132  tok=toks.get();
133 
134  if (tok.String() == "")
135  break;
136 
137  EST_String key=tok.String();
138  EST_String val;
139 
140  tok = toks.peek();
141  if (tok.String() == "=")
142  {
143  // swallow '='
144  toks.get();
145 
146  if (toks.eof())
147  return FALSE;
148 
149  tok=toks.get();
150 
151  if (tok.String() == "")
152  return FALSE;
153 
154  val=tok.String();
155  }
156  else
157  {
158  val=key;
159  key="";
160  }
161 
162  arguments.set(key,val);
163  }
164 
165 
166  toks.close();
167  return TRUE;
168 }
169 
170 EST_String EST_FringeServer::build_command(const EST_String package,
171  const EST_String operation,
172  const EST_Server::Args &arguments)
173 {
174  EST_String c="";
175 
176  if (package != "")
177  c += package + ".";
178 
179  c += operation;
180 
182 
183  for (argp.begin(arguments); argp != 0; ++argp)
184  {
185  c += " ";
186  if (argp->k != "")
187  c += argp->k + "=";
188 
189  c += argp->v.String().quote_if_needed('"');
190  }
191 
192  return c;
193 }
194 
195 
196 
197 bool EST_FringeServer::parse_result(const EST_String resultString,
198  EST_Server::Result &res)
199 {
200  res.set("STRING", resultString);
201  return TRUE;
202 }
203 
204 EST_String EST_FringeServer::build_result(const EST_Server::Result &res)
205 {
206  (void)res;
207  return "";
208 }