2 * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file para.h global paraslash definitions */
28 #include <time.h> /* time(), localtime() */
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #include <sys/socket.h>
37 #include <sys/un.h> /* needed by create_pf_socket */
39 #include "gcc-compat.h"
41 /* some internal constants */
42 #define STRINGSIZE 4096
46 #define PARA_MIN(a,b) ((a) < (b) ? (a) : (b))
47 #define PARA_MAX(a,b) ((a) > (b) ? (a) : (b))
48 #define PARA_ABS(a) ((a) > 0 ? (a) : -(a))
60 #define COMPILE_TIME_LOGLEVEL 0
61 #if DEBUG > COMPILE_TIME_LOGLEVEL
62 #define PARA_DEBUG_LOG(f,...) para_log(DEBUG, "%s: " f, __FUNCTION__, __VA_ARGS__)
64 #define PARA_DEBUG_LOG(...) do {;} while (0)
67 #if INFO > COMPILE_TIME_LOGLEVEL
68 #define PARA_INFO_LOG(f,...) para_log(INFO, "%s: " f, __FUNCTION__, __VA_ARGS__)
70 #define PARA_INFO_LOG(...) do {;} while (0)
73 #if NOTICE > COMPILE_TIME_LOGLEVEL
74 #define PARA_NOTICE_LOG(f,...) para_log(NOTICE, "%s: " f, __FUNCTION__, __VA_ARGS__)
76 #define PARA_NOTICE_LOG(...) do {;} while (0)
79 #if WARNING > COMPILE_TIME_LOGLEVEL
80 #define PARA_WARNING_LOG(f,...) para_log(WARNING, "%s: " f, __FUNCTION__, __VA_ARGS__)
82 #define PARA_WARNING_LOG(...) do {;} while (0)
85 #if ERROR > COMPILE_TIME_LOGLEVEL
86 #define PARA_ERROR_LOG(f,...) para_log(ERROR, "%s: " f, __FUNCTION__, __VA_ARGS__)
88 #define PARA_ERROR_LOG(...) do {;} while (0)
91 #if CRIT > COMPILE_TIME_LOGLEVEL
92 #define PARA_CRIT_LOG(f,...) para_log(CRIT, "%s: " f, __FUNCTION__, __VA_ARGS__)
94 #define PARA_CRIT_LOG(...) do {;} while (0)
97 #if EMERG > COMPILE_TIME_LOGLEVEL
98 #define PARA_EMERG_LOG(f,...) para_log(EMERG, "%s: " f, __FUNCTION__, __VA_ARGS__)
100 #define PARA_EMERG_LOG(...)
104 * define a standard log function that always writes to stderr
106 * \param loglevel_barier If the loglevel of the current message
107 * is less than that, the message is going to be ignored.
110 #define INIT_STDERR_LOGGING(loglevel_barrier) \
111 __printf_2_3 void para_log(int ll, const char* fmt,...) \
114 if (ll < loglevel_barrier) \
116 va_start(argp, fmt); \
117 vfprintf(stderr, fmt, argp); \
122 #define COPYRIGHT "Copyright (c) 1997-2006 by Andre Noll"
124 #define LICENSE "This is free software with ABSOLUTELY NO WARRANTY. " \
125 "See COPYING for details."
127 #define AWAITING_DATA_MSG "\nAwaiting Data."
128 #define PROCEED_MSG "\nProceed.\n"
129 #define PROCEED_MSG_LEN strlen(PROCEED_MSG)
130 #define EOC_MSG "\nEnd of Command."
131 #define CHALLENGE_RESPONSE_MSG "challenge_response:"
134 int para_open_audiod_pipe(char *);
135 int read_audiod_pipe(int, void (*)(char *));
138 int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds);
141 int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff);
142 long unsigned tv2ms(const struct timeval*);
143 void d2tv(double, struct timeval*);
144 void tv_add(const struct timeval*, const struct timeval *, struct timeval *);
145 void tv_scale(const unsigned long, const struct timeval *, struct timeval *);
146 void tv_divide(const unsigned long divisor, const struct timeval *tv,
147 struct timeval *result);
148 int tv_convex_combination(const long a, const struct timeval *tv1,
149 const long b, const struct timeval *tv2,
150 struct timeval *result);
151 void ms2tv(const long unsigned n, struct timeval *tv);
155 SI_STATUS_BAR, SI_STATUS, SI_NUM_PLAYED,
156 SI_MTIME, SI_LENGTH_MIN, SI_LENGTH_SEC,
157 SI_FILE_SIZE, SI_STATUS_FLAGS, SI_FORMAT,
158 SI_SCORE, SI_AUDIO_INFO1, SI_AUDIO_INFO2,
159 SI_AUDIO_INFO3, SI_DBINFO1, SI_DBINFO2,
160 SI_DBINFO3, SI_DECODER_FLAGS, SI_AUDIOD_STATUS,
161 SI_PLAY_TIME, SI_UPTIME, SI_OFFSET,
162 SI_LENGTH, SI_STREAM_START, SI_CURRENT_TIME,
163 SI_AUDIOD_UPTIME, SI_SELECTOR, NUM_STAT_ITEMS
166 int stat_item_valid(const char *item);
167 int stat_line_valid(const char *);
168 void stat_client_write(char *msg, int itemnum);
169 int stat_client_add(int fd, long unsigned mask);
170 unsigned for_each_line(char *, int, void (*)(char *));
171 #define FOR_EACH_STAT_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++)
173 struct stat_item_data {
174 const char *prefix, *postfix;
185 int output_fg, output_bg;
187 int err_msg_fg, err_msg_bg;
188 int welcome_fg, welcome_bg;
191 int default_fg, default_bg;
193 int top_lines_default, top_lines_min;
194 int lines_min, cols_min;
195 struct stat_item_data data[NUM_STAT_ITEMS];
198 void init_theme(int i, struct gui_theme *);
199 void next_theme(struct gui_theme *);
200 void prev_theme(struct gui_theme *);
206 __printf_2_3 void para_log(int, const char*, ...);
208 /* taken from printf man page */
209 #define PARA_VSPRINTF(fmt, p) \
212 p = para_malloc(size); \
215 /* Try to print in the allocated space. */ \
217 n = vsnprintf(p, size, fmt, ap); \
219 /* If that worked, return the string. */ \
220 if (n > -1 && n < size) \
222 /* Else try again with more space. */ \
223 if (n > -1) /* glibc 2.1 */ \
224 size = n + 1; /* precisely what is needed */ \
225 else /* glibc 2.0 */ \
226 size *= 2; /* twice the old size */ \
227 p = para_realloc(p, size); \