Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
fringe_client_main.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 client which talks to fringe. */
37  /* */
38  /*************************************************************************/
39 
40 #include <cstdlib>
41 #include "EST_unix.h"
42 #include "EST_error.h"
43 #include "EST_ServiceTable.h"
44 #include "EST_FringeServer.h"
45 #include "EST_cmd_line.h"
46 
47 /** @name <command>fringe_client</command> <emphasis>Send commands to a running fringe server</emphasis>
48  @id fringe-client-manual
49  * @toc
50  */
51 
52 //@{
53 
54 
55 /**@name Synopsis
56  */
57 //@{
58 
59 //@synopsis
60 
61 /**
62 
63  <command>fringe_client</command> is a simple program for sending
64  commands to a <command>fringe</command> process which is running in
65  server mode.
66 
67  */
68 
69 //@}
70 
71 /**@name OPTIONS
72  */
73 //@{
74 
75 //@options
76 
77 //@}
78 
79 
80 int main(int argc, char *argv[])
81 {
82  EST_String out_file, ext;
83  EST_StrList commands;
84  EST_Option al;
85  int verbose;
86 
87  parse_command_line
88  (argc, argv,
89  EST_String("[options] [command]\n")+
90  "Summary: Send commands to a running fringe server.\n"
91  "use \"-\" to make input and output files stdin/out\n"
92  "-h Options help\n"
93  "-n <string> Name of fringe to connect to (default 'fringe').\n"
94  "-f <ifile> File containing fringe connection information.\n"
95  "-l List available fringe servers.\n"
96  "-v Print what is being done.\n",
97  commands, al);
98 
99  verbose=al.present("-v");
100 
101  if (al.present("-f"))
103  else
105 
106  EST_String name="fringe";
107 
108  if (al.present("-n"))
109  name = al.sval("-n");
110 
111  if (al.present("-l"))
112  {
113  EST_ServiceTable::list(cout, "fringe");
114  exit(0);
115  }
116 
117  EST_FringeServer server(name, verbose?&cout:(ostream *)NULL);
118 
119  switch (server.connect())
120  {
121  case connect_ok:
122  break;
123 
124  case connect_not_found_error:
125  EST_sys_error("Can't find host '%s:%d'", (const char *)server.servername(), server.port());
126  break;
127 
128  case connect_not_allowed_error:
129  EST_sys_error("Can't connect to '%s:%d'", (const char *)server.servername(), server.port());
130  break;
131 
132  default:
133  EST_sys_error("Error connecting to '%s:%d'", (const char *)server.servername(), server.port());
134  break;
135  }
136 
138 
139  for(p.begin(commands); p != 0; ++p)
140  {
141  EST_String package;
142  EST_String operation;
145  EST_FringeServer::Result &res = res_hand.res;
146 
147  if (server.parse_command(*p,
148  package,
149  operation,
150  args))
151  {
152  if (verbose)
153  {
154  printf("command package='%s' operation='%s'\n",
155  (const char *)package,
156  (const char *)operation);
157 
159 
160  for (argp.begin(args); argp != 0; ++argp)
161  printf("\t%10s%s%s\n",
162  (const char *)argp->k,
163  argp->k==""?" : ":" = ",
164  (const char *)argp->v.String());
165  }
166 
167  if (!server.execute(package,
168  operation,
169  args,
170  res_hand))
171  EST_error("Error from Fringe: %s",
172  (const char *)res.S("ERROR"));
173 
174  }
175  else
176  EST_error("badly formatted command '%s'", (const char *)*p);
177  }
178 
179  return(0);
180 }
181 
182 /**@name Finding Fringe.
183 
184 Each <command>fringe</command> which runs in server mode registers
185 it's location in a file called <filename>.estServices</filename> in
186 the users home directory. Multiple servers can be present if they are
187 given different names, and the <option>-n</option> can be used to
188 select which fringe a command is sent to.
189 
190 */