Fix FS#12606 - next track can cause the screen to be cleared
[maemo-rb.git] / apps / plugin.h
blob8123414ff075eb4cf6bddc324d31e907e90647ce
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _PLUGIN_H_
22 #define _PLUGIN_H_
24 /* instruct simulator code to not redefine any symbols when compiling plugins.
25 (the PLUGIN macro is defined in apps/plugins/Makefile) */
26 #ifdef PLUGIN
27 #define NO_REDEFINES_PLEASE
28 #endif
30 #include <stdbool.h>
31 #include <inttypes.h>
32 #include <sys/types.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include "string-extra.h"
38 #include "gcc_extensions.h"
42 /* on some platforms strcmp() seems to be a tricky define which
43 * breaks if we write down strcmp's prototype */
44 #undef strcmp
45 #undef strncmp
46 #undef strchr
48 char* strncpy(char *, const char *, size_t);
49 void* plugin_get_buffer(size_t *buffer_size);
51 #ifndef __PCTOOL__
52 #include "config.h"
53 #include "system.h"
54 #include "dir.h"
55 #include "general.h"
56 #include "kernel.h"
57 #include "thread.h"
58 #include "button.h"
59 #include "action.h"
60 #include "load_code.h"
61 #include "usb.h"
62 #include "font.h"
63 #include "lcd.h"
64 #include "metadata.h"
65 #include "sound.h"
66 #include "mpeg.h"
67 #include "audio.h"
68 #include "mp3_playback.h"
69 #include "talk.h"
70 #ifdef RB_PROFILE
71 #include "profile.h"
72 #endif
73 #include "misc.h"
74 #include "filefuncs.h"
75 #if (CONFIG_CODEC == SWCODEC)
76 #include "pcm_mixer.h"
77 #include "dsp-util.h"
78 #include "dsp.h"
79 #include "codecs.h"
80 #include "playback.h"
81 #include "codec_thread.h"
82 #ifdef HAVE_RECORDING
83 #include "recording.h"
84 #endif
85 #else
86 #include "mas35xx.h"
87 #endif /* CONFIG_CODEC == SWCODEC */
88 #include "settings.h"
89 #include "timer.h"
90 #include "playlist.h"
91 #ifdef HAVE_LCD_BITMAP
92 #include "screendump.h"
93 #include "scrollbar.h"
94 #include "jpeg_load.h"
95 #include "../recorder/bmp.h"
96 #endif
97 #include "statusbar.h"
98 #include "menu.h"
99 #include "rbunicode.h"
100 #include "list.h"
101 #include "tree.h"
102 #include "color_picker.h"
103 #include "buflib.h"
104 #include "buffering.h"
105 #include "tagcache.h"
106 #include "viewport.h"
107 #include "ata_idle_notify.h"
108 #include "settings_list.h"
109 #include "timefuncs.h"
110 #include "crc32.h"
111 #include "rbpaths.h"
113 #ifdef HAVE_ALBUMART
114 #include "albumart.h"
115 #endif
117 #ifdef HAVE_REMOTE_LCD
118 #include "lcd-remote.h"
119 #endif
121 #include "yesno.h"
123 #include "filetypes.h"
125 #ifdef USB_ENABLE_HID
126 #include "usbstack/usb_hid_usage_tables.h"
127 #endif
130 #ifdef PLUGIN
132 #if defined(DEBUG) || defined(SIMULATOR)
133 #undef DEBUGF
134 #define DEBUGF rb->debugf
135 #undef LDEBUGF
136 #define LDEBUGF rb->debugf
137 #else
138 #undef DEBUGF
139 #define DEBUGF(...) do { } while(0)
140 #undef LDEBUGF
141 #define LDEBUGF(...) do { } while(0)
142 #endif
144 #ifdef ROCKBOX_HAS_LOGF
145 #undef LOGF
146 #define LOGF rb->logf
147 #else
148 #define LOGF(...)
149 #endif
151 #endif
153 #define PLUGIN_MAGIC 0x526F634B /* RocK */
155 /* increase this every time the api struct changes */
156 #define PLUGIN_API_VERSION 218
158 /* update this to latest version if a change to the api struct breaks
159 backwards compatibility (and please take the opportunity to sort in any
160 new function which are "waiting" at the end of the function table) */
161 #define PLUGIN_MIN_API_VERSION 218
163 /* plugin return codes */
164 /* internal returns start at 0x100 to make exit(1..255) work */
165 #define INTERNAL_PLUGIN_RETVAL_START 0x100
166 enum plugin_status {
167 PLUGIN_OK = 0, /* PLUGIN_OK == EXIT_SUCCESS */
168 /* 1...255 reserved for exit() */
169 PLUGIN_USB_CONNECTED = INTERNAL_PLUGIN_RETVAL_START,
170 PLUGIN_POWEROFF,
171 PLUGIN_GOTO_WPS,
172 PLUGIN_ERROR = -1,
175 /* NOTE: To support backwards compatibility, only add new functions at
176 the end of the structure. Every time you add a new function,
177 remember to increase PLUGIN_API_VERSION. If you make changes to the
178 existing APIs then also update PLUGIN_MIN_API_VERSION to current
179 version
181 struct plugin_api {
183 /* lcd */
185 #ifdef HAVE_LCD_CONTRAST
186 void (*lcd_set_contrast)(int x);
187 #endif
188 void (*lcd_update)(void);
189 void (*lcd_clear_display)(void);
190 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
191 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
192 void (*lcd_putsxyf)(int x, int y, const unsigned char *fmt, ...);
193 void (*lcd_puts)(int x, int y, const unsigned char *string);
194 void (*lcd_putsf)(int x, int y, const unsigned char *fmt, ...);
195 void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
196 void (*lcd_stop_scroll)(void);
197 #ifdef HAVE_LCD_CHARCELLS
198 void (*lcd_define_pattern)(unsigned long ucs, const char *pattern);
199 unsigned long (*lcd_get_locked_pattern)(void);
200 void (*lcd_unlock_pattern)(unsigned long ucs);
201 void (*lcd_putc)(int x, int y, unsigned long ucs);
202 void (*lcd_put_cursor)(int x, int y, unsigned long ucs);
203 void (*lcd_remove_cursor)(void);
204 void (*lcd_icon)(int icon, bool enable);
205 void (*lcd_double_height)(bool on);
206 #else /* HAVE_LCD_BITMAP */
207 fb_data* lcd_framebuffer;
208 void (*lcd_update_rect)(int x, int y, int width, int height);
209 void (*lcd_set_drawmode)(int mode);
210 int (*lcd_get_drawmode)(void);
211 void (*lcd_setfont)(int font);
212 void (*lcd_drawpixel)(int x, int y);
213 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
214 void (*lcd_hline)(int x1, int x2, int y);
215 void (*lcd_vline)(int x, int y1, int y2);
216 void (*lcd_drawrect)(int x, int y, int width, int height);
217 void (*lcd_fillrect)(int x, int y, int width, int height);
218 void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
219 int stride, int x, int y, int width, int height);
220 void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
221 int width, int height);
222 #if LCD_DEPTH > 1
223 void (*lcd_set_foreground)(unsigned foreground);
224 unsigned (*lcd_get_foreground)(void);
225 void (*lcd_set_background)(unsigned foreground);
226 unsigned (*lcd_get_background)(void);
227 void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
228 int stride, int x, int y, int width, int height);
229 void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
230 int height);
231 fb_data* (*lcd_get_backdrop)(void);
232 void (*lcd_set_backdrop)(fb_data* backdrop);
233 #endif
234 #if LCD_DEPTH == 16
235 void (*lcd_bitmap_transparent_part)(const fb_data *src,
236 int src_x, int src_y, int stride,
237 int x, int y, int width, int height);
238 void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
239 int width, int height);
240 #if MEMORYSIZE > 2
241 void (*lcd_blit_yuv)(unsigned char * const src[3],
242 int src_x, int src_y, int stride,
243 int x, int y, int width, int height);
244 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
245 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
246 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2) \
247 || defined(TOSHIBA_GIGABEAT_S) || defined(PHILIPS_SA9200)
248 void (*lcd_yuv_set_options)(unsigned options);
249 #endif
250 #endif /* MEMORYSIZE > 2 */
251 #elif (LCD_DEPTH < 4) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
252 void (*lcd_blit_mono)(const unsigned char *data, int x, int by, int width,
253 int bheight, int stride);
254 void (*lcd_blit_grey_phase)(unsigned char *values, unsigned char *phases,
255 int bx, int by, int bwidth, int bheight,
256 int stride);
257 #endif /* LCD_DEPTH */
258 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
259 void (*lcd_blit_pal256)(unsigned char *src, int src_x, int src_y, int x, int y,
260 int width, int height);
261 void (*lcd_pal256_update_pal)(fb_data *palette);
262 #endif
263 void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
264 void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
265 int style);
266 #ifdef HAVE_LCD_INVERT
267 void (*lcd_set_invert_display)(bool yesno);
268 #endif /* HAVE_LCD_INVERT */
269 #if defined(HAVE_LCD_MODES)
270 void (*lcd_set_mode)(int mode);
271 #endif
273 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
274 struct event_queue *button_queue;
275 #endif
276 unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation );
277 #ifdef HAVE_LCD_BITMAP
278 bool (*is_diacritic)(const unsigned short char_code, bool *is_rtl);
279 #endif
280 const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code );
281 int (*font_load)(const char *path);
282 void (*font_unload)(int font_id);
283 struct font* (*font_get)(int font);
284 int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
285 int fontnumber);
286 int (*font_get_width)(struct font* pf, unsigned short char_code);
287 void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
288 int width, int height);
289 void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
290 int width, int height, int items,
291 int min_shown, int max_shown,
292 unsigned flags);
293 #endif /* HAVE_LCD_BITMAP */
294 const char* (*get_codepage_name)(int cp);
296 /* backlight */
297 /* The backlight_* functions must be present in the API regardless whether
298 * HAVE_BACKLIGHT is defined or not. The reason is that the stock Ondio has
299 * no backlight but can be modded to have backlight (it's prepared on the
300 * PCB). This makes backlight an all-target feature API wise, and keeps API
301 * compatible between stock and modded Ondio.
302 * For OLED targets like the Sansa Clip, the backlight_* functions control
303 * the display enable, which has essentially the same effect. */
304 void (*backlight_on)(void);
305 void (*backlight_off)(void);
306 void (*backlight_set_timeout)(int index);
307 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
308 void (*backlight_set_brightness)(int val);
309 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
311 #if CONFIG_CHARGING
312 void (*backlight_set_timeout_plugged)(int index);
313 #endif
314 bool (*is_backlight_on)(bool ignore_always_off);
315 void (*splash)(int ticks, const char *str);
316 void (*splashf)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
318 #ifdef HAVE_REMOTE_LCD
319 /* remote lcd */
320 void (*lcd_remote_set_contrast)(int x);
321 void (*lcd_remote_clear_display)(void);
322 void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
323 void (*lcd_remote_puts_scroll)(int x, int y, const unsigned char* string);
324 void (*lcd_remote_stop_scroll)(void);
325 void (*lcd_remote_set_drawmode)(int mode);
326 int (*lcd_remote_get_drawmode)(void);
327 void (*lcd_remote_setfont)(int font);
328 int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
329 void (*lcd_remote_drawpixel)(int x, int y);
330 void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
331 void (*lcd_remote_hline)(int x1, int x2, int y);
332 void (*lcd_remote_vline)(int x, int y1, int y2);
333 void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
334 void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
335 void (*lcd_remote_mono_bitmap_part)(const unsigned char *src, int src_x,
336 int src_y, int stride, int x, int y,
337 int width, int height);
338 void (*lcd_remote_mono_bitmap)(const unsigned char *src, int x, int y,
339 int width, int height);
340 void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
341 void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
342 void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
343 int style);
344 fb_remote_data* lcd_remote_framebuffer;
345 void (*lcd_remote_update)(void);
346 void (*lcd_remote_update_rect)(int x, int y, int width, int height);
348 void (*remote_backlight_on)(void);
349 void (*remote_backlight_off)(void);
350 void (*remote_backlight_set_timeout)(int index);
351 #if CONFIG_CHARGING
352 void (*remote_backlight_set_timeout_plugged)(int index);
353 #endif
354 #endif /* HAVE_REMOTE_LCD */
355 struct screen* screens[NB_SCREENS];
356 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
357 void (*lcd_remote_set_foreground)(unsigned foreground);
358 unsigned (*lcd_remote_get_foreground)(void);
359 void (*lcd_remote_set_background)(unsigned background);
360 unsigned (*lcd_remote_get_background)(void);
361 void (*lcd_remote_bitmap_part)(const fb_remote_data *src,
362 int src_x, int src_y, int stride,
363 int x, int y, int width, int height);
364 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y,
365 int width, int height);
366 #endif
367 void (*viewport_set_defaults)(struct viewport *vp,
368 const enum screen_type screen);
369 #ifdef HAVE_LCD_BITMAP
370 void (*viewportmanager_theme_enable)(enum screen_type screen, bool enable,
371 struct viewport *viewport);
372 void (*viewportmanager_theme_undo)(enum screen_type screen, bool force_redraw);
373 #endif
374 /* list */
375 void (*gui_synclist_init)(struct gui_synclist * lists,
376 list_get_name callback_get_item_name, void * data,
377 bool scroll_all,int selected_size,
378 struct viewport parent[NB_SCREENS]);
379 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
380 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists,
381 list_get_icon icon_callback);
382 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
383 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
384 void (*gui_synclist_draw)(struct gui_synclist * lists);
385 void (*gui_synclist_select_item)(struct gui_synclist * lists,
386 int item_number);
387 void (*gui_synclist_add_item)(struct gui_synclist * lists);
388 void (*gui_synclist_del_item)(struct gui_synclist * lists);
389 void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
390 bool (*gui_synclist_do_button)(struct gui_synclist * lists,
391 int *action, enum list_wrap wrap);
392 void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title,
393 enum themable_icons icon);
394 enum yesno_res (*gui_syncyesno_run)(const struct text_message * main_message,
395 const struct text_message * yes_message,
396 const struct text_message * no_message);
397 void (*simplelist_info_init)(struct simplelist_info *info, char* title,
398 int count, void* data);
399 bool (*simplelist_show_list)(struct simplelist_info *info);
401 /* button */
402 long (*button_get)(bool block);
403 long (*button_get_w_tmo)(int ticks);
404 int (*button_status)(void);
405 #ifdef HAVE_BUTTON_DATA
406 intptr_t (*button_get_data)(void);
407 int (*button_status_wdata)(int *pdata);
408 #endif
409 void (*button_clear_queue)(void);
410 int (*button_queue_count)(void);
411 #ifdef HAS_BUTTON_HOLD
412 bool (*button_hold)(void);
413 #endif
414 #ifdef HAVE_TOUCHSCREEN
415 void (*touchscreen_set_mode)(enum touchscreen_mode);
416 enum touchscreen_mode (*touchscreen_get_mode)(void);
417 #endif
418 #ifdef HAVE_BUTTON_LIGHT
419 void (*buttonlight_set_timeout)(int value);
420 void (*buttonlight_off)(void);
421 void (*buttonlight_on)(void);
422 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
423 void (*buttonlight_set_brightness)(int val);
424 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
425 #endif /* HAVE_BUTTON_LIGHT */
427 /* file */
428 int (*open_utf8)(const char* pathname, int flags);
429 int (*open)(const char* pathname, int flags, ...);
430 int (*close)(int fd);
431 ssize_t (*read)(int fd, void* buf, size_t count);
432 off_t (*lseek)(int fd, off_t offset, int whence);
433 int (*creat)(const char *pathname, mode_t mode);
434 ssize_t (*write)(int fd, const void* buf, size_t count);
435 int (*remove)(const char* pathname);
436 int (*rename)(const char* path, const char* newname);
437 int (*ftruncate)(int fd, off_t length);
438 off_t (*filesize)(int fd);
439 int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
440 int (*read_line)(int fd, char* buffer, int buffer_size);
441 bool (*settings_parseline)(char* line, char** name, char** value);
442 void (*storage_sleep)(void);
443 void (*storage_spin)(void);
444 void (*storage_spindown)(int seconds);
445 #if USING_STORAGE_CALLBACK
446 void (*register_storage_idle_func)(void (*function)(void *data));
447 void (*unregister_storage_idle_func)(void (*function)(void *data), bool run);
448 #endif /* USING_STORAGE_CALLBACK */
449 void (*reload_directory)(void);
450 char *(*create_numbered_filename)(char *buffer, const char *path,
451 const char *prefix, const char *suffix,
452 int numberlen IF_CNFN_NUM_(, int *num));
453 bool (*file_exists)(const char *file);
454 char* (*strip_extension)(char* buffer, int buffer_size, const char *filename);
455 unsigned (*crc_32)(const void *src, unsigned len, unsigned crc32);
457 int (*filetype_get_attr)(const char* file);
461 /* dir */
462 DIR* (*opendir)(const char* name);
463 int (*closedir)(DIR* dir);
464 struct dirent* (*readdir)(DIR* dir);
465 int (*mkdir)(const char *name);
466 int (*rmdir)(const char *name);
467 bool (*dir_exists)(const char *path);
468 struct dirinfo (*dir_get_info)(DIR* parent, struct dirent *entry);
470 /* browsing */
471 void (*browse_context_init)(struct browse_context *browse,
472 int dirfilter, unsigned flags,
473 char *title, enum themable_icons icon,
474 const char *root, const char *selected);
475 int (*rockbox_browse)(struct browse_context *browse);
477 /* kernel/ system */
478 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
479 void (*__div0)(void);
480 #endif
481 unsigned (*sleep)(unsigned ticks);
482 void (*yield)(void);
483 volatile long* current_tick;
484 long (*default_event_handler)(long event);
485 long (*default_event_handler_ex)(long event,
486 void (*callback)(void *), void *parameter);
487 unsigned int (*create_thread)(void (*function)(void), void* stack,
488 size_t stack_size, unsigned flags,
489 const char *name
490 IF_PRIO(, int priority)
491 IF_COP(, unsigned int core));
492 unsigned int (*thread_self)(void);
493 void (*thread_exit)(void);
494 void (*thread_wait)(unsigned int thread_id);
495 #if CONFIG_CODEC == SWCODEC
496 void (*thread_thaw)(unsigned int thread_id);
497 #ifdef HAVE_PRIORITY_SCHEDULING
498 int (*thread_set_priority)(unsigned int thread_id, int priority);
499 #endif
500 void (*mutex_init)(struct mutex *m);
501 void (*mutex_lock)(struct mutex *m);
502 void (*mutex_unlock)(struct mutex *m);
503 #endif
505 void (*reset_poweroff_timer)(void);
506 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
507 int (*system_memory_guard)(int newmode);
508 long *cpu_frequency;
509 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
510 #ifdef CPU_BOOST_LOGGING
511 void (*cpu_boost_)(bool on_off,char*location,int line);
512 #else
513 void (*cpu_boost)(bool on_off);
514 #endif
515 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
516 #endif /* PLATFORM_NATIVE */
517 #ifdef HAVE_SCHEDULER_BOOSTCTRL
518 void (*trigger_cpu_boost)(void);
519 void (*cancel_cpu_boost)(void);
520 #endif
522 void (*commit_dcache)(void);
523 void (*commit_discard_dcache)(void);
524 void (*commit_discard_idcache)(void);
526 /* load code api for overlay */
527 void* (*lc_open)(const char *filename, unsigned char *buf, size_t buf_size);
528 void* (*lc_open_from_mem)(void* addr, size_t blob_size);
529 void* (*lc_get_header)(void *handle);
530 void (*lc_close)(void *handle);
532 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
533 long cycles, void (*timer_callback)(void)
534 IF_COP(, int core));
535 void (*timer_unregister)(void);
536 bool (*timer_set_period)(long count);
538 void (*queue_init)(struct event_queue *q, bool register_queue);
539 void (*queue_delete)(struct event_queue *q);
540 void (*queue_post)(struct event_queue *q, long id, intptr_t data);
541 void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
542 int ticks);
543 #if CONFIG_CODEC == SWCODEC
544 void (*queue_enable_queue_send)(struct event_queue *q,
545 struct queue_sender_list *send,
546 unsigned int thread_id);
547 bool (*queue_empty)(const struct event_queue *q);
548 void (*queue_wait)(struct event_queue *q, struct queue_event *ev);
549 intptr_t (*queue_send)(struct event_queue *q, long id,
550 intptr_t data);
551 void (*queue_reply)(struct event_queue *q, intptr_t retval);
552 #endif /* CONFIG_CODEC == SWCODEC */
554 void (*usb_acknowledge)(long id);
555 #ifdef USB_ENABLE_HID
556 void (*usb_hid_send)(usage_page_t usage_page, int id);
557 #endif
558 #ifdef RB_PROFILE
559 void (*profile_thread)(void);
560 void (*profstop)(void);
561 void (*profile_func_enter)(void *this_fn, void *call_site);
562 void (*profile_func_exit)(void *this_fn, void *call_site);
563 #endif
564 /* event api */
565 bool (*add_event)(unsigned short id, bool oneshot, void (*handler)(void *data));
566 void (*remove_event)(unsigned short id, void (*handler)(void *data));
567 void (*send_event)(unsigned short id, void *data);
569 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
570 /* special simulator hooks */
571 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
572 void (*sim_lcd_ex_init)(unsigned long (*getpixel)(int, int));
573 void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
574 #endif
575 #endif
577 /* strings and memory */
578 int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
579 ATTRIBUTE_PRINTF(3, 4);
580 int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list ap);
581 char* (*strcpy)(char *dst, const char *src);
582 size_t (*strlcpy)(char *dst, const char *src, size_t length);
583 size_t (*strlen)(const char *str);
584 char * (*strrchr)(const char *s, int c);
585 int (*strcmp)(const char *, const char *);
586 int (*strncmp)(const char *, const char *, size_t);
587 int (*strcasecmp)(const char *, const char *);
588 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
589 void* (*memset)(void *dst, int c, size_t length);
590 void* (*memcpy)(void *out, const void *in, size_t n);
591 void* (*memmove)(void *out, const void *in, size_t n);
592 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
593 const unsigned char *_rbctype_;
594 #endif
595 int (*atoi)(const char *str);
596 char *(*strchr)(const char *s, int c);
597 char *(*strcat)(char *s1, const char *s2);
598 size_t (*strlcat)(char *dst, const char *src, size_t length);
599 void *(*memchr)(const void *s1, int c, size_t n);
600 int (*memcmp)(const void *s1, const void *s2, size_t n);
601 char *(*strcasestr) (const char* phaystack, const char* pneedle);
602 char* (*strtok_r)(char *ptr, const char *sep, char **end);
603 /* unicode stuff */
604 const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs);
605 unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
606 unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
607 unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
608 unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
609 unsigned long (*utf8length)(const unsigned char *utf8);
610 int (*utf8seek)(const unsigned char* utf8, int offset);
612 /* the buflib memory management library */
613 void (*buflib_init)(struct buflib_context* ctx, void* buf, size_t size);
614 size_t (*buflib_available)(struct buflib_context* ctx);
615 int (*buflib_alloc)(struct buflib_context* ctx, size_t size);
616 int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size,
617 const char* name, struct buflib_callbacks *ops);
618 int (*buflib_alloc_maximum)(struct buflib_context* ctx, const char* name,
619 size_t* size, struct buflib_callbacks *ops);
620 void (*buflib_buffer_in)(struct buflib_context* ctx, int size);
621 void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size);
622 int (*buflib_free)(struct buflib_context* ctx, int handle);
623 bool (*buflib_shrink)(struct buflib_context* ctx, int handle,
624 void* new_start, size_t new_size);
625 void* (*buflib_get_data)(struct buflib_context* ctx, int handle);
626 const char* (*buflib_get_name)(struct buflib_context* ctx, int handle);
628 /* sound */
629 void (*sound_set)(int setting, int value);
630 int (*sound_default)(int setting);
631 int (*sound_min)(int setting);
632 int (*sound_max)(int setting);
633 const char * (*sound_unit)(int setting);
634 int (*sound_val2phys)(int setting, int value);
635 #ifdef AUDIOHW_HAVE_EQ
636 int (*sound_enum_hw_eq_band_setting)(unsigned int band,
637 unsigned int band_setting);
638 #endif /* AUDIOHW_HAVE_EQ */
639 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
640 void (*mp3_play_data)(const void* start, size_t size,
641 mp3_play_callback_t get_more);
642 void (*mp3_play_pause)(bool play);
643 void (*mp3_play_stop)(void);
644 bool (*mp3_is_playing)(void);
645 #if CONFIG_CODEC != SWCODEC
646 void (*bitswap)(unsigned char *data, int length);
647 #endif
648 #endif /* PLATFORM_NATIVE */
649 #if CONFIG_CODEC == SWCODEC
650 const unsigned long *audio_master_sampr_list;
651 const unsigned long *hw_freq_sampr;
652 void (*pcm_apply_settings)(void);
653 void (*pcm_play_data)(pcm_play_callback_type get_more,
654 pcm_status_callback_type status_cb,
655 const void *start, size_t size);
656 void (*pcm_play_stop)(void);
657 void (*pcm_set_frequency)(unsigned int frequency);
658 bool (*pcm_is_playing)(void);
659 bool (*pcm_is_paused)(void);
660 void (*pcm_play_pause)(bool play);
661 size_t (*pcm_get_bytes_waiting)(void);
662 void (*pcm_calculate_peaks)(int *left, int *right);
663 const void* (*pcm_get_peak_buffer)(int *count);
664 void (*pcm_play_lock)(void);
665 void (*pcm_play_unlock)(void);
666 void (*beep_play)(unsigned int frequency, unsigned int duration,
667 unsigned int amplitude);
668 #ifdef HAVE_RECORDING
669 const unsigned long *rec_freq_sampr;
670 void (*pcm_init_recording)(void);
671 void (*pcm_close_recording)(void);
672 void (*pcm_record_data)(pcm_rec_callback_type more_ready,
673 pcm_status_callback_type status_cb,
674 void *start, size_t size);
675 void (*pcm_stop_recording)(void);
676 void (*pcm_calculate_rec_peaks)(int *left, int *right);
677 void (*audio_set_recording_gain)(int left, int right, int type);
678 #endif /* HAVE_RECORDING */
679 #if INPUT_SRC_CAPS != 0
680 void (*audio_set_output_source)(int monitor);
681 void (*audio_set_input_source)(int source, unsigned flags);
682 #endif
683 void (*dsp_set_crossfeed)(bool enable);
684 void (*dsp_set_eq)(bool enable);
685 void (*dsp_dither_enable)(bool enable);
686 intptr_t (*dsp_configure)(struct dsp_config *dsp, int setting,
687 intptr_t value);
688 int (*dsp_process)(struct dsp_config *dsp, char *dest,
689 const char *src[], int count);
690 int (*dsp_input_count)(struct dsp_config *dsp, int count);
691 int (*dsp_output_count)(struct dsp_config *dsp, int count);
693 enum channel_status (*mixer_channel_status)(enum pcm_mixer_channel channel);
694 const void * (*mixer_channel_get_buffer)(enum pcm_mixer_channel channel,
695 int *count);
696 void (*mixer_channel_calculate_peaks)(enum pcm_mixer_channel channel,
697 int *left, int *right);
698 void (*mixer_channel_play_data)(enum pcm_mixer_channel channel,
699 pcm_play_callback_type get_more,
700 const void *start, size_t size);
701 void (*mixer_channel_play_pause)(enum pcm_mixer_channel channel, bool play);
702 void (*mixer_channel_stop)(enum pcm_mixer_channel channel);
703 void (*mixer_channel_set_amplitude)(enum pcm_mixer_channel channel,
704 unsigned int amplitude);
705 size_t (*mixer_channel_get_bytes_waiting)(enum pcm_mixer_channel channel);
707 void (*system_sound_play)(enum system_sound sound);
708 void (*keyclick_click)(bool rawbutton, int action);
709 #endif /* CONFIG_CODEC == SWCODC */
711 /* playback control */
712 int (*playlist_amount)(void);
713 int (*playlist_resume)(void);
714 void (*playlist_start)(int start_index, int offset);
715 int (*playlist_add)(const char *filename);
716 void (*playlist_sync)(struct playlist_info* playlist);
717 int (*playlist_remove_all_tracks)(struct playlist_info *playlist);
718 int (*playlist_create)(const char *dir, const char *file);
719 int (*playlist_insert_track)(struct playlist_info* playlist,
720 const char *filename, int position, bool queue, bool sync);
721 int (*playlist_insert_directory)(struct playlist_info* playlist,
722 const char *dirname, int position, bool queue,
723 bool recurse);
724 int (*playlist_shuffle)(int random_seed, int start_index);
725 void (*audio_play)(long offset);
726 void (*audio_stop)(void);
727 void (*audio_pause)(void);
728 void (*audio_resume)(void);
729 void (*audio_next)(void);
730 void (*audio_prev)(void);
731 void (*audio_ff_rewind)(long newtime);
732 struct mp3entry* (*audio_next_track)(void);
733 int (*audio_status)(void);
734 struct mp3entry* (*audio_current_track)(void);
735 void (*audio_flush_and_reload_tracks)(void);
736 int (*audio_get_file_pos)(void);
737 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
738 unsigned long (*mpeg_get_last_header)(void);
739 #endif
740 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
741 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHSCREEN)
742 void (*sound_set_pitch)(int32_t pitch);
743 #endif
745 /* MAS communication */
746 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
747 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
748 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
749 int (*mas_readreg)(int reg);
750 int (*mas_writereg)(int reg, unsigned int val);
751 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
752 int (*mas_codec_writereg)(int reg, unsigned int val);
753 int (*mas_codec_readreg)(int reg);
754 void (*i2c_begin)(void);
755 void (*i2c_end)(void);
756 int (*i2c_write)(int address, const unsigned char* buf, int count );
757 #endif
758 #endif
760 /* menu */
761 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
762 struct viewport parent[NB_SCREENS], bool hide_theme);
764 /* scroll bar */
765 struct gui_syncstatusbar *statusbars;
766 void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
768 /* options */
769 const struct settings_list* (*get_settings_list)(int*count);
770 const struct settings_list* (*find_setting)(const void* variable, int *id);
771 bool (*option_screen)(const struct settings_list *setting,
772 struct viewport parent[NB_SCREENS],
773 bool use_temp_var, unsigned char* option_title);
774 bool (*set_option)(const char* string, const void* variable,
775 enum optiontype type, const struct opt_items* options,
776 int numoptions, void (*function)(int));
777 bool (*set_bool_options)(const char* string, const bool* variable,
778 const char* yes_str, int yes_voice,
779 const char* no_str, int no_voice,
780 void (*function)(bool));
781 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
782 const int* variable, void (*function)(int), int step,
783 int min, int max,
784 const char* (*formatter)(char*, size_t, int, const char*) );
785 bool (*set_bool)(const char* string, const bool* variable );
787 #ifdef HAVE_LCD_COLOR
788 bool (*set_color)(struct screen *display, char *title,
789 unsigned *color, unsigned banned_color);
790 #endif
791 /* action handling */
792 int (*get_custom_action)(int context,int timeout,
793 const struct button_mapping* (*get_context_map)(int));
794 int (*get_action)(int context, int timeout);
795 #ifdef HAVE_TOUCHSCREEN
796 int (*action_get_touchscreen_press)(short *x, short *y);
797 #endif
798 bool (*action_userabort)(int timeout);
800 /* power */
801 int (*battery_level)(void);
802 bool (*battery_level_safe)(void);
803 int (*battery_time)(void);
804 int (*battery_voltage)(void);
805 #if CONFIG_CHARGING
806 bool (*charger_inserted)(void);
807 # if CONFIG_CHARGING >= CHARGING_MONITOR
808 bool (*charging_state)(void);
809 # endif
810 #endif
811 #ifdef HAVE_USB_POWER
812 bool (*usb_powered)(void);
813 #endif
815 /* misc */
816 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
817 int* __errno;
818 #endif
819 void (*srand)(unsigned int seed);
820 int (*rand)(void);
821 void (*qsort)(void *base, size_t nmemb, size_t size,
822 int(*compar)(const void *, const void *));
823 int (*kbd_input)(char* buffer, int buflen);
824 struct tm* (*get_time)(void);
825 int (*set_time)(const struct tm *tm);
826 #if CONFIG_RTC
827 time_t (*mktime)(struct tm *t);
828 #endif
829 void* (*plugin_get_buffer)(size_t *buffer_size);
830 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
831 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
832 char* (*plugin_get_current_filename)(void);
833 #if defined(DEBUG) || defined(SIMULATOR)
834 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
835 #endif
836 #ifdef ROCKBOX_HAS_LOGF
837 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
838 #endif
839 struct user_settings* global_settings;
840 struct system_status *global_status;
841 void (*talk_disable)(bool disable);
842 #if CONFIG_CODEC == SWCODEC
843 void (*codec_thread_do_callback)(void (*fn)(void),
844 unsigned int *audio_thread_id);
845 int (*codec_load_file)(const char* codec, struct codec_api *api);
846 int (*codec_run_proc)(void);
847 int (*codec_close)(void);
848 const char *(*get_codec_filename)(int cod_spec);
849 void ** (*find_array_ptr)(void **arr, void *ptr);
850 int (*remove_array_ptr)(void **arr, void *ptr);
851 int (*round_value_to_list32)(unsigned long value,
852 const unsigned long list[],
853 int count,
854 bool signd);
855 #endif /* CONFIG_CODEC == SWCODEC */
856 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
857 bool (*mp3info)(struct mp3entry *entry, const char *filename);
858 int (*count_mp3_frames)(int fd, int startpos, int filesize,
859 void (*progressfunc)(int),
860 unsigned char* buf, size_t buflen);
861 int (*create_xing_header)(int fd, long startpos, long filesize,
862 unsigned char *buf, unsigned long num_frames,
863 unsigned long rec_time, unsigned long header_template,
864 void (*progressfunc)(int), bool generate_toc,
865 unsigned char* tempbuf, size_t tempbuf_len);
866 unsigned long (*find_next_frame)(int fd, long *offset,
867 long max_offset, unsigned long reference_header);
869 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
870 unsigned short (*peak_meter_scale_value)(unsigned short val,
871 int meterwidth);
872 void (*peak_meter_set_use_dbfs)(bool use);
873 bool (*peak_meter_get_use_dbfs)(void);
874 #endif
875 #ifdef HAVE_LCD_BITMAP
876 int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
877 int format, const struct custom_format *cformat);
878 int (*read_bmp_fd)(int fd, struct bitmap *bm, int maxsize,
879 int format, const struct custom_format *cformat);
880 #ifdef HAVE_JPEG
881 int (*read_jpeg_file)(const char* filename, struct bitmap *bm, int maxsize,
882 int format, const struct custom_format *cformat);
883 int (*read_jpeg_fd)(int fd, struct bitmap *bm, int maxsize,
884 int format, const struct custom_format *cformat);
885 #endif
886 void (*screen_dump_set_hook)(void (*hook)(int fh));
887 #endif
888 int (*show_logo)(void);
889 struct tree_context* (*tree_get_context)(void);
890 struct entry* (*tree_get_entries)(struct tree_context* t);
891 struct entry* (*tree_get_entry_at)(struct tree_context* t, int index);
893 void (*set_current_file)(const char* path);
894 void (*set_dirfilter)(int l_dirfilter);
896 #ifdef HAVE_WHEEL_POSITION
897 int (*wheel_status)(void);
898 void (*wheel_send_events)(bool send);
899 #endif
901 #ifdef IRIVER_H100_SERIES
902 /* Routines for the iriver_flash -plugin. */
903 bool (*detect_original_firmware)(void);
904 bool (*detect_flashed_ramimage)(void);
905 bool (*detect_flashed_romimage)(void);
906 #endif
908 void (*led)(bool on);
910 #if (CONFIG_CODEC == SWCODEC)
911 /* buffering API */
912 int (*bufopen)(const char *file, size_t offset, enum data_type type,
913 void *user_data);
914 int (*bufalloc)(const void *src, size_t size, enum data_type type);
915 bool (*bufclose)(int handle_id);
916 int (*bufseek)(int handle_id, size_t newpos);
917 int (*bufadvance)(int handle_id, off_t offset);
918 ssize_t (*bufread)(int handle_id, size_t size, void *dest);
919 ssize_t (*bufgetdata)(int handle_id, size_t size, void **data);
920 ssize_t (*bufgettail)(int handle_id, size_t size, void **data);
921 ssize_t (*bufcuttail)(int handle_id, size_t size);
923 ssize_t (*buf_handle_offset)(int handle_id);
924 void (*buf_set_base_handle)(int handle_id);
925 size_t (*buf_used)(void);
926 #endif
928 #ifdef HAVE_TAGCACHE
929 bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
930 void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
931 void *buffer, long length);
932 bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
933 int tag, int seek);
934 bool (*tagcache_get_next)(struct tagcache_search *tcs);
935 bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
936 int tag, char *buf, long size);
937 void (*tagcache_search_finish)(struct tagcache_search *tcs);
938 long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
939 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
940 bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename);
941 #endif
942 #endif
944 #ifdef HAVE_ALBUMART
945 bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
946 char *buf, int buflen);
947 #endif
949 #ifdef HAVE_SEMAPHORE_OBJECTS
950 void (*semaphore_init)(struct semaphore *s, int max, int start);
951 int (*semaphore_wait)(struct semaphore *s, int timeout);
952 void (*semaphore_release)(struct semaphore *s);
953 #endif
955 const char *rbversion;
957 /* new stuff at the end, sort into place next time
958 the API gets incompatible */
961 /* plugin header */
962 struct plugin_header {
963 struct lc_header lc_hdr; /* must be the first */
964 enum plugin_status(*entry_point)(const void*);
965 const struct plugin_api **api;
968 #ifdef PLUGIN
969 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
970 extern unsigned char plugin_start_addr[];
971 extern unsigned char plugin_end_addr[];
972 #define PLUGIN_HEADER \
973 const struct plugin_api *rb DATA_ATTR; \
974 const struct plugin_header __header \
975 __attribute__ ((section (".header")))= { \
976 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
977 plugin_start_addr, plugin_end_addr }, plugin__start, &rb };
978 #else /* PLATFORM_HOSTED */
979 #define PLUGIN_HEADER \
980 const struct plugin_api *rb DATA_ATTR; \
981 const struct plugin_header __header \
982 __attribute__((visibility("default"))) = { \
983 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \
984 plugin__start, &rb };
985 #endif /* CONFIG_PLATFORM */
986 #endif /* PLUGIN */
988 int plugin_load(const char* plugin, const void* parameter);
989 void* plugin_get_audio_buffer(size_t *buffer_size);
991 /* plugin_tsr,
992 callback returns true to allow the new plugin to load,
993 reenter means the currently running plugin is being reloaded */
994 void plugin_tsr(bool (*exit_callback)(bool reenter));
996 /* defined by the plugin */
997 extern const struct plugin_api *rb;
998 enum plugin_status plugin_start(const void* parameter);
999 enum plugin_status plugin__start(const void* parameter)
1000 NO_PROF_ATTR;
1002 #endif /* __PCTOOL__ */
1003 #endif