skin engine: New logical 'and' and 'or' tags to evaluate multiple tags in a single...
[maemo-rb.git] / apps / plugin.h
blob2fb085de6daccf38d6f94fc4bc1491c8dfe63920
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 216
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 216
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 unsigned char* start, int size,
641 void (*get_more)(unsigned char** start, size_t* size));
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 unsigned char* start, size_t size);
655 void (*pcm_play_stop)(void);
656 void (*pcm_set_frequency)(unsigned int frequency);
657 bool (*pcm_is_playing)(void);
658 bool (*pcm_is_paused)(void);
659 void (*pcm_play_pause)(bool play);
660 size_t (*pcm_get_bytes_waiting)(void);
661 void (*pcm_calculate_peaks)(int *left, int *right);
662 const void* (*pcm_get_peak_buffer)(int *count);
663 void (*pcm_play_lock)(void);
664 void (*pcm_play_unlock)(void);
665 void (*beep_play)(unsigned int frequency, unsigned int duration,
666 unsigned int amplitude);
667 #ifdef HAVE_RECORDING
668 const unsigned long *rec_freq_sampr;
669 void (*pcm_init_recording)(void);
670 void (*pcm_close_recording)(void);
671 void (*pcm_record_data)(pcm_rec_callback_type more_ready,
672 void *start, size_t size);
673 void (*pcm_stop_recording)(void);
674 void (*pcm_calculate_rec_peaks)(int *left, int *right);
675 void (*audio_set_recording_gain)(int left, int right, int type);
676 #endif /* HAVE_RECORDING */
677 #if INPUT_SRC_CAPS != 0
678 void (*audio_set_output_source)(int monitor);
679 void (*audio_set_input_source)(int source, unsigned flags);
680 #endif
681 void (*dsp_set_crossfeed)(bool enable);
682 void (*dsp_set_eq)(bool enable);
683 void (*dsp_dither_enable)(bool enable);
684 intptr_t (*dsp_configure)(struct dsp_config *dsp, int setting,
685 intptr_t value);
686 int (*dsp_process)(struct dsp_config *dsp, char *dest,
687 const char *src[], int count);
688 int (*dsp_input_count)(struct dsp_config *dsp, int count);
689 int (*dsp_output_count)(struct dsp_config *dsp, int count);
691 enum channel_status (*mixer_channel_status)(enum pcm_mixer_channel channel);
692 void * (*mixer_channel_get_buffer)(enum pcm_mixer_channel channel, int *count);
693 void (*mixer_channel_calculate_peaks)(enum pcm_mixer_channel channel,
694 int *left, int *right);
695 void (*mixer_channel_play_data)(enum pcm_mixer_channel channel,
696 pcm_play_callback_type get_more,
697 unsigned char *start, size_t size);
698 void (*mixer_channel_play_pause)(enum pcm_mixer_channel channel, bool play);
699 void (*mixer_channel_stop)(enum pcm_mixer_channel channel);
700 void (*mixer_channel_set_amplitude)(enum pcm_mixer_channel channel,
701 unsigned int amplitude);
702 size_t (*mixer_channel_get_bytes_waiting)(enum pcm_mixer_channel channel);
704 void (*system_sound_play)(enum system_sound sound);
705 void (*keyclick_click)(int button);
706 #endif /* CONFIG_CODEC == SWCODC */
708 /* playback control */
709 int (*playlist_amount)(void);
710 int (*playlist_resume)(void);
711 void (*playlist_start)(int start_index, int offset);
712 int (*playlist_add)(const char *filename);
713 void (*playlist_sync)(struct playlist_info* playlist);
714 int (*playlist_remove_all_tracks)(struct playlist_info *playlist);
715 int (*playlist_create)(const char *dir, const char *file);
716 int (*playlist_insert_track)(struct playlist_info* playlist,
717 const char *filename, int position, bool queue, bool sync);
718 int (*playlist_insert_directory)(struct playlist_info* playlist,
719 const char *dirname, int position, bool queue,
720 bool recurse);
721 int (*playlist_shuffle)(int random_seed, int start_index);
722 void (*audio_play)(long offset);
723 void (*audio_stop)(void);
724 void (*audio_pause)(void);
725 void (*audio_resume)(void);
726 void (*audio_next)(void);
727 void (*audio_prev)(void);
728 void (*audio_ff_rewind)(long newtime);
729 struct mp3entry* (*audio_next_track)(void);
730 int (*audio_status)(void);
731 struct mp3entry* (*audio_current_track)(void);
732 void (*audio_flush_and_reload_tracks)(void);
733 int (*audio_get_file_pos)(void);
734 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
735 unsigned long (*mpeg_get_last_header)(void);
736 #endif
737 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
738 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHSCREEN)
739 void (*sound_set_pitch)(int32_t pitch);
740 #endif
742 /* MAS communication */
743 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
744 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
745 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
746 int (*mas_readreg)(int reg);
747 int (*mas_writereg)(int reg, unsigned int val);
748 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
749 int (*mas_codec_writereg)(int reg, unsigned int val);
750 int (*mas_codec_readreg)(int reg);
751 void (*i2c_begin)(void);
752 void (*i2c_end)(void);
753 int (*i2c_write)(int address, const unsigned char* buf, int count );
754 #endif
755 #endif
757 /* menu */
758 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
759 struct viewport parent[NB_SCREENS], bool hide_theme);
761 /* scroll bar */
762 struct gui_syncstatusbar *statusbars;
763 void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
765 /* options */
766 const struct settings_list* (*get_settings_list)(int*count);
767 const struct settings_list* (*find_setting)(const void* variable, int *id);
768 bool (*option_screen)(const struct settings_list *setting,
769 struct viewport parent[NB_SCREENS],
770 bool use_temp_var, unsigned char* option_title);
771 bool (*set_option)(const char* string, const void* variable,
772 enum optiontype type, const struct opt_items* options,
773 int numoptions, void (*function)(int));
774 bool (*set_bool_options)(const char* string, const bool* variable,
775 const char* yes_str, int yes_voice,
776 const char* no_str, int no_voice,
777 void (*function)(bool));
778 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
779 const int* variable, void (*function)(int), int step,
780 int min, int max,
781 const char* (*formatter)(char*, size_t, int, const char*) );
782 bool (*set_bool)(const char* string, const bool* variable );
784 #ifdef HAVE_LCD_COLOR
785 bool (*set_color)(struct screen *display, char *title,
786 unsigned *color, unsigned banned_color);
787 #endif
788 /* action handling */
789 int (*get_custom_action)(int context,int timeout,
790 const struct button_mapping* (*get_context_map)(int));
791 int (*get_action)(int context, int timeout);
792 #ifdef HAVE_TOUCHSCREEN
793 int (*action_get_touchscreen_press)(short *x, short *y);
794 #endif
795 bool (*action_userabort)(int timeout);
797 /* power */
798 int (*battery_level)(void);
799 bool (*battery_level_safe)(void);
800 int (*battery_time)(void);
801 int (*battery_voltage)(void);
802 #if CONFIG_CHARGING
803 bool (*charger_inserted)(void);
804 # if CONFIG_CHARGING >= CHARGING_MONITOR
805 bool (*charging_state)(void);
806 # endif
807 #endif
808 #ifdef HAVE_USB_POWER
809 bool (*usb_powered)(void);
810 #endif
812 /* misc */
813 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
814 int* __errno;
815 #endif
816 void (*srand)(unsigned int seed);
817 int (*rand)(void);
818 void (*qsort)(void *base, size_t nmemb, size_t size,
819 int(*compar)(const void *, const void *));
820 int (*kbd_input)(char* buffer, int buflen);
821 struct tm* (*get_time)(void);
822 int (*set_time)(const struct tm *tm);
823 #if CONFIG_RTC
824 time_t (*mktime)(struct tm *t);
825 #endif
826 void* (*plugin_get_buffer)(size_t *buffer_size);
827 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
828 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
829 char* (*plugin_get_current_filename)(void);
830 #if defined(DEBUG) || defined(SIMULATOR)
831 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
832 #endif
833 #ifdef ROCKBOX_HAS_LOGF
834 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
835 #endif
836 struct user_settings* global_settings;
837 struct system_status *global_status;
838 void (*talk_disable)(bool disable);
839 #if CONFIG_CODEC == SWCODEC
840 void (*codec_thread_do_callback)(void (*fn)(void),
841 unsigned int *audio_thread_id);
842 int (*codec_load_file)(const char* codec, struct codec_api *api);
843 int (*codec_run_proc)(void);
844 int (*codec_close)(void);
845 const char *(*get_codec_filename)(int cod_spec);
846 void ** (*find_array_ptr)(void **arr, void *ptr);
847 int (*remove_array_ptr)(void **arr, void *ptr);
848 int (*round_value_to_list32)(unsigned long value,
849 const unsigned long list[],
850 int count,
851 bool signd);
852 #endif /* CONFIG_CODEC == SWCODEC */
853 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
854 bool (*mp3info)(struct mp3entry *entry, const char *filename);
855 int (*count_mp3_frames)(int fd, int startpos, int filesize,
856 void (*progressfunc)(int),
857 unsigned char* buf, size_t buflen);
858 int (*create_xing_header)(int fd, long startpos, long filesize,
859 unsigned char *buf, unsigned long num_frames,
860 unsigned long rec_time, unsigned long header_template,
861 void (*progressfunc)(int), bool generate_toc,
862 unsigned char* tempbuf, size_t tempbuf_len);
863 unsigned long (*find_next_frame)(int fd, long *offset,
864 long max_offset, unsigned long reference_header);
866 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
867 unsigned short (*peak_meter_scale_value)(unsigned short val,
868 int meterwidth);
869 void (*peak_meter_set_use_dbfs)(bool use);
870 bool (*peak_meter_get_use_dbfs)(void);
871 #endif
872 #ifdef HAVE_LCD_BITMAP
873 int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
874 int format, const struct custom_format *cformat);
875 int (*read_bmp_fd)(int fd, struct bitmap *bm, int maxsize,
876 int format, const struct custom_format *cformat);
877 #ifdef HAVE_JPEG
878 int (*read_jpeg_file)(const char* filename, struct bitmap *bm, int maxsize,
879 int format, const struct custom_format *cformat);
880 int (*read_jpeg_fd)(int fd, struct bitmap *bm, int maxsize,
881 int format, const struct custom_format *cformat);
882 #endif
883 void (*screen_dump_set_hook)(void (*hook)(int fh));
884 #endif
885 int (*show_logo)(void);
886 struct tree_context* (*tree_get_context)(void);
887 struct entry* (*tree_get_entries)(struct tree_context* t);
888 struct entry* (*tree_get_entry_at)(struct tree_context* t, int index);
890 void (*set_current_file)(const char* path);
891 void (*set_dirfilter)(int l_dirfilter);
893 #ifdef HAVE_WHEEL_POSITION
894 int (*wheel_status)(void);
895 void (*wheel_send_events)(bool send);
896 #endif
898 #ifdef IRIVER_H100_SERIES
899 /* Routines for the iriver_flash -plugin. */
900 bool (*detect_original_firmware)(void);
901 bool (*detect_flashed_ramimage)(void);
902 bool (*detect_flashed_romimage)(void);
903 #endif
905 void (*led)(bool on);
907 #if (CONFIG_CODEC == SWCODEC)
908 /* buffering API */
909 int (*bufopen)(const char *file, size_t offset, enum data_type type,
910 void *user_data);
911 int (*bufalloc)(const void *src, size_t size, enum data_type type);
912 bool (*bufclose)(int handle_id);
913 int (*bufseek)(int handle_id, size_t newpos);
914 int (*bufadvance)(int handle_id, off_t offset);
915 ssize_t (*bufread)(int handle_id, size_t size, void *dest);
916 ssize_t (*bufgetdata)(int handle_id, size_t size, void **data);
917 ssize_t (*bufgettail)(int handle_id, size_t size, void **data);
918 ssize_t (*bufcuttail)(int handle_id, size_t size);
920 ssize_t (*buf_handle_offset)(int handle_id);
921 void (*buf_set_base_handle)(int handle_id);
922 size_t (*buf_used)(void);
923 #endif
925 #ifdef HAVE_TAGCACHE
926 bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
927 void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
928 void *buffer, long length);
929 bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
930 int tag, int seek);
931 bool (*tagcache_get_next)(struct tagcache_search *tcs);
932 bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
933 int tag, char *buf, long size);
934 void (*tagcache_search_finish)(struct tagcache_search *tcs);
935 long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
936 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
937 bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename);
938 #endif
939 #endif
941 #ifdef HAVE_ALBUMART
942 bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
943 char *buf, int buflen);
944 #endif
946 #ifdef HAVE_SEMAPHORE_OBJECTS
947 void (*semaphore_init)(struct semaphore *s, int max, int start);
948 int (*semaphore_wait)(struct semaphore *s, int timeout);
949 void (*semaphore_release)(struct semaphore *s);
950 #endif
952 const char *rbversion;
954 /* new stuff at the end, sort into place next time
955 the API gets incompatible */
958 /* plugin header */
959 struct plugin_header {
960 struct lc_header lc_hdr; /* must be the first */
961 enum plugin_status(*entry_point)(const void*);
962 const struct plugin_api **api;
965 #ifdef PLUGIN
966 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
967 extern unsigned char plugin_start_addr[];
968 extern unsigned char plugin_end_addr[];
969 #define PLUGIN_HEADER \
970 const struct plugin_api *rb DATA_ATTR; \
971 const struct plugin_header __header \
972 __attribute__ ((section (".header")))= { \
973 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
974 plugin_start_addr, plugin_end_addr }, plugin__start, &rb };
975 #else /* PLATFORM_HOSTED */
976 #define PLUGIN_HEADER \
977 const struct plugin_api *rb DATA_ATTR; \
978 const struct plugin_header __header \
979 __attribute__((visibility("default"))) = { \
980 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \
981 plugin__start, &rb };
982 #endif /* CONFIG_PLATFORM */
983 #endif /* PLUGIN */
985 int plugin_load(const char* plugin, const void* parameter);
986 void* plugin_get_audio_buffer(size_t *buffer_size);
988 /* plugin_tsr,
989 callback returns true to allow the new plugin to load,
990 reenter means the currently running plugin is being reloaded */
991 void plugin_tsr(bool (*exit_callback)(bool reenter));
993 /* defined by the plugin */
994 extern const struct plugin_api *rb;
995 enum plugin_status plugin_start(const void* parameter);
996 enum plugin_status plugin__start(const void* parameter)
997 NO_PROF_ATTR;
999 #endif /* __PCTOOL__ */
1000 #endif