00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TOOLS_H_
00034 #define TOOLS_H_
00035
00036 #include "mmstools/mmstypes.h"
00037
00038 #include <vector>
00039
00040 extern "C" {
00041 #include <stdarg.h>
00042 #include <pthread.h>
00043 #include <stdio.h>
00044 #include <sys/time.h>
00045 #include <sys/types.h>
00046 }
00047
00048 #ifdef __ENABLE_LOG__
00049 #define DEBUGMSG(ident, msg...) writeDebugMessage(ident, __FILE__, __LINE__, msg)
00050 #define DEBUGMSG_OUTSTR(ident, msg...) writeDebugMessage(ident, __FILE__, __LINE__, msg);printf("%s\n", ((string)(msg)).c_str())
00051 #else
00052 #define DEBUGMSG(ident, msg...)
00053 #define DEBUGMSG_OUTSTR(ident, msg...) printf("%s\n", ((string)(msg)).c_str())
00054 #endif
00055
00056 #ifdef __ENABLE_DEBUG__
00057 #define DEBUGOUT(msg...) printf(msg)
00058 #define DEBUGERR(msg...) fprintf(stderr, msg)
00059 #else
00060 #define DEBUGOUT(msg...)
00061 #define DEBUGERR(msg...)
00062 #endif
00063
00064 #if __ENABLE_LOG__ || __ENABLE_DEBUG__
00065 #define TRACEOUT(ident, msg...) writeMessage2Stdout(ident, __FILE__, __LINE__, msg)
00066 #else
00067 #define TRACEOUT(ident, msg...)
00068 #endif
00069
00070 #define MSG2OUT(ident, msg...) writeMessage2Stdout(ident, __FILE__, __LINE__, msg)
00071
00072
00073 #ifdef __ENABLE_DEBUG__
00074 #define WRITE_MSG(ident, msg...) printf("%s: ", ident);printf(msg);printf("\n");
00075 #define WRITE_MSGI(msg...) printf("%s: ", identity.c_str());printf(msg);printf("\n");
00076 #else
00077 #define WRITE_MSG(ident, msg...)
00078 #define WRITE_MSGI(msg...)
00079 #endif
00080
00081 #define WRITE_ERR(ident, msg...) fprintf(stderr, "%s: ", ident);fprintf(stderr, msg);printf("\n");
00082 #define WRITE_ERRI(msg...) fprintf(stderr, "%s: ", identity.c_str());fprintf(stderr, msg);printf("\n");
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 string substituteEnvVars(string input);
00094
00095 string maskChars(string str);
00096
00097 string *strToUpr(string *src);
00098
00099 string strToUpr(string src);
00100
00101 string *strToLwr(string *src);
00102
00103 string strToLwr(string src);
00104
00105 int hexToInt(const char *in);
00106
00107 string ucharToHex(unsigned char in);
00108
00109 bool getCurrentTimeBuffer(char *dtbuf, char *datebuf=NULL, char *timebuf=NULL,
00110 time_t *clock=NULL);
00111
00112 bool getCurrentTimeString(string *dtstr, string *datestr=NULL, string *timestr=NULL,
00113 time_t *clock=NULL);
00114
00115 string getDayOfWeek(time_t *clock=NULL);
00116
00117 void initLogging(char *Iam, char *logfile);
00118
00119 string getSimpleTimeString();
00120
00121 void writeMessage(const char *ctrl,...);
00122
00123 int strToInt(string s);
00124
00125 unsigned int strToUInt(string s);
00126
00127 string iToStr(int i);
00128
00129 string fToStr(double i);
00130
00131 string cpToStr(char *);
00132
00133 string cToStr(char);
00134
00135 char *scanForString(char *buf, char *toFind, char **ret=NULL,
00136 int offset=0, unsigned int length=0);
00137
00138 char *scanForString(char *buf, char *toFind, string *ret=NULL,
00139 int offset=0, unsigned int length=0);
00140
00141 string scanForString(string buf, string toFind, string *ret=NULL,
00142 int offset=0, unsigned int length=0);
00143
00144 void split(string str, string delim, vector<string> &results, bool allowEmpty=false);
00145
00146 void msleep(unsigned long msec);
00147
00148 bool scanString(string toscan, string frontkey, string backkey,
00149 unsigned int offset, unsigned int length, string *result, unsigned int *nextpos);
00150
00151 void trim(string& str);
00152
00153 bool strToBool(string s);
00154
00155
00156
00157
00158
00159
00160 void fixPathStr(string &path);
00161
00162 void executeCmd(string cmd, pid_t *cpid=NULL);
00163
00164 bool file_exist( string filename );
00165
00166 void writeDebugMessage(const char *identity, const char *filename, const int lineno, const char *msg, ...);
00167 void writeDebugMessage(const char *identity, const char *filename, const int lineno, const string &msg);
00168
00169 void writeMessage2Stdout(const char *identity, const char *filename, const int lineno, const char *msg, ...);
00170 void writeMessage2Stdout(const char *identity, const char *filename, const int lineno, const string &msg);
00171
00172 unsigned int getMTimeStamp();
00173 unsigned int getMDiff(unsigned int start_ts, unsigned int end_ts);
00174
00175 int64_t timespecDiff(struct timespec *timeA, struct timespec *timeB);
00176
00177
00178
00179 void rotateUCharBuffer180(unsigned char *buffer, int pitch, int w, int h);
00180 void rotateUShortIntBuffer180(unsigned short int *buffer, int pitch, int w, int h);
00181 void rotateUIntBuffer180(unsigned int *buffer, int pitch, int w, int h);
00182
00183
00184 #ifdef __HAVE_BACKTRACE__
00185 void print_trace(char *prefix);
00186 #endif
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 bool convBidiString(const string &in_str, string &out_str, bool bArabic=false);
00197
00198 string XMLencode( const string &Source );
00199
00200 #endif