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 *v)
00123                 {voice = v;};
00124 
00130         inline void setLevel(Audio::Level l)
00131                 {level = l;};
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 
00167         result_t xferCall(const char *dest);
00168 
00175         result_t replayFile(const char *file);
00176 
00184         result_t replayOffset(const char *file, const char *offset);                                                                            
00185 
00194         result_t recordFile(const char *file, timeout_t duration, timeout_t silence = 0);
00195 
00202         result_t speak(const char *format, ...);
00203 
00212         result_t playTone(const char *name, timeout_t duration = 0, unsigned level = 0);
00213         result_t playSingleTone(short f1, timeout_t duration, unsigned level = 0);
00214         result_t playDualTone(short f1, short f2, timeout_t duration, unsigned level = 0);
00215 
00225         result_t recordOffset(const char *file, const char *offset, timeout_t duration, timeout_t silence = 0);                                                                            
00226 
00233         result_t eraseFile(const char *file);
00234 
00242         result_t moveFile(const char *file1, const char *file2);
00243 
00247         result_t clearInput(void);
00248 
00254         bool waitInput(timeout_t timeout);
00255                                            
00264         result_t readInput(char *buffer, unsigned size, timeout_t timeout);
00265 
00272         char readKey(timeout_t timeout);
00273 
00274         result_t sizeSym(const char *id, unsigned size);
00275         result_t addSym(const char *id, const char *value);
00276         result_t setSym(const char *id, const char *value);
00277         result_t getSym(const char *id, char *buf, unsigned size);
00278 
00286         void postSym(const char *id, const char *value);
00287 };       
00288 
00289 class __EXPORT BayonneTSession : public BayonneSession
00290 {
00291 protected:
00292         friend class __EXPORT BayonneSysexec;
00293 
00294         void sysPost(const char *sid, char *id, const char *value);
00295         void sysVar(const char *tsid, char *id, const char *value, int size);
00296         void sysHeader(const char *tsid);
00297         void sysArgs(const char *tsid);
00298         void sysStatus(const char *tsid);  
00299         void sysRecord(const char *tsid, char *token);
00300         void sysReplay(const char *tsid, char *token);
00301         void sysFlush(const char *tsid);
00302         void sysWait(const char *tsid, char *token);
00303         void sysTone(const char *tsid, char *token);
00304         void sysSTone(const char *tsid, char *token);
00305         void sysDTone(const char *tsid, char *token);
00306         void sysPrompt(const char *tsid, const char *voice, const char *text);
00307         void sysInput(const char *tsid, char *token);
00308         void sysHangup(const char *tsid);
00309         void sysExit(const char *tsid, char *token);
00310         void sysReturn(const char *tsid, const char *text);
00311         void sysXfer(const char *tsid, const char *dest);
00312 };
00313 
00320 class __EXPORT BayonneSysexec : protected Thread, protected Bayonne
00321 {
00322 private:
00323         static bool exiting;
00324 #ifndef WIN32
00325         static int iopair[2];
00326 #endif
00327         static BayonneSysexec *libexec;
00328 
00329         static void readline(char *buf, unsigned max);
00330 
00331         void run(void);
00332 
00333         BayonneSysexec();
00334         ~BayonneSysexec();
00335 
00336 public:
00337         static bool create(BayonneSession *s);
00338         static void allocate(const char *path, size_t bs = 0, int pri = 0, const char *modpath = NULL);
00339         static void cleanup(void);
00340         static void startup(void);
00341 };
00342 
00343 }; // namespace
00344 
00345 #endif

Generated on Tue May 2 13:21:08 2006 for Bayonne by  doxygen 1.4.6