00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CCXX_BAYONNE_H_
00039 #define CCXX_BAYONNE_H_
00040
00041 #ifndef CCXX_SCRIPT3_H_
00042 #include <cc++/script3.h>
00043 #endif
00044
00045 #ifndef CCXX_CCAUDIO2_H_
00046 #include <cc++/audio2.h>
00047 #endif
00048
00049 #ifndef CCXX_SOCKET_H_
00050 #include <cc++/socket.h>
00051 #endif
00052
00053 #define BAYONNE_RELEASE 1 // release check sequence
00054 #define NO_TIMESLOT 0xffff
00055 #define MAX_DTMF 32
00056 #define MAX_LIST 256
00057 #define MAX_LIBINPUT 256
00058 #define MAX_PATHNAME 256
00059 #define MIN_AUDIOFEED (120 * 8) // 120 millisecond starting
00060 #define MAX_AUDIOFEED (600 * 8) // 600 millisecond buffer
00061
00062 #ifdef WIN32
00063 #define PFD_INVALID INVALID_HANDLE_VALUE
00064 #else
00065 #define PFD_INVALID -1
00066 #endif
00067
00068 #if SCRIPT_RIPPLE_LEVEL < 2
00069 #error "ccscript 3 0.8.0 or later required"
00070 #endif
00071
00072 namespace ost {
00073
00074 class __EXPORT BayonneMsgport;
00075 class __EXPORT BayonneDriver;
00076 class __EXPORT BayonneSession;
00077 class __EXPORT BayonneSpan;
00078 class __EXPORT BayonneService;
00079 class __EXPORT BayonneTranslator;
00080
00088 class __EXPORT Bayonne : public Script
00089 {
00090 public:
00091 #ifdef WIN32
00092 typedef WORD timeslot_t;
00093 #else
00094 typedef uint16_t timeslot_t;
00095 #endif
00096
00097 protected:
00098 static BayonneSession **timeslots;
00099 static char *status;
00100 static ScriptCommand *server;
00101 static timeslot_t ts_count;
00102 static timeslot_t ts_used;
00103 static std::ostream *logging;
00104 static const char *path_prompts;
00105 static const char *path_tmpfs;
00106 static const char *path_tmp;
00107 static unsigned idle_count;
00108 static unsigned idle_limit;
00109 static bool shutdown_flag;
00110 static char sla[];
00111 static time_t start_time;
00112
00113 public:
00114 static timeout_t step_timer;
00115 static timeout_t reset_timer;
00116 static timeout_t exec_timer;
00117 static unsigned compile_count;
00118 static volatile bool image_loaded;
00119 static bool provision_ripple;
00120 static bool provision_daemon;
00121 static bool provision_system;
00122 static bool provision_check;
00123 static bool provision_user;
00124 static bool provision_test;
00125 static const char *provision_server;
00126 static const char *provision_libexec;
00127
00128 static Audio::Encoding peer_encoding;
00129 static Audio::timeout_t peer_framing;
00130 static BayonneTranslator *init_translator;
00131 static const char *init_voicelib;
00132 static AtomicCounter libexec_count;
00133
00134 static const char *getKeypath(const char *cp);
00135
00139 typedef enum
00140 {
00141 IF_PSTN,
00142 IF_SPAN,
00143 IF_ISDN,
00144 IF_SS7,
00145 IF_INET,
00146 IF_NONE,
00147 IF_POTS=IF_PSTN
00148 } interface_t;
00149
00153 typedef enum
00154 {
00155 NONE,
00156 INCOMING,
00157 OUTGOING,
00158 PICKUP,
00159 FORWARDED,
00160 RECALL,
00161 DIRECT
00162 } calltype_t;
00163
00167 typedef enum
00168 {
00169 BR_TDM,
00170 BR_INET,
00171 BR_SOFT,
00172 BR_GATE,
00173 BR_NONE
00174 } bridge_t;
00175
00181 typedef enum
00182 {
00183 STATE_INITIAL = 0,
00184 STATE_IDLE,
00185 STATE_RESET,
00186 STATE_RELEASE,
00187 STATE_BUSY,
00188 STATE_DOWN,
00189 STATE_RING,
00190 STATE_PICKUP,
00191 STATE_SEIZE,
00192 STATE_STEP,
00193 STATE_EXEC,
00194 STATE_THREAD,
00195 STATE_CLEAR,
00196 STATE_INKEY,
00197 STATE_INPUT,
00198 STATE_READ,
00199 STATE_COLLECT,
00200 STATE_DIAL,
00201 STATE_XFER,
00202 STATE_HOLD,
00203 STATE_RECALL,
00204 STATE_TONE,
00205 STATE_DTMF,
00206 STATE_PLAY,
00207 STATE_RECORD,
00208 STATE_JOIN,
00209 STATE_WAIT,
00210 STATE_CONNECT,
00211 STATE_SLEEP,
00212 STATE_START,
00213 STATE_HANGUP,
00214 STATE_LIBRESET,
00215 STATE_WAITKEY,
00216 STATE_LIBWAIT,
00217 STATE_IRESET,
00218 STATE_FINAL,
00219
00220 STATE_STANDBY = STATE_DOWN,
00221 STATE_LIBEXEC = STATE_EXEC,
00222 STATE_RINGING = STATE_RING,
00223 STATE_RUNNING = STATE_STEP,
00224 STATE_THREADING = STATE_THREAD
00225 } state_t;
00226
00231 typedef enum
00232 {
00233 SIGNAL_EXIT = 0,
00234 SIGNAL_ERROR,
00235 SIGNAL_TIMEOUT,
00236 SIGNAL_DTMF,
00237
00238 SIGNAL_0,
00239 SIGNAL_1,
00240 SIGNAL_2,
00241 SIGNAL_3,
00242 SIGNAL_4,
00243 SIGNAL_5,
00244 SIGNAL_6,
00245 SIGNAL_7,
00246 SIGNAL_8,
00247 SIGNAL_9,
00248 SIGNAL_STAR,
00249 SIGNAL_POUND,
00250 SIGNAL_A,
00251 SIGNAL_OVERRIDE = SIGNAL_A,
00252 SIGNAL_B,
00253 SIGNAL_FLASH = SIGNAL_B,
00254 SIGNAL_C,
00255 SIGNAL_IMMEDIATE = SIGNAL_C,
00256 SIGNAL_D,
00257 SIGNAL_PRIORITY = SIGNAL_D,
00258
00259 SIGNAL_RING,
00260 SIGNAL_TONE,
00261 SIGNAL_EVENT,
00262 SIGNAL_WINK,
00263
00264 SIGNAL_CHILD,
00265 SIGNAL_FAIL,
00266 SIGNAL_PICKUP,
00267 SIGNAL_PART,
00268
00269 SIGNAL_INVALID,
00270 SIGNAL_PARENT,
00271 SIGNAL_WAIT,
00272
00273 SIGNAL_HANGUP = SIGNAL_EXIT
00274 } signal_t;
00275
00281 typedef enum
00282 {
00283
00284
00285 MSGPORT_WAKEUP = 0,
00286 MSGPORT_SHUTDOWN,
00287 MSGPORT_LOGGING,
00288 MSGPORT_REGISTER,
00289
00290
00291
00292 ENTER_STATE = 100,
00293 EXIT_STATE,
00294 EXIT_THREAD,
00295 EXIT_TIMER,
00296 EXIT_PARTING,
00297 NULL_EVENT,
00298 ERROR_STATE,
00299
00300
00301
00302 START_DIRECT = 200,
00303 START_INCOMING,
00304 START_OUTGOING,
00305 START_RECALL,
00306 START_FORWARDED,
00307 STOP_SCRIPT,
00308 STOP_DISCONNECT,
00309 STOP_PARENT,
00310 CANCEL_CHILD,
00311 DETACH_CHILD,
00312 CHILD_RUNNING,
00313 CHILD_FAILED,
00314 CHILD_INVALID,
00315 CHILD_EXPIRED,
00316 CHILD_BUSY,
00317 CHILD_FAX,
00318
00319 START_SCRIPT = START_INCOMING,
00320 START_SELECTED = START_OUTGOING,
00321
00322
00323
00324 ENTER_LIBEXEC = 300,
00325 EXIT_LIBEXEC,
00326 HEAD_LIBEXEC,
00327 ARGS_LIBEXEC,
00328 GOT_LIBEXEC,
00329 READ_LIBEXEC,
00330 DROP_LIBEXEC,
00331 STAT_LIBEXEC,
00332 PROMPT_LIBEXEC,
00333 CLEAR_LIBEXEC,
00334 WAIT_LIBEXEC,
00335 RECORD_LIBEXEC,
00336 REPLAY_LIBEXEC,
00337 RESTART_LIBEXEC,
00338 TONE_LIBEXEC,
00339 XFER_LIBEXEC,
00340 POST_LIBEXEC,
00341
00342
00343
00344 TIMER_EXPIRED = 400,
00345 LINE_WINK,
00346 LINE_PICKUP,
00347 LINE_HANGUP,
00348 LINE_DISCONNECT,
00349 LINE_ON_HOOK,
00350 LINE_OFF_HOOK,
00351 RING_ON,
00352 RING_OFF,
00353 RING_STOP,
00354 LINE_CALLER_ID,
00355 RINGING_DID,
00356 DEVICE_BLOCKED,
00357 DEVICE_UNBLOCKED,
00358 DEVICE_OPEN,
00359 DEVICE_CLOSE,
00360 DSP_READY,
00361
00362
00363
00364 CALL_DETECT = 500,
00365 CALL_CONNECTED,
00366 CALL_RELEASED,
00367 CALL_ACCEPTED,
00368 CALL_ANSWERED,
00369 CALL_HOLD,
00370 CALL_HOLDING=CALL_HOLD,
00371 CALL_NOHOLD,
00372 CALL_DIGITS,
00373 CALL_OFFERED,
00374 CALL_ANI,
00375 CALL_ACTIVE,
00376 CALL_NOACTIVE,
00377 CALL_BILLING,
00378 CALL_RESTART,
00379 CALL_SETSTATE,
00380 CALL_FAILURE,
00381 CALL_ALERTING,
00382 CALL_INFO,
00383 CALL_BUSY,
00384 CALL_DIVERT,
00385 CALL_FACILITY,
00386 CALL_FRAME,
00387 CALL_NOTIFY,
00388 CALL_NSI,
00389 CALL_RINGING,
00390 CALL_DISCONNECT,
00391 CALL_CLEARED,
00392 RESTART_FAILED,
00393 RELEASE_FAILED,
00394
00395
00396
00397 START_RING = 600,
00398 STOP_RING,
00399 CLEAR_TIMESLOT,
00400 START_FLASH,
00401 STOP_FLASH,
00402 DIAL_CONNECT,
00403 DIAL_TIMEOUT,
00404 DIAL_FAILED,
00405 DIAL_INVALID,
00406 DIAL_BUSY,
00407 DIAL_FAX,
00408 DIAL_PAM,
00409
00410 DIAL_MACHINE = DIAL_PAM,
00411
00412
00413
00414 AUDIO_IDLE = 700,
00415 AUDIO_ACTIVE,
00416 AUDIO_EXPIRED,
00417 INPUT_PENDING,
00418 OUTPUT_PENDING,
00419 AUDIO_BUFFER,
00420 TONE_IDLE,
00421 DTMF_KEYDOWN,
00422 DTMF_KEYSYNC,
00423 DTMF_KEYUP,
00424 TONE_START,
00425 TONE_STOP,
00426 AUDIO_START,
00427 AUDIO_STOP,
00428 DTMF_START,
00429 DTMF_STOP,
00430
00431
00432
00433 MAKE_TEST = 800,
00434 MAKE_BUSY,
00435 MAKE_IDLE,
00436 MAKE_DOWN,
00437 MAKE_UP,
00438 MAKE_EXPIRED,
00439 ENABLE_LOGGING,
00440 DISABLE_LOGGING,
00441 PART_EXPIRED,
00442 PART_EXITING,
00443 PART_DISCONNECT,
00444 JOIN_PEER,
00445 PEER_WAITING,
00446
00447
00448
00449 SYSTEM_DOWN = 900,
00450
00451
00452
00453 DRIVER_SPECIFIC = 1000
00454
00455 } event_t;
00456
00457 typedef enum
00458 {
00459 RESULT_SUCCESS = 0,
00460 RESULT_TIMEOUT,
00461 RESULT_INVALID,
00462 RESULT_PENDING,
00463 RESULT_COMPLETE,
00464 RESULT_FAILED,
00465 RESULT_BADPATH = 254,
00466 RESULT_OFFLINE = 255
00467 } result_t;
00468
00469 typedef struct
00470 {
00471 Line line;
00472 char text[MAX_LIBINPUT];
00473 const char *list[MAX_LIBINPUT / 2];
00474 } libaudio_t;
00475
00483 typedef struct
00484 {
00485 event_t id;
00486 timeslot_t timeslot;
00487 uint16 seq;
00488
00489 union
00490 {
00491
00492
00493
00494
00495 struct
00496 {
00497 ScriptImage *img;
00498 Script::Name *scr;
00499 BayonneSession *parent;
00500 const char *dialing;
00501 } start;
00502
00503 struct
00504 {
00505 const char *tid;
00506 #ifdef WIN32
00507 HANDLE pfd;
00508 #else
00509 const char *fname;
00510 #endif
00511 int pid, result;
00512 } libexec;
00513
00514 struct
00515 {
00516 timeout_t duration;
00517 int digit;
00518 } dtmf;
00519
00520 struct
00521 {
00522 const char *err;
00523 const char *msg;
00524 } cpa;
00525
00526 struct
00527 {
00528 const char *name;
00529 bool exit;
00530 } tone;
00531
00532 struct
00533 {
00534 std::ostream *output;
00535 const char *logstate;
00536 } debug;
00537
00538 const char *name;
00539 const char *errmsg;
00540 BayonneSession *pid;
00541 BayonneSession *peer;
00542 void *data;
00543 };
00544
00545 } Event;
00546
00552 typedef bool (BayonneSession::*Handler)(Event *event);
00553
00558 typedef struct
00559 {
00560 const char *name;
00561 Handler handler;
00562 char flag;
00563 } statetab;
00564
00572 typedef struct
00573 {
00574 Handler handler, logstate;
00575 const char *name;
00576 timeout_t timeout;
00577 Name *menu;
00578 unsigned stack;
00579 Line *lib;
00580 #ifdef WIN32
00581 HANDLE pfd;
00582 #else
00583 int pfd;
00584 #endif
00585 result_t result;
00586 int pid;
00587 libaudio_t *libaudio;
00588
00589 union
00590 {
00591 struct
00592 {
00593 unsigned count;
00594 timeout_t interval;
00595 } wait;
00596
00597 struct
00598 {
00599 Audio::Mode mode;
00600 Audio::Level level;
00601 timeout_t total, silence, intersilence;
00602 long lastnum;
00603 bool exitkey;
00604 bool compress;
00605 bool trigger;
00606 const char *pos;
00607 const char *exit;
00608 const char *menu;
00609 const char *note;
00610 const char *list[MAX_LIST];
00611 } audio;
00612
00613 struct
00614 {
00615 timeout_t interdigit;
00616 timeout_t lastdigit;
00617 const char *var;
00618 const char *exit;
00619 const char *format;
00620 const char *ignore;
00621 const char *route;
00622 unsigned count, size, required;
00623 } input;
00624
00625 struct
00626 {
00627 const char *var;
00628 const char *menu;
00629 } inkey;
00630
00631 struct
00632 {
00633 const char *sequence;
00634 bool flashing;
00635 bool dialing;
00636 bool exiting;
00637 bool dtmf;
00638 char *syncdigit;
00639 timeout_t synctimer;
00640 timeout_t duration;
00641 char digits[64];
00642 char sessionid[16];
00643 } tone;
00644
00645 struct
00646 {
00647 timeout_t on, off, interdigit;
00648 unsigned pos;
00649 bool flashing;
00650 bool dialing;
00651 unsigned char digits[64];
00652 } pulse;
00653
00654 struct
00655 {
00656 const char *dial;
00657 const char *exit;
00658 bool dtmf;
00659 BayonneSession *peer;
00660 timeout_t answer_timer;
00661 char digits[64];
00662 } join;
00663
00664 struct
00665 {
00666 const char *ref;
00667 char buf[MAX_LIST * sizeof(char *)];
00668 } url;
00669 };
00670
00671 } State;
00672
00676 static statetab states[];
00677
00682 static Mutex serialize;
00683
00691 static void allocate(timeslot_t timeslots, ScriptCommand *server = NULL);
00692
00696 static void waitLoaded(void);
00697
00703 static unsigned long uptime(void);
00704
00710 static ScriptCompiler *reload(void);
00711
00715 static void down(void);
00716
00723 static bool service(const char *svc);
00724
00732 static BayonneSession *getSession(timeslot_t timeslot);
00733
00742 static BayonneSession *getSid(const char *id);
00743
00751 static timeslot_t toTimeslot(const char *id);
00752
00758 static inline timeslot_t getTimeslotsUsed(void)
00759 {return Bayonne::ts_used;};
00760
00766 static inline timeslot_t getTimeslotCount(void)
00767 {return Bayonne::ts_count;};
00768
00775 static inline timeslot_t getAvailTimeslots(void)
00776 {return Bayonne::ts_count - Bayonne::ts_used;};
00777
00785 static Handler getState(const char *name);
00786
00793 static int getDigit(char dig);
00794
00801 static char getChar(int dtmf);
00802
00813 static bool matchDigits(const char *digits, const char *match, bool partial = false);
00814
00820 static ScriptImage *useImage(void);
00821
00828 static void endImage(ScriptImage *img);
00829
00836 static bool loadPlugin(const char *path);
00837
00844 static bool loadMonitor(const char *path);
00845
00852 static bool loadAudio(const char *path);
00853
00854 static void errlog(const char *level, const char *fmt, ...);
00855 };
00856
00864 class __EXPORT BayonneTranslator : public Bayonne
00865 {
00866 protected:
00867 static BayonneTranslator *first;
00868 BayonneTranslator *next;
00869 const char *id;
00870
00871 static const char *getToken(BayonneSession *s, Line *l, unsigned *idx);
00872 static unsigned addItem(BayonneSession *s, unsigned count, const char *text);
00873 static const char *getLast(BayonneSession *s, unsigned count);
00874
00875 public:
00883 BayonneTranslator(const char *id);
00884
00891 static BayonneTranslator *get(const char *name);
00892
00897 static inline BayonneTranslator *getFirst(void)
00898 {return first;};
00899
00905 inline BayonneTranslator *getNext()
00906 {return next;};
00907
00915 static BayonneTranslator *loadTranslator(const char *name);
00916
00925 virtual unsigned digits(BayonneSession *s, unsigned count, const char *cp);
00926
00935 virtual unsigned spell(BayonneSession *s, unsigned count, const char *cp);
00936
00945 virtual unsigned sayorder(BayonneSession *s, unsigned count, const char *cp);
00946
00955 virtual unsigned number(BayonneSession *s, unsigned count, const char *cp);
00956
00966 virtual unsigned saynumber(BayonneSession *s, unsigned count, const char *cp);
00967
00976 virtual unsigned saycount(BayonneSession *s, unsigned count, const char *cp);
00977
00986 virtual unsigned saytime(BayonneSession *s, unsigned count, const char *cp);
00987
00996 virtual unsigned weekday(BayonneSession *s, unsigned count, const char *cp);
00997
01006 virtual unsigned saydate(BayonneSession *s, unsigned count, const char *cp);
01007
01016 virtual unsigned saybool(BayonneSession *s, unsigned count, const char *cp);
01017
01026 virtual unsigned phone(BayonneSession *s, unsigned count, const char *cp);
01027
01036 virtual unsigned extension(BayonneSession *s, unsigned count, const char *cp);
01037
01044 virtual const char *speak(BayonneSession *session, Line *line = NULL);
01045
01051 inline const char *getId(void)
01052 {return id;};
01053 };
01054
01062 class __EXPORT BayonneAudio : public AudioStream, public Bayonne
01063 {
01064 protected:
01065 char filename[MAX_PATHNAME];
01066 const char **list;
01067 char *getContinuation(void);
01068
01069 public:
01074 AudioTone *tone;
01075
01080 BayonneTranslator *translator;
01081
01085 char vlib[60];
01086
01087 const char *extension, *voicelib, *libext, *prefixdir, *offset;
01088 Encoding encoding;
01089 timeout_t framing;
01090 char var_position[14];
01091
01095 BayonneAudio();
01096
01104 const char *getFilename(const char *name, bool write = false);
01105
01110 void cleanup(void);
01111
01118 void play(const char **list, Mode m = modeRead);
01119
01127 void record(const char *name, Mode m = modeCreate, const char *note = NULL);
01128
01135 const char *getVoicelib(const char *cp);
01136
01142 inline AudioCodec *getCodec(void)
01143 {return codec;};
01144 };
01145
01156 class __EXPORT BayonneMsgport : public Thread, public Buffer, public Bayonne
01157 {
01158 public:
01162 virtual ~BayonneMsgport();
01163
01169 BayonneMsgport(BayonneDriver *driver);
01170
01176 void update(void);
01177
01182 void initial(void);
01183
01184 protected:
01185 BayonneDriver *msgdriver;
01186 Event *msglist;
01187 unsigned msgsize, msghead, msgtail;
01188 timeslot_t tsfirst, tscount;
01189 char msgname[16];
01190
01194 void shutdown(void);
01195
01203 virtual timeout_t getTimeout(Event *event);
01204
01205 void run(void);
01206
01207 size_t onWait(void *buf);
01208 size_t onPost(void *buf);
01209 size_t onPeek(void *buf);
01210 };
01211
01219 class __EXPORT BayonneDriver : public Bayonne, public Keydata, public Mutex
01220 {
01221 protected:
01222 friend class __EXPORT BayonneSession;
01223 friend class __EXPORT BayonneMsgport;
01224 static BayonneDriver *firstDriver;
01225 static BayonneDriver *lastDriver;
01226 static BayonneDriver *trunkDriver;
01227 static BayonneDriver *protoDriver;
01228 static Semaphore oink;
01229 static bool protocols;
01230
01231 BayonneSession *firstIdle, *lastIdle;
01232 BayonneMsgport *msgport;
01233 BayonneDriver *nextDriver;
01234 const char *name;
01235 timeslot_t timeslot, count;
01236 unsigned avail;
01237 unsigned span, spans;
01238 bool running;
01239 std::ostream *logevents;
01240
01241 int audio_priority;
01242 size_t audio_stack;
01243 Audio::Level audio_level;
01244
01245 timeout_t pickup_timer, hangup_timer, seize_timer, ring_timer;
01246 timeout_t reset_timer, release_timer, flash_timer, interdigit_timer;
01247 unsigned answer_count;
01248
01253 virtual void startDriver(void);
01254
01258 virtual void stopDriver(void);
01259
01260 public:
01269 BayonneDriver(Keydata::Define *pairs, const char *cfg, const char *id, bool pri);
01270
01274 ~BayonneDriver();
01275
01279 static inline bool useProtocols(void)
01280 {return protocols;}
01281
01285 static inline BayonneDriver *getTrunking(void)
01286 {return trunkDriver;}
01287
01291 static inline BayonneDriver *getPrimary(void)
01292 {return firstDriver;}
01293
01294
01298 static inline BayonneDriver *getProtocol(void)
01299 {return protoDriver;}
01300
01306 BayonneSession *getIdle(void);
01307
01315 virtual const char *registerScript(ScriptImage *img, Line *line);
01316
01324 virtual const char *assignScript(ScriptImage *img, Line *line);
01325
01332 static BayonneDriver *get(const char *id);
01333
01341 static BayonneDriver *loadDriver(const char *id);
01342
01349 static BayonneDriver *loadTrunking(const char *id);
01350
01358 static BayonneDriver *loadProtocol(const char *id, unsigned timeslots = 0);
01359
01367 static unsigned list(char **items, unsigned max);
01368
01372 static void start(void);
01373
01377 static void stop(void);
01378
01385 static void add(BayonneSession *session);
01386
01393 static void del(BayonneSession *session);
01394
01400 inline timeslot_t getFirst(void)
01401 {return timeslot;};
01402
01408 inline timeslot_t getCount(void)
01409 {return count;};
01410
01416 inline unsigned getSpanFirst(void)
01417 {return span;};
01418
01424 inline unsigned getSpansUsed(void)
01425 {return spans;};
01426
01432 inline const char *getName(void)
01433 {return name;};
01434
01441 inline timeout_t getResetTimer(void)
01442 {return reset_timer;};
01443
01449 inline timeout_t getReleaseTimer(void)
01450 {return release_timer;};
01451
01457 inline timeout_t getHangupTimer(void)
01458 {return hangup_timer;};
01459
01465 inline timeout_t getPickupTimer(void)
01466 {return pickup_timer;};
01467
01473 inline timeout_t getSeizeTimer(void)
01474 {return seize_timer;};
01475
01481 inline timeout_t getFlashTimer(void)
01482 {return flash_timer;};
01483
01489 inline timeout_t getInterdigit(void)
01490 {return interdigit_timer;};
01491
01499 inline timeout_t getRingTimer(void)
01500 {return ring_timer;};
01501
01507 inline unsigned getAnswerCount(void)
01508 {return answer_count;};
01509
01516 BayonneSpan *getSpan(unsigned id);
01517
01525 BayonneSession *getTimeslot(timeslot_t id);
01526
01532 inline BayonneMsgport *getMsgport(void)
01533 {return msgport;};
01534
01540 inline size_t getAudioStack(void)
01541 {return audio_stack;};
01542
01548 inline int getAudioPriority(void)
01549 {return audio_priority;};
01550
01556 inline Audio::Level getAudioLevel(void)
01557 {return audio_level;};
01558
01564 inline void setLogging(std::ostream *output)
01565 {logevents = output;};
01566
01573 inline bool isSpanable(unsigned span);
01574
01585 virtual bool getDestination(const char *target, const char *dial, char *buffer, size_t size);
01586
01592 inline unsigned getAvail(void)
01593 {return avail;}
01594 };
01595
01603 class __EXPORT BayonneSpan : public Bayonne, public Keydata
01604 {
01605 protected:
01606 friend class __EXPORT BayonneSession;
01607 friend class __EXPORT BayonneDriver;
01608
01609 static BayonneSpan *first;
01610 static BayonneSpan *last;
01611 static unsigned spans;
01612 static BayonneSpan **index;
01613
01614 unsigned id;
01615 BayonneDriver *driver;
01616 BayonneSpan *next;
01617 timeslot_t timeslot, count, used;
01618
01619 public:
01626 BayonneSpan(BayonneDriver *d, timeslot_t count);
01627
01634 static BayonneSpan *get(unsigned id);
01635
01642 BayonneSession *getTimeslot(timeslot_t id);
01643
01649 static void allocate(unsigned count = 0);
01650
01656 static inline unsigned getSpans(void)
01657 {return spans;};
01658
01664 inline timeslot_t getFirst(void)
01665 {return timeslot;};
01666
01672 inline timeslot_t getCount(void)
01673 {return count;};
01674
01680 inline unsigned getId(void)
01681 {return id;};
01682
01688 inline BayonneDriver *getDriver(void)
01689 {return driver;};
01690
01696 inline unsigned getAvail(void)
01697 {return count - used;}
01698 };
01699
01706 class __EXPORT BayonneBinder : public ScriptBinder, public Bayonne
01707 {
01708 private:
01709 static BayonneBinder *binder;
01710
01711 protected:
01712 virtual Name *service(ScriptImage *img, ScriptInterp *interp, const char *sid);
01713
01714 BayonneSession *session(ScriptInterp *interp);
01715
01716 bool scriptEvent(ScriptInterp *interp, const char *evt);
01717
01718 bool digitEvent(ScriptInterp *interp, const char *evt);
01719
01720 BayonneBinder(const char *id);
01721
01722 public:
01723 static Name *getService(ScriptImage *img, ScriptInterp *interp, const char *sid);
01724
01725 };
01726
01734 class __EXPORT BayonneSession : public ScriptInterp, public Bayonne
01735 {
01736 private:
01737 friend class __EXPORT BayonneMsgport;
01738 friend class __EXPORT BayonneTranslator;
01739 friend class __EXPORT BayonneDriver;
01740 friend class __EXPORT Bayonne;
01741
01742 BayonneSession() {};
01743
01744 BayonneSession *nextIdle, *prevIdle;
01745 bool isAvail;
01746
01747 protected:
01748 static BayonneTranslator langNone;
01749 static ScriptSymbols *globalSyms;
01750 static Mutex globalLock;
01751
01752 std::ostream *logevents, *logtrace;
01753 BayonneDriver *driver;
01754 BayonneMsgport *msgport;
01755 BayonneSession *peer;
01756 BayonneSpan *span;
01757 timeslot_t timeslot;
01758 uint8 seq;
01759 uint16 evseq;
01760 uint32 tseq;
01761 volatile unsigned children;
01762 bool offhook, dtmf, answered, starting, holding;
01763 time_t exittimer, starttime;
01764 interface_t iface;
01765 bridge_t bridge;
01766 calltype_t type;
01767 event_t seizure;
01775 bool requiresDTMF(void);
01776
01782 virtual bool enableDTMF(void);
01783
01787 virtual void disableDTMF(void);
01788
01797 virtual const char *checkAudio(bool live);
01798
01805 virtual bool filterPosting(Event *event);
01806
01807 virtual bool enterCommon(Event *event);
01808 virtual bool enterInitial(Event *event);
01809 virtual bool enterFinal(Event *event);
01810 virtual bool enterIdle(Event *event);
01811 virtual bool enterReset(Event *event);
01812 virtual bool enterRelease(Event *event);
01813 virtual bool enterRinging(Event *event);
01814 virtual bool enterPickup(Event *event);
01815 virtual bool enterSeize(Event *event);
01816 virtual bool enterHangup(Event *event);
01817 virtual bool enterTone(Event *event);
01818 virtual bool enterDTMF(Event *event);
01819 virtual bool enterPlay(Event *event);
01820 virtual bool enterRecord(Event *event);
01821 virtual bool enterJoin(Event *event);
01822 virtual bool enterWait(Event *event);
01823 virtual bool enterDial(Event *event);
01824 virtual bool enterBusy(Event *event);
01825 virtual bool enterStandby(Event *event);
01826 virtual bool enterXfer(Event *event);
01827 virtual bool enterHold(Event *event);
01828 virtual bool enterRecall(Event *event);
01829
01834 void check(void);
01835
01836 bool stateInitial(Event *event);
01837 bool stateFinal(Event *event);
01838 bool stateIdle(Event *event);
01839 bool stateIdleReset(Event *event);
01840 bool stateReset(Event *event);
01841 bool stateRelease(Event *event);
01842 bool stateBusy(Event *event);
01843 bool stateStandby(Event *event);
01844 bool stateRinging(Event *event);
01845 bool statePickup(Event *event);
01846 bool stateSeize(Event *event);
01847 bool stateRunning(Event *event);
01848 bool stateLibexec(Event *event);
01849 bool stateLibreset(Event *event);
01850 bool stateLibwait(Event *event);
01851 bool stateWaitkey(Event *event);
01852 bool stateThreading(Event *event);
01853 bool stateHangup(Event *event);
01854 bool stateCollect(Event *event);
01855 bool stateSleep(Event *event);
01856 bool stateStart(Event *event);
01857 bool stateClear(Event *event);
01858 bool stateInkey(Event *event);
01859 bool stateInput(Event *event);
01860 bool stateRead(Event *event);
01861 bool stateDial(Event *event);
01862 bool stateXfer(Event *event);
01863 bool stateHold(Event *event);
01864 bool stateRecall(Event *event);
01865 bool stateTone(Event *event);
01866 bool stateDTMF(Event *event);
01867 bool statePlay(Event *event);
01868 bool stateRecord(Event *event);
01869 bool stateJoin(Event *event);
01870 bool stateWait(Event *event);
01871 bool stateConnect(Event *event);
01872
01879 bool putEvent(Event *event);
01880
01886 void libWrite(const char *str);
01887
01888 void libClose(const char *str);
01889
01890 bool isLibexec(const char *tsid);
01891
01892 timeout_t getLibexecTimeout(void);
01893
01894 const char *getWritepath(char *buf = NULL, size_t len = 0);
01895
01896 public:
01903 const char *getExternal(const char *opt);
01904
01910 inline uint16 getEventSequence(void)
01911 {return evseq;};
01912
01913 protected:
01920 ScriptInterp *getInterp(const char *id);
01921
01928 ScriptSymbols *getSymbols(const char *id);
01929
01933 BayonneTranslator *translator;
01934
01942 Name *attachStart(Event *event);
01943
01947 unsigned getId(void);
01948
01953 void setSid(void);
01954
01958 void setState(state_t);
01959
01964 void setRunning(void);
01965
01974 bool setLibexec(result_t result);
01975
01984 bool setLibreset(result_t result);
01985
01986 public:
01992 inline BayonneTranslator *getTranslator(void)
01993 {return translator;};
01994
01995 protected:
02002 inline libaudio_t *getLibaudio(void)
02003 {return state.libaudio;};
02004
02008 void finalize(void);
02009
02015 bool exit(void);
02016
02017 char var_date[12];
02018 char var_time[12];
02019 char var_duration[12];
02020 char var_callid[12];
02021 char var_tid[14];
02022 char var_sid[16];
02023 char var_pid[16];
02024 char var_rings[4];
02025 char var_timeslot[8];
02026 char var_spanid[8];
02027 char var_bankid[4];
02028 char var_spantsid[12];
02029 const char *voicelib;
02030 char *dtmf_digits;
02031 unsigned digit_count, ring_count;
02032
02033 State state;
02034
02035 public:
02043 BayonneSession(BayonneDriver *d, timeslot_t timeslot, BayonneSpan *span = NULL);
02044
02048 virtual ~BayonneSession();
02049
02050 inline const char *defVoicelib(void)
02051 {return voicelib;}
02052
02056 void initialevent(void);
02057
02061 void initialize(void);
02062
02066 void detach(void);
02067
02073 inline BayonneDriver *getDriver(void)
02074 {return driver;}
02075
02082 virtual timeout_t getRemaining(void) = 0;
02083
02090 virtual void startTimer(timeout_t timer) = 0;
02091
02096 virtual void stopTimer(void) = 0;
02097
02103 virtual void setOffhook(bool state);
02104
02108 virtual void makeIdle(void);
02109
02115 void part(event_t reason);
02116
02123 virtual bool postEvent(Event *event);
02124
02125
02126 bool matchLine(Line *line);
02127
02133 virtual void queEvent(Event *event);
02134
02138 virtual void startThread(void);
02139
02143 virtual void enterThread(ScriptThread *thr);
02144
02148 virtual void exitThread(const char *msg);
02149
02153 virtual void clrAudio(void);
02154
02158 virtual timeout_t getToneFraming(void);
02159
02166 const char *getAudio(bool live = true);
02167
02172 void branching(void);
02173
02179 inline bool isOffhook(void)
02180 {return offhook;};
02181
02187 inline interface_t getInterface(void)
02188 {return iface;};
02189
02195 inline bridge_t getBridge(void)
02196 {return bridge;};
02197
02203 inline calltype_t getType(void)
02204 {return type;};
02205
02211 inline timeslot_t getSlot(void)
02212 {return timeslot;};
02213
02219 inline bool isIdle(void)
02220 {return isAvail;};
02221
02227 bool isJoined(void);
02228
02234 timeout_t getJoinTimer(void);
02235
02242 inline bool signalScript(signal_t sig)
02243 {return ScriptInterp::signal(sig);};
02244
02254 virtual bool peerAudio(Audio::Encoded encoded);
02255
02265 virtual bool setPeering(Audio::Encoding encoding, timeout_t framing);
02266
02267 const char *getKeyString(const char *id);
02268 bool getKeyBool(const char *id);
02269 long getKeyValue(const char *id);
02270 timeout_t getSecTimeout(const char *id);
02271 timeout_t getMSecTimeout(const char *id);
02272 timeout_t getTimeoutValue(const char *opt = NULL);
02273 timeout_t getTimeoutKeyword(const char *kw);
02274 const char *getExitKeyword(const char *def);
02275 const char *getMenuKeyword(const char *def);
02276
02277 unsigned getInputCount(const char *digits, unsigned max);
02278
02286 uint32 newTid(void);
02287
02293 inline const char *getTid(void)
02294 {return var_tid;};
02295
02302 bool digitEvent(const char *evt);
02303
02304 inline bool stringEvent(const char *evt)
02305 {return scriptEvent(evt);}
02306
02312 char getDigit(void);
02313
02314 BayonneAudio audio;
02315 };
02316
02325 class __EXPORT BayonneService : public Thread
02326 {
02327 private:
02328 static BayonneService *first;
02329 static BayonneService *last;
02330 BayonneService *next;
02331 friend void startServices(void);
02332 friend void stopServices(void);
02333
02334 protected:
02335 BayonneService(int pri, size_t stack);
02336
02340 virtual void stopService(void);
02341
02345 virtual void startService(void);
02346
02347 public:
02348 static void start(void);
02349 static void stop(void);
02350 };
02351
02352 }
02353
02354 #endif