]> git.tuebingen.mpg.de Git - paraslash.git/blob - para.h
6c853611e381f2ef2a8aef954746520107d16b3a
[paraslash.git] / para.h
1 /*
2  * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 /** \file para.h global paraslash definitions */
20
21 #include "config.h"
22
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <sys/wait.h>
26 #include <signal.h>
27 #include <sys/signal.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <time.h> /* time(), localtime() */
32 #include <unistd.h>
33 #include <errno.h>
34 #include <limits.h>
35 #include <stdarg.h>
36 #include <stropts.h>
37 #include <poll.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <ctype.h>
42 #include <sys/un.h> /* needed by create_pf_socket */
43 #include "gcc-compat.h"
44
45 /* some internal constants */
46 #define STRINGSIZE 4096
47 #define MAXLINE 255
48
49
50 #define MIN(a,b) ((a) < (b) ? (a) : (b))
51 #define MAX(a,b) ((a) > (b) ? (a) : (b))
52 #define ABS(a) ((a) > 0 ? (a) : -(a))
53
54 /* Loglevels */
55 #define DEBUG 1
56 #define INFO  2
57 #define NOTICE 3
58 #define WARNING 4
59 #define ERROR 5
60 #define CRIT 6
61 #define EMERG 7
62
63
64 #define COMPILE_TIME_LOGLEVEL 0
65 #if DEBUG > COMPILE_TIME_LOGLEVEL
66 #define PARA_DEBUG_LOG(f,...) para_log(DEBUG, "%s: " f, __FUNCTION__, __VA_ARGS__)
67 #else
68 #define PARA_DEBUG_LOG(...)
69 #endif
70
71 #if INFO > COMPILE_TIME_LOGLEVEL
72 #define PARA_INFO_LOG(f,...) para_log(INFO, "%s: " f, __FUNCTION__, __VA_ARGS__)
73 #else
74 #define PARA_INFO_LOG(...)
75 #endif
76
77 #if NOTICE > COMPILE_TIME_LOGLEVEL
78 #define PARA_NOTICE_LOG(f,...) para_log(NOTICE, "%s: " f, __FUNCTION__, __VA_ARGS__)
79 #else
80 #define PARA_NOTICE_LOG(...)
81 #endif
82
83 #if WARNING > COMPILE_TIME_LOGLEVEL
84 #define PARA_WARNING_LOG(f,...) para_log(WARNING, "%s: " f, __FUNCTION__, __VA_ARGS__)
85 #else
86 #define PARA_WARNING_LOG(...)
87 #endif
88
89 #if ERROR > COMPILE_TIME_LOGLEVEL
90 #define PARA_ERROR_LOG(f,...) para_log(ERROR, "%s: " f, __FUNCTION__, __VA_ARGS__)
91 #else
92 #define PARA_ERROR_LOG(...)
93 #endif
94
95 #if CRIT > COMPILE_TIME_LOGLEVEL
96 #define PARA_CRIT_LOG(f,...) para_log(CRIT, "%s: " f, __FUNCTION__, __VA_ARGS__)
97 #else
98 #define PARA_CRIT_LOG(...)
99 #endif
100
101 #if EMERG > COMPILE_TIME_LOGLEVEL
102 #define PARA_EMERG_LOG(f,...) para_log(EMERG, "%s: " f, __FUNCTION__, __VA_ARGS__)
103 #else
104 #define PARA_EMERG_LOG(...)
105 #endif
106
107 #define COPYRIGHT "Copyright (c) 1997-2006 by Andre Noll"
108
109 #define LICENSE "This is free software with ABSOLUTELY NO WARRANTY. " \
110         "See COPYING for details."
111
112 #define AWAITING_DATA_MSG "\nAwaiting Data."
113 #define PROCEED_MSG "\nProceed.\n"
114 #define PROCEED_MSG_LEN strlen(PROCEED_MSG)
115 #define EOC_MSG "\nEnd of Command."
116 #define CHALLENGE_RESPONSE_MSG "challenge_response:"
117
118 /* gui_common */
119 int para_open_audiod_pipe(char *);
120 int read_audiod_pipe(int, void (*)(char *));
121
122 /* exec */
123 int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds);
124
125 /* signal */
126 int para_signal_init(void);
127 int para_install_sighandler(int);
128 void para_reap_children(void);
129 pid_t para_reap_child(void);
130 int para_next_signal(void);
131
132 /* time */
133 int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff);
134 long unsigned tv2ms(const struct timeval*);
135 void d2tv(double, struct timeval*);
136 void tv_add(const struct timeval*, const struct timeval *, struct timeval *);
137 void tv_scale(const unsigned long, const struct timeval *, struct timeval *);
138 void tv_divide(const unsigned long div, const struct timeval *tv,
139         struct timeval *result);
140 int tv_convex_combination(const long a, const struct timeval *tv1,
141                 const long b, const struct timeval *tv2,
142                 struct timeval *result);
143 void ms2tv(const long unsigned n, struct timeval *tv);
144
145 /* stat */
146 enum {
147         SI_STATUS_BAR,          SI_STATUS,              SI_NUM_PLAYED,
148         SI_MTIME,               SI_LENGTH_MIN,          SI_LENGTH_SEC,
149         SI_FILE_SIZE,           SI_STATUS_FLAGS,        SI_FORMAT,
150         SI_SCORE,               SI_AUDIO_INFO1,         SI_AUDIO_INFO2,
151         SI_AUDIO_INFO3,         SI_DBINFO1,             SI_DBINFO2,
152         SI_DBINFO3,             SI_DECODER_FLAGS,       SI_AUDIOD_STATUS,
153         SI_PLAY_TIME,           SI_UPTIME,              SI_OFFSET,
154         SI_LENGTH,              SI_STREAM_START,        SI_CURRENT_TIME,
155         SI_AUDIOD_UPTIME,       SI_SELECTOR,            NUM_STAT_ITEMS
156 };
157
158 int stat_item_valid(const char *item);
159 int stat_line_valid(const char *);
160 void stat_client_write(char *msg, int itemnum);
161 int stat_client_add(int fd, long unsigned mask);
162 void dump_empty_status(void);
163 unsigned for_each_line(char *, int, void (*)(char *));
164
165 struct stat_item_data {
166         const char *prefix, *postfix;
167         unsigned x, y, len;
168         int fg, bg, align;
169 };
170
171 /* gui_theme */
172 struct gui_theme {
173         const char *name;
174         const char *author;
175         int sb_fg, sb_bg;
176         int cmd_fg, cmd_bg;
177         int output_fg, output_bg;
178         int msg_fg, msg_bg;
179         int err_msg_fg, err_msg_bg;
180         int welcome_fg, welcome_bg;
181         int sep_fg, sep_bg;
182         const char *sep_str;
183         int default_fg, default_bg;
184
185         int top_lines_default, top_lines_min;
186         int lines_min, cols_min;
187         struct stat_item_data data[NUM_STAT_ITEMS];
188 };
189
190 void init_theme(int i, struct gui_theme *);
191 void next_theme(struct gui_theme *);
192 void prev_theme(struct gui_theme *);
193 #define LEFT 1
194 #define RIGHT 2
195 #define CENTER 3
196
197
198 __printf_2_3 void para_log(int, const char*, ...);
199
200 /* taken from printf man page */
201 #define PARA_VSPRINTF(fmt, p) \
202 { \
203         int n, size = 100; \
204         p = para_malloc(size); \
205         while (1) { \
206                 va_list ap; \
207                 /* Try to print in the allocated space. */ \
208                 va_start(ap, fmt); \
209                 n = vsnprintf(p, size, fmt, ap); \
210                 va_end(ap); \
211                 /* If that worked, return the string. */ \
212                 if (n > -1 && n < size) \
213                         break; \
214                 /* Else try again with more space. */ \
215                 if (n > -1) /* glibc 2.1 */ \
216                         size = n + 1; /* precisely what is needed */ \
217                 else /* glibc 2.0 */ \
218                         size *= 2; /* twice the old size */ \
219                 p = para_realloc(p, size); \
220         } \
221 }
222
223
224