static int codec_load_ram(struct codec_api *api) { struct lc_header *hdr; c_hdr = lc_get_header(curr_handle); hdr = c_hdr ? &c_hdr->lc_hdr : NULL; if (hdr == NULL || (hdr->magic != CODEC_MAGIC #ifdef HAVE_RECORDING && hdr->magic != CODEC_ENC_MAGIC #endif ) || hdr->target_id != TARGET_ID #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || hdr->load_addr != codecbuf || hdr->end_addr > codecbuf + CODEC_SIZE #endif ) { logf("codec header error"); lc_close(curr_handle); curr_handle = NULL; return CODEC_ERROR; } if (hdr->api_version > CODEC_API_VERSION || hdr->api_version < CODEC_MIN_API_VERSION) { logf("codec api version error"); lc_close(curr_handle); curr_handle = NULL; return CODEC_ERROR; } #if (CONFIG_PLATFORM & PLATFORM_NATIVE) codec_size = hdr->end_addr - codecbuf; #else codec_size = 0; #endif *(c_hdr->api) = api; logf("Codec: calling entrypoint"); return c_hdr->entry_point(CODEC_LOAD); }
int codec_close(void) { int status = CODEC_OK; if (curr_handle != NULL) { logf("Codec: cleaning up"); status = c_hdr->entry_point(CODEC_UNLOAD); lc_close(curr_handle); curr_handle = NULL; } return status; }
int main(int argc, char **argv) { int local = 0; unsigned long chan = 0; const char *dst = NULL; const char *src = NULL; const char *iface = NULL; int ch; while ((ch = getopt(argc, argv, "li:c:t:f:")) != -1) { switch (ch) { case 'l': local = 1; break; case 'c': chan = strtoul(optarg, NULL, 10); if (LC_CHAN_MAX < chan) { warnx("channel value must be less than 65536"); usage(); } break; case 't': dst = optarg; break; case 'f': src = optarg; break; default: usage(); } } argc -= optind; argv += optind; if (argc != 1) usage(); iface = argv[0]; /* * If no source or destination address provided, * set both to 'any'. */ if (src == NULL && dst == NULL) { src = "any"; dst = "any"; } /* * Convert source and/or destination with 'any' value to broadcast. */ if (src != NULL && strcmp(src, "any") == 0) src = "ff:ff:ff:ff:ff:ff"; if (dst != NULL && strcmp(dst, "any") == 0) dst = "ff:ff:ff:ff:ff:ff"; /* Initialize a packet device context. */ struct lc_dev dev; if (lc_open(&dev, iface, chan, src, dst, local) == -1) return 1; warnx("packet device opened at %s", iface); /* * If the source address (src) is specified, * read from the socket/device and write to stdout. * * If the destination address (dst) is specified, * read from stdin and write to the socket/device. * * Reading from device to stdout and writing to device from-stdin * are handled in separate threads if both roles are required. * * TODO: signals */ if (src != NULL && dst != NULL) { pthread_t r_thrd, w_thrd; if (pthread_create(&r_thrd, NULL, lc_reader, &dev) != 0) err(1, "pthread_create"); if (pthread_create(&w_thrd, NULL, lc_writer, &dev) != 0) err(1, "pthread_create"); // TODO: statistics if (pthread_join(r_thrd, NULL) != 0) err(1, "pthread_join"); if (pthread_join(w_thrd, NULL) != 0) err(1, "pthread_join"); } else { if (src != NULL) lc_reader(&dev); else if (dst != NULL) lc_writer(&dev); else err(1, "no read nor write mode set"); } // TODO: set signal handler with cleanup lc_close(&dev); return 0; }
int main(int argc, char **argv) { // parameter structures struct arg_lit *param_stop = arg_lit0("p", "stop", "stop animation"); struct arg_lit *param_single = arg_lit0("s", "single", "single animation"); struct arg_lit *param_loop = arg_lit0("l", "loop", "loop animation"); struct arg_int *param_frame = arg_int0("f", "frame", "<n>", "frame data"); struct arg_int *param_pos = arg_int0("p", "pos", "<n>", "frame pos in eeprom"); struct arg_int *param_delay = arg_int0("d", "delay", "<n>", "frame delay in eeprom"); struct arg_lit *param_save = arg_lit0("v", "save", "save one frame to the EEPROM (position, delay and frame required)"); //struct arg_lit *param_tty = arg_lit0("t", "terminal", "terminal mode"); //struct arg_lit *param_daemon = arg_lit0("d", "daemon", "daemon mode"); struct arg_lit *param_help = arg_lit0("h", "help", "show help"); struct arg_file *param_file = arg_filen("i", "ihex-file","<file>", 0, 1, "iHex input file to write to the EEPROM"); struct arg_end *param_end = arg_end(20); // default parameter param_frame->ival[0] = 0x00000000; param_pos->ival[0] = 0; param_delay->ival[0] = 1; // argtable array void *argtable[] = { param_stop, param_single, param_loop, param_frame, param_pos, param_delay, param_save, param_file, //param_tty, //param_daemon, param_help, param_end }; // parse the commandline arguments int nerrors = arg_parse(argc,argv,argtable); if (arg_nullcheck(argtable) != 0) { printf("error: insufficient memory\n"); arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return 0; } if (nerrors == 0 && param_help->count > 0) { printf("usage: ./clcc <OPTIONS>\n"); arg_print_glossary(stdout, argtable, "\t%-25s %s\n"); arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return 0; } // parsing failed or to less parameter given if (nerrors > 0 || argc < 2 || (param_save->count > 0 && (param_pos->count == 0 || param_delay->count == 0 || param_frame->count == 0)) ) { arg_print_errors(stdout,param_end,"clcc"); printf("usage: ./clcc <OPTIONS>\n"); arg_print_syntaxv(stdout,argtable,"\n"); arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return -1; } if (lc_init() != SUCCESSFULLY_CONNECTED) { arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); lc_close(); return -2; } if (param_stop->count > 0) { printf("stop animation loop\n"); lc_setMode(MODE_ANIMATION_STOP); } else if (param_loop->count > 0) { printf("starting animation loop\n"); lc_setMode(MODE_ANIMATION_LOOP); } else if (param_single->count > 0 ) { printf("starting animation as single shot\n"); lc_setMode(MODE_ANIMATION_SINGLE); } else if (param_save->count > 0 && param_pos->count > 0 && param_delay->count > 0 && param_frame->count > 0) { lc_setMode(MODE_ANIMATION_STOP); int frame = param_frame->ival[0]; int delay = param_delay->ival[0]; int pos = param_pos->ival[0]; printf("saving frame: index=%d delay=%d frame=0x%08x\n", pos, delay, frame); lc_saveFrame(frame, delay, pos); } else if (param_frame->count > 0) { lc_setMode(MODE_ANIMATION_STOP); int frame = param_frame->ival[0]; printf("view frame: data=0x%08x\n", frame); lc_setFrame(frame); } //printf("file[%d]=%s\n",i,file->filename[i]);*/ lc_close(); arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return 0; }
int plugin_load(const char* plugin, const void* parameter) { struct plugin_header *p_hdr; struct lc_header *hdr; if (current_plugin_handle && pfn_tsr_exit) { /* if we have a resident old plugin and a callback */ if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false ) { /* not allowing another plugin to load */ return PLUGIN_OK; } lc_close(current_plugin_handle); current_plugin_handle = pfn_tsr_exit = NULL; if (plugin_buffer_handle > 0) plugin_buffer_handle = core_free(plugin_buffer_handle); } splash(0, ID2P(LANG_WAIT)); strcpy(current_plugin, plugin); current_plugin_handle = lc_open(plugin, pluginbuf, PLUGIN_BUFFER_SIZE); if (current_plugin_handle == NULL) { splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin); return -1; } p_hdr = lc_get_header(current_plugin_handle); hdr = p_hdr ? &p_hdr->lc_hdr : NULL; if (hdr == NULL || hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || hdr->load_addr != pluginbuf || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE #endif ) { lc_close(current_plugin_handle); splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL)); return -1; } if (hdr->api_version > PLUGIN_API_VERSION || hdr->api_version < PLUGIN_MIN_API_VERSION) { lc_close(current_plugin_handle); splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION)); return -1; } #if (CONFIG_PLATFORM & PLATFORM_NATIVE) plugin_size = hdr->end_addr - pluginbuf; #else plugin_size = 0; #endif *(p_hdr->api) = &rockbox_api; lcd_clear_display(); lcd_update(); #ifdef HAVE_REMOTE_LCD lcd_remote_clear_display(); lcd_remote_update(); #endif push_current_activity(ACTIVITY_PLUGIN); /* some plugins assume the entry cache doesn't move and save pointers to it * they should be fixed properly instead of this lock */ tree_lock_cache(tree_get_context()); FOR_NB_SCREENS(i) viewportmanager_theme_enable(i, false, NULL); #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(TOUCHSCREEN_BUTTON); #endif /* allow voice to back off if the plugin needs lots of memory */ talk_buffer_set_policy(TALK_BUFFER_LOOSE); plugin_check_open_close__enter(); int rc = p_hdr->entry_point(parameter); tree_unlock_cache(tree_get_context()); pop_current_activity(); if (!pfn_tsr_exit) { /* close handle if plugin is no tsr one */ lc_close(current_plugin_handle); current_plugin_handle = NULL; if (plugin_buffer_handle > 0) plugin_buffer_handle = core_free(plugin_buffer_handle); } talk_buffer_set_policy(TALK_BUFFER_DEFAULT); /* Go back to the global setting in case the plugin changed it */ #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(global_settings.touch_mode); #endif #ifdef HAVE_LCD_BITMAP screen_helper_setfont(FONT_UI); #if LCD_DEPTH > 1 #ifdef HAVE_LCD_COLOR lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color, global_settings.bg_color); #else lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG); #endif #else /* LCD_DEPTH == 1 */ lcd_set_drawmode(DRMODE_SOLID); #endif /* LCD_DEPTH */ #endif /* HAVE_LCD_BITMAP */ #ifdef HAVE_REMOTE_LCD #if LCD_REMOTE_DEPTH > 1 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG, LCD_REMOTE_DEFAULT_BG); #else lcd_remote_set_drawmode(DRMODE_SOLID); #endif #endif lcd_clear_display(); #ifdef HAVE_REMOTE_LCD lcd_remote_clear_display(); #endif FOR_NB_SCREENS(i) viewportmanager_theme_undo(i, true); plugin_check_open_close__exit(); if (rc == PLUGIN_ERROR) splash(HZ*2, str(LANG_PLUGIN_ERROR)); return rc; }
int plugin_load(const char* plugin, const void* parameter) { struct plugin_header *p_hdr; struct lc_header *hdr; if (current_plugin_handle && pfn_tsr_exit) { /* if we have a resident old plugin and a callback */ if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false ) { /* not allowing another plugin to load */ return PLUGIN_OK; } lc_close(current_plugin_handle); current_plugin_handle = pfn_tsr_exit = NULL; } splash(0, ID2P(LANG_WAIT)); strcpy(current_plugin, plugin); current_plugin_handle = lc_open(plugin, pluginbuf, PLUGIN_BUFFER_SIZE); if (current_plugin_handle == NULL) { splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin); return -1; } p_hdr = lc_get_header(current_plugin_handle); hdr = p_hdr ? &p_hdr->lc_hdr : NULL; if (hdr == NULL || hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || hdr->load_addr != pluginbuf || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE #endif ) { lc_close(current_plugin_handle); splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL)); return -1; } if (hdr->api_version > PLUGIN_API_VERSION || hdr->api_version < PLUGIN_MIN_API_VERSION) { lc_close(current_plugin_handle); splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION)); return -1; } #if (CONFIG_PLATFORM & PLATFORM_NATIVE) plugin_size = hdr->end_addr - pluginbuf; #else plugin_size = 0; #endif *(p_hdr->api) = &rockbox_api; lcd_clear_display(); lcd_update(); #ifdef HAVE_REMOTE_LCD lcd_remote_clear_display(); lcd_remote_update(); #endif push_current_activity(ACTIVITY_PLUGIN); /* some plugins assume the entry cache doesn't move and save pointers to it * they should be fixed properly instead of this lock */ tree_lock_cache(tree_get_context()); FOR_NB_SCREENS(i) viewportmanager_theme_enable(i, false, NULL); #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(TOUCHSCREEN_BUTTON); #endif #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE open_files = 0; #endif int rc = p_hdr->entry_point(parameter); tree_unlock_cache(tree_get_context()); pop_current_activity(); if (!pfn_tsr_exit) { /* close handle if plugin is no tsr one */ lc_close(current_plugin_handle); current_plugin_handle = NULL; } /* Go back to the global setting in case the plugin changed it */ #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(global_settings.touch_mode); #endif #ifdef HAVE_LCD_BITMAP screen_helper_setfont(FONT_UI); #if LCD_DEPTH > 1 #ifdef HAVE_LCD_COLOR lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color, global_settings.bg_color); #else lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG); #endif #else /* LCD_DEPTH == 1 */ lcd_set_drawmode(DRMODE_SOLID); #endif /* LCD_DEPTH */ #endif /* HAVE_LCD_BITMAP */ #ifdef HAVE_REMOTE_LCD #if LCD_REMOTE_DEPTH > 1 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG, LCD_REMOTE_DEFAULT_BG); #else lcd_remote_set_drawmode(DRMODE_SOLID); #endif #endif lcd_clear_display(); #ifdef HAVE_REMOTE_LCD lcd_remote_clear_display(); #endif FOR_NB_SCREENS(i) viewportmanager_theme_undo(i, true); #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE if(open_files != 0 && !current_plugin_handle) { int fd; logf("Plugin '%s' leaks file handles", plugin); static const char *lines[] = { ID2P(LANG_PLUGIN_ERROR), "#leak-file-handles" }; static const struct text_message message={ lines, 2 }; button_clear_queue(); /* Empty the keyboard buffer */ gui_syncyesno_run(&message, NULL, NULL); for(fd=0; fd < MAX_OPEN_FILES; fd++) if(open_files & (1<<fd)) close_wrapper(fd); } #endif if (rc == PLUGIN_ERROR) splash(HZ*2, str(LANG_PLUGIN_ERROR)); return rc; }