Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

tools.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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  * substitutes environment variables in a string
00087  *
00088  * @param input string containing the variable components
00089  * @return the string with the replaced components
00090  *
00091  * @note this will only work if the libc supports _XOPEN_SOURCE
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  * Removes double slashes from strings containing filesystem paths.
00157  *
00158  * @param   path    string to fix
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 //! Convert a bidirectional string.
00190 /*!
00191 \param in_str   source string (UTF-8)
00192 \param out_str  destination string (UTF-8)
00193 \return true if successfully converted
00194 \note in_str and out_str can be the same
00195 */
00196 bool convBidiString(const string &in_str, string &out_str, bool bArabic=false);
00197 
00198 string XMLencode( const string &Source );
00199 
00200 #endif /*TOOLS_H_*/

Generated by doxygen