25 #define BAYONNE_NAMESPACE bayonne
26 #define NAMESPACE_BAYONNE namespace bayonne {
28 #ifndef UCOMMON_UCOMMON_H_
29 #include <ucommon/ucommon.h>
49 using namespace UCOMMON_NAMESPACE;
56 class __EXPORT Script :
public CountedObject,
private memalloc
66 typedef bool (Script::interp::*method_t)(void);
81 unsigned short loop, argc;
89 typedef const char *(*check_t)(Script *img, Script::header *scr, Script::line_t *line);
96 typedef struct keyword
102 struct keyword *next;
112 class __EXPORT strict :
public LinkedObject
118 static bool find(Script *img, header *scr,
const char *
id);
119 static void createVar(Script *img, header *scr,
const char *
id);
120 static void createSym(Script *img, header *scr,
const char *
id);
121 static void createAny(Script *img, header *scr,
const char *
id);
122 static void createGlobal(Script *img,
const char *
id);
124 void put(FILE *fp,
const char *header);
134 class __EXPORT symbol :
public LinkedObject
148 class __EXPORT event :
public LinkedObject
158 typedef event event_t;
168 class __EXPORT header :
public LinkedObject
171 LinkedObject *scoped;
172 LinkedObject *events;
173 LinkedObject *methods;
182 inline void link(header *scr)
193 class __EXPORT checks
196 static bool isValue(
const char *text);
197 static bool isText(
const char *text);
199 static const char *chkPush(Script *img, header *scr, line_t *line);
200 static const char *chkApply(Script *img, header *scr, line_t *line);
201 static const char *chkIgnore(Script *img, header *scr, line_t *line);
202 static const char *chkNop(Script *img, header *scr, line_t *line);
203 static const char *chkExit(Script *img, header *scr, line_t *line);
204 static const char *chkVar(Script *img, header *scr, line_t *line);
205 static const char *chkConst(Script *img, header *scr, line_t *line);
206 static const char *chkSet(Script *img, header *scr, line_t *line);
207 static const char *chkClear(Script *img, header *scr, line_t *line);
208 static const char *chkError(Script *img, header *scr, line_t *line);
209 static const char *chkPack(Script *img, header *scr, line_t *line);
210 static const char *chkExpand(Script *img, header *scr, line_t *line);
211 static const char *chkGosub(Script *img, header *src, line_t *line);
212 static const char *chkGoto(Script *img, header *scr, line_t *line);
213 static const char *chkDo(Script *img, header *scr, line_t *line);
214 static const char *chkUntil(Script *img, header *scr, line_t *line);
215 static const char *chkWhile(Script *ing, header *scr, line_t *line);
216 static const char *chkConditional(Script *img, header *scr, line_t *line);
217 static const char *chkContinue(Script *img, header *scr, line_t *line);
218 static const char *chkBreak(Script *img, header *scr, line_t *line);
219 static const char *chkLoop(Script *img, header *scr, line_t *line);
220 static const char *chkPrevious(Script *img, header *scr, line_t *line);
221 static const char *chkIndex(Script *img, header *scr, line_t *line);
222 static const char *chkForeach(Script *img, header *scr, line_t *line);
223 static const char *chkCase(Script *img, header *scr, line_t *line);
224 static const char *chkEndcase(Script *img, header *scr, line_t *line);
225 static const char *chkOtherwise(Script *img, header *scr, line_t *line);
226 static const char *chkIf(Script *img, header *scr, line_t *line);
227 static const char *chkElif(Script *img, header *scr, line_t *line);
228 static const char *chkElse(Script *img, header *scr, line_t *line);
229 static const char *chkEndif(Script *img, header *scr, line_t *line);
230 static const char *chkDefine(Script *img, header *scr, line_t *line);
231 static const char *chkInvoke(Script *img, header *scr, line_t *line);
232 static const char *chkWhen(Script *img, header *scr, line_t *line);
233 static const char *chkStrict(Script *img, header *scr, line_t *line);
234 static const char *chkExpr(Script *img, header *scr, line_t *line);
235 static const char *chkRef(Script *ing, header *scr, line_t *line);
247 unsigned short index;
249 unsigned short resmask;
262 class __EXPORT interp :
protected memalloc
265 typedef char num_t[16];
285 bool attach(Script *image,
const char *entry = NULL);
297 void initialize(
void);
303 bool error(
const char *text);
309 unsigned getResource(
void);
312 symbol *find(
const char *
id);
315 bool trylabel(
const char *
id);
317 void pullScope(
void);
321 void setStack(header *scr, event *ev = NULL);
330 virtual bool match(
const char *pattern,
const char *name);
339 virtual bool isInherited(
const char *name);
348 bool scriptEvent(
const char *name);
355 event *scriptMethod(
const char *name);
358 object_pointer<Script> image;
363 bool setConst(
const char *
id,
const char *value);
364 symbol *createSymbol(
const char *
id);
365 symbol *getVar(
const char *
id,
const char *value = NULL);
366 const char *getValue(
void);
367 const char *getContent(
void);
368 const char *getContent(
const char *text);
369 const char *getKeyword(
const char *
id);
370 method_t getLooping(
void);
371 bool isConditional(
unsigned index);
372 void setRef(header *scope,
const char *
id,
char *data,
unsigned size);
373 void getParams(header *scope, line_t *line);
374 void startScript(header *scr);
376 virtual unsigned getTypesize(
const char *type_id);
377 virtual const char *getTypeinit(
const char *type_id);
378 virtual const char *getFormat(symbol *sym,
const char *
id,
char *temp);
379 virtual bool getCondition(
const char *test,
const char *value);
380 const char *getIndex(
void);
383 bool getExpression(
unsigned index);
396 class __EXPORT error :
public OrderedObject
400 error(Script *img,
unsigned line,
const char *str);
414 class __EXPORT methods :
public interp
428 bool scrExpand(
void);
430 bool scrReturn(
void);
432 bool scrRestart(
void);
440 bool scrContinue(
void);
441 bool scrForeach(
void);
442 bool scrPrevious(
void);
443 bool scrRepeat(
void);
446 bool scrEndcase(
void);
447 bool scrOtherwise(
void);
452 bool scrDefine(
void);
453 bool scrInvoke(
void);
460 static unsigned stepping;
461 static unsigned indexing;
462 static size_t paging;
463 static unsigned sizing;
464 static unsigned stacking;
465 static unsigned decimals;
476 static Script *append(Script *merge,
const char *filename, Script *config = NULL);
486 static Script *compile(
const char *filename, Script *config = NULL);
499 static Script *merge(
const char *filename, Script *root = NULL);
508 static Script *merge(Script *image, Script *root);
515 static void assign(keyword_t *list);
524 static keyword_t *find(
const char *
id);
529 static void init(
void);
531 static unsigned offset(
const char *list,
unsigned index);
532 static void copy(
const char *list,
char *item,
unsigned size);
533 static unsigned count(
const char *list);
534 static const char *
get(
const char *list,
unsigned offset);
535 static char *
get(
char *list,
unsigned offset);
536 static header *find(Script *img,
const char *
id);
537 static bool isEvent(header *scr,
const char *
id);
540 LinkedObject **scripts;
542 bool push(line_t *line);
544 method_t looping(
void);
546 inline unsigned getErrors(
void)
549 inline LinkedObject *getListing(
void)
550 {
return errlist.begin();};
552 inline const char *getFilename(
void)
555 inline bool isStrict(
void)
556 {
return global != NULL;};
558 inline unsigned getLines(
void)
566 friend class methods;
570 void errlog(
unsigned line,
const char *fmt, ...);
577 LinkedObject *global;
578 OrderedIndex errlist;
579 object_pointer<Script> shared;
580 const char *filename;
581 LinkedObject *headers;
595 typedef int16_t snd16_t;
596 typedef int32_t snd32_t;
597 typedef int16_t level_t;
598 typedef int16_t sample_t;
599 typedef int16_t *linear_t;
601 #if _MSC_VER > 1400 // windows broken dll linkage issue...
602 const static unsigned ndata = (-1);
604 const static unsigned ndata;
620 goertzel_state_t row_out[4];
621 goertzel_state_t col_out[4];
622 goertzel_state_t row_out2nd[4];
623 goertzel_state_t col_out2nd[4];
624 goertzel_state_t fax_tone;
625 goertzel_state_t fax_tone2nd;
635 } dtmf_detect_state_t;
639 } tone_detection_descriptor_t;
641 typedef unsigned char *encoded_t;
657 typedef enum Rate rate_t;
675 typedef enum Mode mode_t;
721 speexNarrow = speexVoice,
722 speexWide = speexAudio,
723 g723_4bit = g721ADPCM
725 typedef enum Encoding encoding_t;
736 typedef enum Format format_t;
763 typedef enum Error error_t;
774 unsigned long bitrate;
776 unsigned framesize, framecount, headersize, padding;
783 void setFraming(timeout_t frame);
784 void setRate(rate_t rate);
795 static level_t tolevel(
float dbm);
803 static float todbm(level_t power);
812 static bool is_available(
unsigned device = 0);
821 static const char *getMIME(Info &info);
830 static const char *getName(encoding_t encoding);
839 static const char *getExtension(encoding_t encoding);
851 static encoding_t getEncoding(
const char *name);
859 static encoding_t getStereo(encoding_t encoding);
867 static encoding_t getMono(encoding_t encoding);
875 static bool is_linear(encoding_t encoding);
885 static bool is_buffered(encoding_t encoding);
893 static bool is_mono(encoding_t encoding);
901 static bool is_stereo(encoding_t encoding);
910 static rate_t getRate(encoding_t encoding);
920 static rate_t getRate(encoding_t e, rate_t request);
929 static timeout_t getFraming(encoding_t encoding, timeout_t timeout = 0);
938 static timeout_t getFraming(Info &info, timeout_t timeout = 0);
947 static bool is_endian(encoding_t encoding);
956 static bool is_endian(Info &info);
967 static bool swapEndian(encoding_t encoding,
void *buffer,
unsigned number);
977 static void swapEncoded(Info &info, encoded_t data,
size_t bytes);
989 static bool swapEndian(Info &info,
void *buffer,
unsigned number);
999 static level_t impulse(encoding_t encoding,
void *buffer,
unsigned number);
1009 static level_t impulse(Info &info,
void *buffer,
unsigned number = 0);
1020 static level_t peak(encoding_t encoding,
void *buffer,
unsigned number);
1031 static level_t peak(Info &info,
void *buffer,
unsigned number = 0);
1040 static void toTimestamp(timeout_t duration,
char *address,
size_t size);
1048 static timeout_t toTimeout(
const char *timestamp);
1072 static int getFrame(encoding_t encoding,
int samples = 0);
1086 static int getCount(encoding_t encoding);
1096 static unsigned long toSamples(encoding_t encoding,
size_t bytes);
1106 static unsigned long toSamples(Info &info,
size_t bytes);
1116 static size_t toBytes(Info &info,
unsigned long number);
1126 static size_t toBytes(encoding_t encoding,
unsigned long number);
1136 static void fill(
unsigned char *address,
int number, encoding_t encoding);
1145 static size_t maxFramesize(Info &info);
1154 class __EXPORT resample
1157 unsigned mfact, dfact, max;
1158 unsigned gpos, ppos;
1163 resample(rate_t mul, rate_t div);
1166 size_t process(linear_t from, linear_t to,
size_t count);
1167 size_t estimate(
size_t count);
1177 class __EXPORT
Phrasebook :
public LinkedObject
1188 const char *list[1];
1192 static void _add(
const char *text, rule_t *
state);
1194 static void _dup(
const char *text, rule_t *
state);
1196 static void _lownumber(
int num, rule_t *
state);
1201 virtual bool id(
const char *lang) = 0;
1203 virtual const char *path(
void);
1205 virtual void number(
const char *text, rule_t *
state);
1207 virtual void order(
const char *text, rule_t *
state);
1209 virtual void spell(
const char *text, rule_t *
state);
1211 virtual void literal(
const char *text, rule_t *
state);
1213 virtual void weekday(
const char *text, rule_t *
state);
1215 virtual void date(
const char *text, rule_t *
state);
1217 virtual void fulldate(
const char *text, rule_t *
state);
1219 virtual void year(
const char *text, rule_t *
state);
1221 virtual void time(
const char *text, rule_t *
state);
1223 virtual void zero(
const char *text, rule_t *
state);
1225 virtual void single(
const char *text, rule_t *
state);
1227 virtual void plural(
const char *text, rule_t *
state);
1229 virtual void nonzero(
const char *text, rule_t *
state);
1231 static Phrasebook *find(
const char *locale = NULL);
1233 static void init(rule_t *
state,
size_t size);
1235 static void reset(rule_t *
state);
1246 static shell_t *sys;
1247 static bool daemon_flag;
1248 static bool tool_flag;
1251 class __LOCAL pathinfo_t
1256 const char *appname;
1259 {book = NULL; voices = appname = NULL;};
1261 inline void reset(
void)
1262 {book = NULL; voices = appname = NULL;};
1268 static void init(shell_t *args);
1270 static void tool(shell_t *args);
1272 static inline void set(
const char *
id,
const char *value)
1273 {sys->setsym(
id, value);};
1275 static inline const char *
get(
const char *id)
1276 {
return sys->getsym(
id);};
1278 static inline const char *env(
const char *
id)
1279 {
return sys->getsym(
id);};
1281 static const char *config(
const char *name);
1283 static const char *path(pathinfo_t& pathinfo,
const char *path,
char *buffer,
size_t size,
bool write =
false);
1294 class __EXPORT Tonegen :
public Audio,
protected Env
1297 typedef struct _tonedef {
1298 struct _tonedef *next;
1299 timeout_t duration, silence;
1301 unsigned short f1, f2;
1304 typedef struct _tonekey {
1305 struct _tonekey *next;
1306 struct _tonedef *first;
1307 struct _tonedef *last;
1315 double df1, df2, p1, p2;
1321 unsigned remaining, silent, count;
1346 void single(
unsigned freq, level_t level);
1356 void dual(
unsigned f1,
unsigned f2, level_t l1, level_t l2);
1365 Tonegen(timeout_t duration = 20, rate_t rate = rate8khz);
1375 Tonegen(key_t *key, level_t level, timeout_t frame = 20);
1387 Tonegen(
unsigned f1,
unsigned f2, level_t l1, level_t l2,
1388 timeout_t duration = 20, rate_t sample = rate8khz);
1398 Tonegen(
unsigned freq, level_t level, timeout_t duration = 20, rate_t sample = rate8khz);
1407 inline rate_t getRate(
void)
const
1415 inline size_t getSamples(
void)
const
1423 bool is_silent(
void);
1432 virtual linear_t getFrame(
void);
1442 unsigned getFrames(linear_t buffer,
unsigned number);
1450 inline bool is_complete(
void)
1453 static bool load(
const char *locale = NULL);
1455 static key_t *find(
const char *
id,
const char *locale = NULL);
1467 class __EXPORT DTMFDialer :
public Tonegen
1470 unsigned dtmfframes;
1482 DTMFDialer(
const char *digits, level_t level, timeout_t duration = 20, timeout_t interdigit = 60);
1486 linear_t getFrame(
void);
1498 class __EXPORT MFDialer :
public Tonegen
1514 MFDialer(
const char *digits, level_t level, timeout_t duration = 20, timeout_t interdigit = 60);
1518 linear_t getFrame(
void);
1525 class __EXPORT DTMFDetect :
public Audio
1539 int putSamples(linear_t buffer,
int count);
1547 int getResult(
char *data,
int size);
1550 void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t);
1551 void goertzelUpdate(goertzel_state_t *s, sample_t x[],
int samples);
1552 float goertzelResult(goertzel_state_t *s);
1555 dtmf_detect_state_t *
state;
1556 tone_detection_descriptor_t dtmf_detect_row[4];
1557 tone_detection_descriptor_t dtmf_detect_col[4];
1558 tone_detection_descriptor_t dtmf_detect_row_2nd[4];
1559 tone_detection_descriptor_t dtmf_detect_col_2nd[4];
1560 tone_detection_descriptor_t fax_detect;
1561 tone_detection_descriptor_t fax_detect_2nd;
1576 class __EXPORT
AudioCodec :
public Audio,
public LinkedObject
1579 encoding_t encoding;
1592 virtual AudioCodec *getByFormat(
const char *format)
1611 AudioCodec(
const char *name, encoding_t encoding);
1613 inline const char *getName(
void)
const
1616 inline const char *getDescription(
void)
const
1617 {
return info.annotation;};
1638 static AudioCodec *
get(encoding_t encoding,
const char *format = NULL);
1657 virtual level_t impulse(
void *buffer,
unsigned number = 0);
1666 virtual level_t peak(
void *buffer,
unsigned number = 0);
1678 virtual bool is_silent(level_t threashold,
void *buffer,
unsigned number = 0);
1688 virtual unsigned encode(linear_t buffer,
void *dest,
unsigned number = 0) = 0;
1698 virtual unsigned encodeBuffered(linear_t Buffer, encoded_t dest,
unsigned number);
1708 virtual unsigned decode(linear_t buffer,
void *source,
unsigned number = 0) = 0;
1719 virtual unsigned decodeBuffered(linear_t buffer, encoded_t source,
unsigned len);
1726 virtual unsigned getEstimated(
void);
1733 virtual unsigned getRequired(
void);
1744 virtual unsigned getPacket(encoded_t destination, encoded_t data,
unsigned size);
1751 inline info_t getInfo(
void)
const
1763 class __EXPORT AudioFile:
public Audio
1775 void initialize(
void);
1776 void getWaveFormat(
int size);
1779 ssize_t read(
void *buf,
size_t len);
1780 ssize_t write(
void *buf,
size_t len);
1781 ssize_t peek(
void *buf,
size_t len);
1782 bool seek(
size_t pos);
1784 virtual const char *getContinuation();
1795 unsigned short getShort(
unsigned char *data)
const;
1805 void setShort(
unsigned char *data,
unsigned short value);
1816 unsigned long getLong(
unsigned char *data)
const;
1826 void setLong(
unsigned char *data,
unsigned long value);
1835 AudioFile(
const char *name,
unsigned long offset = 0);
1844 AudioFile(
const char *name, info_t& info,
unsigned long minimum = 0);
1851 virtual ~AudioFile();
1863 void open(
const char *name, mode_t mode = modeWrite, timeout_t framing = 0);
1874 void create(
const char *name, info_t& info, timeout_t framing = 0);
1889 inline size_t getSize(
void)
1890 {
return maxFramesize(info);};
1908 inline int err(
void)
1922 ssize_t getBuffer(encoded_t buffer,
size_t len = 0);
1932 unsigned getLinear(linear_t buffer,
unsigned request = 0);
1941 ssize_t getNative(encoded_t data,
size_t size);
1954 ssize_t putBuffer(encoded_t buffer,
size_t len = 0);
1964 ssize_t putNative(encoded_t data,
size_t size);
1974 unsigned putLinear(linear_t buffer,
unsigned request = 0);
1988 int getSamples(
void *buffer,
unsigned samples = 0);
2001 int putSamples(
void *buffer,
unsigned samples = 0);
2010 int skip(
long number);
2019 int setPosition(
unsigned long samples = ~0l);
2028 int position(
const char *timestamp);
2036 void getPosition(
char *timestamp,
size_t size);
2044 void setLimit(
unsigned long maximum = 0l);
2052 inline void getInfo(info_t& output)
const
2063 int setMinimum(
unsigned long minimum);
2074 inline size_t getAbsolutePosition(
void)
2088 unsigned long getPosition(
void);
2090 inline bool operator!()
const
2093 inline operator bool()
const
2096 inline bool is_open(
void)
const
2104 inline encoding_t getEncoding(
void)
const
2105 {
return info.encoding;};
2112 inline format_t getFormat(
void)
const
2113 {
return info.format;};
2121 inline unsigned getSampleRate(
void)
const
2122 {
return info.rate;};
2129 inline char *getAnnotation(
void)
const
2130 {
return info.annotation;};
2137 bool is_signed(
void)
const;
2157 linear_t bufferFrame;
2158 unsigned bufferPosition;
2159 unsigned bufferChannels;
2160 linear_t encBuffer, decBuffer;
2161 unsigned encSize, decSize;
2163 unsigned bufAudio(linear_t samples,
unsigned count,
unsigned size);
2178 AudioStream(
const char *name, mode_t mode = modeRead, timeout_t framing = 0);
2188 AudioStream(
const char *name, info_t& info, timeout_t framing = 0);
2199 ssize_t getBuffer(encoded_t data,
size_t count);
2208 void open(
const char *name, mode_t mode = modeRead, timeout_t framing = 0);
2218 void create(
const char *name, info_t& info, timeout_t framing = 0);
2236 bool is_streamable(
void);
2241 unsigned getCount(
void);
2252 unsigned getEncoded(
AudioCodec *codec, encoded_t address,
unsigned frames = 1);
2263 unsigned putEncoded(
AudioCodec *codec, encoded_t address,
unsigned frames = 1);
2272 unsigned getEncoded(encoded_t address,
unsigned frames = 1);
2281 unsigned putEncoded(encoded_t address,
unsigned frames = 1);
2290 ssize_t getPacket(encoded_t data);
2300 unsigned getMono(linear_t buffer,
unsigned frames = 1);
2310 unsigned getStereo(linear_t buffer,
unsigned frames = 1);
2320 unsigned putMono(linear_t buffer,
unsigned frames = 1);
2330 unsigned putStereo(linear_t buffer,
unsigned frames = 1);
2341 unsigned bufMono(linear_t buffer,
unsigned count);
2352 unsigned bufStereo(linear_t buffer,
unsigned count);
2370 class __EXPORT Serial
2376 Serial(
const Serial&);
2381 inline int err(
void)
2384 virtual operator bool() = 0;
2385 virtual bool operator!() = 0;
2386 virtual void restore(
void) = 0;
2387 virtual bool set(
const char *format) = 0;
2388 virtual void dtr(timeout_t toggle_time) = 0;
2389 virtual size_t get(
void *addr,
size_t len) = 0;
2390 virtual size_t put(
void *addr,
size_t len) = 0;
2391 virtual void clear(
void) = 0;
2392 virtual bool flush(timeout_t timeout) = 0;
2393 virtual bool wait(timeout_t timeout) = 0;
2394 virtual void text(
char nl1 = 0x13,
char nl2 = 0x10) = 0;
2395 virtual void bin(
size_t size, timeout_t timeout = 0) = 0;
2396 virtual void sync(
void) = 0;
2398 static Serial *create(
const char *name);
2400 static stringpager *list(
void);
2410 class __EXPORT Module :
public LinkedObject,
protected Env
2413 virtual void start(
void);
2415 virtual void stop(
void);
2420 static void startup(
void);
2421 static void shutdown(
void);
2424 typedef Serial *serial_t;
#define NAMESPACE_BAYONNE