Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
libexec.h
Go to the documentation of this file.
1 // Copyright (C) 2005 Open Source Telecom Corp.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccScript. If you copy code from other releases into a copy of GNU
28 // ccScript, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccScript, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
38 #ifndef CCXX_LIBEXEC_H_
39 #define CCXX_LIBEXEC_H_
40 
41 #ifndef CCXX_BAYONNE_H_
42 #include <cc++/bayonne.h>
43 #endif
44 
45 #ifndef CCXX_SLOG_H_
46 #include <cc++/slog.h>
47 #endif
48 
49 #ifndef CCXX_PROCESS_H_
50 #include <cc++/process.h>
51 #endif
52 
53 namespace ost {
54 
63 class __EXPORT Libexec : public Bayonne
64 {
65 protected:
66  Keydata head, args;
67  const char *tsid;
68  const char *voice;
70 
71 public:
72  result_t result;
73  char digits[64];
74  char query[512];
75  char position[32];
76  unsigned exitcode, reply;
77 
81  Libexec();
82 
89  const char *getEnv(const char *id);
90 
97  const char *getArg(const char *id);
98 
107  const char *getPath(const char *filename, char *buffer, unsigned size);
108 
115  const char *getFile(const char *filename);
116 
122  inline void setVoice(const char *voice)
123  {voice = voice;};
124 
130  inline void setLevel(Audio::Level level)
131  {level = level;};
132 
136  void hangupSession(void);
137 
141  void detachSession(unsigned code);
142 
151  result_t sendCommand(const char *text, char *buffer = NULL, unsigned size = 0);
152 
159  result_t sendResult(const char *text);
160 
166  void sendError(const char *msg);
167 
174  result_t xferCall(const char *dest);
175 
182  result_t replayFile(const char *file);
183 
191  result_t replayOffset(const char *file, const char *offset);
192 
201  result_t recordFile(const char *file, timeout_t duration, timeout_t silence = 0);
202 
209  result_t speak(const char *format, ...);
210 
219  result_t playTone(const char *name, timeout_t duration = 0, unsigned level = 0);
220  result_t playSingleTone(short f1, timeout_t duration, unsigned level = 0);
221  result_t playDualTone(short f1, short f2, timeout_t duration, unsigned level = 0);
222 
232  result_t recordOffset(const char *file, const char *offset, timeout_t duration, timeout_t silence = 0);
233 
240  result_t eraseFile(const char *file);
241 
249  result_t moveFile(const char *file1, const char *file2);
250 
254  result_t clearInput(void);
255 
261  bool waitInput(timeout_t timeout);
262 
271  result_t readInput(char *buffer, unsigned size, timeout_t timeout);
272 
279  char readKey(timeout_t timeout);
280 
281  result_t sizeSym(const char *id, unsigned size);
282  result_t addSym(const char *id, const char *value);
283  result_t setSym(const char *id, const char *value);
284  result_t getSym(const char *id, char *buf, unsigned size);
285 
293  void postSym(const char *id, const char *value);
294 };
295 
297 {
298 protected:
299  friend class __EXPORT BayonneSysexec;
300 
301  void sysPost(const char *sid, char *id, const char *value);
302  void sysVar(const char *tsid, char *id, const char *value, int size);
303  void sysHeader(const char *tsid);
304  void sysArgs(const char *tsid);
305  void sysStatus(const char *tsid);
306  void sysRecord(const char *tsid, char *token);
307  void sysReplay(const char *tsid, char *token);
308  void sysFlush(const char *tsid);
309  void sysWait(const char *tsid, char *token);
310  void sysTone(const char *tsid, char *token);
311  void sysSTone(const char *tsid, char *token);
312  void sysDTone(const char *tsid, char *token);
313  void sysPrompt(const char *tsid, const char *voice, const char *text);
314  void sysInput(const char *tsid, char *token);
315  void sysHangup(const char *tsid);
316  void sysExit(const char *tsid, char *token);
317  void sysError(const char *tsid, char *token);
318  void sysReturn(const char *tsid, const char *text);
319  void sysXfer(const char *tsid, const char *dest);
320 };
321 
328 class __EXPORT BayonneSysexec : protected Thread, protected Bayonne
329 {
330 private:
331  static bool exiting;
332 #ifndef WIN32
333  static int iopair[2];
334 #endif
336 
337  static void readline(char *buf, unsigned max);
338 
339  void run(void);
340 
341  BayonneSysexec();
342  ~BayonneSysexec();
343 
344 public:
345  static bool create(BayonneSession *s);
346  static void allocate(const char *path, size_t bs = 0, int pri = 0, const char *modpath = NULL);
347  static void cleanup(void);
348  static void startup(void);
349 };
350 
351 }; // namespace
352 
353 #endif
Keydata head
Definition: libexec.h:66
int16_t Level
Definition: audio2.h:101
unsigned reply
Definition: libexec.h:76
Audio::Level level
Definition: libexec.h:69
static bool exiting
Definition: libexec.h:331
Generic Bayonne master class to reference various useful data types and core static members used for ...
Definition: bayonne.h:251
Core class for any server which impliments libexec functionality.
Definition: libexec.h:328
Keydata objects are used to load and hold "configuration" data for a given application.
Definition: misc.h:352
unsigned long timeout_t
Definition: thread.h:74
Process services.
Container class for applications implimenting the libexec process method of Bayonne interfacing...
Definition: libexec.h:63
static BayonneSysexec * libexec
Definition: libexec.h:335
The primary session object representing a server timeslot and active communication endpoint in Bayonn...
Definition: bayonne.h:2464
#define __EXPORT
Definition: audio2.h:51
const char * voice
Definition: libexec.h:68
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1093
void setVoice(const char *voice)
Set the effective voice library to use.
Definition: libexec.h:122
result_t result
Definition: libexec.h:72
System logging facilities abstraction.
const char * tsid
Definition: libexec.h:67
void setLevel(Audio::Level level)
Set the effective audio level for tones...
Definition: libexec.h:130