Skip to content

Instantly share code, notes, and snippets.

@alenstarx
Last active December 25, 2017 03:07
Show Gist options
  • Save alenstarx/4199c659a20e641b8fbd to your computer and use it in GitHub Desktop.
Save alenstarx/4199c659a20e641b8fbd to your computer and use it in GitHub Desktop.
#ifndef DEF_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <signal.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include <linux/if_ether.h>
#include <malloc.h>
#include <fcntl.h>
#include <termios.h>
#include <ctype.h>
#include <pthread.h>
#include <time.h>
#include <signal.h>
#include <sched.h>
#define msleep(M) usleep(1000*(M))
#define min(a,b) ((a) < (b) ? (a):(b))
#define max(a,b) ((a) > (b) ? (a):(b))
#ifndef __FUNCTION_NAME__
#ifdef WIN32 //WINDOWS
#define __FUNCTION_NAME__ __FUNCTION__
#else //*NIX
#define __FUNCTION_NAME__ __func__
#endif
#endif
#ifdef _WIN32
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
/*
#if 1 //def DEBUG
#define LOGD(...) do{char tmp[1024]={0x00};snprintf(tmp, 1023, __VA_ARGS__); printf("%s (%4d)[D] %s: %s\n", __FILENAME__,__FUNCTION_NAME__, __LINE__, tmp);}while(0)
#define LOGI(...) do{char tmp[1024]={0x00};snprintf(tmp, 1023, __VA_ARGS__); printf("%s (%4d)[I] %s: %s\n", __FILENAME__,__FUNCTION_NAME__, __LINE__, tmp);}while(0)
#define LOGW(...) do{char tmp[1024]={0x00};snprintf(tmp, 1023, __VA_ARGS__); printf("%s (%4d)[W] %s: %s\n", __FILENAME__,__FUNCTION_NAME__, __LINE__, tmp);}while(0)
#define LOGE(...) do{char tmp[1024]={0x00};snprintf(tmp, 1023, __VA_ARGS__); printf("%s (%4d)[E] %s: %s\n", __FILENAME__,__FUNCTION_NAME__, __LINE__, tmp);}while(0)
#else
#define LOGI(...) ((void)0)
#define LOGD(...) ((void)0)
#define LOGW(...) ((void)0)
#define LOGE(...) do{char tmp[1024]={0x00};snprintf(tmp, 1023, __VA_ARGS__); printf("%s (%4d)[E] %s: %s\n", __FILENAME__,__FUNCTION_NAME__, __LINE__, tmp);}while(0)
#endif
*/
#ifdef DEBUG
#define LOG_TAG "vinput"
#include <android/log.h>
#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
#define LOGW(fmt, args...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, fmt, ##args)
#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##args)
#else
#define LOGD(...) ((void)0)
#define LOGE(...) ((void)0)
#define LOGW(...) ((void)0)
#define LOGI(...) ((void)0)
#endif
#endif
#if 0
#include "easylogging++.h"
// el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Format, "%datetime %func[%fbase] %level: %msg");
#if 1 //def DEBUG
// Use default logger
#define LOGI(...) el::Loggers::getLogger("default")->info(__VA_ARGS__)
#define LOGD(...) el::Loggers::getLogger("default")->debug(__VA_ARGS__)
#define LOGW(...) el::Loggers::getLogger("default")->warn(__VA_ARGS__)
#define LOGE(...) el::Loggers::getLogger("default")->error(__VA_ARGS__)
#else
#define LOGI(...)
#define LOGD(...)
#define LOGW(...)
#define LOGE(...) el::Loggers::getLogger("default")->error(__VA_ARGS__)
#endif
#endif
#ifdef _DEBUG
#ifdef WIN32
#define MAXDUGBUFF 512
#include <debugapi.h>
#define D(fmt, ...) do { char buf[MAXDUGBUFF]; memset(buf, 0x00, MAXDUGBUFF); sprintf(buf, "%s (%d) DEBUG: ", __FILE__, __LINE__); OutputDebugStringA(buf); memset(buf, 0x00, MAXDUGBUFF); sprintf(buf, fmt ## "\r\n", ##__VA_ARGS__); OutputDebugStringA(buf); }while (0)
#else
#define D(fmt, ...) do{printf("%s (%d) DEBUG: ", __FILE__, __LINE__);printf(fmt ## "\n", ## __VA_ARGS__);}while(0)
#endif
#else
#define D(fmt, ...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment