1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Björn Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _PLUGIN_H_
#define _PLUGIN_H_
/* instruct simulator code to not redefine any symbols when compiling plugins.
(the PLUGIN macro is defined in apps/plugins/Makefile) */
#ifdef PLUGIN
#define NO_REDEFINES_PLEASE
#endif
#ifndef MEM
#define MEM 2
#endif
#include <stdbool.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "system.h"
#include "dir.h"
#include "general.h"
#include "kernel.h"
#include "thread.h"
#include "button.h"
#include "action.h"
#include "usb.h"
#include "font.h"
#include "lcd.h"
#include "id3.h"
#include "sound.h"
#include "mpeg.h"
#include "audio.h"
#include "mp3_playback.h"
#include "talk.h"
#ifdef RB_PROFILE
#include "profile.h"
#endif
#include "misc.h"
#if (CONFIG_CODEC == SWCODEC)
#include "dsp.h"
#include "codecs.h"
#include "playback.h"
#include "metadata.h"
#ifdef HAVE_RECORDING
#include "recording.h"
#endif
#else
#include "mas.h"
#endif /* CONFIG_CODEC == SWCODEC */
#include "settings.h"
#include "timer.h"
#include "playlist.h"
#ifdef HAVE_LCD_BITMAP
#include "scrollbar.h"
#endif
#include "statusbar.h"
#include "menu.h"
#include "rbunicode.h"
#include "list.h"
#include "tree.h"
#include "color_picker.h"
#include "buffering.h"
#include "tagcache.h"
#ifdef HAVE_ALBUMART
#include "albumart.h"
#endif
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif
#ifdef PLUGIN
#if defined(DEBUG) || defined(SIMULATOR)
#undef DEBUGF
#define DEBUGF rb->debugf
#undef LDEBUGF
#define LDEBUGF rb->debugf
#else
#define DEBUGF(...)
#define LDEBUGF(...)
#endif
#ifdef ROCKBOX_HAS_LOGF
#undef LOGF
#define LOGF rb->logf
#else
#define LOGF(...)
#endif
#endif
#ifdef SIMULATOR
#define PREFIX(_x_) sim_ ## _x_
#else
#define PREFIX(_x_) _x_
#endif
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 93
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 88
/* plugin return codes */
enum plugin_status {
PLUGIN_OK = 0,
PLUGIN_USB_CONNECTED,
PLUGIN_ERROR = -1,
};
/* NOTE: To support backwards compatibility, only add new functions at
the end of the structure. Every time you add a new function,
remember to increase PLUGIN_API_VERSION. If you make changes to the
existing APIs then also update PLUGIN_MIN_API_VERSION to current
version
*/
struct plugin_api {
/* lcd */
void (*lcd_set_contrast)(int x);
void (*lcd_update)(void);
void (*lcd_clear_display)(void);
void (*lcd_setmargins)(int x, int y);
int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
void (*lcd_putsxy)(int x, int y, const unsigned char *string);
void (*lcd_puts)(int x, int y, const unsigned char *string);
void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
void (*lcd_stop_scroll)(void);
#ifdef HAVE_LCD_CHARCELLS
void (*lcd_define_pattern)(unsigned long ucs, const char *pattern);
unsigned long (*lcd_get_locked_pattern)(void);
void (*lcd_unlock_pattern)(unsigned long ucs);
void (*lcd_putc)(int x, int y, unsigned long ucs);
void (*lcd_put_cursor)(int x, int y, unsigned long ucs);
void (*lcd_remove_cursor)(void);
void (*lcd_icon)(int icon, bool enable);
void (*lcd_double_height)(bool on);
#else
void (*lcd_set_drawmode)(int mode);
int (*lcd_get_drawmode)(void);
void (*lcd_setfont)(int font);
void (*lcd_drawpixel)(int x, int y);
void (*lcd_drawline)(int x1, int y1, int x2, int y2);
void (*lcd_hline)(int x1, int x2, int y);
void (*lcd_vline)(int x, int y1, int y2);
void (*lcd_drawrect)(int x, int y, int width, int height);
void (*lcd_fillrect)(int x, int y, int width, int height);
void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
int stride, int x, int y, int width, int height);
void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
int width, int height);
#if LCD_DEPTH > 1
void (*lcd_set_foreground)(unsigned foreground);
unsigned (*lcd_get_foreground)(void);
void (*lcd_set_background)(unsigned foreground);
unsigned (*lcd_get_background)(void);
void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
int stride, int x, int y, int width, int height);
void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
int height);
fb_data* (*lcd_get_backdrop)(void);
void (*lcd_set_backdrop)(fb_data* backdrop);
#endif
#if LCD_DEPTH == 16
void (*lcd_bitmap_transparent_part)(const fb_data *src,
int src_x, int src_y, int stride,
int x, int y, int width, int height);
void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
int width, int height);
#endif
unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation );
const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code );
struct font* (*font_load)(const char *path);
void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
int style);
fb_data* lcd_framebuffer;
void (*lcd_blit) (const fb_data* data, int x, int by, int width,
int bheight, int stride);
void (*lcd_update_rect)(int x, int y, int width, int height);
void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
int width, int height, int items,
int min_shown, int max_shown,
unsigned flags);
struct font* (*font_get)(int font);
int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
int fontnumber);
int (*font_get_width)(struct font* pf, unsigned short char_code);
void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
int width, int height);
#endif
void (*backlight_on)(void);
void (*backlight_off)(void);
void (*backlight_set_timeout)(int index);
#if CONFIG_CHARGING
void (*backlight_set_timeout_plugged)(int index);
#endif
void (*splash)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
#ifdef HAVE_REMOTE_LCD
/* remote lcd */
void (*lcd_remote_set_contrast)(int x);
void (*lcd_remote_clear_display)(void);
void (*lcd_remote_setmargins)(int x, int y);
void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
void (*lcd_remote_puts_scroll)(int x, int y, const unsigned char* string);
void (*lcd_remote_stop_scroll)(void);
void (*lcd_remote_set_drawmode)(int mode);
int (*lcd_remote_get_drawmode)(void);
void (*lcd_remote_setfont)(int font);
int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
void (*lcd_remote_drawpixel)(int x, int y);
void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
void (*lcd_remote_hline)(int x1, int x2, int y);
void (*lcd_remote_vline)(int x, int y1, int y2);
void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
void (*lcd_remote_mono_bitmap_part)(const unsigned char *src, int src_x,
int src_y, int stride, int x, int y,
int width, int height);
void (*lcd_remote_mono_bitmap)(const unsigned char *src, int x, int y,
int width, int height);
void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
int style);
fb_remote_data* lcd_remote_framebuffer;
void (*lcd_remote_update)(void);
void (*lcd_remote_update_rect)(int x, int y, int width, int height);
void (*remote_backlight_on)(void);
void (*remote_backlight_off)(void);
#endif
struct screen* screens[NB_SCREENS];
#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
void (*lcd_remote_set_foreground)(unsigned foreground);
unsigned (*lcd_remote_get_foreground)(void);
void (*lcd_remote_set_background)(unsigned background);
unsigned (*lcd_remote_get_background)(void);
void (*lcd_remote_bitmap_part)(const fb_remote_data *src, int src_x, int src_y,
int stride, int x, int y, int width, int height);
void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y, int width,
int height);
#endif
#if defined(HAVE_LCD_COLOR)
void (*lcd_yuv_blit)(unsigned char * const src[3],
int src_x, int src_y, int stride,
int x, int y, int width, int height);
#endif
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200)
void (*lcd_yuv_set_options)(unsigned options);
#endif
/* list */
void (*gui_synclist_init)(struct gui_synclist * lists,
list_get_name callback_get_item_name,void * data,
bool scroll_all,int selected_size);
void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists, list_get_icon icon_callback);
int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
void (*gui_synclist_draw)(struct gui_synclist * lists);
void (*gui_synclist_select_item)(struct gui_synclist * lists,
int item_number);
void (*gui_synclist_add_item)(struct gui_synclist * lists);
void (*gui_synclist_del_item)(struct gui_synclist * lists);
void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
bool (*gui_synclist_do_button)(struct gui_synclist * lists,
unsigned *action, enum list_wrap wrap);
void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title, int icon);
/* button */
long (*button_get)(bool block);
long (*button_get_w_tmo)(int ticks);
int (*button_status)(void);
void (*button_clear_queue)(void);
int (*button_queue_count)(void);
#ifdef HAS_BUTTON_HOLD
bool (*button_hold)(void);
#endif
/* file */
int (*PREFIX(open))(const char* pathname, int flags);
int (*PREFIX(close))(int fd);
ssize_t (*PREFIX(read))(int fd, void* buf, size_t count);
off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
int (*PREFIX(creat))(const char *pathname);
ssize_t (*PREFIX(write))(int fd, const void* buf, size_t count);
int (*PREFIX(remove))(const char* pathname);
int (*PREFIX(rename))(const char* path, const char* newname);
int (*PREFIX(ftruncate))(int fd, off_t length);
off_t (*PREFIX(filesize))(int fd);
int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
int (*read_line)(int fd, char* buffer, int buffer_size);
bool (*settings_parseline)(char* line, char** name, char** value);
#ifndef SIMULATOR
void (*ata_sleep)(void);
bool (*ata_disk_is_active)(void);
#endif
void (*ata_spindown)(int seconds);
void (*reload_directory)(void);
char *(*create_numbered_filename)(char *buffer, const char *path,
const char *prefix, const char *suffix,
int numberlen IF_CNFN_NUM_(, int *num));
/* dir */
DIR* (*opendir)(const char* name);
int (*closedir)(DIR* dir);
struct dirent* (*readdir)(DIR* dir);
int (*mkdir)(const char *name);
int (*rmdir)(const char *name);
/* kernel/ system */
void (*PREFIX(sleep))(int ticks);
void (*yield)(void);
#ifdef HAVE_PRIORITY_SCHEDULING
void (*priority_yield)(void);
#endif
volatile long* current_tick;
long (*default_event_handler)(long event);
long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
struct thread_entry* threads;
struct thread_entry* (*create_thread)(void (*function)(void), void* stack,
int stack_size, unsigned flags,
const char *name
IF_PRIO(, int priority)
IF_COP(, unsigned int core));
void (*remove_thread)(struct thread_entry *thread);
void (*reset_poweroff_timer)(void);
#ifndef SIMULATOR
int (*system_memory_guard)(int newmode);
long *cpu_frequency;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
#ifdef CPU_BOOST_LOGGING
void (*cpu_boost_)(bool on_off,char*location,int line);
#else
void (*cpu_boost)(bool on_off);
#endif
#endif
#endif
bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
long cycles, int int_prio,
void (*timer_callback)(void));
void (*timer_unregister)(void);
bool (*timer_set_period)(long count);
void (*queue_init)(struct event_queue *q, bool register_queue);
void (*queue_delete)(struct event_queue *q);
void (*queue_post)(struct event_queue *q, long id, intptr_t data);
void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
int ticks);
void (*usb_acknowledge)(long id);
#ifdef RB_PROFILE
void (*profile_thread)(void);
void (*profstop)(void);
void (*profile_func_enter)(void *this_fn, void *call_site);
void (*profile_func_exit)(void *this_fn, void *call_site);
#endif
#ifdef SIMULATOR
/* special simulator hooks */
#if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
void (*sim_lcd_ex_init)(int shades, unsigned long (*getpixel)(int, int));
void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
#endif
#endif
/* strings and memory */
int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
ATTRIBUTE_PRINTF(3, 4);
int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap);
char* (*strcpy)(char *dst, const char *src);
char* (*strncpy)(char *dst, const char *src, size_t length);
size_t (*strlen)(const char *str);
char * (*strrchr)(const char *s, int c);
int (*strcmp)(const char *, const char *);
int (*strncmp)(const char *, const char *, size_t);
int (*strcasecmp)(const char *, const char *);
int (*strncasecmp)(const char *s1, const char *s2, size_t n);
void* (*memset)(void *dst, int c, size_t length);
void* (*memcpy)(void *out, const void *in, size_t n);
void* (*memmove)(void *out, const void *in, size_t n);
const unsigned char *_ctype_;
int (*atoi)(const char *str);
char *(*strchr)(const char *s, int c);
char *(*strcat)(char *s1, const char *s2);
void *(*memchr)(const void *s1, int c, size_t n);
int (*memcmp)(const void *s1, const void *s2, size_t n);
|