33c38c3550667e0d3724b4752d49157226eb266a
[scm/bb/meta-tizen.git] / recipes-multimedia / pulseaudio / pulseaudio_5.0 / 0037-add-support-for-dlog-samsung.patch
1 From: "vivian,zhang" <vivian.zhang@intel.com>
2 Date: Tue, 18 Jun 2013 16:20:04 +0800
3 Subject: add support for dlog - samsung
4
5 Change-Id: Ieddf2f3bdab50926372e9e2b5cedb2756b6cfd5c
6 Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
7 ---
8  configure.ac                | 18 +++++++++
9  src/Makefile.am             |  9 +++++
10  src/daemon/cmdline.c        |  8 +++-
11  src/daemon/daemon-conf.c    | 10 ++++-
12  src/pulsecore/cli-command.c |  8 ++++
13  src/pulsecore/log.c         | 95 +++++++++++++++++++++++++++++++++++++++++++++
14  src/pulsecore/log.h         |  4 ++
15  7 files changed, 150 insertions(+), 2 deletions(-)
16
17 diff --git a/configure.ac b/configure.ac
18 index 9a79b36..c0beac0 100644
19 --- a/configure.ac
20 +++ b/configure.ac
21 @@ -643,6 +643,24 @@ PKG_CHECK_MODULES(LIBJSON, [ json-c >= 0.11 ], [],
22  
23  PKG_CHECK_MODULES(LIBSNDFILE, [ sndfile >= 1.0.20 ])
24  
25 +dnl use dlog --------------------------------------------------------------------------
26 +AC_ARG_ENABLE(dlog, AC_HELP_STRING([--enable-dlog], [using dlog]),
27 +[
28 + case "${enableval}" in
29 +        yes) USE_DLOG=yes ;;
30 +        no)  USE_DLOG=no ;;
31 +        *)   AC_MSG_ERROR(bad value ${enableval} for --enable-dlog) ;;
32 + esac
33 + ],[USE_DLOG=no])
34 +
35 +if test "x$USE_DLOG" = "xyes"; then
36 +       PKG_CHECK_MODULES(DLOG, dlog)
37 +       AC_SUBST(DLOG_CFLAGS)
38 +       AC_SUBST(DLOG_LIBS)
39 +fi
40 +AM_CONDITIONAL(USE_DLOG, test "x$USE_DLOG" = "xyes")
41 +dnl end --------------------------------------------------------------------
42 +
43  #### atomic-ops ####
44  
45  AC_MSG_CHECKING([whether we need libatomic_ops])
46 diff --git a/src/Makefile.am b/src/Makefile.am
47 index ae841e3..3e41300 100644
48 --- a/src/Makefile.am
49 +++ b/src/Makefile.am
50 @@ -172,6 +172,10 @@ else
51  pulseaudio_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(IMMEDIATE_LDFLAGS) -dlopen force $(foreach f,$(PREOPEN_LIBS),-dlopen $(f))
52  endif
53  
54 +if USE_DLOG
55 +pulseaudio_CFLAGS += -DUSE_DLOG
56 +endif
57 +
58  ###################################
59  #       Utility programs          #
60  ###################################
61 @@ -740,6 +744,11 @@ libpulsecommon_@PA_MAJORMINOR@_la_CFLAGS += $(DBUS_CFLAGS)
62  libpulsecommon_@PA_MAJORMINOR@_la_LIBADD += $(DBUS_LIBS)
63  endif
64  
65 +if USE_DLOG
66 +libpulsecommon_@PA_MAJORMINOR@_la_CFLAGS += $(DLOG_CFLAGS) -DUSE_DLOG
67 +libpulsecommon_@PA_MAJORMINOR@_la_LIBADD += $(DLOG_LIBS)
68 +endif
69 +
70  ###################################
71  #         Client library          #
72  ###################################
73 diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c
74 index 68579c5..5bb1a0a 100644
75 --- a/src/daemon/cmdline.c
76 +++ b/src/daemon/cmdline.c
77 @@ -140,8 +140,12 @@ void pa_cmdline_help(const char *argv0) {
78             "      --scache-idle-time=SECS           Unload autoloaded samples when idle and\n"
79             "                                        this time passed\n"
80             "      --log-level[=LEVEL]               Increase or set verbosity level\n"
81 -           "  -v  --verbose                         Increase the verbosity level\n"
82 +           "  -v                                    Increase the verbosity level\n"
83 +#ifdef USE_DLOG
84 +           "      --log-target={auto,syslog,stderr,file:PATH,newfile:PATH,dlog,dlog-color}\n"
85 +#else
86             "      --log-target={auto,syslog,stderr,file:PATH,newfile:PATH}\n"
87 +#endif
88             "                                        Specify the log target\n"
89             "      --log-meta[=BOOL]                 Include code location in log messages\n"
90             "      --log-time[=BOOL]                 Include timestamps in log messages\n"
91 @@ -325,6 +329,8 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
92                  if (pa_daemon_conf_set_log_target(conf, optarg) < 0) {
93  #ifdef HAVE_JOURNAL
94                      pa_log(_("Invalid log target: use either 'syslog', 'journal','stderr' or 'auto' or a valid file name 'file:<path>', 'newfile:<path>'."));
95 +#elif defined(USE_DLOG)
96 +                    pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto' or a valid file name 'file:<path>', 'newfile:<path>' or 'dlog' or 'dlog-color'."));
97  #else
98                      pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto' or a valid file name 'file:<path>', 'newfile:<path>'."));
99  #endif
100 diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
101 index ce777a6..1dde213 100644
102 --- a/src/daemon/daemon-conf.c
103 +++ b/src/daemon/daemon-conf.c
104 @@ -188,9 +188,17 @@ int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
105  
106          if (!log_target)
107              return -1;
108 +
109 +        c->log_target = log_target;
110      }
111  
112 -    c->log_target = log_target;
113 +#ifdef USE_DLOG
114 +    else if (!strcmp(string, "dlog")) {
115 +        c->log_target = PA_LOG_DLOG;
116 +    } else if (!strcmp(string, "dlog-color")) {
117 +        c->log_target = PA_LOG_DLOG_COLOR;
118 +    }
119 +#endif
120  
121      return 0;
122  }
123 diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
124 index 8c956ac..2497b41 100644
125 --- a/src/pulsecore/cli-command.c
126 +++ b/src/pulsecore/cli-command.c
127 @@ -188,7 +188,11 @@ static const struct command commands[] = {
128      { "kill-client",             pa_cli_command_kill_client,        "Kill a client (args: index)", 2},
129      { "kill-sink-input",         pa_cli_command_kill_sink_input,    "Kill a sink input (args: index)", 2},
130      { "kill-source-output",      pa_cli_command_kill_source_output, "Kill a source output (args: index)", 2},
131 +#ifdef USE_DLOG
132 +    { "set-log-target",          pa_cli_command_log_target,         "Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH|dlog|dlog-color)", 2},
133 +#else
134      { "set-log-target",          pa_cli_command_log_target,         "Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH)", 2},
135 +#endif
136      { "set-log-level",           pa_cli_command_log_level,          "Change the log level (args: numeric level)", 2},
137      { "set-log-meta",            pa_cli_command_log_meta,           "Show source code location in log messages (args: bool)", 2},
138      { "set-log-time",            pa_cli_command_log_time,           "Show timestamps in log messages (args: bool)", 2},
139 @@ -1508,7 +1512,11 @@ static int pa_cli_command_log_target(pa_core *c, pa_tokenizer *t, pa_strbuf *buf
140      pa_assert(fail);
141  
142      if (!(m = pa_tokenizer_get(t, 1))) {
143 +#ifdef USE_DLOG
144 +        pa_strbuf_puts(buf, "You need to specify a log target (null|auto|syslog|stderr|file:PATH|newfile:PATH|dlog|dlog-color).\n");
145 +#else
146          pa_strbuf_puts(buf, "You need to specify a log target (null|auto|syslog|stderr|file:PATH|newfile:PATH).\n");
147 +#endif
148          return -1;
149      }
150  
151 diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
152 index cf96dce..dfb1d0f 100644
153 --- a/src/pulsecore/log.c
154 +++ b/src/pulsecore/log.c
155 @@ -61,6 +61,27 @@
156  
157  #include "log.h"
158  
159 +#ifdef USE_DLOG
160 +#include <dlog.h>
161 +#define        DLOG_TAG        "PULSEAUDIO"
162 +
163 +#define COLOR_BLACK            30
164 +#define COLOR_RED              31
165 +#define COLOR_GREEN            32
166 +#define COLOR_BLUE             34
167 +#define COLOR_MAGENTA          35
168 +#define COLOR_CYAN             36
169 +#define COLOR_WHITE            97
170 +#define COLOR_B_GRAY           100
171 +#define COLOR_B_RED            101
172 +#define COLOR_B_GREEN          102
173 +#define COLOR_B_YELLOW         103
174 +#define COLOR_B_BLUE           104
175 +#define COLOR_B_MAGENTA        105
176 +#define COLOR_B_CYAN           106
177 +#define COLOR_REVERSE          7
178 +
179 +#endif
180  #define ENV_LOG_SYSLOG "PULSE_LOG_SYSLOG"
181  #define ENV_LOG_LEVEL "PULSE_LOG"
182  #define ENV_LOG_COLORS "PULSE_LOG_COLORS"
183 @@ -545,6 +566,74 @@ void pa_log_levelv_meta(
184  
185                  break;
186              }
187 +
188 +#ifdef USE_DLOG
189 +            case PA_LOG_DLOG: {
190 +                char *local_t;
191 +
192 +                openlog(ident, LOG_PID, LOG_USER);
193 +
194 +                if ((local_t = pa_utf8_to_locale(t)))
195 +                    t = local_t;
196 +
197 +                switch (level)
198 +                {
199 +                                       case PA_LOG_DEBUG:
200 +                                               SLOG (LOG_DEBUG, DLOG_TAG, "%s%s%s%s",  timestamp, location, t, pa_strempty(bt));
201 +                                               break;
202 +                                       case PA_LOG_INFO:
203 +                                       case PA_LOG_NOTICE:     // no notice category in dlog, use info instead.
204 +                                               SLOG (LOG_INFO, DLOG_TAG, "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
205 +                                               break;
206 +                                       case PA_LOG_WARN:
207 +                                               SLOG (LOG_WARN, DLOG_TAG, "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
208 +                                               break;
209 +                                       case PA_LOG_ERROR:
210 +                                               SLOG (LOG_ERROR, DLOG_TAG, "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
211 +                                               break;
212 +                                       default:
213 +                                               SLOG (LOG_DEBUG, DLOG_TAG, "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
214 +                                               break;
215 +                }
216 +
217 +                pa_xfree(local_t);
218 +
219 +                break;
220 +            }
221 +            case PA_LOG_DLOG_COLOR: {
222 +                               char *local_t;
223 +
224 +                               openlog(ident, LOG_PID, LOG_USER);
225 +
226 +                               if ((local_t = pa_utf8_to_locale(t)))
227 +                                       t = local_t;
228 +
229 +                               switch (level)
230 +                               {
231 +                                       case PA_LOG_DEBUG:
232 +                                               SLOG (LOG_DEBUG, DLOG_TAG, "\033[%dm%s%s%s%s\033[0m", COLOR_GREEN, timestamp, location, t, pa_strempty(bt));
233 +                                               break;
234 +                                       case PA_LOG_INFO:
235 +                                       case PA_LOG_NOTICE:     // no notice category in dlog, use info instead.
236 +                                               SLOG (LOG_INFO, DLOG_TAG, "\033[%dm%s%s%s%s\033[0m", COLOR_BLUE, timestamp, location, t, pa_strempty(bt));
237 +                                               break;
238 +                                       case PA_LOG_WARN:
239 +                                               SLOG (LOG_WARN, DLOG_TAG, "\033[%dm%s%s%s%s\033[0m", COLOR_MAGENTA, timestamp, location, t, pa_strempty(bt));
240 +                                               break;
241 +                                       case PA_LOG_ERROR:
242 +                                               SLOG (LOG_ERROR, DLOG_TAG, "\033[%dm%s%s%s%s\033[0m", COLOR_RED, timestamp, location, t, pa_strempty(bt));
243 +                                               break;
244 +                                       default:
245 +                                               SLOG (LOG_DEBUG, DLOG_TAG, "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
246 +                                               break;
247 +                               }
248 +
249 +                               pa_xfree(local_t);
250 +
251 +                               break;
252 +                       }
253 +
254 +#endif
255              case PA_LOG_NULL:
256              default:
257                  break;
258 @@ -629,6 +718,12 @@ pa_log_target *pa_log_parse_target(const char *string) {
259          t = pa_log_target_new(PA_LOG_FILE, string + 5);
260      else if (pa_startswith(string, "newfile:"))
261          t = pa_log_target_new(PA_LOG_NEWFILE, string + 8);
262 +#ifdef USE_DLOG
263 +    else if (pa_streq(string, "dlog"))
264 +        t = pa_log_target_new(PA_LOG_DLOG, NULL);
265 +    else if (pa_streq(string, "dlog-color"))
266 +        t = pa_log_target_new(PA_LOG_DLOG_COLOR, NULL);
267 +#endif
268      else
269          pa_log(_("Invalid log target."));
270  
271 diff --git a/src/pulsecore/log.h b/src/pulsecore/log.h
272 index 5e9611d..031040f 100644
273 --- a/src/pulsecore/log.h
274 +++ b/src/pulsecore/log.h
275 @@ -41,6 +41,10 @@ typedef enum pa_log_target_type {
276      PA_LOG_NULL,        /* to /dev/null */
277      PA_LOG_FILE,        /* to a user specified file */
278      PA_LOG_NEWFILE,     /* with an automatic suffix to avoid overwriting anything */
279 +#ifdef USE_DLOG
280 +    PA_LOG_DLOG,
281 +    PA_LOG_DLOG_COLOR,
282 +#endif
283  } pa_log_target_type_t;
284  
285  typedef enum pa_log_level {