summaryrefslogtreecommitdiff
path: root/common/include/debug.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/include/debug.h')
-rwxr-xr-xcommon/include/debug.h240
1 files changed, 240 insertions, 0 deletions
diff --git a/common/include/debug.h b/common/include/debug.h
new file mode 100755
index 0000000..4f6bf64
--- /dev/null
+++ b/common/include/debug.h
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __ELM_MYPHOTOCAM_DEBUG_H__
+#define __ELM_MYPHOTOCAM_DEBUG_H__
+
+#include <assert.h>
+
+
+/*
+ Category :
+ FATAL
+ ERROR
+ WARN
+ HIGH
+ MED
+ LOW
+ DEBUG
+*/
+
+
+enum
+{
+ DBG_MSG_LOW = 0,
+ DBG_MSG_MED = 1,
+ DBG_MSG_HIGH = 2,
+
+ DBG_MSG_WARN = 3,
+ DBG_MSG_ERROR = 4,
+ DBG_MSG_FATAL = 5,
+
+ DBG_MSG_CUST5 = 6,
+ DBG_MSG_CUST6 = 7,
+ DBG_MSG_CUST7 = 8,
+ DBG_MSG_CUST8 = 9,
+ DBG_MSG_CUST9 = 10,
+ DBG_MSG_CUST10 = 11,
+ DBG_MSG_CUST11 = 12,
+ DBG_MSG_CUST12 = 13,
+ DBG_MSG_CUST13 = 14,
+};
+
+
+// level
+enum
+{
+ DBG_MSG_BIT_LOW = (1<<DBG_MSG_LOW),
+ DBG_MSG_BIT_MED = (1<<DBG_MSG_MED),
+ DBG_MSG_BIT_HIGH = (1<<DBG_MSG_HIGH),
+ DBG_MSG_BIT_WARN = (1<<DBG_MSG_WARN),
+ DBG_MSG_BIT_ERROR = (1<<DBG_MSG_ERROR),
+ DBG_MSG_BIT_FATAL = (1<<DBG_MSG_FATAL),
+
+ DBG_MSG_BIT_CUST5 = (1<<DBG_MSG_CUST5),
+ DBG_MSG_BIT_CUST6 = (1<<DBG_MSG_CUST6),
+ DBG_MSG_BIT_CUST7 = (1<<DBG_MSG_CUST7),
+ DBG_MSG_BIT_CUST8 = (1<<DBG_MSG_CUST8),
+ DBG_MSG_BIT_CUST9 = (1<<DBG_MSG_CUST9),
+ DBG_MSG_BIT_CUST10 = (1<<DBG_MSG_CUST10),
+ DBG_MSG_BIT_CUST11 = (1<<DBG_MSG_CUST11),
+ DBG_MSG_BIT_CUST12 = (1<<DBG_MSG_CUST12),
+ DBG_MSG_BIT_CUST13 = (1<<DBG_MSG_CUST13),
+};
+
+#define DBG_MSG_LVL_DEBUG (DBG_MSG_BIT_CUST13)
+
+#define DBG_MSG_LVL_ALL (DBG_MSG_LVL_LOW)
+
+#define DBG_MSG_LVL_FATAL (DBG_MSG_BIT_FATAL)
+#define DBG_MSG_LVL_ERROR (DBG_MSG_LVL_FATAL | DBG_MSG_BIT_ERROR)
+#define DBG_MSG_LVL_WARN (DBG_MSG_LVL_ERROR | DBG_MSG_BIT_WARN)
+#define DBG_MSG_LVL_HIGH (DBG_MSG_LVL_WARN | DBG_MSG_BIT_HIGH)
+#define DBG_MSG_LVL_MED (DBG_MSG_LVL_HIGH | DBG_MSG_BIT_MED)
+#define DBG_MSG_LVL_LOW (DBG_MSG_LVL_MED | DBG_MSG_BIT_LOW)
+#define DBG_MSG_LVL_NONE (0)
+
+
+// Get time of day
+#include <sys/time.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Time analyzer
+#define DEFINE_PERFORM_TIME(aa) long aa = 0; struct timeval tv
+
+#define BEGIN_PERFORM_TIME(aa) \
+ { \
+ gettimeofday(&tv, NULL); \
+ aa = tv.tv_sec * 1000 + tv.tv_usec / 1000; \
+ } while(0)
+
+#define END_PERFORM_TIME(aa) \
+ { \
+ gettimeofday(&tv, NULL); \
+ aa = ( tv.tv_sec * 1000 + tv.tv_usec / 1000 ) - aa; \
+ } while(0)
+
+// TODO : Need align(1)
+typedef struct {
+ const char *fname;
+ int nline;
+ const char *szcategory;
+ int msg_level;
+ const char *szlevel;
+ unsigned long time;
+} debug_msg_type;
+
+void _custom_debug_msg(debug_msg_type *debug_msg, const char *msg, ...);
+
+/* coverity[+kill] */
+#define __MSG_FATAL(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_FATAL) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_FATAL, \
+ "FATAL", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+#define __MSG_ERROR(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_ERROR) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_ERROR, \
+ "ERROR", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+
+#define __MSG_WARN(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_WARN) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_WARN, \
+ "WARN", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+#define __MSG_HIGH(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_HIGH) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_HIGH, \
+ "HIGH", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+#define __MSG_MED(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_MED) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_MED, \
+ "MED", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+
+#define __MSG_LOW(level, szCat, ...) \
+ do { \
+ if ((level) & DBG_MSG_BIT_LOW) \
+ { \
+ static debug_msg_type msg______unique______name___ = { \
+ __FILE__, \
+ __LINE__, \
+ szCat, \
+ DBG_MSG_LOW, \
+ "LOW", \
+ }; \
+ _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
+ } \
+ } while(0)
+
+
+#define ASSERT(level, szCat, expr) \
+ do { \
+ if( !(expr) ) \
+ { \
+ __MSG_FATAL(level, szCat, "[%s] ASSERT : " #expr , __func__ ); \
+ } \
+ } while(0)
+
+#define NEVER_GET_HERE(level, szCat) \
+ do { \
+ __MSG_FATAL(level, szCat, "NeverGetHere : %s(%d)", __func__, __LINE__); \
+ } while(0)
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // __ELM_MYPHOTOCAM_DEBUG_H__
+