Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_SiodServer.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  /* Simple scheme server. */
37  /* */
38  /*************************************************************************/
39 
40 #include "EST_system.h"
41 #include "EST_unix.h"
42 #include "EST_ServiceTable.h"
43 #include "EST_SiodServer.h"
44 #include "EST_Pathname.h"
45 #include "EST_error.h"
46 #include "EST_Token.h"
47 #include "siod.h"
48 
49 static EST_Regex ipnum("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
50 
51 
52 EST_SiodServer::ResultHandler::ResultHandler()
53 {
54 }
55 
56 EST_SiodServer::ResultHandler::~ResultHandler()
57 {
58 }
59 
60 void EST_SiodServer::ResultHandler::process(void)
61 {
62 }
63 
64 EST_SiodServer::RequestHandler::RequestHandler()
65 {
66 }
67 
68 EST_SiodServer::RequestHandler::~RequestHandler()
69 {
70 }
71 
72 EST_String EST_SiodServer::RequestHandler::process(void)
73 {
74  volatile LISP sexp = scheme(args.val("sexp"));
75  volatile LISP result = NULL;
76 
77  CATCH_ERRORS()
78  {
79  res.set_val("sexp", est_val(NIL));
80  return "siod error";
81  }
82 
83  result = leval(sexp, current_env);
84 
85  END_CATCH_ERRORS();
86 
87  res.set_val("sexp", est_val(result));
88 
89  return "";
90 }
91 
92 EST_SiodServer::EST_SiodServer(EST_String name, ostream *trace)
93  : EST_Server(name, "siod", trace)
94 {
95 }
96 
97 EST_SiodServer::EST_SiodServer(EST_String name)
98  : EST_Server(name, "siod")
99 {
100 }
101 
102 EST_SiodServer::EST_SiodServer(EST_String hostname, int port, ostream *trace)
103  : EST_Server(hostname, port, trace)
104 {
105 }
106 
107 EST_SiodServer::EST_SiodServer(EST_Server::Mode mode, EST_String name)
108  : EST_Server(mode, name, "siod")
109 {
110 }
111 
112 EST_SiodServer::EST_SiodServer(EST_Server::Mode mode, EST_String name, ostream *trace)
113  : EST_Server(mode, name, "siod", trace)
114 {
115 }
116 
117 EST_SiodServer::EST_SiodServer(EST_String hostname, int port)
118  : EST_Server(hostname, port)
119 {
120 }
121 
123 {
124 }
125 
126 bool EST_SiodServer::parse_command(const EST_String command,
127  EST_String &package,
128  EST_String &operation,
129  EST_SiodServer::Args &arguments)
130 {
131  package="scheme";
132  operation="eval";
133 
134  LISP sexp = read_from_string((char *)(const char *)command);
135 
136  arguments.set_val("sexp", est_val(sexp));
137 
138  return TRUE;
139 }
140 
141 EST_String EST_SiodServer::build_command(const EST_String package,
142  const EST_String operation,
143  const EST_SiodServer::Args &arguments)
144 {
145  (void)operation;
146  if (package == "scheme" && operation == "eval")
147  {
148  LISP sexp = scheme(arguments.val("sexp"));
149  return siod_sprint(sexp);
150  }
151  else
152  return "";
153 }
154 
155 bool EST_SiodServer::parse_result(const EST_String resultString,
156  EST_Server::Result &res)
157 {
158  LISP sexp = read_from_string((char *)(const char *)resultString);
159 
160  res.set_val("sexp", est_val(sexp));
161  return TRUE;
162 }
163 
164 EST_String EST_SiodServer::build_result(const EST_Server::Result &res)
165 {
166 
167  LISP sexp = scheme(res.val("sexp"));
168  return siod_sprint(sexp);
169 }
170 
171 
172