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 #ifndef __YATECLASS_H
00026 #define __YATECLASS_H
00027
00028 #ifndef __cplusplus
00029 #error C++ is required
00030 #endif
00031
00032 #include <sys/types.h>
00033 #include <stddef.h>
00034 #include <unistd.h>
00035 #include <errno.h>
00036
00037 #ifndef _WORDSIZE
00038 #if defined(__arch64__) || defined(__x86_64__) \
00039 || defined(__amd64__) || defined(__ia64__) \
00040 || defined(__alpha__) || defined(__sparcv9)
00041 #define _WORDSIZE 64
00042 #else
00043 #define _WORDSIZE 32
00044 #endif
00045 #endif
00046
00047 #ifndef _WINDOWS
00048 #if defined(WIN32) || defined(_WIN32)
00049 #define _WINDOWS
00050 #endif
00051 #endif
00052
00053 #ifdef _WINDOWS
00054
00055 #include <windows.h>
00056 #include <io.h>
00057 #include <direct.h>
00058
00062 typedef signed __int8 int8_t;
00063 typedef unsigned __int8 u_int8_t;
00064 typedef unsigned __int8 uint8_t;
00065 typedef signed __int16 int16_t;
00066 typedef unsigned __int16 u_int16_t;
00067 typedef unsigned __int16 uint16_t;
00068 typedef signed __int32 int32_t;
00069 typedef unsigned __int32 u_int32_t;
00070 typedef unsigned __int32 uint32_t;
00071 typedef signed __int64 int64_t;
00072 typedef unsigned __int64 u_int64_t;
00073 typedef unsigned __int64 uint64_t;
00074
00075 typedef int pid_t;
00076 typedef int socklen_t;
00077 typedef unsigned long in_addr_t;
00078
00079 #ifndef strcasecmp
00080 #define strcasecmp _stricmp
00081 #endif
00082
00083 #ifndef strncasecmp
00084 #define strncasecmp _strnicmp
00085 #endif
00086
00087 #define vsnprintf _vsnprintf
00088 #define snprintf _snprintf
00089 #define strdup _strdup
00090 #define open _open
00091 #define dup2 _dup2
00092 #define read _read
00093 #define write _write
00094 #define close _close
00095 #define getpid _getpid
00096 #define chdir _chdir
00097 #define mkdir(p,m) _mkdir(p)
00098 #define unlink _unlink
00099
00100 #define O_RDWR _O_RDWR
00101 #define O_RDONLY _O_RDONLY
00102 #define O_WRONLY _O_WRONLY
00103 #define O_APPEND _O_APPEND
00104 #define O_BINARY _O_BINARY
00105 #define O_EXCL _O_EXCL
00106 #define O_CREAT _O_CREAT
00107 #define O_TRUNC _O_TRUNC
00108 #define O_NOCTTY 0
00109
00110 #define S_IRUSR _S_IREAD
00111 #define S_IWUSR _S_IWRITE
00112 #define S_IXUSR 0
00113 #define S_IRWXU (_S_IREAD|_S_IWRITE)
00114
00115 #ifdef LIBYATE_EXPORTS
00116 #define YATE_API __declspec(dllexport)
00117 #else
00118 #ifndef LIBYATE_STATIC
00119 #define YATE_API __declspec(dllimport)
00120 #endif
00121 #endif
00122
00123 #define FMT64 "%I64d"
00124 #define FMT64U "%I64u"
00125
00126 #else
00127
00128 #include <sys/time.h>
00129 #include <sys/socket.h>
00130
00131 #if defined(__FreeBSD__)
00132 #include <netinet/in_systm.h>
00133 #endif
00134
00135 #include <netinet/in.h>
00136 #include <netinet/ip.h>
00137 #include <netinet/tcp.h>
00138 #include <arpa/inet.h>
00139 #include <netdb.h>
00140
00144 #ifndef SOCKET
00145 typedef int SOCKET;
00146 #endif
00147 #ifndef HANDLE
00148 typedef int HANDLE;
00149 #endif
00150
00151 #ifndef O_BINARY
00152 #define O_BINARY 0
00153 #endif
00154
00155 #if _WORDSIZE == 64
00156 #define FMT64 "%ld"
00157 #define FMT64U "%lu"
00158 #else
00159 #define FMT64 "%lld"
00160 #define FMT64U "%llu"
00161 #endif
00162
00163 #endif
00164
00165 #ifndef O_LARGEFILE
00166 #define O_LARGEFILE 0
00167 #endif
00168
00169 #ifndef IPTOS_LOWDELAY
00170 #define IPTOS_LOWDELAY 0x10
00171 #define IPTOS_THROUGHPUT 0x08
00172 #define IPTOS_RELIABILITY 0x04
00173 #endif
00174 #ifndef IPTOS_MINCOST
00175 #define IPTOS_MINCOST 0x02
00176 #endif
00177 #ifndef IPPROTO_SCTP
00178 #define IPPROTO_SCTP 132
00179 #endif
00180
00181 #ifndef YATE_API
00182 #define YATE_API
00183 #endif
00184
00185 #ifdef _WINDOWS
00186 #undef RAND_MAX
00187 #define RAND_MAX 2147483647
00188 extern "C" {
00189 YATE_API long int random();
00190 YATE_API void srandom(unsigned int seed);
00191 }
00192 #endif
00193
00197 namespace TelEngine {
00198
00199 #ifdef HAVE_GCC_FORMAT_CHECK
00200 #define FORMAT_CHECK(f) __attribute__((format(printf,(f),(f)+1)))
00201 #else
00202 #define FORMAT_CHECK(f)
00203 #endif
00204
00209 YATE_API void abortOnBug();
00210
00215 YATE_API bool abortOnBug(bool doAbort);
00216
00222 enum DebugLevel {
00223 DebugFail = 0,
00224 DebugGoOn = 2,
00225 DebugConf = 3,
00226 DebugStub = 4,
00227 DebugWarn = 5,
00228 DebugMild = 6,
00229 DebugCall = 7,
00230 DebugNote = 8,
00231 DebugInfo = 9,
00232 DebugAll = 10
00233 };
00234
00239 YATE_API int debugLevel();
00240
00246 YATE_API int debugLevel(int level);
00247
00253 YATE_API bool debugAt(int level);
00254
00261 YATE_API const char* debugColor(int level);
00262
00268 class YATE_API DebugEnabler
00269 {
00270 public:
00276 inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
00277 : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
00278 { debugLevel(level); }
00279
00280 inline ~DebugEnabler()
00281 { m_name = 0; m_chain = 0; }
00282
00287 inline int debugLevel() const
00288 { return m_chain ? m_chain->debugLevel() : m_level; }
00289
00295 int debugLevel(int level);
00296
00301 inline bool debugEnabled() const
00302 { return m_chain ? m_chain->debugEnabled() : m_enabled; }
00303
00308 inline void debugEnabled(bool enable)
00309 { m_enabled = enable; m_chain = 0; }
00310
00315 inline const char* debugName() const
00316 { return m_name; }
00317
00323 bool debugAt(int level) const;
00324
00329 inline bool debugChained() const
00330 { return m_chain != 0; }
00331
00336 inline void debugChain(const DebugEnabler* chain = 0)
00337 { m_chain = (chain != this) ? chain : 0; }
00338
00343 void debugCopy(const DebugEnabler* original = 0);
00344
00345 protected:
00350 inline void debugName(const char* name)
00351 { m_name = name; }
00352
00353 private:
00354 int m_level;
00355 bool m_enabled;
00356 const DebugEnabler* m_chain;
00357 const char* m_name;
00358 };
00359
00360 #if 0
00361
00366 void DDebug(int level, const char* format, ...);
00367
00373 void DDebug(const char* facility, int level, const char* format, ...);
00374
00380 void DDebug(const DebugEnabler* local, int level, const char* format, ...);
00381
00387 void XDebug(int level, const char* format, ...);
00388
00394 void XDebug(const char* facility, int level, const char* format, ...);
00395
00401 void XDebug(const DebugEnabler* local, int level, const char* format, ...);
00402
00408 void NDebug(int level, const char* format, ...);
00409
00415 void NDebug(const char* facility, int level, const char* format, ...);
00416
00422 void NDebug(const DebugEnabler* local, int level, const char* format, ...);
00423 #endif
00424
00425 #if defined(_DEBUG) || defined(DEBUG) || defined(XDEBUG)
00426 #undef DEBUG
00427 #define DEBUG 1
00428 #endif
00429
00430 #ifdef DEBUG
00431 #define DDebug Debug
00432 #else
00433 #ifdef _WINDOWS
00434 #define DDebug
00435 #else
00436 #define DDebug(arg...)
00437 #endif
00438 #endif
00439
00440 #ifdef XDEBUG
00441 #define XDebug Debug
00442 #else
00443 #ifdef _WINDOWS
00444 #define XDebug
00445 #else
00446 #define XDebug(arg...)
00447 #endif
00448 #endif
00449
00450 #ifndef NDEBUG
00451 #define NDebug Debug
00452 #else
00453 #ifdef _WINDOWS
00454 #define NDebug
00455 #else
00456 #define NDebug(arg...)
00457 #endif
00458 #endif
00459
00465 YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
00466
00473 YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
00474
00481 YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
00482
00487 YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
00488
00495 class YATE_API Debugger
00496 {
00497 public:
00501 enum Formatting {
00502 None = 0,
00503 Relative,
00504 Absolute,
00505 Textual,
00506 };
00507
00513 explicit Debugger(const char* name, const char* format = 0, ...);
00514
00521 Debugger(int level, const char* name, const char* format = 0, ...);
00522
00526 ~Debugger();
00527
00532 static void setOutput(void (*outFunc)(const char*,int) = 0);
00533
00538 static void setIntOut(void (*outFunc)(const char*,int) = 0);
00539
00545 static void enableOutput(bool enable = true, bool colorize = false);
00546
00551 static void setFormatting(Formatting format);
00552
00553 private:
00554 const char* m_name;
00555 };
00556
00561 struct TokenDict {
00565 const char* token;
00566
00570 int value;
00571 };
00572
00573 class String;
00574 class Mutex;
00575
00576 #if 0
00577
00582 void YCLASS(class type,class base);
00583
00590 void YCLASS2(class type,class base1,class base2);
00591
00599 void YCLASS3(class type,class base1,class base2,class base3);
00600
00606 void YCLASSIMP(class type,class base);
00607
00614 void YCLASSIMP2(class type,class base1,class base2);
00615
00623 void YCLASSIMP3(class type,class base1,class base2,class base3);
00624
00631 class* YOBJECT(class type,GenObject* pntr);
00632
00637 void YNOCOPY(class type);
00638 #endif
00639
00640 #define YCLASS(type,base) \
00641 public: virtual void* getObject(const String& name) const \
00642 { return (name == #type) ? const_cast<type*>(this) : base::getObject(name); }
00643
00644 #define YCLASS2(type,base1,base2) \
00645 public: virtual void* getObject(const String& name) const \
00646 { if (name == #type) return const_cast<type*>(this); \
00647 void* tmp = base1::getObject(name); \
00648 return tmp ? tmp : base2::getObject(name); }
00649
00650 #define YCLASS3(type,base1,base2,base3) \
00651 public: virtual void* getObject(const String& name) const \
00652 { if (name == #type) return const_cast<type*>(this); \
00653 void* tmp = base1::getObject(name); \
00654 if (tmp) return tmp; \
00655 tmp = base2::getObject(name); \
00656 return tmp ? tmp : base3::getObject(name); }
00657
00658 #define YCLASSIMP(type,base) \
00659 void* type::getObject(const String& name) const \
00660 { return (name == #type) ? const_cast<type*>(this) : base::getObject(name); }
00661
00662 #define YCLASSIMP2(type,base1,base2) \
00663 void* type::getObject(const String& name) const \
00664 { if (name == #type) return const_cast<type*>(this); \
00665 void* tmp = base1::getObject(name); \
00666 return tmp ? tmp : base2::getObject(name); }
00667
00668 #define YCLASSIMP3(type,base1,base2,base3) \
00669 void* type::getObject(const String& name) const \
00670 { if (name == #type) return const_cast<type*>(this); \
00671 void* tmp = base1::getObject(name); \
00672 if (tmp) return tmp; \
00673 tmp = base2::getObject(name); \
00674 return tmp ? tmp : base3::getObject(name); }
00675
00676 #define YOBJECT(type,pntr) (static_cast<type*>(GenObject::getObject(#type,pntr)))
00677
00678 #define YNOCOPY(type) private: \
00679 type(const type&); \
00680 void operator=(const type&)
00681
00682
00686 class YATE_API GenObject
00687 {
00688 public:
00692 virtual ~GenObject() { }
00693
00700 virtual bool alive() const;
00701
00705 virtual void destruct();
00706
00713 virtual const String& toString() const;
00714
00720 virtual void* getObject(const String& name) const;
00721
00728 static inline void* getObject(const String& name, const GenObject* obj)
00729 { return obj ? obj->getObject(name) : 0; }
00730 };
00731
00737 inline void destruct(GenObject* obj)
00738 { if (obj) obj->destruct(); }
00739
00746 template <class Obj> void destruct(Obj*& obj)
00747 { if (obj) { obj->destruct(); obj = 0; } }
00748
00753 class YATE_API RefObject : public GenObject
00754 {
00755 YNOCOPY(RefObject);
00756 public:
00761 RefObject();
00762
00766 virtual ~RefObject();
00767
00774 virtual bool alive() const;
00775
00780 bool ref();
00781
00790 bool deref();
00791
00796 inline int refcount() const
00797 { return m_refcount; }
00798
00803 virtual void destruct();
00804
00809 inline Mutex& refMutex()
00810 { return *m_mutex; }
00811
00812 protected:
00818 virtual void zeroRefs();
00819
00828 virtual bool zeroRefsTest();
00829
00835 bool refInternal();
00836
00842 bool resurrect();
00843
00849 virtual void destroyed();
00850
00851 private:
00852 int m_refcount;
00853 Mutex* m_mutex;
00854 };
00855
00861 class YATE_API RefPointerBase
00862 {
00863 protected:
00867 inline RefPointerBase()
00868 : m_pointer(0) { }
00869
00876 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
00877
00881 void* m_pointer;
00882 };
00883
00887 template <class Obj = RefObject> class RefPointer : public RefPointerBase
00888 {
00889 protected:
00894 inline Obj* pointer() const
00895 { return static_cast<Obj*>(m_pointer); }
00896
00901 inline void assign(Obj* object = 0)
00902 { RefPointerBase::assign(pointer(),object,object); }
00903
00904 public:
00908 inline RefPointer()
00909 { }
00910
00915 inline RefPointer(const RefPointer<Obj>& value)
00916 : RefPointerBase()
00917 { assign(value); }
00918
00923 inline RefPointer(Obj* object)
00924 { assign(object); }
00925
00929 inline ~RefPointer()
00930 { assign(); }
00931
00935 inline RefPointer<Obj>& operator=(const RefPointer<Obj>& value)
00936 { assign(value.pointer()); return *this; }
00937
00941 inline RefPointer<Obj>& operator=(Obj* object)
00942 { assign(object); return *this; }
00943
00948 inline operator Obj*() const
00949 { return pointer(); }
00950
00954 inline Obj* operator->() const
00955 { return pointer(); }
00956
00960 inline Obj& operator*() const
00961 { return *pointer(); }
00962 };
00963
00967 template <class Obj = GenObject> class GenPointer : public GenObject
00968 {
00969 private:
00973 Obj* m_pointer;
00974
00975 public:
00979 inline GenPointer()
00980 : m_pointer(0)
00981 { }
00982
00987 inline GenPointer(const GenPointer<Obj>& value)
00988 : m_pointer(value)
00989 { }
00990
00995 inline GenPointer(Obj* object)
00996 : m_pointer(object)
00997 { }
00998
01002 inline GenPointer<Obj>& operator=(const GenPointer<Obj>& value)
01003 { m_pointer = value; return *this; }
01004
01008 inline GenPointer<Obj>& operator=(Obj* object)
01009 { m_pointer = object; return *this; }
01010
01015 inline operator Obj*() const
01016 { return m_pointer; }
01017
01021 inline Obj* operator->() const
01022 { return m_pointer; }
01023
01027 inline Obj& operator*() const
01028 { return *m_pointer; }
01029 };
01030
01035 class YATE_API ObjList : public GenObject
01036 {
01037 YNOCOPY(ObjList);
01038 public:
01042 ObjList();
01043
01047 virtual ~ObjList();
01048
01054 virtual void* getObject(const String& name) const;
01055
01060 unsigned int length() const;
01061
01066 unsigned int count() const;
01067
01072 inline GenObject* get() const
01073 { return m_obj; }
01074
01081 GenObject* set(const GenObject* obj, bool delold = true);
01082
01087 inline ObjList* next() const
01088 { return m_next; }
01089
01094 ObjList* last() const;
01095
01100 ObjList* skipNull() const;
01101
01106 ObjList* skipNext() const;
01107
01113 GenObject* at(int index) const;
01114
01120 ObjList* operator+(int index) const;
01121
01127 inline GenObject* operator[](signed int index) const
01128 { return at(index); }
01129
01135 inline GenObject* operator[](unsigned int index) const
01136 { return at(index); }
01137
01143 GenObject* operator[](const String& str) const;
01144
01150 ObjList* find(const GenObject* obj) const;
01151
01157 ObjList* find(const String& str) const;
01158
01164 int index(const GenObject* obj) const;
01165
01171 int index(const String& str) const;
01172
01179 ObjList* insert(const GenObject* obj, bool compact = true);
01180
01187 ObjList* append(const GenObject* obj, bool compact = true);
01188
01194 GenObject* remove(bool delobj = true);
01195
01202 GenObject* remove(GenObject* obj, bool delobj = true);
01203
01210 GenObject* remove(const String& str, bool delobj = true);
01211
01215 void clear();
01216
01221 inline bool autoDelete()
01222 { return m_delete; }
01223
01228 inline void setDelete(bool autodelete)
01229 { m_delete = autodelete; }
01230
01235 static const ObjList& empty();
01236
01237 private:
01238 ObjList* m_next;
01239 GenObject* m_obj;
01240 bool m_delete;
01241 };
01242
01251 class YATE_API Array : public RefObject
01252 {
01253 public:
01259 explicit Array(int columns = 0, int rows = 0);
01260
01264 virtual ~Array();
01265
01271 virtual void* getObject(const String& name) const;
01272
01279 bool addRow(ObjList* row = 0, int index = -1);
01280
01287 bool addColumn(ObjList* column = 0, int index = -1);
01288
01294 bool delRow(int index);
01295
01301 bool delColumn(int index);
01302
01309 GenObject* get(int column, int row) const;
01310
01317 GenObject* take(int column, int row);
01318
01326 bool set(GenObject* obj, int column, int row);
01327
01332 inline int getRows() const
01333 { return m_rows; }
01334
01339 inline int getColumns() const
01340 { return m_columns; }
01341
01342 private:
01343 int m_rows;
01344 int m_columns;
01345 ObjList m_obj;
01346 };
01347
01348 class Regexp;
01349 class StringMatchPrivate;
01350
01358 class YATE_API String : public GenObject
01359 {
01360 public:
01364 String();
01365
01371 String(const char* value, int len = -1);
01372
01378 explicit String(char value, unsigned int repeat = 1);
01379
01384 explicit String(int value);
01385
01390 explicit String(unsigned int value);
01391
01396 explicit String(bool value);
01397
01402 String(const String& value);
01403
01408 String(const String* value);
01409
01413 virtual ~String();
01414
01420 virtual void* getObject(const String& name) const;
01421
01426 static const String& empty();
01427
01433 inline static const char* boolText(bool value)
01434 { return value ? "true" : "false"; }
01435
01440 inline const char* c_str() const
01441 { return m_string; }
01442
01447 inline const char* safe() const
01448 { return m_string ? m_string : ""; }
01449
01455 inline const char* safe(const char* defStr) const
01456 { return m_string ? m_string : (defStr ? defStr : ""); }
01457
01462 inline unsigned int length() const
01463 { return m_length; }
01464
01469 inline bool null() const
01470 { return !m_string; }
01471
01479 static int lenUtf8(const char* value, unsigned int maxSeq = 4, bool overlong = false);
01480
01487 inline int lenUtf8(unsigned int maxSeq = 4, bool overlong = false) const
01488 { return lenUtf8(m_string,maxSeq,overlong); }
01489
01490
01498 int fixUtf8(const char* replace = 0, unsigned int maxSeq = 4, bool overlong = false);
01499
01504 unsigned int hash() const;
01505
01511 static unsigned int hash(const char* value);
01512
01516 void clear();
01517
01523 char at(int index) const;
01524
01531 String substr(int offs, int len = -1) const;
01532
01536 String& trimBlanks();
01537
01542 String& trimSpaces();
01543
01548 virtual const String& toString() const;
01549
01556 int toInteger(int defvalue = 0, int base = 0) const;
01557
01565 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
01566
01572 double toDouble(double defvalue = 0.0) const;
01573
01579 bool toBoolean(bool defvalue = false) const;
01580
01585 bool isBoolean() const;
01586
01591 String& toUpper();
01592
01597 String& toLower();
01598
01604 inline char operator[](signed int index) const
01605 { return at(index); }
01606
01612 inline char operator[](unsigned int index) const
01613 { return at(index); }
01614
01619 inline operator const char*() const
01620 { return m_string; };
01621
01628 String& assign(const char* value, int len = -1);
01629
01636 String& assign(char value, unsigned int repeat = 1);
01637
01646 String& hexify(void* data, unsigned int len, char sep = 0, bool upCase = false);
01647
01651 inline String& operator=(const String& value)
01652 { return operator=(value.c_str()); }
01653
01658 inline String& operator=(const String* value)
01659 { return operator=(value ? value->c_str() : ""); }
01660
01665 String& operator=(const char* value);
01666
01670 String& operator=(char value);
01671
01675 String& operator=(int value);
01676
01680 String& operator=(unsigned int value);
01681
01685 inline String& operator=(bool value)
01686 { return operator=(boolText(value)); }
01687
01692 String& operator+=(const char* value);
01693
01697 String& operator+=(char value);
01698
01702 String& operator+=(int value);
01703
01707 String& operator+=(unsigned int value);
01708
01712 inline String& operator+=(bool value)
01713 { return operator+=(boolText(value)); }
01714
01718 bool operator==(const char* value) const;
01719
01723 bool operator!=(const char* value) const;
01724
01728 bool operator==(const String& value) const;
01729
01733 bool operator!=(const String& value) const;
01734
01738 bool operator&=(const char* value) const;
01739
01743 bool operator|=(const char* value) const;
01744
01748 inline String& operator<<(const char* value)
01749 { return operator+=(value); }
01750
01754 inline String& operator<<(char value)
01755 { return operator+=(value); }
01756
01760 inline String& operator<<(int value)
01761 { return operator+=(value); }
01762
01766 inline String& operator<<(unsigned int value)
01767 { return operator+=(value); }
01768
01772 inline String& operator<<(bool value)
01773 { return operator+=(value); }
01774
01779 String& operator>>(const char* skip);
01780
01784 String& operator>>(char& store);
01785
01789 String& operator>>(int& store);
01790
01794 String& operator>>(unsigned int& store);
01795
01799 String& operator>>(bool& store);
01800
01807 String& append(const char* value, const char* separator = 0, bool force = false);
01808
01815 String& append(const ObjList* list, const char* separator = 0, bool force = false);
01816
01823 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
01824 { return append(&list,separator,force); }
01825
01831 String& append(double value, unsigned int decimals = 3);
01832
01839 int find(char what, unsigned int offs = 0) const;
01840
01847 int find(const char* what, unsigned int offs = 0) const;
01848
01854 int rfind(char what) const;
01855
01863 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
01864
01872 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
01873
01885 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
01886
01893 String& extractTo(const char* sep, String& store);
01894
01901 String& extractTo(const char* sep, bool& store);
01902
01910 String& extractTo(const char* sep, int& store, int base = 0);
01911
01920 String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
01921
01928 String& extractTo(const char* sep, double& store);
01929
01935 virtual bool matches(const String& value) const
01936 { return operator==(value); }
01937
01943 bool matches(const Regexp& rexp);
01944
01950 int matchOffset(int index = 0) const;
01951
01957 int matchLength(int index = 0) const;
01958
01964 inline String matchString(int index = 0) const
01965 { return substr(matchOffset(index),matchLength(index)); }
01966
01972 String replaceMatches(const String& templ) const;
01973
01978 int matchCount() const;
01979
01986 ObjList* split(char separator, bool emptyOK = true) const;
01987
01994 static String msgEscape(const char* str, char extraEsc = 0);
01995
02001 inline String msgEscape(char extraEsc = 0) const
02002 { return msgEscape(c_str(),extraEsc); }
02003
02011 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
02012
02019 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
02020 { return msgUnescape(c_str(),errptr,extraEsc); }
02021
02028 static String sqlEscape(const char* str, char extraEsc = 0);
02029
02035 inline String sqlEscape(char extraEsc = 0) const
02036 { return sqlEscape(c_str(),extraEsc); }
02037
02045 static String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0);
02046
02053 inline String uriEscape(char extraEsc = 0, const char* noEsc = 0) const
02054 { return uriEscape(c_str(),extraEsc,noEsc); }
02055
02062 static String uriUnescape(const char* str, int* errptr = 0);
02063
02069 inline String uriUnescape(int* errptr = 0) const
02070 { return uriUnescape(c_str(),errptr); }
02071
02072 protected:
02076 virtual void changed();
02077
02078 private:
02079 void clearMatches();
02080 char* m_string;
02081 unsigned int m_length;
02082
02083 mutable unsigned int m_hash;
02084 StringMatchPrivate* m_matches;
02085 };
02086
02092 inline const char* c_str(const String* str)
02093 { return str ? str->c_str() : (const char*)0; }
02094
02100 inline const char* c_safe(const char* str)
02101 { return str ? str : ""; }
02102
02108 inline const char* c_safe(const String* str)
02109 { return str ? str->safe() : ""; }
02110
02116 inline bool null(const char* str)
02117 { return !(str && *str); }
02118
02124 inline bool null(const String* str)
02125 { return !str || str->null(); }
02126
02130 YATE_API String operator+(const String& s1, const String& s2);
02131
02135 YATE_API String operator+(const String& s1, const char* s2);
02136
02140 YATE_API String operator+(const char* s1, const String& s2);
02141
02146 inline const char *strcpy(String& dest, const char* src)
02147 { dest = src; return dest.c_str(); }
02148
02153 inline const char *strcat(String& dest, const char* src)
02154 { dest += src; return dest.c_str(); }
02155
02164 YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
02165
02172 YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
02173
02174
02179 class YATE_API Regexp : public String
02180 {
02181 friend class String;
02182 public:
02186 Regexp();
02187
02194 explicit Regexp(const char* value, bool extended = false, bool insensitive = false);
02195
02200 Regexp(const Regexp& value);
02201
02205 virtual ~Regexp();
02206
02210 inline Regexp& operator=(const char* value)
02211 { String::operator=(value); return *this; }
02212
02217 bool compile() const;
02218
02224 bool matches(const char* value) const;
02225
02231 virtual bool matches(const String& value) const
02232 { return Regexp::matches(value.safe()); }
02233
02239 void setFlags(bool extended, bool insensitive);
02240
02245 bool isExtended() const;
02246
02251 bool isCaseInsensitive() const;
02252
02253 protected:
02257 virtual void changed();
02258
02259 private:
02260 void cleanup();
02261 bool matches(const char* value, StringMatchPrivate* matchlist) const;
02262 mutable void* m_regexp;
02263 int m_flags;
02264 };
02265
02270 class YATE_API NamedString : public String
02271 {
02272 YNOCOPY(NamedString);
02273 public:
02279 explicit NamedString(const char* name, const char* value = 0);
02280
02285 inline const String& name() const
02286 { return m_name; }
02287
02292 virtual const String& toString() const;
02293
02299 virtual void* getObject(const String& name) const;
02300
02304 inline NamedString& operator=(const char* value)
02305 { String::operator=(value); return *this; }
02306
02307 private:
02308 NamedString();
02309 String m_name;
02310 };
02311
02318 class YATE_API NamedPointer : public NamedString
02319 {
02320 public:
02327 explicit NamedPointer(const char* name, GenObject* data = 0, const char* value = 0);
02328
02332 virtual ~NamedPointer();
02333
02338 inline GenObject* userData() const
02339 { return m_data; }
02340
02346 GenObject* takeData();
02347
02353 void userData(GenObject* data);
02354
02360 inline void* userObject(const String& name) const
02361 { return m_data ? m_data->getObject(name) : 0; }
02362
02366 inline NamedPointer& operator=(const char* value)
02367 { NamedString::operator=(value); return *this; }
02368
02374 virtual void* getObject(const String& name) const;
02375
02376 protected:
02380 virtual void changed();
02381
02382 private:
02383 NamedPointer();
02384 GenObject* m_data;
02385 };
02386
02394 class YATE_API HashList : public GenObject
02395 {
02396 YNOCOPY(HashList);
02397 public:
02402 explicit HashList(unsigned int size = 17);
02403
02407 virtual ~HashList();
02408
02414 virtual void* getObject(const String& name) const;
02415
02420 inline unsigned int length() const
02421 { return m_size; }
02422
02427 unsigned int count() const;
02428
02435 inline ObjList* getList(unsigned int index) const
02436 { return (index < m_size) ? m_lists[index] : 0; }
02437
02443 inline ObjList* getHashList(unsigned int hash) const
02444 { return getList(hash % m_size); }
02445
02451 inline ObjList* getHashList(const String& str) const
02452 { return getHashList(str.hash()); }
02453
02459 GenObject* operator[](const String& str) const;
02460
02466 ObjList* find(const GenObject* obj) const;
02467
02473 ObjList* find(const String& str) const;
02474
02480 ObjList* append(const GenObject* obj);
02481
02488 GenObject* remove(GenObject* obj, bool delobj = true);
02489
02493 void clear();
02494
02501 bool resync(GenObject* obj);
02502
02508 bool resync();
02509
02510 private:
02511 unsigned int m_size;
02512 ObjList** m_lists;
02513 };
02514
02521 class YATE_API ListIterator
02522 {
02523 YNOCOPY(ListIterator);
02524 public:
02531 ListIterator(ObjList& list, int offset = 0);
02532
02539 ListIterator(HashList& list, int offset = 0);
02540
02544 ~ListIterator();
02545
02550 inline unsigned int length() const
02551 { return m_length; }
02552
02556 void clear();
02557
02563 void assign(ObjList& list, int offset = 0);
02564
02570 void assign(HashList& list, int offset = 0);
02571
02578 GenObject* get(unsigned int index) const;
02579
02592 GenObject* get();
02593
02598 inline bool eof() const
02599 { return m_current >= m_length; }
02600
02604 inline void reset()
02605 { m_current = 0; }
02606
02607 private:
02608 ObjList* m_objList;
02609 HashList* m_hashList;
02610 GenObject** m_objects;
02611 unsigned int m_length;
02612 unsigned int m_current;
02613 };
02614
02619 class YATE_API Time
02620 {
02621 public:
02625 inline Time()
02626 : m_time(now())
02627 { }
02628
02633 inline Time(u_int64_t usec)
02634 : m_time(usec)
02635 { }
02636
02641 inline explicit Time(const struct timeval* tv)
02642 : m_time(fromTimeval(tv))
02643 { }
02644
02649 inline explicit Time(const struct timeval& tv)
02650 : m_time(fromTimeval(tv))
02651 { }
02652
02657 inline ~Time()
02658 { }
02659
02664 inline u_int32_t sec() const
02665 { return (u_int32_t)((m_time+500000) / 1000000); }
02666
02671 inline u_int64_t msec() const
02672 { return (m_time+500) / 1000; }
02673
02678 inline u_int64_t usec() const
02679 { return m_time; }
02680
02684 inline operator u_int64_t() const
02685 { return m_time; }
02686
02690 inline Time& operator=(u_int64_t usec)
02691 { m_time = usec; return *this; }
02692
02696 inline Time& operator+=(int64_t delta)
02697 { m_time += delta; return *this; }
02698
02702 inline Time& operator-=(int64_t delta)
02703 { m_time -= delta; return *this; }
02704
02709 inline void toTimeval(struct timeval* tv) const
02710 { toTimeval(tv, m_time); }
02711
02717 static void toTimeval(struct timeval* tv, u_int64_t usec);
02718
02724 static u_int64_t fromTimeval(const struct timeval* tv);
02725
02731 inline static u_int64_t fromTimeval(const struct timeval& tv)
02732 { return fromTimeval(&tv); }
02733
02738 static u_int64_t now();
02739
02744 static u_int64_t msecNow();
02745
02750 static u_int32_t secNow();
02751
02765 static unsigned int toEpoch(int year, unsigned int month, unsigned int day,
02766 unsigned int hour, unsigned int minute, unsigned int sec, int offset = 0);
02767
02779 static bool toDateTime(unsigned int epochTimeSec, int& year, unsigned int& month,
02780 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec);
02781
02787 static inline bool isLeap(unsigned int year)
02788 { return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); }
02789
02790 private:
02791 u_int64_t m_time;
02792 };
02793
02798 class YATE_API DataBlock : public GenObject
02799 {
02800 public:
02801
02805 DataBlock();
02806
02810 DataBlock(const DataBlock& value);
02811
02818 DataBlock(void* value, unsigned int len, bool copyData = true);
02819
02823 virtual ~DataBlock();
02824
02830 virtual void* getObject(const String& name) const;
02831
02835 static const DataBlock& empty();
02836
02841 inline void* data() const
02842 { return m_data; }
02843
02850 inline unsigned char* data(unsigned int offs, unsigned int len = 1) const
02851 { return (offs + len <= m_length) ? (static_cast<unsigned char*>(m_data) + offs) : 0; }
02852
02859 inline int at(unsigned int offs, int defvalue = -1) const
02860 { return (offs < m_length) ? static_cast<unsigned char*>(m_data)[offs] : defvalue; }
02861
02866 inline bool null() const
02867 { return !m_data; }
02868
02873 inline unsigned int length() const
02874 { return m_length; }
02875
02880 void clear(bool deleteData = true);
02881
02888 DataBlock& assign(void* value, unsigned int len, bool copyData = true);
02889
02895 inline void append(void* value, unsigned int len) {
02896 DataBlock tmp(value,len,false);
02897 append(tmp);
02898 tmp.clear(false);
02899 }
02900
02905 void append(const DataBlock& value);
02906
02911 void append(const String& value);
02912
02917 void insert(const DataBlock& value);
02918
02923 inline void resize(unsigned int len) {
02924 if (len != length())
02925 assign(0,len);
02926 }
02927
02932 void truncate(unsigned int len);
02933
02938 void cut(int len);
02939
02945 inline int operator[](signed int index) const
02946 { return at(index); }
02947
02953 inline int operator[](unsigned int index) const
02954 { return at(index); }
02955
02959 DataBlock& operator=(const DataBlock& value);
02960
02964 inline DataBlock& operator+=(const DataBlock& value)
02965 { append(value); return *this; }
02966
02970 inline DataBlock& operator+=(const String& value)
02971 { append(value); return *this; }
02972
02981 bool convert(const DataBlock& src, const String& sFormat,
02982 const String& dFormat, unsigned maxlen = 0);
02983
02994 bool unHexify(const char* data, unsigned int len, char sep = 0);
02995
03001 String sqlEscape(char extraEsc) const;
03002
03003 private:
03004 void* m_data;
03005 unsigned int m_length;
03006 };
03007
03012 class YATE_API MD5
03013 {
03014 public:
03018 MD5();
03019
03024 MD5(const MD5& original);
03025
03031 MD5(const void* buf, unsigned int len);
03032
03037 MD5(const DataBlock& data);
03038
03043 MD5(const String& str);
03044
03048 ~MD5();
03049
03053 MD5& operator=(const MD5& original);
03054
03058 void clear();
03059
03064 void finalize();
03065
03072 bool update(const void* buf, unsigned int len);
03073
03079 inline bool update(const DataBlock& data)
03080 { return update(data.data(), data.length()); }
03081
03087 inline bool update(const String& str)
03088 { return update(str.c_str(), str.length()); }
03089
03093 inline MD5& operator<<(const String& value)
03094 { update(value); return *this; }
03095
03099 inline MD5& operator<<(const DataBlock& data)
03100 { update(data); return *this; }
03101
03105 MD5& operator<<(const char* value);
03106
03112 const unsigned char* rawDigest();
03113
03118 inline static unsigned int rawLength()
03119 { return 16; }
03120
03126 const String& hexDigest();
03127
03128 private:
03129 void init();
03130 void* m_private;
03131 String m_hex;
03132 unsigned char m_bin[16];
03133 };
03134
03139 class YATE_API SHA1
03140 {
03141 public:
03145 SHA1();
03146
03151 SHA1(const SHA1& original);
03152
03158 SHA1(const void* buf, unsigned int len);
03159
03164 SHA1(const DataBlock& data);
03165
03170 SHA1(const String& str);
03171
03175 ~SHA1();
03176
03180 SHA1& operator=(const SHA1& original);
03181
03185 void clear();
03186
03191 void finalize();
03192
03199 bool update(const void* buf, unsigned int len);
03200
03206 inline bool update(const DataBlock& data)
03207 { return update(data.data(), data.length()); }
03208
03214 inline bool update(const String& str)
03215 { return update(str.c_str(), str.length()); }
03216
03220 inline SHA1& operator<<(const String& value)
03221 { update(value); return *this; }
03222
03226 inline SHA1& operator<<(const DataBlock& data)
03227 { update(data); return *this; }
03228
03232 SHA1& operator<<(const char* value);
03233
03239 const unsigned char* rawDigest();
03240
03245 inline static unsigned int rawLength()
03246 { return 20; }
03247
03253 const String& hexDigest();
03254
03255 private:
03256 void init();
03257 void* m_private;
03258 String m_hex;
03259 unsigned char m_bin[20];
03260 };
03261
03266 class YATE_API Base64 : public DataBlock
03267 {
03268 YNOCOPY(Base64);
03269 public:
03273 inline Base64()
03274 { }
03275
03282 inline Base64(void* src, unsigned int len, bool copyData = true)
03283 : DataBlock(src,len,copyData)
03284 { }
03285
03295 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
03296
03308 bool decode(DataBlock& dest, bool liberal = true);
03309
03313 inline Base64& operator<<(const String& value)
03314 { append(value); return *this; }
03315
03319 inline Base64& operator<<(const DataBlock& data)
03320 { append(data); return *this; }
03321
03325 inline Base64& operator<<(const char* value)
03326 { return operator<<(String(value)); }
03327 };
03328
03329 class NamedIterator;
03330
03335 class YATE_API NamedList : public String
03336 {
03337 friend class NamedIterator;
03338 public:
03343 explicit NamedList(const char* name);
03344
03349 NamedList(const NamedList& original);
03350
03357 NamedList(const char* name, const NamedList& original, const String& prefix);
03358
03364 NamedList& operator=(const NamedList& value);
03365
03371 virtual void* getObject(const String& name) const;
03372
03377 inline unsigned int length() const
03378 { return m_params.length(); }
03379
03384 inline unsigned int count() const
03385 { return m_params.count(); }
03386
03390 inline void clearParams()
03391 { m_params.clear(); }
03392
03398 NamedList& addParam(NamedString* param);
03399
03407 NamedList& addParam(const char* name, const char* value, bool emptyOK = true);
03408
03414 NamedList& setParam(NamedString* param);
03415
03422 NamedList& setParam(const char* name, const char* value);
03423
03430 NamedList& clearParam(const String& name, char childSep = 0);
03431
03437 NamedList& clearParam(NamedString* param);
03438
03446 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
03447
03453 NamedList& copyParams(const NamedList& original);
03454
03462 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
03463
03471 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
03472
03480 NamedList& copySubParams(const NamedList& original, const String& prefix, bool skipPrefix = true);
03481
03487 int getIndex(const NamedString* param) const;
03488
03494 int getIndex(const String& name) const;
03495
03501 NamedString* getParam(const String& name) const;
03502
03508 NamedString* getParam(unsigned int index) const;
03509
03515 const String& operator[](const String& name) const;
03516
03523 const char* getValue(const String& name, const char* defvalue = 0) const;
03524
03531 int getIntValue(const String& name, int defvalue = 0) const;
03532
03540 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
03541
03548 double getDoubleValue(const String& name, double defvalue = 0.0) const;
03549
03556 bool getBoolValue(const String& name, bool defvalue = false) const;
03557
03565 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
03566
03575 void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
03576
03581 static const NamedList& empty();
03582
03583 private:
03584 NamedList();
03585 ObjList m_params;
03586 };
03587
03593 class YATE_API NamedIterator
03594 {
03595 public:
03600 inline NamedIterator(const NamedList& list)
03601 : m_list(&list), m_item(list.m_params.skipNull())
03602 { }
03603
03608 inline NamedIterator(const NamedIterator& original)
03609 : m_list(original.m_list), m_item(original.m_item)
03610 { }
03611
03616 inline NamedIterator& operator=(const NamedList& list)
03617 { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
03618
03623 inline NamedIterator& operator=(const NamedIterator& original)
03624 { m_list = original.m_list; m_item = original.m_item; return *this; }
03625
03630 const NamedString* get();
03631
03635 inline bool eof() const
03636 { return !m_item; }
03637
03641 inline void reset()
03642 { m_item = m_list->m_params.skipNull(); }
03643
03644 private:
03645 NamedIterator();
03646 const NamedList* m_list;
03647 const ObjList* m_item;
03648 };
03649
03655 class YATE_API URI : public String
03656 {
03657 public:
03661 URI();
03662
03667 URI(const URI& uri);
03668
03673 explicit URI(const String& uri);
03674
03679 explicit URI(const char* uri);
03680
03689 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
03690
03694 void parse() const;
03695
03700 inline URI& operator=(const URI& value)
03701 { String::operator=(value); return *this; }
03702
03707 inline URI& operator=(const String& value)
03708 { String::operator=(value); return *this; }
03709
03714 inline URI& operator=(const char* value)
03715 { String::operator=(value); return *this; }
03716
03721 inline const String& getDescription() const
03722 { parse(); return m_desc; }
03723
03728 inline const String& getProtocol() const
03729 { parse(); return m_proto; }
03730
03735 inline const String& getUser() const
03736 { parse(); return m_user; }
03737
03742 inline const String& getHost() const
03743 { parse(); return m_host; }
03744
03749 inline int getPort() const
03750 { parse(); return m_port; }
03751
03756 inline const String& getExtra() const
03757 { parse(); return m_extra; }
03758
03759 protected:
03765 virtual void changed();
03766 mutable bool m_parsed;
03767 mutable String m_desc;
03768 mutable String m_proto;
03769 mutable String m_user;
03770 mutable String m_host;
03771 mutable String m_extra;
03772 mutable int m_port;
03773 };
03774
03775 class ExpEvaluator;
03776 class ExpOperation;
03777
03782 class YATE_API ExpExtender : public RefObject
03783 {
03784 public:
03793 virtual bool runFunction(ExpEvaluator* eval, ObjList& stack, const ExpOperation& oper);
03794
03802 virtual bool runField(ExpEvaluator* eval, ObjList& stack, const ExpOperation& oper);
03803 };
03804
03809 class YATE_API ExpEvaluator
03810 {
03811 public:
03815 enum Parser {
03816 C,
03817 SQL,
03818 };
03819
03823 enum Opcode {
03824
03825 OpcNone,
03826 OpcNull,
03827 OpcPush,
03828 OpcDrop,
03829 OpcDup,
03830 OpcSwap,
03831 OpcRot,
03832 OpcOver,
03833
03834 OpcAdd,
03835 OpcSub,
03836 OpcMul,
03837 OpcDiv,
03838 OpcMod,
03839 OpcNeg,
03840
03841 OpcAnd,
03842 OpcOr,
03843 OpcXor,
03844 OpcNot,
03845 OpcShl,
03846 OpcShr,
03847
03848 OpcLAnd,
03849 OpcLOr,
03850 OpcLXor,
03851 OpcLNot,
03852
03853 OpcCat,
03854
03855 OpcReM,
03856 OpcReIM,
03857 OpcReNm,
03858 OpcReINm,
03859 OpcLike,
03860 OpcILike,
03861 OpcNLike,
03862 OpcNIlike,
03863
03864 OpcEq,
03865 OpcNe,
03866 OpcGt,
03867 OpcLt,
03868 OpcGe,
03869 OpcLe,
03870
03871 OpcCond,
03872
03873 OpcAs,
03874
03875 OpcField,
03876
03877 OpcFunc,
03878 };
03879
03884 explicit ExpEvaluator(const TokenDict* operators = 0);
03885
03890 explicit ExpEvaluator(Parser style);
03891
03896 ExpEvaluator(const ExpEvaluator& original);
03897
03901 virtual ~ExpEvaluator();
03902
03908 int compile(const char* expr);
03909
03915 bool evaluate(ObjList* results);
03916
03922 inline bool evaluate(ObjList& results)
03923 { return evaluate(&results); }
03924
03932 int evaluate(NamedList& results, unsigned int index = 0, const char* prefix = 0);
03933
03940 int evaluate(Array& results, unsigned int index);
03941
03946 inline bool simplify()
03947 { return trySimplify(); }
03948
03953 inline bool null() const
03954 { return m_opcodes.count() == 0; }
03955
03960 String dump() const;
03961
03966 inline const TokenDict* operators()
03967 { return m_operators; }
03968
03973 inline ExpExtender* extender() const
03974 { return m_extender; }
03975
03980 void extender(ExpExtender* ext);
03981
03982 protected:
03988 char skipWhites(const char*& expr) const;
03989
03995 int getKeyword(const char* str) const;
03996
04003 bool gotError(const char* error = 0, const char* text = 0);
04004
04010 virtual bool runCompile(const char*& expr);
04011
04017 virtual Opcode getOperator(const char*& expr) const;
04018
04024 virtual const char* getOperator(Opcode oper) const;
04025
04031 virtual int getPrecedence(Opcode oper);
04032
04039 virtual bool getSeparator(const char*& expr, bool remove);
04040
04046 virtual bool getOperand(const char*& expr);
04047
04053 virtual bool getNumber(const char*& expr);
04054
04060 virtual bool getString(const char*& expr);
04061
04067 virtual bool getFunction(const char*& expr);
04068
04074 virtual bool getField(const char*& expr);
04075
04080 void addOpcode(Opcode oper);
04081
04086 void addOpcode(const String& value);
04087
04092 void addOpcode(long int value);
04093
04100 void addOpcode(Opcode oper, const String& name, long int value = 0);
04101
04107 ExpOperation* popOne(ObjList& stack);
04108
04113 virtual bool trySimplify();
04114
04120 virtual bool runEvaluate(ObjList& stack);
04121
04129 virtual bool runOperation(ObjList& stack, const ExpOperation& oper);
04130
04138 virtual bool runFunction(ObjList& stack, const ExpOperation& oper);
04139
04146 virtual bool runField(ObjList& stack, const ExpOperation& oper);
04147
04151 const TokenDict* m_operators;
04152
04156 ObjList m_opcodes;
04157
04158 private:
04159 ExpExtender* m_extender;
04160 };
04161
04166 class YATE_API ExpOperation : public NamedString
04167 {
04168 friend class ExpEvaluator;
04169 public:
04174 inline ExpOperation(const ExpOperation& original)
04175 : NamedString(original.name(),original),
04176 m_opcode(original.opcode()), m_number(original.number())
04177 { }
04178
04184 inline ExpOperation(const ExpOperation& original, const char* name)
04185 : NamedString(name,original),
04186 m_opcode(original.opcode()), m_number(original.number())
04187 { }
04188
04194 inline explicit ExpOperation(const String& value, const char* name = 0)
04195 : NamedString(name,value),
04196 m_opcode(ExpEvaluator::OpcPush), m_number(0)
04197 { }
04198
04204 inline explicit ExpOperation(long int value, const char* name = 0)
04205 : NamedString(name,""),
04206 m_opcode(ExpEvaluator::OpcPush), m_number(value)
04207 { String::operator=((int)value); }
04208
04215 inline ExpOperation(ExpEvaluator::Opcode oper, const char* name = 0, long int value = 0)
04216 : NamedString(name,""),
04217 m_opcode(oper), m_number(value)
04218 { }
04219
04224 inline ExpEvaluator::Opcode opcode() const
04225 { return m_opcode; }
04226
04231 inline long int number() const
04232 { return m_number; }
04233 private:
04234 ExpEvaluator::Opcode m_opcode;
04235 long int m_number;
04236 };
04237
04242 class YATE_API TableEvaluator
04243 {
04244 public:
04249 TableEvaluator(const TableEvaluator& original);
04250
04255 TableEvaluator(ExpEvaluator::Parser style);
04256
04261 TableEvaluator(const TokenDict* operators);
04262
04266 virtual ~TableEvaluator();
04267
04272 virtual bool evalWhere();
04273
04279 virtual bool evalSelect(ObjList& results);
04280
04285 virtual unsigned int evalLimit();
04286
04291 void extender(ExpExtender* ext);
04292
04293 protected:
04294 ExpEvaluator m_select;
04295 ExpEvaluator m_where;
04296 ExpEvaluator m_limit;
04297 unsigned int m_limitVal;
04298 };
04299
04300 class MutexPrivate;
04301 class SemaphorePrivate;
04302 class ThreadPrivate;
04303
04308 class YATE_API Lockable
04309 {
04310 public:
04314 virtual ~Lockable();
04315
04321 virtual bool lock(long maxwait = -1) = 0;
04322
04327 virtual bool unlock() = 0;
04328
04334 virtual bool locked() const = 0;
04335
04341 virtual bool check(long maxwait = -1);
04342
04349 virtual bool unlockAll();
04350
04356 static void wait(unsigned long maxwait);
04357
04362 static unsigned long wait();
04363
04370 static void startUsingNow();
04371
04377 static void disableSafety();
04378 };
04379
04384 class YATE_API Mutex : public Lockable
04385 {
04386 friend class MutexPrivate;
04387 public:
04394 explicit Mutex(bool recursive = false, const char* name = 0);
04395
04400 Mutex(const Mutex& original);
04401
04405 ~Mutex();
04406
04411 Mutex& operator=(const Mutex& original);
04412
04418 virtual bool lock(long maxwait = -1);
04419
04424 virtual bool unlock();
04425
04431 virtual bool locked() const;
04432
04437 const char* owner() const;
04438
04443 bool recursive() const;
04444
04449 static int count();
04450
04455 static int locks();
04456
04461 static bool efficientTimedLock();
04462
04463 private:
04464 MutexPrivate* privDataCopy() const;
04465 MutexPrivate* m_private;
04466 };
04467
04474 class MutexPool
04475 {
04476 public:
04487 MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
04488
04492 ~MutexPool();
04493
04501 inline unsigned int index(void* ptr) const
04502 { return ((unsigned int)(unsigned long)ptr) % m_length; }
04503
04511 inline Mutex* mutex(void* ptr) const
04512 { return m_data[index(ptr)]; }
04513
04519 inline Mutex* mutex(unsigned int idx) const
04520 { return m_data[idx % m_length]; }
04521
04522 private:
04523 String* m_name;
04524 Mutex** m_data;
04525 unsigned int m_length;
04526 };
04527
04532 class YATE_API Semaphore : public Lockable
04533 {
04534 friend class SemaphorePrivate;
04535 public:
04541 explicit Semaphore(unsigned int maxcount = 1, const char* name = 0);
04542
04547 Semaphore(const Semaphore& original);
04548
04552 ~Semaphore();
04553
04558 Semaphore& operator=(const Semaphore& original);
04559
04565 virtual bool lock(long maxwait = -1);
04566
04571 virtual bool unlock();
04572
04578 virtual bool locked() const;
04579
04584 static int count();
04585
04590 static int locks();
04591
04596 static bool efficientTimedLock();
04597
04598 private:
04599 SemaphorePrivate* privDataCopy() const;
04600 SemaphorePrivate* m_private;
04601 };
04602
04608 class YATE_API Lock
04609 {
04610 YNOCOPY(Lock);
04611 public:
04617 inline Lock(Lockable& lck, long maxwait = -1)
04618 { m_lock = lck.lock(maxwait) ? &lck : 0; }
04619
04625 inline Lock(Lockable* lck, long maxwait = -1)
04626 { m_lock = (lck && lck->lock(maxwait)) ? lck : 0; }
04627
04631 inline ~Lock()
04632 { if (m_lock) m_lock->unlock(); }
04633
04638 inline Lockable* locked() const
04639 { return m_lock; }
04640
04644 inline void drop()
04645 { if (m_lock) m_lock->unlock(); m_lock = 0; }
04646
04647 private:
04648 Lockable* m_lock;
04649
04651 inline void* operator new(size_t);
04652
04654 inline void* operator new[](size_t);
04655 };
04656
04663 class YATE_API Lock2
04664 {
04665 YNOCOPY(Lock2);
04666 public:
04673 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
04674 : m_mx1(0), m_mx2(0)
04675 { lock(mx1,mx2,maxwait); }
04676
04683 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
04684 : m_mx1(0), m_mx2(0)
04685 { lock(&mx1,&mx2,maxwait); }
04686
04690 inline ~Lock2()
04691 { drop(); }
04692
04697 inline bool locked() const
04698 { return m_mx1 != 0; }
04699
04707 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
04708
04716 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
04717 { return lock(&mx1,&mx2,maxwait); }
04718
04722 void drop();
04723
04724 private:
04725 Mutex* m_mx1;
04726 Mutex* m_mx2;
04727
04729 inline void* operator new(size_t);
04730
04732 inline void* operator new[](size_t);
04733 };
04734
04740 class YATE_API Runnable
04741 {
04742 public:
04747 virtual void run() = 0;
04748
04752 virtual ~Runnable();
04753 };
04754
04761 class YATE_API Thread : public Runnable
04762 {
04763 friend class ThreadPrivate;
04764 friend class MutexPrivate;
04765 friend class SemaphorePrivate;
04766 YNOCOPY(Thread);
04767 public:
04771 enum Priority {
04772 Lowest,
04773 Low,
04774 Normal,
04775 High,
04776 Highest
04777 };
04778
04782 virtual void cleanup();
04783
04788 bool startup();
04789
04794 bool error() const;
04795
04800 bool running() const;
04801
04806 inline int locks() const
04807 { return m_locks; }
04808
04813 inline bool locked() const
04814 { return m_locking || m_locks; }
04815
04820 const char* name() const;
04821
04826 static const char* currentName();
04827
04833 static void yield(bool exitCheck = false);
04834
04840 static void idle(bool exitCheck = false);
04841
04847 static void sleep(unsigned int sec, bool exitCheck = false);
04848
04854 static void msleep(unsigned long msec, bool exitCheck = false);
04855
04862 static void usleep(unsigned long usec, bool exitCheck = false);
04863
04868 static unsigned long idleUsec();
04869
04874 static unsigned long idleMsec();
04875
04880 static void idleMsec(unsigned long msec);
04881
04887 static Thread* current();
04888
04893 static int count();
04894
04900 static bool check(bool exitNow = true);
04901
04905 static void exit();
04906
04911 void cancel(bool hard = false);
04912
04917 inline bool isCurrent() const
04918 { return current() == this; }
04919
04920
04927 static Priority priority(const char* name, Priority defvalue = Normal);
04928
04934 static const char* priority(Priority prio);
04935
04940 static void killall();
04941
04946 static void preExec();
04947
04953 static int lastError();
04954
04961 static inline bool errorString(String& buffer)
04962 { return errorString(buffer,lastError()); }
04963
04974 static bool errorString(String& buffer, int code);
04975
04976 protected:
04982 Thread(const char *name = 0, Priority prio = Normal);
04983
04989 Thread(const char *name, const char* prio);
04990
04994 virtual ~Thread();
04995
04996 private:
04997 ThreadPrivate* m_private;
04998 int m_locks;
04999 bool m_locking;
05000 };
05001
05002 class Socket;
05003
05008 class YATE_API SocketAddr : public GenObject
05009 {
05010 public:
05014 inline SocketAddr()
05015 : m_address(0), m_length(0)
05016 { }
05017
05022 inline SocketAddr(const SocketAddr& value)
05023 : GenObject(),
05024 m_address(0), m_length(0)
05025 { assign(value.address(),value.length()); }
05026
05031 explicit SocketAddr(int family);
05032
05038 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
05039
05043 virtual ~SocketAddr();
05044
05049 inline SocketAddr& operator=(const SocketAddr& value)
05050 { assign(value.address(),value.length()); return *this; }
05051
05057 bool operator==(const SocketAddr& other) const;
05058
05064 inline bool operator!=(const SocketAddr& other) const
05065 { return !operator==(other); }
05066
05070 void clear();
05071
05077 bool assign(int family);
05078
05084 void assign(const struct sockaddr* addr, socklen_t len = 0);
05085
05091 bool local(const SocketAddr& remote);
05092
05097 inline bool valid() const
05098 { return m_length && m_address; }
05099
05104 inline bool null() const
05105 { return !(m_length && m_address); }
05106
05111 inline int family() const
05112 { return m_address ? m_address->sa_family : 0; }
05113
05118 inline const String& host() const
05119 { return m_host; }
05120
05125 virtual bool host(const String& name);
05126
05131 int port() const;
05132
05138 bool port(int newport);
05139
05144 inline struct sockaddr* address() const
05145 { return m_address; }
05146
05151 inline socklen_t length() const
05152 { return m_length; }
05153
05159 static bool supports(int family);
05160
05161 protected:
05165 virtual void stringify();
05166
05167 struct sockaddr* m_address;
05168 socklen_t m_length;
05169 String m_host;
05170 };
05171
05176 class YATE_API SocketFilter : public GenObject
05177 {
05178 friend class Socket;
05179 YNOCOPY(SocketFilter);
05180 public:
05184 SocketFilter();
05185
05189 virtual ~SocketFilter();
05190
05196 virtual void* getObject(const String& name) const;
05197
05202 virtual void timerTick(const Time& when);
05203
05213 virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
05214
05219 inline Socket* socket() const
05220 { return m_socket; }
05221
05226 bool valid() const;
05227
05228 private:
05229 Socket* m_socket;
05230 };
05231
05236 class YATE_API Stream
05237 {
05238 public:
05242 enum SeekPos {
05243 SeekBegin,
05244 SeekEnd,
05245 SeekCurrent
05246 };
05247
05251 virtual ~Stream();
05252
05257 inline int error() const
05258 { return m_error; }
05259
05264 virtual bool terminate() = 0;
05265
05270 virtual bool canRetry() const;
05271
05276 virtual bool inProgress() const;
05277
05282 virtual bool valid() const = 0;
05283
05289 virtual bool setBlocking(bool block = true);
05290
05297 virtual int writeData(const void* buffer, int length) = 0;
05298
05304 int writeData(const char* str);
05305
05311 inline int writeData(const String& str)
05312 { return writeData(str.c_str(), str.length()); }
05313
05319 inline int writeData(const DataBlock& buf)
05320 { return writeData(buf.data(), buf.length()); }
05321
05328 virtual int readData(void* buffer, int length) = 0;
05329
05334 virtual int64_t length();
05335
05342 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
05343
05349 inline int64_t seek(int64_t offset)
05350 { return seek(SeekBegin,offset); }
05351
05358 static bool allocPipe(Stream*& reader, Stream*& writer);
05359
05366 static bool allocPair(Stream*& str1, Stream*& str2);
05367
05372 static bool supportsPipes();
05373
05378 static bool supportsPairs();
05379
05380 protected:
05384 inline Stream()
05385 : m_error(0)
05386 { }
05387
05391 inline void clearError()
05392 { m_error = 0; }
05393
05394 int m_error;
05395 };
05396
05401 class YATE_API MemoryStream : public Stream
05402 {
05403 YNOCOPY(MemoryStream);
05404 public:
05408 inline MemoryStream()
05409 : m_offset(0)
05410 { }
05411
05416 inline MemoryStream(const DataBlock& data)
05417 : m_data(data), m_offset(0)
05418 { }
05419
05424 inline const DataBlock& data() const
05425 { return m_data; }
05426
05431 virtual bool terminate()
05432 { return true; }
05437 virtual bool valid() const
05438 { return true; }
05439
05446 virtual int writeData(const void* buffer, int len);
05447
05454 virtual int readData(void* buffer, int len);
05455
05460 virtual int64_t length()
05461 { return m_data.length(); }
05462
05469 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
05470
05471 protected:
05475 DataBlock m_data;
05476
05480 int64_t m_offset;
05481 };
05482
05487 class YATE_API File : public Stream
05488 {
05489 YNOCOPY(File);
05490 public:
05494 File();
05495
05500 explicit File(HANDLE handle);
05501
05505 virtual ~File();
05506
05519 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
05520 bool create = false, bool append = false, bool binary = false,
05521 bool pubReadable = false, bool pubWritable = false);
05522
05527 virtual bool terminate();
05528
05533 void attach(HANDLE handle);
05534
05539 HANDLE detach();
05540
05545 inline HANDLE handle() const
05546 { return m_handle; }
05547
05552 virtual bool canRetry() const;
05553
05558 virtual bool valid() const;
05559
05564 static HANDLE invalidHandle();
05565
05571 virtual bool setBlocking(bool block = true);
05572
05577 virtual int64_t length();
05578
05585 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
05586
05593 virtual int writeData(const void* buffer, int length);
05594
05601 virtual int readData(void* buffer, int length);
05602
05608 bool getFileTime(unsigned int& secEpoch);
05609
05616 virtual bool md5(String& buffer);
05617
05625 static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
05626
05634 static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
05635
05642 static bool exists(const char* name, int* error = 0);
05643
05651 static bool rename(const char* oldFile, const char* newFile, int* error = 0);
05652
05659 static bool remove(const char* name, int* error = 0);
05660
05668 static bool md5(const char* name, String& buffer, int* error = 0);
05669
05676 static bool mkDir(const char* path, int* error = 0);
05677
05684 static bool rmDir(const char* path, int* error = 0);
05685
05697 static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
05698 int* error = 0);
05699
05706 static bool createPipe(File& reader, File& writer);
05707
05708 protected:
05709
05713 void copyError();
05714
05715 HANDLE m_handle;
05716 };
05717
05722 class YATE_API Socket : public Stream
05723 {
05724 YNOCOPY(Socket);
05725 public:
05729 enum TOS {
05730 LowDelay = IPTOS_LOWDELAY,
05731 MaxThroughput = IPTOS_THROUGHPUT,
05732 MaxReliability = IPTOS_RELIABILITY,
05733 MinCost = IPTOS_MINCOST,
05734 };
05735
05739 Socket();
05740
05745 explicit Socket(SOCKET handle);
05746
05753 Socket(int domain, int type, int protocol = 0);
05754
05758 virtual ~Socket();
05759
05767 virtual bool create(int domain, int type, int protocol = 0);
05768
05773 virtual bool terminate();
05774
05779 void attach(SOCKET handle);
05780
05785 SOCKET detach();
05786
05791 inline SOCKET handle() const
05792 { return m_handle; }
05793
05798 virtual bool canRetry() const;
05799
05804 virtual bool inProgress() const;
05805
05810 virtual bool valid() const;
05811
05816 static SOCKET invalidHandle();
05817
05822 static int socketError();
05823
05832 virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
05833
05842 virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
05843
05849 virtual bool setTOS(int tos);
05850
05856 virtual bool setBlocking(bool block = true);
05857
05865 virtual bool setReuse(bool reuse = true, bool exclusive = false);
05866
05873 virtual bool setLinger(int seconds = -1);
05874
05881 virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
05882
05888 inline bool bind(const SocketAddr& addr)
05889 { return bind(addr.address(), addr.length()); }
05890
05896 virtual bool listen(unsigned int backlog = 0);
05897
05904 virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
05905
05911 Socket* accept(SocketAddr& addr);
05912
05919 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
05920
05928 bool updateError();
05929
05934 static bool efficientSelect();
05935
05941 static bool canSelect(SOCKET handle);
05942
05947 virtual bool canSelect() const;
05948
05955 virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
05956
05962 inline bool connect(const SocketAddr& addr)
05963 { return connect(addr.address(), addr.length()); }
05964
05971 virtual bool shutdown(bool stopReads, bool stopWrites);
05972
05979 virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
05980
05986 bool getSockName(SocketAddr& addr);
05987
05994 virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
05995
06001 bool getPeerName(SocketAddr& addr);
06002
06012 virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
06013
06022 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
06023 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
06024
06032 virtual int send(const void* buffer, int length, int flags = 0);
06033
06040 virtual int writeData(const void* buffer, int length);
06041
06051 virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
06052
06061 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
06062
06070 virtual int recv(void* buffer, int length, int flags = 0);
06071
06078 virtual int readData(void* buffer, int length);
06079
06088 virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
06089
06098 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
06099
06105 bool installFilter(SocketFilter* filter);
06106
06112 void removeFilter(SocketFilter* filter, bool delobj = false);
06113
06117 void clearFilters();
06118
06125 virtual void timerTick(const Time& when);
06126
06134 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
06135
06136 protected:
06137
06141 void copyError();
06142
06149 bool checkError(int retcode, bool strict = false);
06150
06160 bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
06161
06162 SOCKET m_handle;
06163 ObjList m_filters;
06164 };
06165
06170 class YATE_API SctpSocket : public Socket
06171 {
06172 YNOCOPY(SctpSocket);
06173 public:
06177 inline SctpSocket()
06178 { }
06179
06184 inline explicit SctpSocket(SOCKET fd)
06185 : Socket(fd)
06186 { }
06187
06191 virtual ~SctpSocket();
06192
06198 virtual bool bindx(ObjList& addresses) = 0;
06199
06205 virtual bool connectx(ObjList& addresses) = 0;
06206
06216 virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
06217
06223 virtual Socket* accept(SocketAddr& addr)
06224 { return 0; }
06225
06234 virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
06235
06245 virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
06246
06253 virtual bool setStreams(int inbound, int outbound) = 0;
06254
06260 virtual bool subscribeEvents() = 0;
06261
06268 virtual bool getStreams(int& inbound, int& outbound) = 0;
06269
06275 virtual bool setPayload(u_int32_t payload) = 0;
06276 };
06277
06282 class YATE_API Cipher : public GenObject
06283 {
06284 public:
06288 enum Direction {
06289 Bidir,
06290 Encrypt,
06291 Decrypt,
06292 };
06293
06298 inline static const TokenDict* directions()
06299 { return s_directions; }
06300
06307 inline static Direction direction(const char* name, Direction defdir = Bidir)
06308 { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
06309
06313 virtual ~Cipher();
06314
06320 virtual void* getObject(const String& name) const;
06321
06327 virtual bool valid(Direction dir = Bidir) const;
06328
06333 virtual unsigned int blockSize() const = 0;
06334
06339 virtual unsigned int initVectorSize() const;
06340
06346 unsigned int bufferSize(unsigned int len) const;
06347
06353 bool bufferFull(unsigned int len) const;
06354
06362 virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
06363
06370 inline bool setKey(const DataBlock& key, Direction dir = Bidir)
06371 { return setKey(key.data(),key.length(),dir); }
06372
06380 virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
06381
06388 inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
06389 { return initVector(vect.data(),vect.length(),dir); }
06390
06398 virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
06399
06405 inline bool encrypt(DataBlock& data)
06406 { return encrypt(data.data(),data.length()); }
06407
06415 virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
06416
06422 inline bool decrypt(DataBlock& data)
06423 { return decrypt(data.data(),data.length()); }
06424
06425 private:
06426 static const TokenDict s_directions[];
06427 };
06428
06434 class YATE_API Compressor : public String
06435 {
06436 YCLASS(Compressor,String)
06437 YNOCOPY(Compressor);
06438 public:
06444 inline Compressor(const char* format, const char* name = 0)
06445 : String(name), m_format(format)
06446 {}
06447
06451 virtual ~Compressor()
06452 {}
06453
06458 inline const String& format() const
06459 { return m_format; }
06460
06468 virtual bool init(bool comp = true, bool decomp = true,
06469 const NamedList& params = NamedList::empty())
06470 { return true; }
06471
06476 virtual void finalize(bool comp)
06477 {}
06478
06487 virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
06488
06497 virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
06498
06509 virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
06510
06519 inline int writeComp(const DataBlock& data, bool flush)
06520 { return writeComp(data.data(),data.length(),flush); }
06521
06530 inline int writeComp(const String& data, bool flush)
06531 { return writeComp(data.c_str(),data.length(),flush); }
06532
06539 virtual int readComp(DataBlock& buf, bool flush) = 0;
06540
06549 virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
06550
06558 inline int writeDecomp(const DataBlock& data, bool flush)
06559 { return writeDecomp(data.data(),data.length(),flush); }
06560
06568 inline int writeDecomp(const String& data, bool flush)
06569 { return writeDecomp(data.c_str(),data.length(),flush); }
06570
06577 virtual int readDecomp(DataBlock& buf, bool flush) = 0;
06578
06579 protected:
06580 String m_format;
06581 };
06582
06588 class YATE_API SysUsage
06589 {
06590 public:
06594 enum Type {
06595 WallTime,
06596 UserTime,
06597 KernelTime
06598 };
06599
06603 static void init();
06604
06609 static u_int64_t startTime();
06610
06616 static u_int64_t usecRunTime(Type type = WallTime);
06617
06623 static u_int64_t msecRunTime(Type type = WallTime);
06624
06630 static u_int32_t secRunTime(Type type = WallTime);
06631
06637 static double runTime(Type type = WallTime);
06638
06639 };
06640
06641 };
06642
06643 #endif
06644
06645