1. Changed license year
[apps/home/mobileprint.git] / mobileprint / previewgen / include / pgen_debug.h
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.org/license/
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 #ifndef _PGEN_DEBUG_H_INCLUDED_
21 #define _PGEN_DEBUG_H_INCLUDED_
22
23
24 /* debugging macros definitions */
25
26 /*#define PREVIEWGEN_STANDALONE_DEBUG*/
27 #define PREVIEWGEN_DLOG_DEBUG
28 #if defined PREVIEWGEN_STANDALONE_DEBUG
29 /* standalone preview generation (e.g. for testing) */
30
31 #include <stdio.h>
32
33 #define PGEN_DEBUG(fmt, arg...) \
34         do { \
35                 fprintf(stderr, "DEBUG:%s:%s(%d): " fmt "\n", \
36                                 __FILE__, __func__, __LINE__, ##arg); \
37         } while (0)
38 #define PGEN_TRACE_BEGIN        fprintf(stderr, "TRACE:%s ENTER\n", __func__);
39 #define PGEN_TRACE_END          fprintf(stderr, "TRACE:%s LEAVE\n", __func__);
40
41 #define PGEN_RET_IF(expr, fmt, args...) \
42         do { \
43                 if(expr) { \
44                         PGEN_DEBUG("[%s] Return, message "fmt, #expr, ##args );\
45                         return; \
46                 } \
47         } while (0)
48
49 #define PGEN_RETV_IF(expr, val, fmt, args...) \
50         do { \
51                 if(expr) { \
52                         PGEN_DEBUG("[%s] Return value, message "fmt, #expr, ##args );\
53                         return (val); \
54                 } \
55         } while (0)
56
57 #define PGEN_IF_FREE_MEM(mem) \
58         do { \
59                 if(mem) { \
60                         free(mem); \
61                         mem = NULL; \
62                 } \
63         } while (0)
64
65
66 #elif defined PREVIEWGEN_DLOG_DEBUG
67 /* standalone debugging with dlog */
68 #undef LOG_TAG
69 #define LOG_TAG "MOBILEPRINT_PREVIEWGEN"
70 #include <dlog.h>
71
72 #define PGEN_DEBUG      LOGD
73 #define PGEN_INFO       LOGI
74 #define PGEN_RET_IF(expr, fmt, args...) \
75         do { \
76                 if(expr) { \
77                         PGEN_DEBUG("[%s] Return, message "fmt, \
78                                         #expr, ##args ); \
79                         return; \
80                 } \
81         } while (0)
82
83 #define PGEN_RETV_IF(expr, val, fmt, args...) \
84         do { \
85                 if(expr) { \
86                         PGEN_DEBUG("[%s] Return value, message "fmt, \
87                                         #expr, ##args ); \
88                         return (val); \
89                 } \
90         } while (0)
91
92 #define PGEN_TRACE_BEGIN        PGEN_INFO("ENTER FUNCTION: %s\n", __FUNCTION__);
93 #define PGEN_TRACE_END          PGEN_INFO("EXIT FUNCTION: %s\n", __FUNCTION__);
94
95 #define PGEN_IF_FREE_MEM(mem) \
96         do { \
97                 if(mem) { \
98                         free(mem); \
99                         mem = NULL; \
100                 } \
101         } while (0)
102
103
104 #else
105 /* connection to mobileprint debugging */
106
107 #include <pts_debug.h>
108
109 #define PGEN_DEBUG(fmt, arg...)         PTS_DEBUG(fmt, ##arg)
110 #define PGEN_TRACE_BEGIN                PTS_TRACE_BEGIN
111 #define PGEN_TRACE_END                  PTS_TRACE_END
112 #define PGEN_RET_IF                     PTS_RET_IF
113 #define PGEN_RETV_IF                    PTS_RETV_IF
114 #define PGEN_IF_FREE_MEM                PTS_IF_FREE_MEM
115
116 #endif /* PREVIEWGEN_DEBUG */
117
118
119 #endif /* _PGEN_DEBUG_H_INCLUDED_ */
120