322 lines
12 KiB
C
322 lines
12 KiB
C
/**
|
||
* @file: $RCSfile: systrace.h,v $
|
||
* @brief: $System trace API definiens.
|
||
*
|
||
* @version: $Revision: 1.2 $
|
||
* @date: $Date: 2019/02/19 07:18:52 $
|
||
* @author: $Author: lizhongming $
|
||
* @state: $State: Exp $
|
||
*
|
||
* @latest: $Id: systrace.h,v 1.2 2019/02/19 07:18:52 lizhongming Exp $
|
||
*/
|
||
|
||
#ifndef _SAS_TRACE_H_
|
||
#define _SAS_TRACE_H_
|
||
|
||
#define SASLOG_DEBUG (0)
|
||
#define SASLOG_WARN (1)
|
||
#define SASLOG_ERROR (2)
|
||
|
||
#define ANSI_TEXT_NORMAL "0"
|
||
#define ANSI_TEXT_HIGHLIGHT "1"
|
||
#define ANSI_TEXT_BLINK "5"
|
||
|
||
#define ANSI_COLOR_BLACK "30m"
|
||
#define ANSI_COLOR_RED "31m"
|
||
#define ANSI_COLOR_GREEN "32m"
|
||
//¸ßÁÁÏÂÓÐЧ
|
||
#define ANSI_COLOR_BROWN "33m"
|
||
#define ANSI_COLOR_BLUE "34m"
|
||
//¸ßÁÁÏÂÓÐЧ
|
||
#define ANSI_COLOR_PINK "35m"
|
||
#define ANSI_COLOR_LIGHTBLUE "36m"
|
||
#define ANSI_COLOR_WHITE "37m"
|
||
|
||
#define ANSI_COLOR_NORMAL "0m"
|
||
|
||
#ifdef _OS_UNIX_
|
||
#define ERROR_HIGHLIGHT_BEGIN "\033[1m\033[31m\033[40m"
|
||
#define ERROR_HIGHLIGHT_END "\033[0m"
|
||
#define WARN_HIGHLIGHT_BEGIN "\033[32m\033[40m"
|
||
#define WARN_HIGHLIGHT_END "\033[0m"
|
||
#else
|
||
#define ERROR_HIGHLIGHT_BEGIN ""
|
||
#define ERROR_HIGHLIGHT_END ""
|
||
#define WARN_HIGHLIGHT_BEGIN ""
|
||
#define WARN_HIGHLIGHT_END ""
|
||
#endif
|
||
|
||
APR_DECLARE_DATA extern uint32_t g_addition_log;
|
||
APR_DECLARE_DATA extern int g_tmp_debug ;
|
||
|
||
//warn
|
||
#define echo_warn(s) \
|
||
echo_msg_warnex(__FILE__,__LINE__,("%s"),s)
|
||
#define echo_warn1(fmt,s0) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0))
|
||
#define echo_warn2(fmt,s0,s1) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1))
|
||
#define echo_warn3(fmt,s0,s1,s2) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2))
|
||
#define echo_warn4(fmt,s0,s1,s2,s3) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3))
|
||
#define echo_warn5(fmt,s0,s1,s2,s3,s4) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4))
|
||
#define echo_warn6(fmt,s0,s1,s2,s3,s4,s5) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5))
|
||
#define echo_warn7(fmt,s0,s1,s2,s3,s4,s5,s6) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6))
|
||
#define echo_warn8(fmt,s0,s1,s2,s3,s4,s5,s6,s7) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6),(s7))
|
||
#define echo_warn9(fmt,s0,s1,s2,s3,s4,s5,s6,s7,s8) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8))
|
||
#define echo_warn10(fmt,s0,s1,s2,s3,s4,s5,s6,s7,s8,s9) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9))
|
||
#define echo_warn11(fmt,s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10))
|
||
#define echo_warn12(fmt,s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11) \
|
||
echo_msg_warnex(__FILE__,__LINE__,(fmt),(s0),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10),(s11))
|
||
|
||
//err
|
||
#define echo_err(s,rv) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),("%s"),(s))
|
||
#define echo_errg(s) \
|
||
echo_msg_errex(__FILE__,__LINE__,(APR_EGENERAL),("%s"),(s))
|
||
#define echo_err1(fmt,rv,s1) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1))
|
||
#define echo_err2(fmt,rv,s1,s2) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2))
|
||
#define echo_err3(fmt,rv,s1,s2,s3) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3))
|
||
#define echo_err4(fmt,rv,s1,s2,s3,s4) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4))
|
||
#define echo_err5(fmt,rv,s1,s2,s3,s4,s5) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5))
|
||
#define echo_err6(fmt,rv,s1,s2,s3,s4,s5,s6) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6))
|
||
#define echo_err7(fmt,rv,s1,s2,s3,s4,s5,s6,s7) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7))
|
||
#define echo_err8(fmt,rv,s1,s2,s3,s4,s5,s6,s7,s8) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8))
|
||
#define echo_err9(fmt,rv,s1,s2,s3,s4,s5,s6,s7,s8,s9) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9))
|
||
#define echo_err10(fmt,rv,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10))
|
||
#define echo_err11(fmt,rv,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10),(s11))
|
||
#define echo_err12(fmt,rv,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12) \
|
||
echo_msg_errex(__FILE__,__LINE__,(rv),(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10),(s11),(s12))
|
||
|
||
//msg
|
||
#define echo_msg(s) \
|
||
echo_msg_debugex(__FILE__,__LINE__,("%s"),(s))
|
||
#define echo_msg1(fmt,s1) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1))
|
||
#define echo_msg2(fmt,s1,s2) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2))
|
||
#define echo_msg3(fmt,s1,s2,s3) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3))
|
||
#define echo_msg4(fmt,s1,s2,s3,s4) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4))
|
||
#define echo_msg5(fmt,s1,s2,s3,s4,s5) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5))
|
||
#define echo_msg6(fmt,s1,s2,s3,s4,s5,s6) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6))
|
||
#define echo_msg7(fmt,s1,s2,s3,s4,s5,s6,s7) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7))
|
||
#define echo_msg8(fmt,s1,s2,s3,s4,s5,s6,s7,s8) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8))
|
||
#define echo_msg9(fmt,s1,s2,s3,s4,s5,s6,s7,s8,s9) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9))
|
||
#define echo_msg10(fmt,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10) )
|
||
#define echo_msg11(fmt,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10),(s11))
|
||
#define echo_msg12(fmt,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12) \
|
||
echo_msg_debugex(__FILE__,__LINE__,(fmt),(s1),(s2),(s3),(s4),(s5),(s6),(s7),(s8),(s9),(s10),(s11),(s12))
|
||
|
||
|
||
#define MON_SEND 0 /**< ͨѶ¼àÊÓ·½Ïò·¢ËÍ */
|
||
#define MON_RECV 1 /**< ͨѶ¼àÊÓ·½Ïò½ÓÊÕ */
|
||
|
||
#define MON_COM 1 /**< ¶Ë¿ÚÀàÐÍ´®¿Ú */
|
||
#define MON_TCP 2 /**< ¶Ë¿ÚÀàÐÍTCP */
|
||
#define MON_UDP 3 /**< ¶Ë¿ÚÀàÐÍUDP */
|
||
#define MON_LOG 4 /**< ÐÅÏ¢ÀàÐÍ¡¡¡¡ */
|
||
|
||
#define LEVEL_NORMAL 1 /**< Õý³£LOGµÈ¼¶ */
|
||
#define LEVEL_WARN 2 /**< ¸æ¾¯LOGµÈ¼¶ */
|
||
#define LEVEL_ERROR 3 /**< ´íÎóLOGµÈ¼¶ */
|
||
|
||
#define MON_HEADER_LEN 22
|
||
#define MTRACEBUFLEN 3000 /**< ÿ´Î¿ÉÒÔTraceµÄ×î´óÊý¾Ý³¤¶È */
|
||
|
||
typedef struct trace_t trace_t;
|
||
struct trace_t {
|
||
apr_pool_t *pool;
|
||
//apr_pool_t *addr_pool;
|
||
apr_socket_t *sockdes;
|
||
apr_sockaddr_t *addr;
|
||
apr_thread_mutex_t *mutex;
|
||
};
|
||
|
||
typedef struct LOGSTAS LOGSTAS;
|
||
struct LOGSTAS {
|
||
byte_t debug:1;
|
||
byte_t warn:1;
|
||
byte_t error:1;
|
||
byte_t log3:1;
|
||
byte_t log4:1;
|
||
byte_t log5:1;
|
||
byte_t res:2;
|
||
}ALIGNPACKED;
|
||
typedef struct log_config_t log_config_t;
|
||
struct log_config_t{
|
||
char *msg_cache;
|
||
LOGSTAS status;
|
||
uint32_t log_udp_ip;
|
||
uint32_t DiffHostFromIp;
|
||
};
|
||
|
||
#ifdef _OS_WIN32_
|
||
#pragma pack(push,1)
|
||
#endif
|
||
|
||
typedef struct monbuf_t monbuf_t;
|
||
struct monbuf_t {
|
||
byte_t sync_code[4]; /**< ͬ²½×Ö EB 90 EB 90 */
|
||
byte_t ied_len; /**< ×°ÖÃÃû³Æ³¤¶È */
|
||
byte_t orient; /**< ¼àÊӵķ½Ïò£ºMON_SEND / MON_RECV */
|
||
byte_t type; /**< ¶Ë¿ÚÀàÐÍ£ºMON_COM / MON_TCP / MON_UDP */
|
||
byte_t node_len; /**< ½ÚµãÃû³Æ³¤¶È */
|
||
uint32_t node_id; /**< ½ÚµãºÅ */
|
||
uint32_t ied_id; /**< ×°ÖúŠ*/
|
||
uint32_t localhost; /**< TCP»òUDPʱ±íʾ±¾»úIPµØÖ· */
|
||
uint32_t remotehost; /**< TCP»òUDPʱ±íʾ¶Ô¶ËIPµØÖ· */
|
||
uint16_t localport; /**< TCP»òUDPʱ±íʾ±¾»ú¶Ë¿ÚºÅ */
|
||
uint16_t remoteport; /**< TCP»òUDPʱ±íʾ¶Ô¶Ë¶Ë¿ÚºÅ */
|
||
uint32_t len; /**< ÓÐЧÊý¾Ý³¤¶È(Êý¾Ý**dataµÄ³¤¶È) */
|
||
byte_t node_name[32]; /**< ½ÚµãÃû³Æ */
|
||
byte_t ied_name[32]; /**< ×°ÖÃÃû³Æ */
|
||
byte_t serial_name[16]; /**< ´®¿ÚÃû³Æ */
|
||
byte_t serial_len; /**< ´®¿ÚÃû³Æ³¤¶È */
|
||
byte_t data[MTRACEBUFLEN+10]; /**< ´ý·¢ËÍÊý¾ÝÊý¾Ý»º³åÇø */
|
||
//ÔÚ´ý·¢ËÍÊý¾ÝÊý¾Ý»º³åÇøºóÔö¼ÓËÄ×Ö½Ú(uint32_t)£¬ÓÃÓÚ´ú±íÖ÷±¸»ú¼°¶à»ú
|
||
}ALIGNPACKED;
|
||
|
||
#ifdef _OS_WIN32_
|
||
#pragma pack(pop)
|
||
#endif
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif /* __cplusplus */
|
||
|
||
/**
|
||
* @brief ÔÚUNIX»·¾³Ï£¬Êä³ö´øÑÕÉ«µÄÎı¾
|
||
* @param foreground ǰ¾°É«
|
||
* @param background ±³¾°É«
|
||
* @param str ÒªÊä³öµÄÎı¾
|
||
*/
|
||
APR_DECLARE(void) echo_color(char * foreground,char * background,char * str);
|
||
|
||
APR_DECLARE(int) trace_driver_create(trace_t * t,char * ip,apr_port_t port,apr_pool_t * pool);
|
||
|
||
APR_DECLARE(int) trace_driver_destory(trace_t * t);
|
||
|
||
APR_DECLARE(int) trace_driver_send(trace_t * t,const char * msg, apr_size_t len);
|
||
|
||
APR_DECLARE(apr_status_t) create_log_handle(apr_pool_t * pool);
|
||
|
||
APR_DECLARE(log_config_t *) get_log_handle(void);
|
||
|
||
APR_DECLARE(void) echo_msg_debugex(char * file_name,int line_no,char *fmt,...);
|
||
|
||
APR_DECLARE(void) echo_msg_warnex(char * file_name,int line_no, char *fmt,...);
|
||
|
||
APR_DECLARE(void) echo_msg_errex(char * file_name,int line_no,apr_status_t rv, char *fmt,...);
|
||
|
||
APR_DECLARE(int) trace_data(byte_t type,
|
||
byte_t orient,
|
||
uint32_t localhost,
|
||
uint32_t localport,
|
||
uint32_t remotehost,
|
||
uint32_t remoteport,
|
||
const char *serial_name,
|
||
int serial_len,
|
||
uint32_t node_id,
|
||
const char *node_name,
|
||
int node_len,
|
||
uint32_t client_id,
|
||
uint32_t ied_id,
|
||
const char *ied_name,
|
||
int ied_len,
|
||
const char *buf,
|
||
int len,
|
||
uint32_t traceIp);
|
||
|
||
/**
|
||
* @brief ½«TCP»òUDPÊý¾Ý·¢Ë͸øÍ¨Ðű¨ÎļàÊÓ³ÌÐò
|
||
* @param type ±»¼àÊӵĶ˿ÚÀàÐÍ£ºMON_TCP / MON_UDP
|
||
* @param orient ±»¼àÊÓµÄÊý¾Ý·¢ËÍ·½Ïò£ºMON_SEND / MON_RECV
|
||
* @param connect ±»¼àÊӵı¾µØÁ¬½Ó
|
||
* @param node_id ±»¼àÊÓµÄNODE½ÚµãºÅ
|
||
* @param node_name ±»¼àÊÓµÄNODE½ÚµãÃû³Æ
|
||
* @param ied_id ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDºÅ
|
||
* @param ied_name ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDÃû³Æ
|
||
* @param buf ±»¼àÊÓµÄÊý¾Ý»º³åÇø
|
||
* @param len ±»¼àÊÓµÄÓÐЧÊý¾Ý³¤¶È
|
||
* @param client_id ½ÚµãºÅ
|
||
* @param traceIp µã¶ÔµãUDP·¢ËͶË
|
||
*/
|
||
APR_DECLARE(void) trace_connect_buf(byte_t type,byte_t orient,void *connect,
|
||
uint32_t node_id,const char *node_name,uint32_t client_id,
|
||
uint32_t ied_id,const char *ied_name,
|
||
const char *buf,int len,uint32_t traceIp);
|
||
|
||
/**
|
||
* @brief ½«windows´®¿ÚÊý¾Ý·¢Ë͸øÍ¨Ðű¨ÎļàÊÓ³ÌÐò
|
||
* @param orient ±»¼àÊÓµÄÊý¾Ý·¢ËÍ·½Ïò£ºMON_SEND / MON_RECV
|
||
* @param serial_port ±»¼àÊӵĴ®¿ÚºÅ
|
||
* @param node_id ±»¼àÊÓµÄNODE½ÚµãºÅ
|
||
* @param node_name ±»¼àÊÓµÄNODE½ÚµãÃû³Æ
|
||
* @param ied_id ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDºÅ
|
||
* @param ied_name ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDÃû³Æ
|
||
* @param buf ±»¼àÊÓµÄÊý¾Ý»º³åÇø
|
||
* @param len ±»¼àÊÓµÄÓÐЧÊý¾Ý³¤¶È
|
||
* @param client_id ¿Í»§¶Ë½ÚµãºÅ
|
||
* @param traceIp µã¶ÔµãUDP·¢ËͶË
|
||
*/
|
||
APR_DECLARE(void) trace_wserial_buf(byte_t orient,int serial_port,
|
||
uint32_t node_id,const char *node_name,uint32_t client_id,
|
||
uint32_t ied_id,const char *ied_name,
|
||
const char *buf,int len,uint32_t traceIp);
|
||
|
||
/**
|
||
* @brief ½«linux´®¿ÚÊý¾Ý·¢Ë͸øÍ¨Ðű¨ÎļàÊÓ³ÌÐò
|
||
* @param orient ±»¼àÊÓµÄÊý¾Ý·¢ËÍ·½Ïò£ºMON_SEND / MON_RECV
|
||
* @param serial_name ±»¼àÊӵĴ®¿ÚÃû³Æ
|
||
* @param node_id ±»¼àÊÓµÄNODE½ÚµãºÅ
|
||
* @param node_name ±»¼àÊÓµÄNODE½ÚµãÃû³Æ
|
||
* @param ied_id ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDºÅ
|
||
* @param ied_name ±»¼àÊÓµÄNODE½ÚµãÖÐijIEDµÄIEDÃû³Æ
|
||
* @param buf ±»¼àÊÓµÄÊý¾Ý»º³åÇø
|
||
* @param len ±»¼àÊÓµÄÓÐЧÊý¾Ý³¤¶È
|
||
* @param client_id ¿Í»§¶Ë½ÚµãºÅ
|
||
* @param traceIp µã¶ÔµãUDP·¢ËͶË
|
||
*/
|
||
APR_DECLARE(void) trace_serial_buf(byte_t orient,const char *serial_name,
|
||
uint32_t node_id,const char *node_name,uint32_t client_id,
|
||
uint32_t ied_id,const char *ied_name,
|
||
const char *buf,int len,uint32_t traceIp);
|
||
|
||
APR_DECLARE(void) trace_log_buf(byte_t level,uint32_t m_id,uint32_t client_id,const char *m_name,int ied_len,const char *buf,int len,uint32_t traceIp);
|
||
|
||
APR_DECLARE(void) trace_tmp_debug(int node_id,char *str);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif /* __cplusplus */
|
||
|
||
#endif
|