libexec.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Open Source Telecom Corp.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccScript.  If you copy code from other releases into a copy of GNU
00028 // ccScript, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccScript, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00038 #ifndef CCXX_LIBEXEC_H_
00039 #define CCXX_LIBEXEC_H_
00040 
00041 #ifndef CCXX_BAYONNE_H_
00042 #include <cc++/bayonne.h>
00043 #endif
00044 
00045 #ifndef CCXX_SLOG_H_
00046 #include <cc++/slog.h>
00047 #endif
00048 
00049 #ifndef CCXX_PROCESS_H_
00050 #include <cc++/process.h>
00051 #endif
00052 
00053 namespace ost {
00054 
00063 class __EXPORT Libexec : public Bayonne
00064 {
00065 protected:
00066         Keydata head, args;
00067         const char *tsid;
00068         const char *voice;
00069         Audio::Level level;
00070 
00071 public:
00072         result_t result;
00073         char digits[64];
00074         char query[512];
00075         char position[32];
00076         unsigned exitcode, reply;
00077 
00081         Libexec();
00082 
00089         const char *getEnv(const char *id);
00090 
00097         const char *getArg(const char *id);     
00098 
00107         const char *getPath(const char *filename, char *buffer, unsigned size);
00108 
00115         const char *getFile(const char *filename);
00116 
00122         inline void setVoice(const char *voice)
00123                 {voice = voice;};
00124 
00130         inline void setLevel(Audio::Level level)
00131                 {level = level;};
00132 
00136         void hangupSession(void);
00137 
00141         void detachSession(unsigned code);
00142 
00151         result_t sendCommand(const char *text, char *buffer = NULL, unsigned size = 0);
00152 
00159         result_t sendResult(const char *text);
00160 
00166         void sendError(const char *msg);
00167 
00174         result_t xferCall(const char *dest);
00175 
00182         result_t replayFile(const char *file);
00183 
00191         result_t replayOffset(const char *file, const char *offset);                                                                            
00192 
00201         result_t recordFile(const char *file, timeout_t duration, timeout_t silence = 0);
00202 
00209         result_t speak(const char *format, ...);
00210 
00219         result_t playTone(const char *name, timeout_t duration = 0, unsigned level = 0);
00220         result_t playSingleTone(short f1, timeout_t duration, unsigned level = 0);
00221         result_t playDualTone(short f1, short f2, timeout_t duration, unsigned level = 0);
00222 
00232         result_t recordOffset(const char *file, const char *offset, timeout_t duration, timeout_t silence = 0);                                                                            
00233 
00240         result_t eraseFile(const char *file);
00241 
00249         result_t moveFile(const char *file1, const char *file2);
00250 
00254         result_t clearInput(void);
00255 
00261         bool waitInput(timeout_t timeout);
00262                                            
00271         result_t readInput(char *buffer, unsigned size, timeout_t timeout);
00272 
00279         char readKey(timeout_t timeout);
00280 
00281         result_t sizeSym(const char *id, unsigned size);
00282         result_t addSym(const char *id, const char *value);
00283         result_t setSym(const char *id, const char *value);
00284         result_t getSym(const char *id, char *buf, unsigned size);
00285 
00293         void postSym(const char *id, const char *value);
00294 };       
00295 
00296 class __EXPORT BayonneTSession : public BayonneSession
00297 {
00298 protected:
00299         friend class __EXPORT BayonneSysexec;
00300 
00301         void sysPost(const char *sid, char *id, const char *value);
00302         void sysVar(const char *tsid, char *id, const char *value, int size);
00303         void sysHeader(const char *tsid);
00304         void sysArgs(const char *tsid);
00305         void sysStatus(const char *tsid);  
00306         void sysRecord(const char *tsid, char *token);
00307         void sysReplay(const char *tsid, char *token);
00308         void sysFlush(const char *tsid);
00309         void sysWait(const char *tsid, char *token);
00310         void sysTone(const char *tsid, char *token);
00311         void sysSTone(const char *tsid, char *token);
00312         void sysDTone(const char *tsid, char *token);
00313         void sysPrompt(const char *tsid, const char *voice, const char *text);
00314         void sysInput(const char *tsid, char *token);
00315         void sysHangup(const char *tsid);
00316         void sysExit(const char *tsid, char *token);
00317         void sysError(const char *tsid, char *token);
00318         void sysReturn(const char *tsid, const char *text);
00319         void sysXfer(const char *tsid, const char *dest);
00320 };
00321 
00328 class __EXPORT BayonneSysexec : protected Thread, protected Bayonne
00329 {
00330 private:
00331         static bool exiting;
00332 #ifndef WIN32
00333         static int iopair[2];
00334 #endif
00335         static BayonneSysexec *libexec;
00336 
00337         static void readline(char *buf, unsigned max);
00338 
00339         void run(void);
00340 
00341         BayonneSysexec();
00342         ~BayonneSysexec();
00343 
00344 public:
00345         static bool create(BayonneSession *s);
00346         static void allocate(const char *path, size_t bs = 0, int pri = 0, const char *modpath = NULL);
00347         static void cleanup(void);
00348         static void startup(void);
00349 };
00350 
00351 }; // namespace
00352 
00353 #endif

Generated on Wed Jan 16 04:45:26 2008 for Bayonne by  doxygen 1.5.4