Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 int main(int argc, char *argv[])
48 {
49  EST_String out_file, ext;
50  EST_StrList commands;
51  EST_Option al;
52  int verbose;
53 
54  parse_command_line
55  (argc, argv,
56  EST_String("[options] [command]\n")+
57  "Summary: Send commands to a running fringe server.\n"
58  "use \"-\" to make input and output files stdin/out\n"
59  "-h Options help\n"
60  "-n <string> Name of fringe to connect to (default 'fringe').\n"
61  "-f <ifile> File containing fringe connection information.\n"
62  "-l List available fringe servers.\n"
63  "-v Print what is being done.\n",
64  commands, al);
65 
66  verbose=al.present("-v");
67 
68  if (al.present("-f"))
70  else
72 
73  EST_String name="fringe";
74 
75  if (al.present("-n"))
76  name = al.sval("-n");
77 
78  if (al.present("-l"))
79  {
80  EST_ServiceTable::list(cout, "fringe");
81  exit(0);
82  }
83 
84  EST_FringeServer server(name, verbose?&cout:(ostream *)NULL);
85 
86  switch (server.connect())
87  {
88  case connect_ok:
89  break;
90 
91  case connect_not_found_error:
92  EST_sys_error("Can't find host '%s:%d'", (const char *)server.servername(), server.port());
93  break;
94 
95  case connect_not_allowed_error:
96  EST_sys_error("Can't connect to '%s:%d'", (const char *)server.servername(), server.port());
97  break;
98 
99  default:
100  EST_sys_error("Error connecting to '%s:%d'", (const char *)server.servername(), server.port());
101  break;
102  }
103 
105 
106  for(p.begin(commands); p != 0; ++p)
107  {
108  EST_String package;
109  EST_String operation;
112  EST_FringeServer::Result &res = res_hand.res;
113 
114  if (server.parse_command(*p,
115  package,
116  operation,
117  args))
118  {
119  if (verbose)
120  {
121  printf("command package='%s' operation='%s'\n",
122  (const char *)package,
123  (const char *)operation);
124 
126 
127  for (argp.begin(args); argp != 0; ++argp)
128  printf("\t%10s%s%s\n",
129  (const char *)argp->k,
130  argp->k==""?" : ":" = ",
131  (const char *)argp->v.String());
132  }
133 
134  if (!server.execute(package,
135  operation,
136  args,
137  res_hand))
138  EST_error("Error from Fringe: %s",
139  (const char *)res.S("ERROR"));
140 
141  }
142  else
143  EST_error("badly formatted command '%s'", (const char *)*p);
144  }
145 
146  return(0);
147 }
148 
149 
A class providing mechanisms to talk to fringe.
const EST_String S(const EST_String &path) const
Definition: EST_Features.h:158
const EST_String & sval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:87
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
static void list(ostream &s, const EST_String type)
List the table to given stream.
static void read_table(void)
Read the users default table. ~/.estServices
void begin(const Container &over)
Set the iterator ready to run over this container.