Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

open_plugin.c access open_plugin_entry through a function

just a few updates to open_plugin save a bit of space by granting access through a getter function

Change-Id: I2c0eaa1ade867510798b213006064ee1c00aa016

authored by

William Wilgus and committed by
William Wilgus
6f54bb63 626be18d

+108 -58
+96 -48
apps/open_plugin.c
··· 32 32 #include "logf.h" 33 33 34 34 #define ROCK_EXT "rock" 35 - #define ROCK_LEN 5 35 + #define ROCK_LEN sizeof(ROCK_EXT) 36 36 #define OP_EXT "opx" 37 - #define OP_LEN 4 38 - 39 - struct open_plugin_entry_t open_plugin_entry = {0}; 37 + #define OP_LEN sizeof(OP_EXT) 40 38 41 39 static const uint32_t open_plugin_csum = OPEN_PLUGIN_CHECKSUM; 42 40 ··· 44 42 45 43 static const char* strip_rockbox_root(const char *path) 46 44 { 47 - int dlen = strlen(ROCKBOX_DIR); 45 + int dlen = ROCKBOX_DIR_LEN; 48 46 if (strncmp(path, ROCKBOX_DIR, dlen) == 0) 49 47 path+= dlen; 50 48 return path; ··· 55 53 if (entry == NULL) 56 54 return; 57 55 memset(entry, 0, op_entry_sz); 58 - entry->lang_id = -1; 56 + entry->lang_id = OPEN_PLUGIN_LANG_INVALID; 59 57 } 60 58 61 59 static int op_entry_checksum(struct open_plugin_entry_t *entry) 62 60 { 61 + /*Note: since we use langids as checksums everytime someone moves the lang file 62 + * around it could mess with our indexing so invalidate entries when this occurs 63 + */ 63 64 if (entry == NULL || entry->checksum != open_plugin_csum + 64 65 (entry->lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) 65 66 { ··· 117 118 #endif 118 119 (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0)) 119 120 { 120 - splash(HZ * 2, "OpenPlugin Invalid entry"); 121 + splashf(HZ * 2, "%s Invalid entry", str(LANG_OPEN_PLUGIN)); 121 122 ret = OPEN_PLUGIN_NOT_FOUND; 122 123 } 123 124 if (ret == OPEN_PLUGIN_NOT_FOUND) ··· 215 216 return 0; 216 217 } 217 218 218 - static int op_get_entry(uint32_t hash, int32_t lang_id, 219 + static int op_load_entry(uint32_t hash, int32_t lang_id, 219 220 struct open_plugin_entry_t *entry, const char *dat_file) 220 221 { 221 222 int opret = OPEN_PLUGIN_NOT_FOUND; ··· 238 239 } 239 240 240 241 /* if another entry is loaded; flush it to disk before we destroy it */ 241 - op_update_dat(&open_plugin_entry, true); 242 + 243 + op_update_dat(open_plugin_get_entry(), true); 242 244 243 245 logf("OP get_entry hash: %x lang id: %d db: %s", hash, lang_id, dat_file); 244 246 ··· 252 254 return opret; 253 255 } 254 256 257 + /******************************************************************************/ 258 + /******************************************************************************/ 259 + /* ************************************************************************** */ 260 + /* * PUBLIC INTERFACE FUNCTIONS * *********************************************/ 261 + /* ************************************************************************** */ 262 + /******************************************************************************/ 263 + /******************************************************************************/ 264 + 265 + /* open_plugin_get_entry() 266 + * returns the internal open_plugin_entry 267 + */ 268 + struct open_plugin_entry_t * open_plugin_get_entry(void) 269 + { 270 + /* holds entry data to load/run/store */ 271 + static struct open_plugin_entry_t open_plugin_entry = {0}; 272 + return &open_plugin_entry; 273 + } 274 + 275 + /* open_plugin_add_path() 276 + * adds a plugin path and calling parameters to open_plugin_entry 277 + * hash of the key is created for later recall of the plugin path and parameters 278 + * returns hash of the key or 0 on error 279 + */ 255 280 uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) 256 281 { 257 - int len; 282 + size_t len; 258 283 uint32_t hash; 259 284 int32_t lang_id; 260 285 char *pos = "\0"; 286 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 261 287 262 288 if(key == NULL) 263 289 { 264 290 logf("OP add_path No Key, *Clearing entry*"); 265 - op_clear_entry(&open_plugin_entry); 291 + op_clear_entry(op_entry); 266 292 return 0; 267 293 } 268 294 ··· 271 297 logf("OP add_path key: %s lang id: %d", skey, lang_id); 272 298 open_plugin_get_hash(strip_rockbox_root(skey), &hash); 273 299 274 - if(open_plugin_entry.hash != hash) 300 + if(op_entry->hash != hash) 275 301 { 276 302 logf("OP add_path *Flush entry*"); 277 303 /* the entry in ram needs saved */ 278 - op_update_dat(&open_plugin_entry, true); 304 + op_update_dat(op_entry, true); 279 305 } 280 306 281 307 if (plugin) 282 308 { 283 - open_plugin_entry.hash = hash; 284 - open_plugin_entry.lang_id = lang_id; 285 - open_plugin_entry.checksum = open_plugin_csum + 309 + op_entry->hash = hash; 310 + op_entry->lang_id = lang_id; 311 + op_entry->checksum = open_plugin_csum + 286 312 (lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); 287 313 /* name */ 288 314 if (path_basename(plugin, (const char **)&pos) == 0) 289 315 pos = "\0"; 290 316 291 - len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ); 317 + len = strlcpy(op_entry->name, pos, OPEN_PLUGIN_NAMESZ); 292 318 if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) 293 319 { 294 320 /* path */ 295 - strmemccpy(open_plugin_entry.path, plugin, OPEN_PLUGIN_BUFSZ); 321 + strmemccpy(op_entry->path, plugin, OPEN_PLUGIN_BUFSZ); 296 322 297 323 if(!parameter) 298 324 parameter = ""; 299 - strmemccpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); 325 + strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ); 300 326 goto retnhash; 301 327 } 302 328 else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) 303 329 { 304 - op_get_entry(0, OPEN_PLUGIN_LANG_IGNORE, &open_plugin_entry, plugin); 330 + op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin); 305 331 goto retnhash; 306 332 } 307 333 } ··· 309 335 logf("OP add_path Invalid, *Clearing entry*"); 310 336 if (lang_id != LANG_SHORTCUTS) /* from shortcuts menu */ 311 337 splashf(HZ * 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); 312 - op_clear_entry(&open_plugin_entry); 338 + op_clear_entry(op_entry); 313 339 hash = 0; 314 340 315 341 retnhash: 316 342 logf("OP add_path name: %s %s %s", 317 - open_plugin_entry.name, 318 - open_plugin_entry.path, 319 - open_plugin_entry.param); 343 + op_entry->name, op_entry->path, op_entry->param); 320 344 return hash; 321 345 } 322 346 347 + /* open_plugin_browse() 348 + * allows fthe user to browse for a plugin to set to a supplied key 349 + * if key is a lang_id that is used otherwise a hash of the key is created 350 + * for later recall of the plugin path 351 + */ 323 352 void open_plugin_browse(const char *key) 324 353 { 325 - logf("OP browse"); 354 + logf("%s", __func__); 326 355 struct browse_context browse; 327 356 char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; 328 - open_plugin_get_entry(key, &open_plugin_entry); 357 + open_plugin_load_entry(key); 358 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 329 359 330 360 logf("OP browse key: %s name: %s", 331 - (key ? P2STR((unsigned char *)key):"No Key") ,open_plugin_entry.name); 332 - logf("OP browse %s %s", open_plugin_entry.path, open_plugin_entry.param); 361 + (key ? P2STR((unsigned char *)key):"No Key"), open_plugin_entry.name); 362 + logf("OP browse %s %s", op_entry->path, op_entry->param); 333 363 334 - if (open_plugin_entry.path[0] == '\0') 335 - strcpy(open_plugin_entry.path, PLUGIN_DIR"/"); 364 + if (op_entry->path[0] == '\0') 365 + strcpy(op_entry->path, PLUGIN_DIR"/"); 336 366 337 367 browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "", 338 - Icon_Plugin, open_plugin_entry.path, NULL); 368 + Icon_Plugin, op_entry->path, NULL); 339 369 340 370 browse.buf = tmp_buf; 341 371 browse.bufsize = OPEN_PLUGIN_BUFSZ; ··· 344 374 open_plugin_add_path(key, tmp_buf, NULL); 345 375 } 346 376 347 - int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry) 377 + /* open_plugin_load_entry() 378 + * recall of the plugin path and parameters based on supplied key 379 + * returns the index in OPEN_PLUGIN_DAT where the entry was found (>= 0) 380 + * if the entry was found but has not been saved returns OPEN_PLUGIN_NEEDS_FLUSHED 381 + * otherwise returns OPEN_PLUGIN_NOT_FOUND (< 0) if key was not found 382 + */ 383 + int open_plugin_load_entry(const char *key) 348 384 { 349 - if (key == NULL || entry == NULL) 350 - return OPEN_PLUGIN_NOT_FOUND; 385 + if (key == NULL) 386 + key = ID2P(LANG_OPEN_PLUGIN_NOT_A_PLUGIN); /* won't be found */ 387 + 388 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 351 389 int opret; 352 390 uint32_t hash = 0; 353 391 int32_t lang_id = P2ID((unsigned char *)key); 354 392 const char* skey = P2STR((unsigned char *)key); /* string|LANGPTR => string */ 355 393 394 + /*Note: P2ID() returns -1 if key isnt a valid lang_id */ 356 395 if (lang_id <= OPEN_PLUGIN_LANG_INVALID) 357 396 open_plugin_get_hash(strip_rockbox_root(skey), &hash); /* in open_plugin.h */ 358 397 359 - opret = op_get_entry(hash, lang_id, entry, OPEN_PLUGIN_DAT); 398 + opret = op_load_entry(hash, lang_id, op_entry, OPEN_PLUGIN_DAT); 360 399 logf("OP entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); 361 400 362 401 if (opret == OPEN_PLUGIN_NOT_FOUND && lang_id > OPEN_PLUGIN_LANG_INVALID) 363 402 { /* try rb defaults */ 364 - opret = op_get_entry(hash, lang_id, entry, OPEN_RBPLUGIN_DAT); 403 + opret = op_load_entry(hash, lang_id, op_entry, OPEN_RBPLUGIN_DAT); 365 404 logf("OP rb_entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); 366 405 /* add to the user plugin.dat file if found */ 367 - op_update_dat(entry, false); 406 + op_update_dat(op_entry, false); 368 407 369 408 } 370 409 logf("OP entry ret: %s", (opret == OPEN_PLUGIN_NOT_FOUND ? "Not Found":"Found")); 371 410 return opret; 372 411 } 373 412 413 + /* open_plugin_run() 414 + * recall of the plugin path and parameters based on supplied key 415 + * runs the plugin using plugin_load see plugin_load for return values 416 + */ 374 417 int open_plugin_run(const char *key) 375 418 { 376 419 int ret = 0; 377 - int opret = open_plugin_get_entry(key, &open_plugin_entry); 420 + int opret = open_plugin_load_entry(key); 421 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 378 422 if (opret == OPEN_PLUGIN_NEEDS_FLUSHED) 379 - op_update_dat(&open_plugin_entry, false); 380 - const char *path = open_plugin_entry.path; 381 - const char *param = open_plugin_entry.param; 423 + op_update_dat(op_entry, false); 424 + const char *path = op_entry->path; 425 + const char *param = op_entry->param; 382 426 383 427 logf("OP run key: %s ret: %d name: %s", 384 - (key ? P2STR((unsigned char *)key):"No Key"), opret, open_plugin_entry.name); 385 - logf("OP run: %s %s %s", open_plugin_entry.name, path, param); 428 + (key ? P2STR((unsigned char *)key):"No Key"), opret, op_entry->name); 429 + logf("OP run: %s %s %s", op_entry->name, path, param); 386 430 387 431 if (param[0] == '\0') 388 432 param = NULL; ··· 392 436 ret = plugin_load(path, param); 393 437 394 438 if (ret != GO_TO_PLUGIN) 395 - op_clear_entry(&open_plugin_entry); 439 + op_clear_entry(op_entry); 396 440 397 441 return ret; 398 442 } 399 443 444 + /* open_plugin_cache_flush() 445 + * saves the current open_plugin_entry to disk 446 + */ 400 447 void open_plugin_cache_flush(void) 401 448 { 402 - logf("OP *cache flush*"); 449 + logf("%s", __func__); 450 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 403 451 /* start_in_screen == 0 is 'Previous Screen' it is actually 404 452 * defined as (GO_TO_PREVIOUS = -2) + 2 for *Legacy?* reasons AFAICT */ 405 453 if (global_settings.start_in_screen == 0 && 406 454 global_status.last_screen == GO_TO_PLUGIN && 407 - open_plugin_entry.lang_id > OPEN_PLUGIN_LANG_INVALID) 455 + op_entry->lang_id > OPEN_PLUGIN_LANG_INVALID) 408 456 { 409 457 /* flush the last item as LANG_PREVIOUS_SCREEN if the user wants to resume */ 410 - open_plugin_entry.lang_id = LANG_PREVIOUS_SCREEN; 458 + op_entry->lang_id = LANG_PREVIOUS_SCREEN; 411 459 } 412 - op_update_dat(&open_plugin_entry, true); 460 + op_update_dat(op_entry, true); 413 461 } 414 462 415 463 #endif /* ndef __PCTOOL__ */
+2 -3
apps/open_plugin.h
··· 64 64 offsetof(struct open_plugin_entry_t, lang_id) + \ 65 65 offsetof(struct open_plugin_entry_t, checksum) + \ 66 66 offsetof(struct open_plugin_entry_t, name) + \ 67 - /*offsetof(struct open_plugin_entry_t, key)+*/ \ 68 67 offsetof(struct open_plugin_entry_t, path) + \ 69 68 offsetof(struct open_plugin_entry_t, param)) 70 69 ··· 79 78 } 80 79 81 80 #ifndef PLUGIN 82 - extern struct open_plugin_entry_t open_plugin_entry; 81 + struct open_plugin_entry_t* open_plugin_get_entry(void); 83 82 uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter); 84 - int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry); 83 + int open_plugin_load_entry(const char *key); 85 84 void open_plugin_browse(const char *key); 86 85 int open_plugin_run(const char *key); 87 86 void open_plugin_cache_flush(void); /* flush to disk */
+10 -7
apps/root_menu.c
··· 760 760 761 761 while(loops-- > 0) /* just to keep things from getting out of hand */ 762 762 { 763 - int opret = open_plugin_get_entry(key, &open_plugin_entry); 764 - char *path = open_plugin_entry.path; 765 - char *param = open_plugin_entry.param; 763 + 764 + int opret = open_plugin_load_entry(key); 765 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 766 + char *path = op_entry->path; 767 + char *param = op_entry->param; 766 768 if (param[0] == '\0') 767 769 param = NULL; 768 770 if (path[0] == '\0' && key) ··· 792 794 if (opret != OPEN_PLUGIN_NEEDS_FLUSHED || last_screen != GO_TO_WPS) 793 795 { 794 796 /* Keep the entry in case of GO_TO_PREVIOUS */ 795 - open_plugin_entry.hash = 0; /*remove hash -- prevents flush to disk */ 796 - open_plugin_entry.lang_id = LANG_PREVIOUS_SCREEN; 797 + op_entry->hash = 0; /*remove hash -- prevents flush to disk */ 798 + op_entry->lang_id = LANG_PREVIOUS_SCREEN; 797 799 /*open_plugin_add_path(NULL, NULL, NULL);// clear entry */ 798 800 } 799 801 break; ··· 962 964 char *key; 963 965 if (global_status.last_screen == GO_TO_SHORTCUTMENU) 964 966 { 965 - if (open_plugin_entry.lang_id == LANG_OPEN_PLUGIN) 966 - open_plugin_entry.lang_id = LANG_SHORTCUTS; 967 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 968 + if (op_entry->lang_id == LANG_OPEN_PLUGIN) 969 + op_entry->lang_id = LANG_SHORTCUTS; 967 970 shortcut_origin = last_screen; 968 971 key = ID2P(LANG_SHORTCUTS); 969 972 }