Fix flag for the viewport. Text is supposed to be centered.
[maemo-rb.git] / apps / plugin.h
blobd83f6f484558c50631a5f4c492cbf61d843e235a
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 215
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 214
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 #endif
417 #ifdef HAVE_BUTTON_LIGHT
418 void (*buttonlight_set_timeout)(int value);
419 void (*buttonlight_off)(void);
420 void (*buttonlight_on)(void);
421 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
422 void (*buttonlight_set_brightness)(int val);
423 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
424 #endif /* HAVE_BUTTON_LIGHT */
426 /* file */
427 int (*open_utf8)(const char* pathname, int flags);
428 int (*open)(const char* pathname, int flags, ...);
429 int (*close)(int fd);
430 ssize_t (*read)(int fd, void* buf, size_t count);
431 off_t (*lseek)(int fd, off_t offset, int whence);
432 int (*creat)(const char *pathname, mode_t mode);
433 ssize_t (*write)(int fd, const void* buf, size_t count);
434 int (*remove)(const char* pathname);
435 int (*rename)(const char* path, const char* newname);
436 int (*ftruncate)(int fd, off_t length);
437 off_t (*filesize)(int fd);
438 int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
439 int (*read_line)(int fd, char* buffer, int buffer_size);
440 bool (*settings_parseline)(char* line, char** name, char** value);
441 void (*storage_sleep)(void);
442 void (*storage_spin)(void);
443 void (*storage_spindown)(int seconds);
444 #if USING_STORAGE_CALLBACK
445 void (*register_storage_idle_func)(void (*function)(void *data));
446 void (*unregister_storage_idle_func)(void (*function)(void *data), bool run);
447 #endif /* USING_STORAGE_CALLBACK */
448 void (*reload_directory)(void);
449 char *(*create_numbered_filename)(char *buffer, const char *path,
450 const char *prefix, const char *suffix,
451 int numberlen IF_CNFN_NUM_(, int *num));
452 bool (*file_exists)(const char *file);
453 char* (*strip_extension)(char* buffer, int buffer_size, const char *filename);
454 unsigned (*crc_32)(const void *src, unsigned len, unsigned crc32);
456 int (*filetype_get_attr)(const char* file);
460 /* dir */
461 DIR* (*opendir)(const char* name);
462 int (*closedir)(DIR* dir);
463 struct dirent* (*readdir)(DIR* dir);
464 int (*mkdir)(const char *name);
465 int (*rmdir)(const char *name);
466 bool (*dir_exists)(const char *path);
467 struct dirinfo (*dir_get_info)(DIR* parent, struct dirent *entry);
469 /* browsing */
470 void (*browse_context_init)(struct browse_context *browse,
471 int dirfilter, unsigned flags,
472 char *title, enum themable_icons icon,
473 const char *root, const char *selected);
474 int (*rockbox_browse)(struct browse_context *browse);
476 /* kernel/ system */
477 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
478 void (*__div0)(void);
479 #endif
480 unsigned (*sleep)(unsigned ticks);
481 void (*yield)(void);
482 volatile long* current_tick;
483 long (*default_event_handler)(long event);
484 long (*default_event_handler_ex)(long event,
485 void (*callback)(void *), void *parameter);
486 unsigned int (*create_thread)(void (*function)(void), void* stack,
487 size_t stack_size, unsigned flags,
488 const char *name
489 IF_PRIO(, int priority)
490 IF_COP(, unsigned int core));
491 unsigned int (*thread_self)(void);
492 void (*thread_exit)(void);
493 void (*thread_wait)(unsigned int thread_id);
494 #if CONFIG_CODEC == SWCODEC
495 void (*thread_thaw)(unsigned int thread_id);
496 #ifdef HAVE_PRIORITY_SCHEDULING
497 int (*thread_set_priority)(unsigned int thread_id, int priority);
498 #endif
499 void (*mutex_init)(struct mutex *m);
500 void (*mutex_lock)(struct mutex *m);
501 void (*mutex_unlock)(struct mutex *m);
502 #endif
504 void (*reset_poweroff_timer)(void);
505 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
506 int (*system_memory_guard)(int newmode);
507 long *cpu_frequency;
508 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
509 #ifdef CPU_BOOST_LOGGING
510 void (*cpu_boost_)(bool on_off,char*location,int line);
511 #else
512 void (*cpu_boost)(bool on_off);
513 #endif
514 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
515 #endif /* PLATFORM_NATIVE */
516 #ifdef HAVE_SCHEDULER_BOOSTCTRL
517 void (*trigger_cpu_boost)(void);
518 void (*cancel_cpu_boost)(void);
519 #endif
521 void (*commit_dcache)(void);
522 void (*commit_discard_dcache)(void);
524 /* load code api for overlay */
525 void* (*lc_open)(const char *filename, unsigned char *buf, size_t buf_size);
526 void* (*lc_open_from_mem)(void* addr, size_t blob_size);
527 void* (*lc_get_header)(void *handle);
528 void (*lc_close)(void *handle);
530 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
531 long cycles, void (*timer_callback)(void)
532 IF_COP(, int core));
533 void (*timer_unregister)(void);
534 bool (*timer_set_period)(long count);
536 void (*queue_init)(struct event_queue *q, bool register_queue);
537 void (*queue_delete)(struct event_queue *q);
538 void (*queue_post)(struct event_queue *q, long id, intptr_t data);
539 void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
540 int ticks);
541 #if CONFIG_CODEC == SWCODEC
542 void (*queue_enable_queue_send)(struct event_queue *q,
543 struct queue_sender_list *send,
544 unsigned int thread_id);
545 bool (*queue_empty)(const struct event_queue *q);
546 void (*queue_wait)(struct event_queue *q, struct queue_event *ev);
547 intptr_t (*queue_send)(struct event_queue *q, long id,
548 intptr_t data);
549 void (*queue_reply)(struct event_queue *q, intptr_t retval);
550 #endif /* CONFIG_CODEC == SWCODEC */
552 void (*usb_acknowledge)(long id);
553 #ifdef USB_ENABLE_HID
554 void (*usb_hid_send)(usage_page_t usage_page, int id);
555 #endif
556 #ifdef RB_PROFILE
557 void (*profile_thread)(void);
558 void (*profstop)(void);
559 void (*profile_func_enter)(void *this_fn, void *call_site);
560 void (*profile_func_exit)(void *this_fn, void *call_site);
561 #endif
562 /* event api */
563 bool (*add_event)(unsigned short id, bool oneshot, void (*handler)(void *data));
564 void (*remove_event)(unsigned short id, void (*handler)(void *data));
565 void (*send_event)(unsigned short id, void *data);
567 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
568 /* special simulator hooks */
569 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
570 void (*sim_lcd_ex_init)(unsigned long (*getpixel)(int, int));
571 void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
572 #endif
573 #endif
575 /* strings and memory */
576 int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
577 ATTRIBUTE_PRINTF(3, 4);
578 int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list ap);
579 char* (*strcpy)(char *dst, const char *src);
580 size_t (*strlcpy)(char *dst, const char *src, size_t length);
581 size_t (*strlen)(const char *str);
582 char * (*strrchr)(const char *s, int c);
583 int (*strcmp)(const char *, const char *);
584 int (*strncmp)(const char *, const char *, size_t);
585 int (*strcasecmp)(const char *, const char *);
586 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
587 void* (*memset)(void *dst, int c, size_t length);
588 void* (*memcpy)(void *out, const void *in, size_t n);
589 void* (*memmove)(void *out, const void *in, size_t n);
590 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
591 const unsigned char *_rbctype_;
592 #endif
593 int (*atoi)(const char *str);
594 char *(*strchr)(const char *s, int c);
595 char *(*strcat)(char *s1, const char *s2);
596 size_t (*strlcat)(char *dst, const char *src, size_t length);
597 void *(*memchr)(const void *s1, int c, size_t n);
598 int (*memcmp)(const void *s1, const void *s2, size_t n);
599 char *(*strcasestr) (const char* phaystack, const char* pneedle);
600 char* (*strtok_r)(char *ptr, const char *sep, char **end);
601 /* unicode stuff */
602 const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs);
603 unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
604 unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
605 unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
606 unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
607 unsigned long (*utf8length)(const unsigned char *utf8);
608 int (*utf8seek)(const unsigned char* utf8, int offset);
610 /* the buflib memory management library */
611 void (*buflib_init)(struct buflib_context* ctx, void* buf, size_t size);
612 size_t (*buflib_available)(struct buflib_context* ctx);
613 int (*buflib_alloc)(struct buflib_context* ctx, size_t size);
614 int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size,
615 const char* name, struct buflib_callbacks *ops);
616 int (*buflib_alloc_maximum)(struct buflib_context* ctx, const char* name,
617 size_t* size, struct buflib_callbacks *ops);
618 void (*buflib_buffer_in)(struct buflib_context* ctx, int size);
619 void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size);
620 int (*buflib_free)(struct buflib_context* ctx, int handle);
621 bool (*buflib_shrink)(struct buflib_context* ctx, int handle,
622 void* new_start, size_t new_size);
623 void* (*buflib_get_data)(struct buflib_context* ctx, int handle);
624 const char* (*buflib_get_name)(struct buflib_context* ctx, int handle);
626 /* sound */
627 void (*sound_set)(int setting, int value);
628 int (*sound_default)(int setting);
629 int (*sound_min)(int setting);
630 int (*sound_max)(int setting);
631 const char * (*sound_unit)(int setting);
632 int (*sound_val2phys)(int setting, int value);
633 #ifdef AUDIOHW_HAVE_EQ
634 int (*sound_enum_hw_eq_band_setting)(unsigned int band,
635 unsigned int band_setting);
636 #endif /* AUDIOHW_HAVE_EQ */
637 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
638 void (*mp3_play_data)(const unsigned char* start, int size,
639 void (*get_more)(unsigned char** start, size_t* size));
640 void (*mp3_play_pause)(bool play);
641 void (*mp3_play_stop)(void);
642 bool (*mp3_is_playing)(void);
643 #if CONFIG_CODEC != SWCODEC
644 void (*bitswap)(unsigned char *data, int length);
645 #endif
646 #endif /* PLATFORM_NATIVE */
647 #if CONFIG_CODEC == SWCODEC
648 const unsigned long *audio_master_sampr_list;
649 const unsigned long *hw_freq_sampr;
650 void (*pcm_apply_settings)(void);
651 void (*pcm_play_data)(pcm_play_callback_type get_more,
652 unsigned char* start, size_t size);
653 void (*pcm_play_stop)(void);
654 void (*pcm_set_frequency)(unsigned int frequency);
655 bool (*pcm_is_playing)(void);
656 bool (*pcm_is_paused)(void);
657 void (*pcm_play_pause)(bool play);
658 size_t (*pcm_get_bytes_waiting)(void);
659 void (*pcm_calculate_peaks)(int *left, int *right);
660 const void* (*pcm_get_peak_buffer)(int *count);
661 void (*pcm_play_lock)(void);
662 void (*pcm_play_unlock)(void);
663 void (*beep_play)(unsigned int frequency, unsigned int duration,
664 unsigned int amplitude);
665 #ifdef HAVE_RECORDING
666 const unsigned long *rec_freq_sampr;
667 void (*pcm_init_recording)(void);
668 void (*pcm_close_recording)(void);
669 void (*pcm_record_data)(pcm_rec_callback_type more_ready,
670 void *start, size_t size);
671 void (*pcm_stop_recording)(void);
672 void (*pcm_calculate_rec_peaks)(int *left, int *right);
673 void (*audio_set_recording_gain)(int left, int right, int type);
674 #endif /* HAVE_RECORDING */
675 #if INPUT_SRC_CAPS != 0
676 void (*audio_set_output_source)(int monitor);
677 void (*audio_set_input_source)(int source, unsigned flags);
678 #endif
679 void (*dsp_set_crossfeed)(bool enable);
680 void (*dsp_set_eq)(bool enable);
681 void (*dsp_dither_enable)(bool enable);
682 intptr_t (*dsp_configure)(struct dsp_config *dsp, int setting,
683 intptr_t value);
684 int (*dsp_process)(struct dsp_config *dsp, char *dest,
685 const char *src[], int count);
686 int (*dsp_input_count)(struct dsp_config *dsp, int count);
687 int (*dsp_output_count)(struct dsp_config *dsp, int count);
689 enum channel_status (*mixer_channel_status)(enum pcm_mixer_channel channel);
690 void * (*mixer_channel_get_buffer)(enum pcm_mixer_channel channel, int *count);
691 void (*mixer_channel_calculate_peaks)(enum pcm_mixer_channel channel,
692 int *left, int *right);
693 void (*mixer_channel_play_data)(enum pcm_mixer_channel channel,
694 pcm_play_callback_type get_more,
695 unsigned char *start, size_t size);
696 void (*mixer_channel_play_pause)(enum pcm_mixer_channel channel, bool play);
697 void (*mixer_channel_stop)(enum pcm_mixer_channel channel);
698 void (*mixer_channel_set_amplitude)(enum pcm_mixer_channel channel,
699 unsigned int amplitude);
700 size_t (*mixer_channel_get_bytes_waiting)(enum pcm_mixer_channel channel);
702 void (*system_sound_play)(enum system_sound sound);
703 void (*keyclick_click)(int button);
704 #endif /* CONFIG_CODEC == SWCODC */
706 /* playback control */
707 int (*playlist_amount)(void);
708 int (*playlist_resume)(void);
709 void (*playlist_start)(int start_index, int offset);
710 int (*playlist_add)(const char *filename);
711 void (*playlist_sync)(struct playlist_info* playlist);
712 int (*playlist_remove_all_tracks)(struct playlist_info *playlist);
713 int (*playlist_create)(const char *dir, const char *file);
714 int (*playlist_insert_track)(struct playlist_info* playlist,
715 const char *filename, int position, bool queue, bool sync);
716 int (*playlist_insert_directory)(struct playlist_info* playlist,
717 const char *dirname, int position, bool queue,
718 bool recurse);
719 int (*playlist_shuffle)(int random_seed, int start_index);
720 void (*audio_play)(long offset);
721 void (*audio_stop)(void);
722 void (*audio_pause)(void);
723 void (*audio_resume)(void);
724 void (*audio_next)(void);
725 void (*audio_prev)(void);
726 void (*audio_ff_rewind)(long newtime);
727 struct mp3entry* (*audio_next_track)(void);
728 int (*audio_status)(void);
729 struct mp3entry* (*audio_current_track)(void);
730 void (*audio_flush_and_reload_tracks)(void);
731 int (*audio_get_file_pos)(void);
732 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
733 unsigned long (*mpeg_get_last_header)(void);
734 #endif
735 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
736 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHSCREEN)
737 void (*sound_set_pitch)(int32_t pitch);
738 #endif
740 /* MAS communication */
741 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
742 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
743 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
744 int (*mas_readreg)(int reg);
745 int (*mas_writereg)(int reg, unsigned int val);
746 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
747 int (*mas_codec_writereg)(int reg, unsigned int val);
748 int (*mas_codec_readreg)(int reg);
749 void (*i2c_begin)(void);
750 void (*i2c_end)(void);
751 int (*i2c_write)(int address, const unsigned char* buf, int count );
752 #endif
753 #endif
755 /* menu */
756 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
757 struct viewport parent[NB_SCREENS], bool hide_theme);
759 /* scroll bar */
760 struct gui_syncstatusbar *statusbars;
761 void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
763 /* options */
764 const struct settings_list* (*get_settings_list)(int*count);
765 const struct settings_list* (*find_setting)(const void* variable, int *id);
766 bool (*option_screen)(const struct settings_list *setting,
767 struct viewport parent[NB_SCREENS],
768 bool use_temp_var, unsigned char* option_title);
769 bool (*set_option)(const char* string, const void* variable,
770 enum optiontype type, const struct opt_items* options,
771 int numoptions, void (*function)(int));
772 bool (*set_bool_options)(const char* string, const bool* variable,
773 const char* yes_str, int yes_voice,
774 const char* no_str, int no_voice,
775 void (*function)(bool));
776 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
777 const int* variable, void (*function)(int), int step,
778 int min, int max,
779 const char* (*formatter)(char*, size_t, int, const char*) );
780 bool (*set_bool)(const char* string, const bool* variable );
782 #ifdef HAVE_LCD_COLOR
783 bool (*set_color)(struct screen *display, char *title,
784 unsigned *color, unsigned banned_color);
785 #endif
786 /* action handling */
787 int (*get_custom_action)(int context,int timeout,
788 const struct button_mapping* (*get_context_map)(int));
789 int (*get_action)(int context, int timeout);
790 #ifdef HAVE_TOUCHSCREEN
791 int (*action_get_touchscreen_press)(short *x, short *y);
792 #endif
793 bool (*action_userabort)(int timeout);
795 /* power */
796 int (*battery_level)(void);
797 bool (*battery_level_safe)(void);
798 int (*battery_time)(void);
799 int (*battery_voltage)(void);
800 #if CONFIG_CHARGING
801 bool (*charger_inserted)(void);
802 # if CONFIG_CHARGING >= CHARGING_MONITOR
803 bool (*charging_state)(void);
804 # endif
805 #endif
806 #ifdef HAVE_USB_POWER
807 bool (*usb_powered)(void);
808 #endif
810 /* misc */
811 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
812 int* __errno;
813 #endif
814 void (*srand)(unsigned int seed);
815 int (*rand)(void);
816 void (*qsort)(void *base, size_t nmemb, size_t size,
817 int(*compar)(const void *, const void *));
818 int (*kbd_input)(char* buffer, int buflen);
819 struct tm* (*get_time)(void);
820 int (*set_time)(const struct tm *tm);
821 #if CONFIG_RTC
822 time_t (*mktime)(struct tm *t);
823 #endif
824 void* (*plugin_get_buffer)(size_t *buffer_size);
825 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
826 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
827 char* (*plugin_get_current_filename)(void);
828 #if defined(DEBUG) || defined(SIMULATOR)
829 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
830 #endif
831 #ifdef ROCKBOX_HAS_LOGF
832 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
833 #endif
834 struct user_settings* global_settings;
835 struct system_status *global_status;
836 void (*talk_disable)(bool disable);
837 #if CONFIG_CODEC == SWCODEC
838 void (*codec_thread_do_callback)(void (*fn)(void),
839 unsigned int *audio_thread_id);
840 int (*codec_load_file)(const char* codec, struct codec_api *api);
841 int (*codec_run_proc)(void);
842 int (*codec_close)(void);
843 const char *(*get_codec_filename)(int cod_spec);
844 void ** (*find_array_ptr)(void **arr, void *ptr);
845 int (*remove_array_ptr)(void **arr, void *ptr);
846 int (*round_value_to_list32)(unsigned long value,
847 const unsigned long list[],
848 int count,
849 bool signd);
850 #endif /* CONFIG_CODEC == SWCODEC */
851 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
852 bool (*mp3info)(struct mp3entry *entry, const char *filename);
853 int (*count_mp3_frames)(int fd, int startpos, int filesize,
854 void (*progressfunc)(int),
855 unsigned char* buf, size_t buflen);
856 int (*create_xing_header)(int fd, long startpos, long filesize,
857 unsigned char *buf, unsigned long num_frames,
858 unsigned long rec_time, unsigned long header_template,
859 void (*progressfunc)(int), bool generate_toc,
860 unsigned char* tempbuf, size_t tempbuf_len);
861 unsigned long (*find_next_frame)(int fd, long *offset,
862 long max_offset, unsigned long reference_header);
864 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
865 unsigned short (*peak_meter_scale_value)(unsigned short val,
866 int meterwidth);
867 void (*peak_meter_set_use_dbfs)(bool use);
868 bool (*peak_meter_get_use_dbfs)(void);
869 #endif
870 #ifdef HAVE_LCD_BITMAP
871 int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
872 int format, const struct custom_format *cformat);
873 int (*read_bmp_fd)(int fd, struct bitmap *bm, int maxsize,
874 int format, const struct custom_format *cformat);
875 #ifdef HAVE_JPEG
876 int (*read_jpeg_file)(const char* filename, struct bitmap *bm, int maxsize,
877 int format, const struct custom_format *cformat);
878 int (*read_jpeg_fd)(int fd, struct bitmap *bm, int maxsize,
879 int format, const struct custom_format *cformat);
880 #endif
881 void (*screen_dump_set_hook)(void (*hook)(int fh));
882 #endif
883 int (*show_logo)(void);
884 struct tree_context* (*tree_get_context)(void);
885 struct entry* (*tree_get_entries)(struct tree_context* t);
886 struct entry* (*tree_get_entry_at)(struct tree_context* t, int index);
888 void (*set_current_file)(const char* path);
889 void (*set_dirfilter)(int l_dirfilter);
891 #ifdef HAVE_WHEEL_POSITION
892 int (*wheel_status)(void);
893 void (*wheel_send_events)(bool send);
894 #endif
896 #ifdef IRIVER_H100_SERIES
897 /* Routines for the iriver_flash -plugin. */
898 bool (*detect_original_firmware)(void);
899 bool (*detect_flashed_ramimage)(void);
900 bool (*detect_flashed_romimage)(void);
901 #endif
903 void (*led)(bool on);
905 #if (CONFIG_CODEC == SWCODEC)
906 /* buffering API */
907 int (*bufopen)(const char *file, size_t offset, enum data_type type,
908 void *user_data);
909 int (*bufalloc)(const void *src, size_t size, enum data_type type);
910 bool (*bufclose)(int handle_id);
911 int (*bufseek)(int handle_id, size_t newpos);
912 int (*bufadvance)(int handle_id, off_t offset);
913 ssize_t (*bufread)(int handle_id, size_t size, void *dest);
914 ssize_t (*bufgetdata)(int handle_id, size_t size, void **data);
915 ssize_t (*bufgettail)(int handle_id, size_t size, void **data);
916 ssize_t (*bufcuttail)(int handle_id, size_t size);
918 ssize_t (*buf_handle_offset)(int handle_id);
919 void (*buf_set_base_handle)(int handle_id);
920 size_t (*buf_used)(void);
921 #endif
923 #ifdef HAVE_TAGCACHE
924 bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
925 void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
926 void *buffer, long length);
927 bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
928 int tag, int seek);
929 bool (*tagcache_get_next)(struct tagcache_search *tcs);
930 bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
931 int tag, char *buf, long size);
932 void (*tagcache_search_finish)(struct tagcache_search *tcs);
933 long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
934 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
935 bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename);
936 #endif
937 #endif
939 #ifdef HAVE_ALBUMART
940 bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
941 char *buf, int buflen);
942 #endif
944 #ifdef HAVE_SEMAPHORE_OBJECTS
945 void (*semaphore_init)(struct semaphore *s, int max, int start);
946 int (*semaphore_wait)(struct semaphore *s, int timeout);
947 void (*semaphore_release)(struct semaphore *s);
948 #endif
950 const char *rbversion;
952 /* new stuff at the end, sort into place next time
953 the API gets incompatible */
955 void (*commit_discard_idcache)(void);
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