1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
// Copyright (C) 2005 Open Source Telecom Corp.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// This exception applies only to the code released under the name GNU
// ccScript. If you copy code from other releases into a copy of GNU
// ccScript, as the General Public License permits, the exception does
// not apply to the code that you add in this way. To avoid misleading
// anyone as to the status of such modified files, you must delete
// this exception notice from them.
//
// If you write modifications of your own for GNU ccScript, it is your choice
// whether to permit this exception to apply to your modifications.
// If you do not wish that, delete this exception notice.
//
#ifndef CCXX_LIBEXEC_H_
#define CCXX_LIBEXEC_H_
#ifndef CCXX_BAYONNE_H_
#include <cc++/bayonne.h>
#endif
#ifndef CCXX_SLOG_H_
#include <cc++/slog.h>
#endif
#ifndef CCXX_PROCESS_H_
#include <cc++/process.h>
#endif
namespace ost {
/**
* Container class for applications implimenting the libexec process
* method of Bayonne interfacing. This is intended for writing external
* apps and is neatly tucked away into libbayonne as well.
*
* @author David Sugar <dyfet@gnutelephony.org>
* @short Libexec process interface class.
*/
class __EXPORT Libexec : public Bayonne
{
protected:
Keydata head, args;
const char *tsid;
const char *voice;
Audio::Level level;
public:
result_t result;
char digits[64];
char query[512];
char position[32];
unsigned exitcode, reply;
/**
* Initialize libexec.
*/
Libexec();
/**
* Get a header record item.
*
* @param id of header or sys env item.
* @return string value of requested item or NULL.
*/
const char *getEnv(const char *id);
/**
* Get a named libexec command line argument.
*
* @param id of libexec argument.
* @return string value of requested argument or NULL.
*/
const char *getArg(const char *id);
/**
* Get a fully qualified and resolved pathname.
*
* @return pointer to buffer or NULL if invalid.
* @param filename path to evaluate.
* @param buffer to save into.
* @param size of buffer.
*/
const char *getPath(const char *filename, char *buffer, unsigned size);
/**
* Get and verify partial pathname for file oriented libexec commands.
*
* @return pointer to buffer or NULL if invalid.
* @param filename path to evaluate.
*/
const char *getFile(const char *filename);
/**
* Set the effective voice library to use.
*
* @param voice to set or NULL for default.
*/
inline void setVoice(const char *voice)
{voice = voice;};
/**
* Set the effective audio level for tones...
*
* @param level to set.
*/
inline void setLevel(Audio::Level level)
{level = level;};
/**
* Hangup running session...
*/
void hangupSession(void);
/**
* Resume server session, libexec continues detached.
*/
void detachSession(unsigned code);
/**
* Send a command through to server and capture result.
*
* @return result code.
* @param command to send.
* @param optional query buffer.
* @param optional query size.
*/
result_t sendCommand(const char *text, char *buffer = NULL, unsigned size = 0);
/**
* Send a result to the server.
*
* @return result code from server.
* @param result to send.
*/
result_t sendResult(const char *text);
/**
* Send an error to the server.
*
* @param error msg to send.
*/
void sendError(const char *msg);
/**
* Transfer a call.
*
* @return result code from server.
* @param destination to transfer.
*/
result_t xferCall(const char *dest);
/**
* Replay an audio file.
*
* @return result code.
* @param name of file to play.
*/
result_t replayFile(const char *file);
/**
* Replay an audio file from a specified offset.
*
* @return result code.
* @param name of file to play.
* @param offset to play from.
*/
result_t replayOffset(const char *file, const char *offset);
/**
* Record an audio file.
*
* @return result code.
* @param name of file to record.
* @param total duration of file.
* @param optional silence detect.
*/
result_t recordFile(const char *file, timeout_t duration, timeout_t silence = 0);
/**
* Play a phrase.
*
* @return result code.
* @param text of phrase to play.
*/
result_t speak(const char *format, ...);
/**
* Play a tone.
*
* @return result code.
* @param name of tone to play.
* @param duration for tone.
* @param audio level of tone.
*/
result_t playTone(const char *name, timeout_t duration = 0, unsigned level = 0);
result_t playSingleTone(short f1, timeout_t duration, unsigned level = 0);
result_t playDualTone(short f1, short f2, timeout_t duration, unsigned level = 0);
/**
* Record an audio file to a specified offset.
*
* @return result code.
* @param name of file to record.
* @param offset to record info.
* @param total duration of file.
* @param optional silence detect.
*/
result_t recordOffset(const char *file, const char *offset, timeout_t duration, timeout_t silence = 0);
/**
* Erase an audio file.
*
* @return result code.
* @param name of file to erase.
*/
result_t eraseFile(const char *file);
/**
* Move an audio file.
*
* @return result code.
* @param name of file to move.
* @param destination of move.
*/
result_t moveFile(const char *file1, const char *file2);
/**
* Flush input.
*/
result_t clearInput(void);
/**
* Wait for input.
*
* @return true if input waiting.
*/
bool waitInput(timeout_t timeout);
/**
* Read a line of input.
*
* @return result code.
* @param input buffer.
* @param size of input buffer.
* @param timeout for input.
*/
result_t readInput(char *buffer, unsigned size, timeout_t timeout);
/**
* Read a single key of input.
*
* @return key input or 0.
* @param timeout for read.
*/
char readKey(timeout_t timeout);
result_t sizeSym(const char *id, unsigned size);
result_t addSym(const char *id, const char *value);
result_t setSym(const char *id, const char *value);
result_t getSym(const char *id, char *buf, unsigned size);
/**
* Post a symbol asychrononous event to server. This sets the
* symbol value, and also generates a @posted:symname event.
*
* @param id of symbol to post.
* @param value of symbol.
*/
void postSym(const char *id, const char *value);
};
class __EXPORT BayonneTSession : public BayonneSession
{
protected:
friend class __EXPORT BayonneSysexec;
void sysPost(const char *sid, char *id, const char *value);
void sysVar(const char *tsid, char *id, const char *value, int size);
void sysHeader(const char *tsid);
void sysArgs(const char *tsid);
void sysStatus(const char *tsid);
void sysRecord(const char *tsid, char *token);
void sysReplay(const char *tsid, char *token);
void sysFlush(const char *tsid);
void sysWait(const char *tsid, char *token);
void sysTone(const char *tsid, char *token);
void sysSTone(const char *tsid, char *token);
void sysDTone(const char *tsid, char *token);
void sysPrompt(const char *tsid, const char *voice, const char *text);
void sysInput(const char *tsid, char *token);
void sysHangup(const char *tsid);
void sysExit(const char *tsid, char *token);
void sysError(const char *tsid, char *token);
void sysReturn(const char *tsid, const char *text);
void sysXfer(const char *tsid, const char *dest);
};
/**
* Core class for any server which impliments libexec functionality.
*
* @author David Sugar
* @short Server system execution interface
*/
class __EXPORT BayonneSysexec : protected Thread, protected Bayonne
{
private:
static bool exiting;
#ifndef WIN32
static int iopair[2];
#endif
static BayonneSysexec *libexec;
static void readline(char *buf, unsigned max);
void run(void);
BayonneSysexec();
~BayonneSysexec();
public:
static bool create(BayonneSession *s);
static void allocate(const char *path, size_t bs = 0, int pri = 0, const char *modpath = NULL);
static void cleanup(void);
static void startup(void);
};
}; // namespace
#endif
|