Check if the file could be modified, error if not.
[Rockbox.git] / apps / plugin.h
blob2604cae4f94cd0f9e2f62016ef736d5cb59cb4d1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef _PLUGIN_H_
20 #define _PLUGIN_H_
22 /* instruct simulator code to not redefine any symbols when compiling plugins.
23 (the PLUGIN macro is defined in apps/plugins/Makefile) */
24 #ifdef PLUGIN
25 #define NO_REDEFINES_PLEASE
26 #endif
28 #ifndef MEM
29 #define MEM 2
30 #endif
32 #include <stdbool.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <sys/types.h>
36 #include "config.h"
37 #include "dir.h"
38 #include "kernel.h"
39 #include "button.h"
40 #include "font.h"
41 #include "system.h"
42 #include "lcd.h"
43 #include "id3.h"
44 #include "mpeg.h"
45 #include "audio.h"
46 #include "mp3_playback.h"
47 #if (HWCODEC == MASNONE)
48 #include "pcm_playback.h"
49 #endif
50 #include "settings.h"
51 #include "thread.h"
52 #include "playlist.h"
53 #ifdef HAVE_LCD_BITMAP
54 #include "widgets.h"
55 #endif
56 #include "sound.h"
58 #ifdef HAVE_REMOTE_LCD
59 #include "lcd-remote.h"
60 #endif
62 #ifdef PLUGIN
63 #if defined(DEBUG) || defined(SIMULATOR)
64 #undef DEBUGF
65 #define DEBUGF rb->debugf
66 #undef LDEBUGF
67 #define LDEBUGF rb->debugf
68 #else
69 #define DEBUGF(...)
70 #define LDEBUGF(...)
71 #endif
72 #endif
74 #ifdef SIMULATOR
75 #define PREFIX(_x_) sim_ ## _x_
76 #else
77 #define PREFIX(_x_) _x_
78 #endif
80 /* increase this every time the api struct changes */
81 #define PLUGIN_API_VERSION 39
83 /* update this to latest version if a change to the api struct breaks
84 backwards compatibility (and please take the opportunity to sort in any
85 new function which are "waiting" at the end of the function table) */
86 #define PLUGIN_MIN_API_VERSION 32
88 /* plugin return codes */
89 enum plugin_status {
90 PLUGIN_OK = 0,
91 PLUGIN_USB_CONNECTED,
93 PLUGIN_WRONG_API_VERSION = -1,
94 PLUGIN_WRONG_MODEL = -2,
95 PLUGIN_ERROR = -3,
98 /* different (incompatible) plugin models */
99 enum model {
100 PLAYER,
101 RECORDER
104 #ifdef HAVE_LCD_CHARCELLS
105 #define MODEL PLAYER
106 #else
107 #define MODEL RECORDER
108 #endif
110 /* compatibility test macro */
111 #define TEST_PLUGIN_API(_api_) \
112 do { \
113 int _rc_ = _api_->plugin_test(PLUGIN_API_VERSION, MODEL, MEM); \
114 if (_rc_<0) \
115 return _rc_; \
116 } while(0)
118 /* NOTE: To support backwards compatibility, only add new functions at
119 the end of the structure. Every time you add a new function,
120 remember to increase PLUGIN_API_VERSION. If you make changes to the
121 existing APIs then also update PLUGIN_MIN_API_VERSION to current
122 version
124 struct plugin_api {
125 /* these two fields must always be first, to ensure
126 TEST_PLUGIN_API will always work */
127 int version;
128 int (*plugin_test)(int api_version, int model, int memsize);
130 /* lcd */
131 void (*lcd_clear_display)(void);
132 void (*lcd_puts)(int x, int y, const unsigned char *string);
133 void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
134 void (*lcd_stop_scroll)(void);
135 void (*lcd_set_contrast)(int x);
136 #ifdef HAVE_LCD_CHARCELLS
137 void (*lcd_define_pattern)(int which,const char *pattern);
138 unsigned char (*lcd_get_locked_pattern)(void);
139 void (*lcd_unlock_pattern)(unsigned char pat);
140 void (*lcd_putc)(int x, int y, unsigned short ch);
141 void (*lcd_put_cursor)(int x, int y, char cursor_char);
142 void (*lcd_remove_cursor)(void);
143 void (*PREFIX(lcd_icon))(int icon, bool enable);
144 #else
145 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
146 void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
147 void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
148 int style);
149 void (*lcd_bitmap)(const unsigned char *src, int x, int y,
150 int nx, int ny, bool clear);
151 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
152 void (*lcd_clearline)(int x1, int y1, int x2, int y2);
153 void (*lcd_drawpixel)(int x, int y);
154 void (*lcd_clearpixel)(int x, int y);
155 void (*lcd_setfont)(int font);
156 struct font* (*font_get)(int font);
157 void (*lcd_clearrect)(int x, int y, int nx, int ny);
158 void (*lcd_fillrect)(int x, int y, int nx, int ny);
159 void (*lcd_drawrect)(int x, int y, int nx, int ny);
160 void (*lcd_invertrect)(int x, int y, int nx, int ny);
161 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
162 void (*lcd_update)(void);
163 void (*lcd_update_rect)(int x, int y, int width, int height);
164 void (*scrollbar)(int x, int y, int width, int height, int items,
165 int min_shown, int max_shown, int orientation);
166 void (*checkbox)(int x, int y, int width, int height, bool checked);
167 unsigned char* lcd_framebuffer;
168 void (*lcd_blit) (const unsigned char* p_data, int x, int y, int width,
169 int height, int stride);
170 #ifndef SIMULATOR
171 void (*lcd_roll)(int pixels);
172 #endif
173 #endif
174 void (*backlight_on)(void);
175 void (*backlight_off)(void);
176 void (*backlight_set_timeout)(int index);
177 void (*splash)(int ticks, bool center, const char *fmt, ...);
179 #ifdef HAVE_REMOTE_LCD
180 void (*remote_clear_display)(void);
181 void (*remote_puts)(int x, int y, const unsigned char *string);
182 void (*remote_lcd_puts_scroll)(int x, int y, const unsigned char* string);
183 void (*remote_lcd_stop_scroll)(void);
184 void (*remote_set_contrast)(int x);
186 void (*remote_putsxy)(int x, int y, const unsigned char *string);
187 void (*remote_puts_style)(int x, int y, const unsigned char *str, int style);
188 void (*remote_puts_scroll_style)(int x, int y, const unsigned char* string,
189 int style);
190 void (*remote_bitmap)(const unsigned char *src, int x, int y,
191 int nx, int ny, bool clear);
192 void (*remote_drawline)(int x1, int y1, int x2, int y2);
193 void (*remote_clearline)(int x1, int y1, int x2, int y2);
194 void (*remote_drawpixel)(int x, int y);
195 void (*remote_clearpixel)(int x, int y);
196 void (*remote_setfont)(int font);
197 struct font* (*remote_font_get)(int font);
198 void (*remote_clearrect)(int x, int y, int nx, int ny);
199 void (*remote_fillrect)(int x, int y, int nx, int ny);
200 void (*remote_drawrect)(int x, int y, int nx, int ny);
201 void (*remote_invertrect)(int x, int y, int nx, int ny);
202 int (*remote_getstringsize)(const unsigned char *str, int *w, int *h);
203 void (*remote_update)(void);
204 void (*remote_update_rect)(int x, int y, int width, int height);
205 // void (*remote_scrollbar)(int x, int y, int width, int height, int items,
206 // int min_shown, int max_shown, int orientation);
207 //void (*remote_checkbox)(int x, int y, int width, int height, bool checked);
208 void (*remote_backlight_on)(void);
209 void (*remote_backlight_off)(void);
210 unsigned char* lcd_remote_framebuffer;
211 #endif
213 /* button */
214 long (*button_get)(bool block);
215 long (*button_get_w_tmo)(int ticks);
216 int (*button_status)(void);
217 void (*button_clear_queue)(void);
219 /* file */
220 int (*PREFIX(open))(const char* pathname, int flags);
221 int (*close)(int fd);
222 ssize_t (*read)(int fd, void* buf, size_t count);
223 off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
224 int (*PREFIX(creat))(const char *pathname, mode_t mode);
225 ssize_t (*write)(int fd, const void* buf, size_t count);
226 int (*PREFIX(remove))(const char* pathname);
227 int (*PREFIX(rename))(const char* path, const char* newname);
228 int (*PREFIX(ftruncate))(int fd, off_t length);
229 off_t (*PREFIX(filesize))(int fd);
230 int (*fdprintf)(int fd, const char *fmt, ...);
231 int (*read_line)(int fd, char* buffer, int buffer_size);
232 bool (*settings_parseline)(char* line, char** name, char** value);
233 #ifndef SIMULATOR
234 int (*ata_sleep)(void);
235 #endif
237 /* dir */
238 DIR* (*PREFIX(opendir))(const char* name);
239 int (*PREFIX(closedir))(DIR* dir);
240 struct dirent* (*PREFIX(readdir))(DIR* dir);
242 /* kernel/ system */
243 void (*PREFIX(sleep))(int ticks);
244 void (*yield)(void);
245 long* current_tick;
246 long (*default_event_handler)(long event);
247 long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
248 int (*create_thread)(void* function, void* stack, int stack_size, const char *name);
249 void (*remove_thread)(int threadnum);
250 void (*reset_poweroff_timer)(void);
251 #ifndef SIMULATOR
252 int (*system_memory_guard)(int newmode);
253 #endif
255 /* strings and memory */
256 int (*snprintf)(char *buf, size_t size, const char *fmt, ...);
257 char* (*strcpy)(char *dst, const char *src);
258 char* (*strncpy)(char *dst, const char *src, size_t length);
259 size_t (*strlen)(const char *str);
260 char * (*strrchr)(const char *s, int c);
261 int (*strcmp)(const char *, const char *);
262 int (*strcasecmp)(const char *, const char *);
263 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
264 void* (*memset)(void *dst, int c, size_t length);
265 void* (*memcpy)(void *out, const void *in, size_t n);
266 const char *_ctype_;
267 int (*atoi)(const char *str);
268 char *(*strchr)(const char *s, int c);
269 char *(*strcat)(char *s1, const char *s2);
270 int (*memcmp)(const void *s1, const void *s2, size_t n);
272 /* sound */
273 void (*sound_set)(int setting, int value);
274 #ifndef SIMULATOR
275 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size));
276 void (*mp3_play_pause)(bool play);
277 void (*mp3_play_stop)(void);
278 bool (*mp3_is_playing)(void);
279 void (*bitswap)(unsigned char *data, int length);
280 #endif
282 /* playback control */
283 void (*PREFIX(audio_play))(int offset);
284 void (*audio_stop)(void);
285 void (*audio_pause)(void);
286 void (*audio_resume)(void);
287 void (*audio_next)(void);
288 void (*audio_prev)(void);
289 void (*audio_ff_rewind)(int newtime);
290 struct mp3entry* (*audio_next_track)(void);
291 int (*playlist_amount)(void);
292 int (*audio_status)(void);
293 bool (*audio_has_changed_track)(void);
294 struct mp3entry* (*audio_current_track)(void);
295 void (*audio_flush_and_reload_tracks)(void);
296 int (*audio_get_file_pos)(void);
297 #if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE)
298 unsigned long (*mpeg_get_last_header)(void);
299 #endif
300 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
301 void (*sound_set_pitch)(int pitch);
302 #endif
304 /* MAS communication */
305 #if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE)
306 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
307 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
308 int (*mas_readreg)(int reg);
309 int (*mas_writereg)(int reg, unsigned int val);
310 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
311 int (*mas_codec_writereg)(int reg, unsigned int val);
312 int (*mas_codec_readreg)(int reg);
313 #endif
314 #endif
316 /* misc */
317 void (*srand)(unsigned int seed);
318 int (*rand)(void);
319 void (*qsort)(void *base, size_t nmemb, size_t size,
320 int(*compar)(const void *, const void *));
321 int (*kbd_input)(char* buffer, int buflen);
322 struct tm* (*get_time)(void);
323 int (*set_time)(const struct tm *tm);
324 void* (*plugin_get_buffer)(int* buffer_size);
325 void* (*plugin_get_audio_buffer)(int* buffer_size);
326 #ifndef SIMULATOR
327 int (*plugin_register_timer)(int cycles, int prio, void (*timer_callback)(void));
328 void (*plugin_unregister_timer)(void);
329 #endif
330 void (*plugin_tsr)(void (*exit_callback)(void));
331 #if defined(DEBUG) || defined(SIMULATOR)
332 void (*debugf)(const char *fmt, ...);
333 #endif
334 struct user_settings* global_settings;
335 bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
336 int (*count_mp3_frames)(int fd, int startpos, int filesize,
337 void (*progressfunc)(int));
338 int (*create_xing_header)(int fd, int startpos, int filesize,
339 unsigned char *buf, int num_frames,
340 unsigned long header_template,
341 void (*progressfunc)(int), bool generate_toc);
342 unsigned long (*find_next_frame)(int fd, long *offset,
343 long max_offset, unsigned long last_header);
344 int (*battery_level)(void);
345 bool (*battery_level_safe)(void);
346 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
347 unsigned short (*peak_meter_scale_value)(unsigned short val,
348 int meterwidth);
349 void (*peak_meter_set_use_dbfs)(int use);
350 int (*peak_meter_get_use_dbfs)(void);
351 #endif
353 /* new stuff at the end, sort into place next time
354 the API gets incompatible */
355 #ifndef SIMULATOR
356 long *cpu_frequency;
357 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
358 void (*cpu_boost)(bool on_off);
359 #endif
360 #endif
361 int (*PREFIX(mkdir))(const char *name, int mode);
362 #if CONFIG_KEYPAD == IRIVER_H100_PAD
363 bool (*button_hold)(void);
364 #endif
365 #if (CONFIG_HWCODEC == MASNONE) && !defined(SIMULATOR)
366 void (*pcm_play_data)(const unsigned char *start, int size,
367 void (*get_more)(unsigned char** start, long*size));
368 void (*pcm_play_stop)(void);
369 void (*pcm_set_frequency)(unsigned int frequency);
370 bool (*pcm_is_playing)(void);
371 void (*pcm_set_volume)(int volume);
372 void (*pcm_play_pause)(bool play);
373 #endif
374 #ifdef HAVE_LCD_BITMAP
375 int (*read_bmp_file)(char* filename, int *get_width, int *get_height,
376 char *bitmap, int maxsize);
377 #endif
378 struct tagdb_header *tagdbheader;
379 int *tagdb_fd;
380 int *tagdb_initialized;
381 int (*tagdb_init) (void);
382 char *(*strcasestr) (const char* phaystack, const char* pneedle);
385 /* defined by the plugin loader (plugin.c) */
386 int plugin_load(const char* plugin, void* parameter);
387 void* plugin_get_buffer(int *buffer_size);
388 void* plugin_get_audio_buffer(int *buffer_size);
389 int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void));
390 void plugin_unregister_timer(void);
391 void plugin_tsr(void (*exit_callback)(void));
393 /* defined by the plugin */
394 enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)
395 __attribute__ ((section (".entry")));
397 #endif