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