123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #ifndef _PX_TOOL_H_
- #define _PX_TOOL_H_
- #include "cJSON.h"
- #include "pxVersion.h"
- #define PROCESSPATH "/tmp/run/"
- #define LOGFILEPATH "/home/nvidia/newdisk/zxf"
- #define IPSTRLEN 16
- /***********************************************/
- /************MICRO******************************/
- /***********************************************/
- #define MACLEN 6
- #define MACSTRUPER(mac)"%02X:%02X:%02X:%02X:%02X:%02X",\
- mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]
- #define new(type) (type*)malloc(sizeof(type))
- typedef signed char s8;
- typedef unsigned char u8;
- typedef signed short s16;
- typedef unsigned short u16;
- typedef signed int s32;
- typedef unsigned int u32;
- typedef signed long long s64;
- typedef unsigned long long u64;
- /***********************************************/
- /************DEAMON & LOG***********************/
- /***********************************************/
- typedef enum
- {
- NONE=0,
- ERROR,
- WARNING,
- INIT,
- EVENT,
- INFO,
- DEBUG,
- PACKGE
- }LOGLEVEL_E;
- //tm_mon tm_mday tm_hour tm_min
- #define LOGROTATETIME timenow->tm_mday
- void pxDeamonUniq(char *pname);
- void pxOpenLogFile(char *pname);
- int pxGetLogLevel();
- void pxSetLogLevel(LOGLEVEL_E l);
- void __pxLog(LOGLEVEL_E l, char *log, ...);
- #ifdef _WIN32
- #define pxLog(l,args,...); do{if(pxGetLogLevel()>=l)__pxLog(l,##args);}while(0);
- #else
- #define pxLog(l,args...); do{if(pxGetLogLevel()>=l)__pxLog(l,##args);}while(0);
- #endif
- void pxLogPackage(unsigned char *p,int len);
- /***********************************************/
- /************JSON*******************************/
- /***********************************************/
- cJSON* pxReadJsonFile_malloc(char *path);
- int pxJsonStrdup(cJSON* json,char *name,char **value);
- int pxJsonIntcpy(cJSON* json,char *name,int *value);
- /***********************************************/
- /************LIST*******************************/
- /***********************************************/
- typedef struct list_head {
- struct list_head *next, *prev;
- }LISTNODE_S;
- #define list_entry(ptr, type, member) ( \
- (type *)( (char *)ptr - offsetof(type,member) ))
- #define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
- #define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head) -> next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
-
- #define LIST_NODE(name) \
- struct list_head name = { &(name), &(name) }
- static inline void INIT_LIST_NODE(struct list_head *list)
- {
- list->next = list;
- list->prev = list;
- }
- static inline void list_add(struct list_head *newNode, struct list_head *headNode)
- {
- if(!newNode || !headNode)
- return;
- newNode->next=headNode;
- newNode->prev=headNode->prev;
- headNode->prev->next=newNode;
- headNode->prev=newNode;
- }
- static inline void list_del(struct list_head *newNode)
- {
- if(!newNode)
- return;
- newNode->prev->next=newNode->next;
- newNode->next->prev=newNode->prev;
- newNode->next=newNode;
- newNode->prev=newNode;
- }
- #ifdef PXCURL
- char* PxCurl(const char *url,const char *interface,const char *token,const char *data);
- #endif
- void writeFile(char *fileName,char *buffer);
- int PxExecute(char *ret,int retLenth,char *cmd,...);
- #endif
|