/**************************************************************************** ** File name : HTPublic.h ** Description : define common api ** Create date : 2018.09.01 ** Auther by : Liuyx ** Version info : V1.0.01 ** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd ** Update record: ** DATE AUTHER DESC ** ------------------------------------------------------------------------- ** 2018.09.01 Liuyx first build ****************************************************************************/ #ifndef __HT_PUBLIC_H #define __HT_PUBLIC_H #ifdef _WIN32 #pragma comment(lib,"ws2_32.lib") #endif #include #include #include #include #include #include #include #include #include /* timespec{} for pselect() */ #include #include #include #include /* for nonblocking */ #include #include #include "HTType.h" using namespace std; #ifdef _WIN32 #include #include #include #include #include #include #else #include #include #include #include #include #include #include #include /* sockaddr_in{} and other Internet defns */ #include /* inet(3) functions */ #include #include #include #include #include #include #include #include #include #endif /* #if defined(__linux__) && defined(__NR_gettid) #define GETTID() syscall(__NR_gettid) #else #define GETTID() getpid() #endif */ #ifdef _WIN32 #define GETTID() GetCurrentThreadId() // 获取线程ID #define GETPID() GetCurrentProcessId() // 获取主进程ID #else #define GETTID() syscall(__NR_gettid) #define GETPID() getpid() // 获取主进程ID #endif #define DEF_PID_FILE "../run/pid_file.pid" // 程序主进程ID文件 #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ void vSetPid(); int iGetPid(); // 时间函数 void vGetHostTime (char *pszTime) ; time_t vGetHostTimeFmt (char *pszTime) ; time_t vGetHostTimeFmtBeforBay(char *pszTime, int beforbay); void vTranHostTimeFmt (time_t t, char *pszTime); time_t strTime2int(char *pszTime); time_t strTimeFmt2int(char *pszTime); void getCurrentBefor360Hour(char *pstime, char *petime); time_t vGeOneDayTimeFmt(char *pSTime, char *pETime); void vFormatTimes(char *pszInTimeStr, char *pszOutFormatTime); time_t getUTCLongTime (void) ; void getUTCFmtTime (char *pszTime) ; void UTC2FmtTime (time_t utc, char *pszTime) ; void UTC2LocalTime (time_t utc, char *pszTime) ; void diffTimes(unsigned int c, char *pszTime); unsigned int uiTime (void) ; int getCurrTimeDiff(unsigned char *bcd_t) ; time_t local2Utc(unsigned char *pTime, int iLen); time_t local2UtcTime(time_t localTime); int getuuid(char *str, int inlen); void vGetHostTimeOnMillsecond(char *pszTime); // 获取时间,YYYYMMDDHH24MISS:MLSS time_t vGetHostTimeFmtOnMillsecond(char *pszTime); // 获取时间,YYYY-MM-DD HH24:MI:SS+MLSS unsigned int getWarnID(unsigned char *pTime, int iLen, unsigned int id); // 目录操作函数 int iDirOrFileExist(const char *pszName); int iBuildDirent(const char *pName); int iSplitNumberFiled(char *pstr, char node, int no); int iSplitStringFiled(char *pstr, char node, char no, char *pFiled); int get_file_size(const char *path); int getFileCreateTime(const char *path, char *pCreateTime); bool bSplitFilenameByFullPath(char *pFullPath, char *pPrantPath, char *pFilename, char *pExt); // 将Linux文件路径转为Windows的路径格式 void Unix2WindowPath(char *pszPath); void Window2UnixPath(char *pszPath); void getGnssData(unsigned char *p_date); void getGnssTime(unsigned char *p_time); void setPostionDate(unsigned char *pDate, unsigned char *pTime); void setPostionTime(unsigned char *pDate, unsigned char *pTime); int iTrimVersionHeadChar(char *strver); void LRTrim(unsigned char *str); int RigthTrim(unsigned char *str); int LeftTrim(unsigned char *str); void MiddleTrim(unsigned char *str); bool isStringDigit(char *pstr); int stringcasecmp(const char *ps1, const char *ps2); int stringncasecmp(const char *ps1, const char *ps2, int length); int bits_check(unsigned char *map, int field_no); void getDateFromTime(char* p_time,char* p_date); void getTimeFromTime(char* p_time,char* p_times); void bcd_to_asc(unsigned char *pusFrom, unsigned int uiFromLen,unsigned char *pusTo); void asc_to_bcd(unsigned char *pusFrom, unsigned int uiFromLen, unsigned char *pusTo); unsigned int htoni(unsigned int us); unsigned int ntohi(unsigned int us); double getRandByTime(); #ifdef ntohll utint64 ntohll(utint64 arg64) ; #endif #ifdef htonll utint64 htonll(utint64 arg64) ; #endif unsigned int int64To32(utint64 u64); void LocalTime2Bcd(char *pLocalTime, char *pBcd); int getStringLen(unsigned char *pstr, int length); int getHexString(unsigned char *str, int length, unsigned char *pstr); /************************************************************************* Function : 32位整数转二进制字符串 Param in : num : source uint Param out : pBin : object strings.(min length = 32) Return Code : none *************************************************************************/ void uint32_binstr(unsigned int num, char* pBin); /************************************************************************* Function : 64位整数转二进制字符串 Param in : num : source uint Param out : pBin : object strings.(min length = 64) Return Code : none *************************************************************************/ void uint64_binstr(utint64 num, char* pBin); /************************************************************************* Function : 二进制字符串转32位整数 Param in : pBin : source bin string(eg. 1010101001111), need '\0' end. Param out : : none Return Code : uint32 interger *************************************************************************/ unsigned int binstr_uint32(char *pBin); /************************************************************************* Function : 二进制字符串转64位整数 Param in : pBin : source bin string(eg. 1010101001111), need '\0' end. Param out : : none Return Code : utint64 interger *************************************************************************/ utint64 binstr_uint64(char *pBin); /************************************************************************* Function : 字符串反转 Param in : str : source string(eg. 1010101001111), need '\0' end. len : source length Param out : : str Return Code : str, null is faild *************************************************************************/ char* strSwap(char* szT,int len); #ifdef __cplusplus } #endif int replaceAll(std::string& input, const std::string& search, const std::string& replace); #endif // end __HT_PUBLIC_H