-
Notifications
You must be signed in to change notification settings - Fork 16
/
yateclass.h
13402 lines (11825 loc) · 424 KB
/
yateclass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* yateclass.h
* This file is part of the YATE Project http://YATE.null.ro
*
* Base classes and types, not related to the engine or telephony
*
* Yet Another Telephony Engine - a fully featured software PBX and IVR
* Copyright (C) 2004-2023 Null Team
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribution.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __YATECLASS_H
#define __YATECLASS_H
#ifndef __cplusplus
#error C++ is required
#endif
#include <limits.h>
#include <sys/types.h>
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#ifndef _WORDSIZE
#if defined(__arch64__) || defined(__x86_64__) \
|| defined(__amd64__) || defined(__ia64__) \
|| defined(__alpha__) || defined(__sparcv9) || defined(__mips64)
#define _WORDSIZE 64
#else
#define _WORDSIZE 32
#endif
#endif
#ifndef _WINDOWS
#if defined(WIN32) || defined(_WIN32)
#define _WINDOWS
#endif
#endif
#ifdef _WINDOWS
#include <windows.h>
#include <io.h>
#include <direct.h>
/**
* Windows definitions for commonly used types
*/
typedef signed __int8 int8_t;
typedef unsigned __int8 u_int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 u_int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 u_int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 u_int64_t;
typedef unsigned __int64 uint64_t;
typedef int pid_t;
typedef int socklen_t;
typedef unsigned long in_addr_t;
#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
#ifndef strncasecmp
#define strncasecmp _strnicmp
#endif
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#define strdup _strdup
#define strtoll _strtoi64
#define strtoull _strtoui64
#define open _open
#define dup2 _dup2
#define read _read
#define write _write
#define close _close
#define getpid _getpid
#define chdir _chdir
#define mkdir(p,m) _mkdir(p)
#define unlink _unlink
#define llabs _abs64
#define O_RDWR _O_RDWR
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_APPEND _O_APPEND
#define O_BINARY _O_BINARY
#define O_EXCL _O_EXCL
#define O_CREAT _O_CREAT
#define O_TRUNC _O_TRUNC
#define O_NOCTTY 0
#define S_IRUSR _S_IREAD
#define S_IWUSR _S_IWRITE
#define S_IXUSR 0
#define S_IRWXU (_S_IREAD|_S_IWRITE)
#ifdef LIBYATE_EXPORTS
#define YATE_API __declspec(dllexport)
#else
#ifndef LIBYATE_STATIC
#define YATE_API __declspec(dllimport)
#endif
#endif
#define FMT64 "%I64d"
#define FMT64U "%I64u"
#else /* _WINDOWS */
#include <sys/time.h>
#include <sys/socket.h>
#if defined(__FreeBSD__)
#include <netinet/in_systm.h>
#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
/**
* Non-Windows definitions for commonly used types
*/
#ifndef SOCKET
typedef int SOCKET;
#endif
#ifndef HANDLE
typedef int HANDLE;
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
#if _WORDSIZE == 64 && !defined(__APPLE__)
#define FMT64 "%ld"
#define FMT64U "%lu"
#else
#define FMT64 "%lld"
#define FMT64U "%llu"
#endif
#endif /* ! _WINDOWS */
#ifndef LLONG_MAX
#ifdef _I64_MAX
#define LLONG_MAX _I64_MAX
#else
#define LLONG_MAX 9223372036854775807LL
#endif
#endif
#ifndef LLONG_MIN
#ifdef _I64_MIN
#define LLONG_MIN _I64_MIN
#else
#define LLONG_MIN (-LLONG_MAX - 1LL)
#endif
#endif
#ifndef ULLONG_MAX
#ifdef _UI64_MAX
#define ULLONG_MAX _UI64_MAX
#else
#define ULLONG_MAX 18446744073709551615ULL
#endif
#endif
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
#endif
#ifndef IPTOS_LOWDELAY
#define IPTOS_LOWDELAY 0x10
#define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04
#endif
#ifndef IPTOS_MINCOST
#define IPTOS_MINCOST 0x02
#endif
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif
#ifndef YATE_API
#define YATE_API
#endif
#ifdef _WINDOWS
#undef RAND_MAX
#define RAND_MAX 2147483647
#endif
/**
* Holds all Telephony Engine related classes.
*/
namespace TelEngine {
#ifdef HAVE_GCC_FORMAT_CHECK
#define FORMAT_CHECK(f) __attribute__((format(printf,(f),(f)+1)))
#else
#define FORMAT_CHECK(f)
#endif
#define YIGNORE(v) while (v) { break; }
#ifdef HAVE_BLOCK_RETURN
#define YSTRING(s) (*({static const String str("" s);&str;}))
#define YATOM(s) (*({static const String* str(0);str ? str : String::atom(str,"" s);}))
#else
#define YSTRING(s) ("" s)
#define YATOM(s) ("" s)
#endif
#define YSTRING_INIT_HASH ((unsigned) -1)
class Lockable;
class Semaphore;
class Mutex;
class RWLock;
class WLock;
class RLock;
class RWLockPrivate;
class String;
class DataBlock;
class ObjList;
class NamedCounter;
class MutexPrivate;
class SemaphorePrivate;
class ThreadPrivate;
struct TokenDictStr;
struct TokenDictStr64;
/**
* Abort execution (and coredump if allowed) if the abort flag is set.
* This function may not return.
*/
YATE_API void abortOnBug();
/**
* Set the abort on bug flag. The default flag state is false.
* @return The old state of the flag.
*/
YATE_API bool abortOnBug(bool doAbort);
/**
* Standard debugging levels.
* The DebugFail level is special - it is always displayed and may abort
* the program if @ref abortOnBug() is set.
*/
enum DebugLevel {
DebugFail = 0,
DebugTest = 1,
DebugCrit = 2,
DebugGoOn = DebugCrit,
DebugConf = 3,
DebugStub = 4,
DebugWarn = 5,
DebugMild = 6,
DebugNote = 7,
DebugCall = 8,
DebugInfo = 9,
DebugAll = 10
};
/**
* Retrieve the current global debug level
* @return The current global debug level
*/
YATE_API int debugLevel();
/**
* Set the current global debug level.
* @param level The desired debug level
* @return The new global debug level (may be different)
*/
YATE_API int debugLevel(int level);
/**
* Check if debugging output should be generated
* @param level The global debug level we are testing
* @return True if messages should be output, false otherwise
*/
YATE_API bool debugAt(int level);
/**
* Get an ANSI string to colorize debugging output
* @param level The debug level who's color is requested.
* Negative or out of range will reset to the default color
* @return ANSI string that sets color corresponding to level
*/
YATE_API const char* debugColor(int level);
/**
* Get the name of a debugging or alarm level
* @param level The debug level
* @return Short C string describing the level
*/
YATE_API const char* debugLevelName(int level);
/**
* Holds a local debugging level that can be modified separately from the
* global debugging
* @short A holder for a debug level
*/
class YATE_API DebugEnabler
{
public:
/**
* Constructor
* @param level The initial local debug level
* @param enabled Enable debugging on this object
*/
inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
: m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
{ debugLevel(level); }
inline ~DebugEnabler()
{ m_name = 0; m_chain = 0; }
/**
* Retrieve the current local debug level
* @return The current local debug level
*/
inline int debugLevel() const
{ return m_chain ? m_chain->debugLevel() : m_level; }
/**
* Set the current local debug level.
* @param level The desired debug level
* @return The new debug level (may be different)
*/
int debugLevel(int level);
/**
* Retrieve the current debug activation status
* @return True if local debugging is enabled
*/
inline bool debugEnabled() const
{ return m_chain ? m_chain->debugEnabled() : m_enabled; }
/**
* Set the current debug activation status
* @param enable The new debug activation status, true to enable
*/
inline void debugEnabled(bool enable)
{ m_enabled = enable; m_chain = 0; }
/**
* Get the current debug name
* @return Name of the debug activation if set or NULL
*/
inline const char* debugName() const
{ return m_name; }
/**
* Check if debugging output should be generated
* @param level The debug level we are testing
* @return True if messages should be output, false otherwise
*/
bool debugAt(int level) const;
/**
* Check if this enabler is chained to another one
* @return True if local debugging is chained to other enabler
*/
inline bool debugChained() const
{ return m_chain != 0; }
/**
* Chain this debug holder to a parent or detach from existing one
* @param chain Pointer to parent debug level, NULL to detach
*/
inline void debugChain(const DebugEnabler* chain = 0)
{ m_chain = (chain != this) ? chain : 0; }
/**
* Copy debug settings from another object or from engine globals
* @param original Pointer to a DebugEnabler to copy settings from
*/
void debugCopy(const DebugEnabler* original = 0);
/**
* Set debug from description
* @param desc Debug description. [level [NNN][+-]] or 'reset'
*/
void debugSet(const char* desc);
protected:
/**
* Set the current debug name
* @param name Static debug name or NULL
*/
inline void debugName(const char* name)
{ m_name = name; }
private:
int m_level;
bool m_enabled;
const DebugEnabler* m_chain;
const char* m_name;
};
#if 0 /* for documentation generator */
/**
* Convenience macro.
* Does the same as @ref Debug if DEBUG is \#defined (compiling for debugging)
* else it does not get compiled at all.
*/
void DDebug(int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if DEBUG is \#defined (compiling for debugging)
* else it does not get compiled at all.
*/
void DDebug(const char* facility, int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if DEBUG is \#defined (compiling for debugging)
* else it does not get compiled at all.
*/
void DDebug(const DebugEnabler* local, int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if XDEBUG is \#defined (compiling for extra
* debugging) else it does not get compiled at all.
*/
void XDebug(int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if XDEBUG is \#defined (compiling for extra
* debugging) else it does not get compiled at all.
*/
void XDebug(const char* facility, int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if XDEBUG is \#defined (compiling for extra
* debugging) else it does not get compiled at all.
*/
void XDebug(const DebugEnabler* local, int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if NDEBUG is not \#defined
* else it does not get compiled at all (compiling for mature release).
*/
void NDebug(int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if NDEBUG is not \#defined
* else it does not get compiled at all (compiling for mature release).
*/
void NDebug(const char* facility, int level, const char* format, ...);
/**
* Convenience macro.
* Does the same as @ref Debug if NDEBUG is not \#defined
* else it does not get compiled at all (compiling for mature release).
*/
void NDebug(const DebugEnabler* local, int level, const char* format, ...);
#endif
#if defined(_DEBUG) || defined(DEBUG) || defined(XDEBUG)
#undef DEBUG
#define DEBUG 1
#endif
#ifdef DEBUG
#define DDebug Debug
#else
#ifdef _WINDOWS
#define DDebug do { break; } while
#else
#define DDebug(arg...)
#endif
#endif
#ifdef XDEBUG
#define XDebug Debug
#else
#ifdef _WINDOWS
#define XDebug do { break; } while
#else
#define XDebug(arg...)
#endif
#endif
#ifndef NDEBUG
#define NDebug Debug
#else
#ifdef _WINDOWS
#define NDebug do { break; } while
#else
#define NDebug(arg...)
#endif
#endif
/**
* Outputs a debug string.
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
/**
* Outputs a debug string for a specific facility.
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string for a specific facility.
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string and emits an alarm if a callback is installed
* @param component Component that emits the alarm
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void Alarm(const char* component, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string and emits an alarm if a callback is installed
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void Alarm(const DebugEnabler* component, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string and emits an alarm if a callback is installed
* @param component Component that emits the alarm
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void Alarm(const char* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string and emits an alarm if a callback is installed
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void Alarm(const DebugEnabler* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a string to the debug console with formatting
* @param format A printf() style format string
*/
YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, const char* facility, int level,
const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, const DebugEnabler* local, int level,
const char* format, ...) FORMAT_CHECK(4);
#if 0 /* for documentation generator */
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
#endif
#define TraceDebugObj(pGenObj,...) \
TraceDebug((!!(pGenObj)) ? (pGenObj)->traceId() : "",##__VA_ARGS__)
#define Trace(traceId,...) \
do { if (!TelEngine::null(traceId)) TraceDebug(traceId,##__VA_ARGS__); } while(false)
#define TraceObj(pGenObj,...) \
do { if (!!(pGenObj) && (pGenObj)->traceId()) TraceDebug((pGenObj)->traceId(),##__VA_ARGS__); } while (false)
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Component that emits the alarm
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const char* component, int level,
const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
int level, const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Component that emits the alarm
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const char* component, const char* info,
int level, const char* format, ...) FORMAT_CHECK(5);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
const char* info, int level, const char* format, ...) FORMAT_CHECK(5);
/**
* This class is used as an automatic variable that logs messages on creation
* and destruction (when the instruction block is left or function returns).
* IMPORTANT: the name is not copied so it should best be static.
* @short An object that logs messages on creation and destruction
*/
class YATE_API Debugger
{
public:
/**
* Timestamp formatting
*/
enum Formatting {
None = 0,
Relative, // from program start
Absolute, // from EPOCH (1-1-1970)
Textual, // absolute GMT in YYYYMMDDhhmmss.uuuuuu format
TextLocal, // local time in YYYYMMDDhhmmss.uuuuuu format
TextSep, // absolute GMT in YYYY-MM-DD_hh:mm:ss.uuuuuu format
TextLSep, // local time in YYYY-MM-DD_hh:mm:ss.uuuuuu format
};
/**
* The constructor prints the method entry message and indents.
* @param name Name of the function or block entered, must be static
* @param format printf() style format string
*/
explicit Debugger(const char* name, const char* format = 0, ...);
/**
* The constructor prints the method entry message and indents.
* @param level The level of the message
* @param name Name of the function or block entered, must be static
* @param format printf() style format string
*/
Debugger(int level, const char* name, const char* format = 0, ...);
/**
* The constructor prints the method entry message and indents.
* @param enabler DebugEnabler to use for level check
* @param level The level of the message
* @param name Name of the function or block entered, must be static
* @param format printf() style format string
*/
Debugger(DebugEnabler* enabler, int level, const char* name, const char* format = 0, ...);
/**
* The destructor prints the method leave message and deindents.
*/
~Debugger();
/**
* Set the output callback
* @param outFunc Pointer to the output function, NULL to use stderr
*/
static void setOutput(void (*outFunc)(const char*,int) = 0);
/**
* Set the interactive output callback
* @param outFunc Pointer to the output function, NULL to disable
*/
static void setIntOut(void (*outFunc)(const char*,int) = 0);
/**
* Set the alarm hook callback
* @param alarmFunc Pointer to the alarm callback function, NULL to disable
*/
static void setAlarmHook(void (*alarmFunc)(const char*,int,const char*,const char*) = 0);
/**
* Set the relay hook callback that will process all Output, Debug and Alarm
* @param relayFunc Pointer to the relay callback function, NULL to disable
*/
static void setRelayHook(void (*relayFunc)(int,const char*,const char*,const char*) = 0);
/**
* Enable or disable the debug output
* @param enable Set to true to globally enable output
* @param colorize Enable ANSI colorization of output
*/
static void enableOutput(bool enable = true, bool colorize = false);
/**
* Retrieve the start timestamp
* @return Start timestamp value in seconds
*/
static uint32_t getStartTimeSec();
/**
* Retrieve the format of timestamps
* @return The current formatting type for timestamps
*/
static Formatting getFormatting();
/**
* Set the format of timestamps on output messages and set the time start reference
* @param format Desired timestamp formatting
* @param startTimeSec Optional start timestamp (in seconds)
*/
static void setFormatting(Formatting format, uint32_t startTimeSec = 0);
/**
* Fill a buffer with a current timestamp prefix
* @param buf Buffer to fill, must be at least 28 characters long
* @param format Desired timestamp formatting
* @return Length of the prefix written in buffer excluding final NUL
*/
static unsigned int formatTime(char* buf, Formatting format = getFormatting());
/**
* Processes a preformatted string as Output, Debug or Alarm.
* This method is intended to relay messages from other processes, DO NOT USE!
* @param level The level of the debug or alarm, negative for an output
* @param buffer Preformatted text buffer, MUST HAVE SPACE for at least strlen + 2
* @param component Component that emits the alarm if applicable
* @param info Extra alarm information if applicable
*/
static void relayOutput(int level, char* buffer, const char* component = 0, const char* info = 0);
/**
* Set Output function display timestamp
* @param on True to enable, false to disable
*/
static void outputTimestamp(bool on);
/**
* Check if Output function displays timestamp
* @return True if Output function displays timestamp, false if not
*/
static bool outputTimestamp();
private:
const char* m_name;
int m_level;
};
/**
* A structure to build (mainly static) Token-to-ID translation tables.
* A table of such structures must end with an entry with a null token
*/
struct TokenDict {
/**
* Token to match
*/
const char* token;
/**
* Value the token translates to
*/
int value;
};
/**
* A structure to build (mainly static) Token-to-ID translation tables.
* Value is 64bit integer.
* A table of such structures must end with an entry with a null token
*/
struct TokenDict64 {
/**
* Token to match
*/
const char* token;
/**
* Value the token translates to
*/
int64_t value;
};
#if 0 /* for documentation generator */
/**
* Macro to ignore the result of a function
* @param value Returned value to be ignored, must be interpretable as boolean
*/
void YIGNORE(primitive value);
/**
* Macro to create a local static String if supported by compiler, use with caution
* @param string Literal constant string
* @return A const String& if supported, literal string if not supported
*/
constant YSTRING(const char* string);
/**
* Macro to create a shared static String if supported by compiler, use with caution
* @param string Literal constant string
* @return A const String& if supported, literal string if not supported
*/
constant YATOM(const char* string);
/**
* Macro to create a GenObject class from a base class and implement @ref GenObject::getObject
* @param type Class that is declared
* @param base Base class that is inherited
*/
void YCLASS(class type,class base);
/**
* Macro to create a GenObject class from two base classes and implement @ref GenObject::getObject
* @param type Class that is declared
* @param base1 First base class that is inherited
* @param base2 Second base class that is inherited
*/
void YCLASS2(class type,class base1,class base2);
/**
* Macro to create a GenObject class from three base classes and implement @ref GenObject::getObject
* @param type Class that is declared
* @param base1 First base class that is inherited
* @param base2 Second base class that is inherited
* @param base3 Third base class that is inherited
*/
void YCLASS3(class type,class base1,class base2,class base3);
/**
* Macro to create a GenObject class from a base class and implement @ref GenObject::getObject
* Try to obtain something from a data member first
* @param dataPtr Pointer to member data variable
* @param type Class that is declared
* @param base Base class that is inherited
*/
void YCLASS_DATA(var dataPtr,class type,class base);
/**
* Macro to create a GenObject class from two base classes and implement @ref GenObject::getObject
* Try to obtain something from a data member first
* @param dataPtr Pointer to member data variable
* @param type Class that is declared
* @param base1 First base class that is inherited
* @param base2 Second base class that is inherited
*/
void YCLASS2_DATA(var dataPtr,class type,class base1,class base2);
/**
* Macro to create a GenObject class from three base classes and implement @ref GenObject::getObject
* Try to obtain something from a data member first
* @param dataPtr Pointer to member data variable
* @param type Class that is declared
* @param base1 First base class that is inherited
* @param base2 Second base class that is inherited
* @param base3 Third base class that is inherited
*/
void YCLASS3_DATA(var dataPtr,class type,class base1,class base2,class base3);
/**
* Macro to implement @ref GenObject::getObject in a derived class
* @param type Class that is declared
* @param base Base class that is inherited
*/