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 ScriptImage **localimages;
00100 static char *status;
00101 static ScriptCommand *server;
00102 static timeslot_t ts_limit;
00103 static timeslot_t ts_count;
00104 static timeslot_t ts_used;
00105 static std::ostream *logging;
00106 static const char *path_prompts;
00107 static const char *path_tmpfs;
00108 static const char *path_tmp;
00109 static unsigned idle_count;
00110 static unsigned idle_limit;
00111 static bool shutdown_flag;
00112 static char sla[];
00113 static time_t start_time;
00114
00115 public:
00116 static timeout_t step_timer;
00117 static timeout_t reset_timer;
00118 static timeout_t exec_timer;
00119 static unsigned compile_count;
00120 static volatile bool image_loaded;
00121 static bool provision_defines;
00122 static bool provision_daemon;
00123 static bool provision_system;
00124 static bool provision_check;
00125 static bool provision_user;
00126 static bool provision_test;
00127 static const char *provision_server;
00128 static const char *provision_libexec;
00129
00130 static Audio::Encoding peer_encoding;
00131 static Audio::timeout_t peer_framing;
00132 static BayonneTranslator *init_translator;
00133 static const char *init_voicelib;
00134 static AtomicCounter libexec_count;
00135
00136 static const char *getKeypath(const char *cp);
00137
00141 typedef enum
00142 {
00143 IF_PSTN,
00144 IF_SPAN,
00145 IF_ISDN,
00146 IF_SS7,
00147 IF_INET,
00148 IF_NONE,
00149 IF_POTS=IF_PSTN
00150 } interface_t;
00151
00155 typedef enum
00156 {
00157 NONE,
00158 INCOMING,
00159 OUTGOING,
00160 PICKUP,
00161 FORWARDED,
00162 RECALL,
00163 DIRECT
00164 } calltype_t;
00165
00169 typedef enum
00170 {
00171 BR_TDM,
00172 BR_INET,
00173 BR_SOFT,
00174 BR_GATE,
00175 BR_NONE
00176 } bridge_t;
00177
00183 typedef enum
00184 {
00185 STATE_INITIAL = 0,
00186 STATE_IDLE,
00187 STATE_RESET,
00188 STATE_RELEASE,
00189 STATE_BUSY,
00190 STATE_DOWN,
00191 STATE_RING,
00192 STATE_PICKUP,
00193 STATE_SEIZE,
00194 STATE_STEP,
00195 STATE_EXEC,
00196 STATE_THREAD,
00197 STATE_CLEAR,
00198 STATE_INKEY,
00199 STATE_INPUT,
00200 STATE_READ,
00201 STATE_COLLECT,
00202 STATE_DIAL,
00203 STATE_XFER,
00204 STATE_HOLD,
00205 STATE_RECALL,
00206 STATE_TONE,
00207 STATE_DTMF,
00208 STATE_PLAY,
00209 STATE_RECORD,
00210 STATE_JOIN,
00211 STATE_WAIT,
00212 STATE_CONNECT,
00213 STATE_SLEEP,
00214 STATE_START,
00215 STATE_HANGUP,
00216 STATE_LIBRESET,
00217 STATE_WAITKEY,
00218 STATE_LIBWAIT,
00219 STATE_IRESET,
00220 STATE_FINAL,
00221
00222 STATE_STANDBY = STATE_DOWN,
00223 STATE_LIBEXEC = STATE_EXEC,
00224 STATE_RINGING = STATE_RING,
00225 STATE_RUNNING = STATE_STEP,
00226 STATE_THREADING = STATE_THREAD
00227 } state_t;
00228
00233 typedef enum
00234 {
00235 SIGNAL_EXIT = 0,
00236 SIGNAL_ERROR,
00237 SIGNAL_TIMEOUT,
00238 SIGNAL_DTMF,
00239
00240 SIGNAL_0,
00241 SIGNAL_1,
00242 SIGNAL_2,
00243 SIGNAL_3,
00244 SIGNAL_4,
00245 SIGNAL_5,
00246 SIGNAL_6,
00247 SIGNAL_7,
00248 SIGNAL_8,
00249 SIGNAL_9,
00250 SIGNAL_STAR,
00251 SIGNAL_POUND,
00252 SIGNAL_A,
00253 SIGNAL_OVERRIDE = SIGNAL_A,
00254 SIGNAL_B,
00255 SIGNAL_FLASH = SIGNAL_B,
00256 SIGNAL_C,
00257 SIGNAL_IMMEDIATE = SIGNAL_C,
00258 SIGNAL_D,
00259 SIGNAL_PRIORITY = SIGNAL_D,
00260
00261 SIGNAL_RING,
00262 SIGNAL_TONE,
00263 SIGNAL_EVENT,
00264 SIGNAL_WINK,
00265
00266 SIGNAL_CHILD,
00267 SIGNAL_FAIL,
00268 SIGNAL_PICKUP,
00269 SIGNAL_PART,
00270
00271 SIGNAL_INVALID,
00272 SIGNAL_PARENT,
00273 SIGNAL_WAIT,
00274
00275 SIGNAL_HANGUP = SIGNAL_EXIT
00276 } signal_t;
00277
00283 typedef enum
00284 {
00285
00286
00287 MSGPORT_WAKEUP = 0,
00288 MSGPORT_SHUTDOWN,
00289 MSGPORT_LOGGING,
00290 MSGPORT_REGISTER,
00291
00292
00293
00294 ENTER_STATE = 100,
00295 EXIT_STATE,
00296 EXIT_THREAD,
00297 EXIT_TIMER,
00298 EXIT_PARTING,
00299 NULL_EVENT,
00300 ERROR_STATE,
00301
00302
00303
00304 START_DIRECT = 200,
00305 START_INCOMING,
00306 START_OUTGOING,
00307 START_RECALL,
00308 START_FORWARDED,
00309 STOP_SCRIPT,
00310 STOP_DISCONNECT,
00311 STOP_PARENT,
00312 CANCEL_CHILD,
00313 DETACH_CHILD,
00314 CHILD_RUNNING,
00315 CHILD_FAILED,
00316 CHILD_INVALID,
00317 CHILD_EXPIRED,
00318 CHILD_BUSY,
00319 CHILD_FAX,
00320
00321 START_SCRIPT = START_INCOMING,
00322 START_SELECTED = START_OUTGOING,
00323
00324
00325
00326 ENTER_LIBEXEC = 300,
00327 EXIT_LIBEXEC,
00328 HEAD_LIBEXEC,
00329 ARGS_LIBEXEC,
00330 GOT_LIBEXEC,
00331 READ_LIBEXEC,
00332 DROP_LIBEXEC,
00333 STAT_LIBEXEC,
00334 PROMPT_LIBEXEC,
00335 CLEAR_LIBEXEC,
00336 WAIT_LIBEXEC,
00337 RECORD_LIBEXEC,
00338 REPLAY_LIBEXEC,
00339 RESTART_LIBEXEC,
00340 TONE_LIBEXEC,
00341 XFER_LIBEXEC,
00342 POST_LIBEXEC,
00343 ERROR_LIBEXEC,
00344
00345
00346
00347 TIMER_EXPIRED = 400,
00348 LINE_WINK,
00349 LINE_PICKUP,
00350 LINE_HANGUP,
00351 LINE_DISCONNECT,
00352 LINE_ON_HOOK,
00353 LINE_OFF_HOOK,
00354 RING_ON,
00355 RING_OFF,
00356 RING_STOP,
00357 LINE_CALLER_ID,
00358 RINGING_DID,
00359 DEVICE_BLOCKED,
00360 DEVICE_UNBLOCKED,
00361 DEVICE_OPEN,
00362 DEVICE_CLOSE,
00363 DSP_READY,
00364
00365
00366
00367 CALL_DETECT = 500,
00368 CALL_CONNECTED,
00369 CALL_RELEASED,
00370 CALL_ACCEPTED,
00371 CALL_ANSWERED,
00372 CALL_HOLD,
00373 CALL_HOLDING=CALL_HOLD,
00374 CALL_NOHOLD,
00375 CALL_DIGITS,
00376 CALL_OFFERED,
00377 CALL_ANI,
00378 CALL_ACTIVE,
00379 CALL_NOACTIVE,
00380 CALL_BILLING,
00381 CALL_RESTART,
00382 CALL_SETSTATE,
00383 CALL_FAILURE,
00384 CALL_ALERTING,
00385 CALL_INFO,
00386 CALL_BUSY,
00387 CALL_DIVERT,
00388 CALL_FACILITY,
00389 CALL_FRAME,
00390 CALL_NOTIFY,
00391 CALL_NSI,
00392 CALL_RINGING,
00393 CALL_DISCONNECT,
00394 CALL_CLEARED,
00395 CALL_PROCEEDING,
00396 RESTART_FAILED,
00397 RELEASE_FAILED,
00398
00399
00400
00401 START_RING = 600,
00402 STOP_RING,
00403 CLEAR_TIMESLOT,
00404 START_FLASH,
00405 STOP_FLASH,
00406 DIAL_CONNECT,
00407 DIAL_TIMEOUT,
00408 DIAL_FAILED,
00409 DIAL_INVALID,
00410 DIAL_BUSY,
00411 DIAL_FAX,
00412 DIAL_PAM,
00413
00414 DIAL_MACHINE = DIAL_PAM,
00415
00416
00417
00418 AUDIO_IDLE = 700,
00419 AUDIO_ACTIVE,
00420 AUDIO_EXPIRED,
00421 INPUT_PENDING,
00422 OUTPUT_PENDING,
00423 AUDIO_BUFFER,
00424 TONE_IDLE,
00425 DTMF_KEYDOWN,
00426 DTMF_KEYSYNC,
00427 DTMF_KEYUP,
00428 TONE_START,
00429 TONE_STOP,
00430 AUDIO_START,
00431 AUDIO_STOP,
00432 DTMF_GENDOWN,
00433 DTMF_GENUP,
00434 DTMF_GENTONE = DTMF_GENUP,
00435
00436
00437
00438 MAKE_TEST = 800,
00439 MAKE_BUSY,
00440 MAKE_IDLE,
00441 MAKE_DOWN,
00442 MAKE_UP,
00443 MAKE_EXPIRED,
00444 ENABLE_LOGGING,
00445 DISABLE_LOGGING,
00446 PART_EXPIRED,
00447 PART_EXITING,
00448 PART_DISCONNECT,
00449 JOIN_PEER,
00450 PEER_WAITING,
00451
00452
00453
00454 SYSTEM_DOWN = 900,
00455
00456
00457
00458 DRIVER_SPECIFIC = 1000
00459
00460 } event_t;
00461
00462 typedef enum
00463 {
00464 RESULT_SUCCESS = 0,
00465 RESULT_TIMEOUT,
00466 RESULT_INVALID,
00467 RESULT_PENDING,
00468 RESULT_COMPLETE,
00469 RESULT_FAILED,
00470 RESULT_BADPATH = 254,
00471 RESULT_OFFLINE = 255
00472 } result_t;
00473
00474 typedef struct
00475 {
00476 Line line;
00477 char text[MAX_LIBINPUT];
00478 const char *list[MAX_LIBINPUT / 2];
00479 } libaudio_t;
00480
00481 typedef struct
00482 {
00483 const char *remote;
00484 const char *userid;
00485 const char *type;
00486 const char *status;
00487 } regauth_t;
00488
00496 typedef struct
00497 {
00498 event_t id;
00499 timeslot_t timeslot;
00500 uint16 seq;
00501
00502 union
00503 {
00504
00505
00506
00507
00508 struct
00509 {
00510 ScriptImage *img;
00511 Script::Name *scr;
00512 BayonneSession *parent;
00513 const char *dialing;
00514 } start;
00515
00516 struct
00517 {
00518 const char *tid;
00519 #ifdef WIN32
00520 HANDLE pfd;
00521 #else
00522 const char *fname;
00523 #endif
00524 int pid, result;
00525 } libexec;
00526
00527 struct
00528 {
00529 const char *tid;
00530 const char *errmsg;
00531 } liberror;
00532
00533 struct
00534 {
00535 timeout_t duration;
00536 int digit;
00537 } dtmf;
00538
00539 struct
00540 {
00541 const char *err;
00542 const char *msg;
00543 } cpa;
00544
00545 struct
00546 {
00547 const char *name;
00548 bool exit;
00549 } tone;
00550
00551 struct
00552 {
00553 std::ostream *output;
00554 const char *logstate;
00555 } debug;
00556
00557 const char *name;
00558 const char *errmsg;
00559 BayonneSession *pid;
00560 BayonneSession *peer;
00561 void *data;
00562 };
00563
00564 } Event;
00565
00571 typedef bool (BayonneSession::*Handler)(Event *event);
00572
00577 typedef struct
00578 {
00579 const char *name;
00580 Handler handler;
00581 char flag;
00582 } statetab;
00583
00591 typedef struct
00592 {
00593 Handler handler, logstate;
00594 const char *name;
00595 timeout_t timeout;
00596 Name *menu;
00597 unsigned stack;
00598 Line *lib;
00599 #ifdef WIN32
00600 HANDLE pfd;
00601 #else
00602 int pfd;
00603 #endif
00604 result_t result;
00605 int pid;
00606 libaudio_t *libaudio;
00607
00608 union
00609 {
00610 struct
00611 {
00612 unsigned count;
00613 timeout_t interval;
00614 } wait;
00615
00616 struct
00617 {
00618 Audio::Mode mode;
00619 Audio::Level level;
00620 timeout_t total, silence, intersilence;
00621 long lastnum;
00622 bool exitkey;
00623 bool compress;
00624 bool trigger;
00625 const char *pos;
00626 const char *exit;
00627 const char *menu;
00628 const char *note;
00629 const char *list[MAX_LIST];
00630 } audio;
00631
00632 struct
00633 {
00634 timeout_t interdigit;
00635 timeout_t lastdigit;
00636 const char *var;
00637 const char *exit;
00638 const char *format;
00639 const char *ignore;
00640 const char *route;
00641 unsigned count, size, required;
00642 } input;
00643
00644 struct
00645 {
00646 const char *var;
00647 const char *menu;
00648 } inkey;
00649
00650 struct
00651 {
00652 const char *sequence;
00653 bool flashing;
00654 bool dialing;
00655 bool exiting;
00656 bool dtmf;
00657 char *syncdigit;
00658 timeout_t synctimer;
00659 timeout_t duration;
00660 char digits[64];
00661 char sessionid[16];
00662 } tone;
00663
00664 struct
00665 {
00666 timeout_t on, off, interdigit;
00667 unsigned pos;
00668 bool flashing;
00669 bool dialing;
00670 unsigned char digits[64];
00671 } pulse;
00672
00673 struct
00674 {
00675 const char *dial;
00676 const char *exit;
00677 bool dtmf;
00678 BayonneSession *peer;
00679 timeout_t answer_timer;
00680 char digits[64];
00681 } join;
00682
00683 struct
00684 {
00685 const char *ref;
00686 char buf[MAX_LIST * sizeof(char *)];
00687 } url;
00688 };
00689
00690 } State;
00691
00695 static statetab states[];
00696
00701 static Mutex serialize;
00702
00710 static void allocate(timeslot_t timeslots, ScriptCommand *pointer = NULL, timeslot_t overdraft = 0);
00711
00715 static void allocateLocal(void);
00716
00720 static void waitLoaded(void);
00721
00727 static unsigned long uptime(void);
00728
00734 static ScriptCompiler *reload(void);
00735
00739 static void down(void);
00740
00747 static bool service(const char *service);
00748
00756 static BayonneSession *getSession(timeslot_t timeslot);
00757
00764 static ScriptImage **getLocalImage(timeslot_t timeslot);
00765
00776 static BayonneSession *startDialing(const char *dial,
00777 const char *name, const char *caller, const char *display, BayonneSession *parent = NULL);
00778
00787 static BayonneSession *getSid(const char *id);
00788
00796 static timeslot_t toTimeslot(const char *id);
00797
00803 static inline timeslot_t getTimeslotsUsed(void)
00804 {return Bayonne::ts_used;};
00805
00811 static inline timeslot_t getTimeslotCount(void)
00812 {return Bayonne::ts_count;};
00813
00820 static inline timeslot_t getAvailTimeslots(void)
00821 {return Bayonne::ts_count - Bayonne::ts_used;};
00822
00830 static Handler getState(const char *name);
00831
00838 static int getDigit(char dtmf);
00839
00846 static char getChar(int dtmf);
00847
00858 static bool matchDigits(const char *digits, const char *match, bool partial = false);
00859
00865 static ScriptImage *useImage(void);
00866
00873 static void endImage(ScriptImage *image);
00874
00881 static bool loadPlugin(const char *path);
00882
00889 static bool loadMonitor(const char *path);
00890
00897 static bool loadAudio(const char *path);
00898
00899 static void errlog(const char *level, const char *fmt, ...);
00900 };
00901
00909 class __EXPORT BayonneConfig : public Keydata
00910 {
00911 private:
00912 static BayonneConfig *first;
00913
00914 BayonneConfig *next;
00915 const char *id;
00916
00917 public:
00918 BayonneConfig(const char *id, Define *def, const char *path);
00919 BayonneConfig(const char *id, const char *path);
00920 void setEnv(const char *id);
00921 static BayonneConfig *get(const char *id);
00922 static void rebuild(ScriptImage *img);
00923 };
00924
00932 class __EXPORT BayonneTranslator : public Bayonne
00933 {
00934 protected:
00935 static BayonneTranslator *first;
00936 BayonneTranslator *next;
00937 const char *id;
00938
00939 static const char *getToken(BayonneSession *s, Line *l, unsigned *idx);
00940 static unsigned addItem(BayonneSession *s, unsigned count, const char *text);
00941 static const char *getLast(BayonneSession *s, unsigned count);
00942
00943 public:
00951 BayonneTranslator(const char *iso);
00952
00953 virtual ~BayonneTranslator();
00954
00961 static BayonneTranslator *get(const char *name);
00962
00967 static inline BayonneTranslator *getFirst(void)
00968 {return first;};
00969
00975 inline BayonneTranslator *getNext()
00976 {return next;};
00977
00985 static BayonneTranslator *loadTranslator(const char *iso);
00986
00995 virtual unsigned digits(BayonneSession *sessiob, unsigned count, const char *string);
00996
01005 virtual unsigned spell(BayonneSession *session, unsigned count, const char *string);
01006
01015 virtual unsigned sayorder(BayonneSession *session, unsigned count, const char *string);
01016
01025 virtual unsigned number(BayonneSession *session, unsigned count, const char *string);
01026
01036 virtual unsigned saynumber(BayonneSession *session, unsigned count, const char *string);
01037
01046 virtual unsigned saycount(BayonneSession *session, unsigned count, const char *string);
01047
01056 virtual unsigned sayhour(BayonneSession *session, unsigned count, const char *string);
01057
01066 virtual unsigned saytime(BayonneSession *session, unsigned count, const char *string);
01067
01076 virtual unsigned weekday(BayonneSession *session, unsigned count, const char *string);
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086 virtual unsigned sayday(BayonneSession *session, unsigned count, const char *string);
01087
01096 virtual unsigned saydate(BayonneSession *session, unsigned count, const char *string);
01097
01106 virtual unsigned saybool(BayonneSession *session, unsigned count, const char *string);
01107
01116 virtual unsigned phone(BayonneSession *session, unsigned count, const char *string);
01117
01126 virtual unsigned extension(BayonneSession *session, unsigned count, const char *string);
01127
01135 virtual const char *speak(BayonneSession *session, Line *line = NULL);
01136
01142 inline const char *getId(void)
01143 {return id;};
01144 };
01145
01153 class __EXPORT BayonneAudio : public AudioStream, public Bayonne
01154 {
01155 protected:
01156 char filename[MAX_PATHNAME];
01157 const char **list;
01158 char *getContinuation(void);
01159
01160 public:
01165 AudioTone *tone;
01166
01171 BayonneTranslator *translator;
01172
01176 char vlib[60];
01177
01178 const char *extension, *voicelib, *libext, *prefixdir, *offset;
01179 Encoding encoding;
01180 timeout_t framing;
01181 char var_position[14];
01182
01186 BayonneAudio();
01187
01195 const char *getFilename(const char *name, bool write = false);
01196
01201 void cleanup(void);
01202
01209 void play(const char **list, Mode mode = modeRead);
01210
01218 void record(const char *name, Mode mode = modeCreate, const char *annotation = NULL);
01219
01226 const char *getVoicelib(const char *iso);
01227
01233 inline AudioCodec *getCodec(void)
01234 {return codec;};
01235 };
01236
01247 class __EXPORT BayonneMsgport : public Thread, public Buffer, public Bayonne
01248 {
01249 public:
01253 virtual ~BayonneMsgport();
01254
01260 BayonneMsgport(BayonneDriver *driver);
01261
01267 void update(void);
01268
01273 void initial(void);
01274
01275 protected:
01276 BayonneDriver *msgdriver;
01277 Event *msglist;
01278 unsigned msgsize, msghead, msgtail;
01279 timeslot_t tsfirst, tscount;
01280 char msgname[16];
01281
01285 void shutdown(void);
01286
01294 virtual timeout_t getTimeout(Event *event);
01295
01296 void run(void);
01297
01298 size_t onWait(void *buf);
01299 size_t onPost(void *buf);
01300 size_t onPeek(void *buf);
01301 };
01302
01310 class __EXPORT BayonneDriver : public Bayonne, public Keydata, public Mutex
01311 {
01312 protected:
01313 friend class __EXPORT BayonneSession;
01314 friend class __EXPORT BayonneMsgport;
01315 static BayonneDriver *firstDriver;
01316 static BayonneDriver *lastDriver;
01317 static BayonneDriver *trunkDriver;
01318 static BayonneDriver *protoDriver;
01319 static Semaphore oink;
01320 static bool protocols;
01321
01322 BayonneSession *firstIdle, *lastIdle;
01323 BayonneMsgport *msgport;
01324 BayonneDriver *nextDriver;
01325 const char *name;
01326 timeslot_t timeslot, count;
01327 unsigned avail;
01328 unsigned span, spans;
01329 bool running;
01330 std::ostream *logevents;
01331
01332 int audio_priority;
01333 size_t audio_stack;
01334 Audio::Level audio_level;
01335
01336 timeout_t pickup_timer, hangup_timer, seize_timer, ring_timer;
01337 timeout_t reset_timer, release_timer, flash_timer, interdigit_timer;
01338 unsigned answer_count;
01339
01344 virtual void startDriver(void);
01345
01349 virtual void stopDriver(void);
01350
01351 public:
01360 BayonneDriver(Keydata::Define *pairs, const char *key, const char *id, bool virt = false);
01361
01365 ~BayonneDriver();
01366
01370 static inline bool useProtocols(void)
01371 {return protocols;}
01372
01376 static inline BayonneDriver *getTrunking(void)
01377 {return trunkDriver;}
01378
01382 static inline BayonneDriver *getPrimary(void)
01383 {return firstDriver;}
01384
01385
01389 static inline BayonneDriver *getProtocol(void)
01390 {return protoDriver;}
01391
01397 BayonneSession *getIdle(void);
01398
01406 virtual const char *registerScript(ScriptImage *image, Line *line);
01407
01415 virtual const char *assignScript(ScriptImage *image, Line *line);
01416
01423 static BayonneDriver *get(const char *id);
01424
01431 static BayonneDriver *loadDriver(const char *id);
01432
01439 static BayonneDriver *loadTrunking(const char *id);
01440
01448 static BayonneDriver *loadProtocol(const char *id, unsigned timeslots = 0);
01449
01457 static unsigned list(char **items, unsigned max);
01458
01462 static void start(void);
01463
01467 static void stop(void);
01468
01475 static void add(BayonneSession *session);
01476
01483 static void del(BayonneSession *session);
01484
01490 inline timeslot_t getFirst(void)
01491 {return timeslot;};
01492
01498 inline timeslot_t getCount(void)
01499 {return count;};
01500
01506 inline unsigned getSpanFirst(void)
01507 {return span;};
01508
01514 inline unsigned getSpansUsed(void)
01515 {return spans;};
01516
01522 inline const char *getName(void)
01523 {return name;};
01524
01531 inline timeout_t getResetTimer(void)
01532 {return reset_timer;};
01533
01539 inline timeout_t getReleaseTimer(void)
01540 {return release_timer;};
01541
01547 inline timeout_t getHangupTimer(void)
01548 {return hangup_timer;};
01549
01555 inline timeout_t getPickupTimer(void)
01556 {return pickup_timer;};
01557
01563 inline timeout_t getSeizeTimer(void)
01564 {return seize_timer;};
01565
01571 inline timeout_t getFlashTimer(void)
01572 {return flash_timer;};
01573
01579 inline timeout_t getInterdigit(void)
01580 {return interdigit_timer;};
01581
01589 inline timeout_t getRingTimer(void)
01590 {return ring_timer;};
01591
01597 inline unsigned getAnswerCount(void)
01598 {return answer_count;};
01599
01606 BayonneSpan *getSpan(unsigned id);
01607
01615 BayonneSession *getTimeslot(timeslot_t id);
01616
01622 inline BayonneMsgport *getMsgport(void)
01623 {return msgport;};
01624
01630 inline size_t getAudioStack(void)
01631 {return audio_stack;};
01632
01638 inline int getAudioPriority(void)
01639 {return audio_priority;};
01640
01646 inline Audio::Level getAudioLevel(void)
01647 {return audio_level;};
01648
01654 inline void setLogging(std::ostream *output)
01655 {logevents = output;};
01656
01663 inline bool isSpanable(unsigned span);
01664
01675 virtual bool getDestination(const char *target, const char *dial, char *output, size_t size);
01676
01682 inline unsigned getAvail(void)
01683 {return avail;}
01684
01692 virtual unsigned getRegistration(regauth_t *data, unsigned count);
01693 };
01694
01702 class __EXPORT BayonneSpan : public Bayonne, public Keydata
01703 {
01704 protected:
01705 friend class __EXPORT BayonneSession;
01706 friend class __EXPORT BayonneDriver;
01707
01708 static BayonneSpan *first;
01709 static BayonneSpan *last;
01710 static unsigned spans;
01711 static BayonneSpan **index;
01712
01713 unsigned id;
01714 BayonneDriver *driver;
01715 BayonneSpan *next;
01716 timeslot_t timeslot, count, used;
01717
01718 public:
01725 BayonneSpan(BayonneDriver *driver, timeslot_t timeslots);
01726
01733 static BayonneSpan *get(unsigned id);
01734
01741 BayonneSession *getTimeslot(timeslot_t id);
01742
01748 static void allocate(unsigned total = 0);
01749
01755 static inline unsigned getSpans(void)
01756 {return spans;};
01757
01763 inline timeslot_t getFirst(void)
01764 {return timeslot;};
01765
01771 inline timeslot_t getCount(void)
01772 {return count;};
01773
01779 inline unsigned getId(void)
01780 {return id;};
01781
01787 inline BayonneDriver *getDriver(void)
01788 {return driver;};
01789
01795 inline unsigned getAvail(void)
01796 {return count - used;}
01797 };
01798
01805 class __EXPORT BayonneBinder : public ScriptBinder, public Bayonne
01806 {
01807 private:
01808 static BayonneBinder *binder;
01809
01810 protected:
01811 virtual const char *submit(const char **data);
01812
01813 BayonneSession *session(ScriptInterp *interp);
01814
01815 bool scriptEvent(ScriptInterp *interp, const char *evt);
01816
01817 bool digitEvent(ScriptInterp *interp, const char *evt);
01818
01819 BayonneBinder(const char *id);
01820
01821 public:
01822 static const char *submitRequest(const char **data);
01823 };
01824
01832 class __EXPORT BayonneSession : public ScriptInterp, public Bayonne
01833 {
01834 private:
01835 friend class __EXPORT BayonneMsgport;
01836 friend class __EXPORT BayonneTranslator;
01837 friend class __EXPORT BayonneDriver;
01838 friend class __EXPORT Bayonne;
01839
01840 BayonneSession() {};
01841
01842 BayonneSession *nextIdle, *prevIdle;
01843 bool isAvail;
01844
01845 protected:
01846 static BayonneTranslator langNone;
01847 static ScriptSymbols *globalSyms;
01848 static Mutex globalLock;
01849
01850 std::ostream *logevents, *logtrace;
01851 BayonneDriver *driver;
01852 BayonneMsgport *msgport;
01853 BayonneSession *peer;
01854 BayonneSpan *span;
01855 timeslot_t timeslot;
01856 uint8 seq;
01857 uint16 evseq;
01858 uint32 tseq;
01859 bool offhook, dtmf, answered, starting, holding;
01860 time_t audiotimer, starttime;
01861 interface_t iface;
01862 bridge_t bridge;
01863 calltype_t type;
01864 event_t seizure;
01865
01866 Name *getScript(const char *scr);
01867
01875 bool requiresDTMF(void);
01876
01882 virtual bool enableDTMF(void);
01883
01887 virtual void disableDTMF(void);
01888
01897 virtual const char *checkAudio(bool live);
01898
01905 virtual bool filterPosting(Event *event);
01906
01907 virtual bool enterCommon(Event *event);
01908 virtual bool enterInitial(Event *event);
01909 virtual bool enterFinal(Event *event);
01910 virtual bool enterIdle(Event *event);
01911 virtual bool enterReset(Event *event);
01912 virtual bool enterRelease(Event *event);
01913 virtual bool enterRinging(Event *event);
01914 virtual bool enterPickup(Event *event);
01915 virtual bool enterSeize(Event *event);
01916 virtual bool enterHangup(Event *event);
01917 virtual bool enterTone(Event *event);
01918 virtual bool enterDTMF(Event *event);
01919 virtual bool enterPlay(Event *event);
01920 virtual bool enterRecord(Event *event);
01921 virtual bool enterJoin(Event *event);
01922 virtual bool enterWait(Event *event);
01923 virtual bool enterDial(Event *event);
01924 virtual bool enterBusy(Event *event);
01925 virtual bool enterStandby(Event *event);
01926 virtual bool enterXfer(Event *event);
01927 virtual bool enterHold(Event *event);
01928 virtual bool enterRecall(Event *event);
01929
01934 void check(void);
01935
01936 void renameRecord(void);
01937 bool stateInitial(Event *event);
01938 bool stateFinal(Event *event);
01939 bool stateIdle(Event *event);
01940 bool stateIdleReset(Event *event);
01941 bool stateReset(Event *event);
01942 bool stateRelease(Event *event);
01943 bool stateBusy(Event *event);
01944 bool stateStandby(Event *event);
01945 bool stateRinging(Event *event);
01946 bool statePickup(Event *event);
01947 bool stateSeize(Event *event);
01948 bool stateRunning(Event *event);
01949 bool stateLibexec(Event *event);
01950 bool stateLibreset(Event *event);
01951 bool stateLibwait(Event *event);
01952 bool stateWaitkey(Event *event);
01953 bool stateThreading(Event *event);
01954 bool stateHangup(Event *event);
01955 bool stateCollect(Event *event);
01956 bool stateSleep(Event *event);
01957 bool stateStart(Event *event);
01958 bool stateClear(Event *event);
01959 bool stateInkey(Event *event);
01960 bool stateInput(Event *event);
01961 bool stateRead(Event *event);
01962 bool stateDial(Event *event);
01963 bool stateXfer(Event *event);
01964 bool stateHold(Event *event);
01965 bool stateRecall(Event *event);
01966 bool stateTone(Event *event);
01967 bool stateDTMF(Event *event);
01968 bool statePlay(Event *event);
01969 bool stateRecord(Event *event);
01970 bool stateJoin(Event *event);
01971 bool stateWait(Event *event);
01972 bool stateConnect(Event *event);
01973
01980 bool putEvent(Event *event);
01981
01987 void libWrite(const char *string);
01988
01989 void libClose(const char *string);
01990
01991 bool isLibexec(const char *tsid);
01992
01993 timeout_t getLibexecTimeout(void);
01994
01995 const char *getWritepath(char *buf = NULL, size_t len = 0);
01996
01997 public:
02004 const char *getExternal(const char *option);