static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events)) { int sd; struct init_request rq; sd = accept(w->fd, NULL, NULL); if (sd < 0) { _pe("Failed serving API request"); return; } while (1) { int result = 0; ssize_t len; len = read(sd, &rq, sizeof(rq)); if (len <= 0) { if (-1 == len) { if (EINTR == errno) continue; if (EAGAIN == errno) break; _e("Failed reading initctl request, error %d: %s", errno, strerror(errno)); } break; } if (rq.magic != INIT_MAGIC || len != sizeof(rq)) { _e("Invalid initctl request."); break; } switch (rq.cmd) { case INIT_CMD_RUNLVL: switch (rq.runlevel) { case '0': _d("Halting system (SIGUSR2)"); do_shutdown(SIGUSR2); break; case 's': case 'S': _d("Cannot enter bootstrap after boot ..."); rq.runlevel = '1'; /* Fall through to regular processing */ case '1'...'5': case '7'...'9': _d("Setting new runlevel %c", rq.runlevel); service_runlevel(rq.runlevel - '0'); break; case '6': _d("Rebooting system (SIGUSR1)"); do_shutdown(SIGUSR1); break; default: _d("Unsupported runlevel: %d", rq.runlevel); break; } break; case INIT_CMD_DEBUG: debug = !debug; if (debug) silent = 0; else silent = quiet ? 1 : SILENT_MODE; break; case INIT_CMD_RELOAD: /* 'init q' and 'initctl reload' */ service_reload_dynamic(); break; case INIT_CMD_START_SVC: result = do_start(rq.data, sizeof(rq.data)); break; case INIT_CMD_STOP_SVC: result = do_pause(rq.data, sizeof(rq.data)); break; case INIT_CMD_RESTART_SVC: result = do_restart(rq.data, sizeof(rq.data)); break; #ifndef INETD_DISABLED case INIT_CMD_QUERY_INETD: result = do_query_inetd(rq.data, sizeof(rq.data)); break; #endif case INIT_CMD_EMIT: result = do_handle_emit(rq.data, sizeof(rq.data)); break; case INIT_CMD_GET_RUNLEVEL: rq.runlevel = runlevel; result = 0; break; case INIT_CMD_ACK: _d("Client failed reading ACK."); goto leave; default: _d("Unsupported cmd: %d", rq.cmd); break; } if (result) rq.cmd = INIT_CMD_NACK; else rq.cmd = INIT_CMD_ACK; len = write(sd, &rq, sizeof(rq)); if (len != sizeof(rq)) _d("Failed sending ACK/NACK back to client."); } leave: close(sd); }
int main(int argc, char *argv[]) { fmiCallbackFunctions callBackFunctions; fmi_dll_t* fmu; const char* FMUPath = "C:\\P510-JModelica\\FMIToolbox\\trunk\\src\\wrapperfolder\\Furuta.fmu"; const char* tmpPath = "C:\\Documents and Settings\\p418_baa\\Desktop\\XMLtest\\temporaryfolder"; const char* dllPath; const char* modelIdentifier; const char* modelName; const char* model_description_path; const char* instanceName; const char* GUID; fmi_dll_standard_enu_t standard = FMI_ME1; /* or FMI_CS1 */ fmiBoolean loggingOn = fmiTrue; fmi1_xml_model_description_t* md; jm_status_enu_t status; PRINT_MY_DEBUG; if (jm_status_error == fmi_zip_unzip(FMUPath, tmpPath)) { printf("Failed to unzip the FMU file\n"); abort(); } callBackFunctions.logger = mylogger; callBackFunctions.allocateMemory = calloc; callBackFunctions.freeMemory = free; model_description_path = fmi_import_get_model_description_path(tmpPath, callBackFunctions); md = fmi1_xml_allocate_model_description(0); if(!md) abort(); if(fmi1_xml_parse(md, model_description_path)) { printf("Error parsing XML file %s:%s\n", FMUPath, fmi1_xml_get_last_error(md)); fmi1_xml_free_model_description(md); abort(); } printf("Model name: %s\n", fmi1_xml_get_model_name(md)); printf("Model identifier: %s\n", fmi1_xml_get_model_identifier(md)); printf("Model GUID: %s\n", fmi1_xml_get_GUID(md)); modelIdentifier = fmi1_xml_get_model_identifier(md); modelName = fmi1_xml_get_model_name(md); GUID = fmi1_xml_get_GUID(md); modelIdentifier = fmi1_xml_get_model_identifier(md); dllPath = fmi_import_get_dll_path(tmpPath, modelIdentifier, callBackFunctions); fmu = fmi_dll_common_create_dllfmu(dllPath, modelIdentifier, callBackFunctions, standard); if (fmu == NULL) { printf("An error occured while fmi_dll_common_create_dllfmu was called, an error message should been printed.\n"); do_pause(); return 0; } status = fmi_dll_common_load_dll(fmu); if (status == jm_status_error) { printf("Error in fmi_dll_common_load_dll: %s\n", fmi_dll_common_get_last_error(fmu)); do_pause(); return 0; } status = fmi_dll_common_load_fcn(fmu); if (status == jm_status_error) { printf("Error in fmi_dll_common_load_fcn: %s\n", fmi_dll_common_get_last_error(fmu)); do_pause(); return 0; } printf("fmi_dll_1_0_me_get_version: %s\n", fmi_dll_1_0_me_get_version(fmu)); fmi_dll_common_free_dll(fmu); fmi_dll_common_destroy_dllfmu(fmu); fmi1_xml_free_model_description(md); printf("Everything seems to be OK since you got this far=)!\n"); do_pause(); }
void pause_numeric (GFC_INTEGER_4 code) { st_printf ("PAUSE %d\n", (int) code); do_pause (); }
static jboolean parseOptions(char *options) { TransportSpec *currentTransport = NULL; char *end; char *current; int length; char *str; char *errmsg; /* Set defaults */ gdata->assertOn = DEFAULT_ASSERT_ON; gdata->assertFatal = DEFAULT_ASSERT_FATAL; logfile = DEFAULT_LOGFILE; /* Options being NULL will end up being an error. */ if (options == NULL) { options = ""; } /* Check for "help" BEFORE we add any environmental settings */ if ((strcmp(options, "help")) == 0) { printUsage(); forceExit(0); /* Kill entire process, no core dump wanted */ } /* These buffers are never freed */ { char *envOptions; /* * Add environmentally specified options. */ envOptions = getenv("_JAVA_JDWP_OPTIONS"); if (envOptions != NULL) { options = add_to_options(options, envOptions); if ( options==NULL ) { EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options"); } } /* * Allocate a buffer for names derived from option strings. It should * never be longer than the original options string itself. * Also keep a copy of the options in gdata->options. */ length = (int)strlen(options); gdata->options = jvmtiAllocate(length + 1); if (gdata->options == NULL) { EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options"); } (void)strcpy(gdata->options, options); names = jvmtiAllocate(length + 1); if (names == NULL) { EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options"); } transports = bagCreateBag(sizeof(TransportSpec), 3); if (transports == NULL) { EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"transports"); } } current = names; end = names + length; str = options; while (*str) { char buf[100]; /*LINTED*/ if (!get_tok(&str, buf, (int)sizeof(buf), '=')) { goto syntax_error; } if (strcmp(buf, "transport") == 0) { currentTransport = bagAdd(transports); /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } currentTransport->name = current; current += strlen(current) + 1; } else if (strcmp(buf, "address") == 0) { if (currentTransport == NULL) { errmsg = "address specified without transport"; goto bad_option_with_errmsg; } /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } currentTransport->address = current; current += strlen(current) + 1; } else if (strcmp(buf, "timeout") == 0) { if (currentTransport == NULL) { errmsg = "timeout specified without transport"; goto bad_option_with_errmsg; } /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } currentTransport->timeout = atol(current); current += strlen(current) + 1; } else if (strcmp(buf, "launch") == 0) { /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } launchOnInit = current; current += strlen(current) + 1; } else if (strcmp(buf, "onthrow") == 0) { /* Read class name and convert in place to a signature */ *current = 'L'; /*LINTED*/ if (!get_tok(&str, current + 1, (int)(end - current - 1), ',')) { goto syntax_error; } initOnException = current; while (*current != '\0') { if (*current == '.') { *current = '/'; } current++; } *current++ = ';'; *current++ = '\0'; } else if (strcmp(buf, "assert") == 0) { /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } if (strcmp(current, "y") == 0) { gdata->assertOn = JNI_TRUE; gdata->assertFatal = JNI_FALSE; } else if (strcmp(current, "fatal") == 0) { gdata->assertOn = JNI_TRUE; gdata->assertFatal = JNI_TRUE; } else if (strcmp(current, "n") == 0) { gdata->assertOn = JNI_FALSE; gdata->assertFatal = JNI_FALSE; } else { goto syntax_error; } current += strlen(current) + 1; } else if (strcmp(buf, "pause") == 0) { if ( !get_boolean(&str, &dopause) ) { goto syntax_error; } if ( dopause ) { do_pause(); } } else if (strcmp(buf, "coredump") == 0) { if ( !get_boolean(&str, &docoredump) ) { goto syntax_error; } } else if (strcmp(buf, "errorexit") == 0) { if ( !get_boolean(&str, &(gdata->doerrorexit)) ) { goto syntax_error; } } else if (strcmp(buf, "exitpause") == 0) { errmsg = "The exitpause option removed, use -XX:OnError"; goto bad_option_with_errmsg; } else if (strcmp(buf, "precrash") == 0) { errmsg = "The precrash option removed, use -XX:OnError"; goto bad_option_with_errmsg; } else if (strcmp(buf, "logfile") == 0) { /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } logfile = current; current += strlen(current) + 1; } else if (strcmp(buf, "logflags") == 0) { /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } /*LINTED*/ logflags = (unsigned)strtol(current, NULL, 0); } else if (strcmp(buf, "debugflags") == 0) { /*LINTED*/ if (!get_tok(&str, current, (int)(end - current), ',')) { goto syntax_error; } /*LINTED*/ gdata->debugflags = (unsigned)strtol(current, NULL, 0); } else if ( strcmp(buf, "suspend")==0 ) { if ( !get_boolean(&str, &suspendOnInit) ) { goto syntax_error; } } else if ( strcmp(buf, "server")==0 ) { if ( !get_boolean(&str, &isServer) ) { goto syntax_error; } } else if ( strcmp(buf, "strict")==0 ) { /* Obsolete, but accept it */ if ( !get_boolean(&str, &isStrict) ) { goto syntax_error; } } else if ( strcmp(buf, "quiet")==0 ) { if ( !get_boolean(&str, &(gdata->quiet)) ) { goto syntax_error; } } else if ( strcmp(buf, "onuncaught")==0 ) { if ( !get_boolean(&str, &initOnUncaught) ) { goto syntax_error; } } else if ( strcmp(buf, "mutf8")==0 ) { if ( !get_boolean(&str, &(gdata->modifiedUtf8)) ) { goto syntax_error; } } else if ( strcmp(buf, "stdalloc")==0 ) { /* Obsolete, but accept it */ if ( !get_boolean(&str, &useStandardAlloc) ) { goto syntax_error; } } else { goto syntax_error; } } /* Setup logging now */ if ( logfile!=NULL ) { setup_logging(logfile, logflags); (void)atexit(&atexit_finish_logging); } if (bagSize(transports) == 0) { errmsg = "no transport specified"; goto bad_option_with_errmsg; } /* * TO DO: Remove when multiple transports are allowed. (replace with * check below. */ if (bagSize(transports) > 1) { errmsg = "multiple transports are not supported in this release"; goto bad_option_with_errmsg; } if (!isServer) { jboolean specified = bagEnumerateOver(transports, checkAddress, NULL); if (!specified) { /* message already printed */ goto bad_option_no_msg; } } /* * The user has selected to wait for an exception before init happens */ if ((initOnException != NULL) || (initOnUncaught)) { initOnStartup = JNI_FALSE; if (launchOnInit == NULL) { /* * These rely on the launch=/usr/bin/foo * suboption, so it is an error if user did not * provide one. */ errmsg = "Specify launch=<command line> when using onthrow or onuncaught suboption"; goto bad_option_with_errmsg; } } return JNI_TRUE; syntax_error: ERROR_MESSAGE(("JDWP option syntax error: %s=%s", AGENTLIB, options)); return JNI_FALSE; bad_option_with_errmsg: ERROR_MESSAGE(("JDWP %s: %s=%s", errmsg, AGENTLIB, options)); return JNI_FALSE; bad_option_no_msg: ERROR_MESSAGE(("JDWP %s: %s=%s", "invalid option", AGENTLIB, options)); return JNI_FALSE; }
/* * f05_char_dev_write: - use to write data into RMI stream * First byte is indication of parameter to change * * @filep : file structure for write * @buf: user-level buffer pointer contains data to be written * @count: number of byte be be written * @f_pos: offset (starting register address) * * @return number of bytes written from user buffer (buf) if succeeds * negative number if error occurs. */ static ssize_t f05_char_dev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { struct f05_data *f05 = NULL; struct f05_raw_data_char_dev *my_dev = NULL; struct rmi_function_container *fn_dev; struct rmi_driver *driver; struct rmi_driver_data *driver_data; struct rmi_function_container *f01_dev; char tmpbuf[2]; char command; int retval = 0; if (!filp) { dev_err(&fn_dev->dev, "%s: called with NULL file pointer\n", __func__); return -EINVAL; } my_dev = filp->private_data; if (!my_dev) { dev_err(&fn_dev->dev, "%s: called with NULL private_data\n", __func__); return -EINVAL; } f05 = container_of(my_dev, struct f05_data, raw_data_feed); fn_dev = f05->fn_dev; driver = fn_dev->rmi_dev->driver; driver_data = dev_get_drvdata(&fn_dev->rmi_dev->dev); retval = copy_from_user(tmpbuf, buf, count); command = tmpbuf[0]; switch (command) { case F05_REPORT_SET_TYPE: if (count < 1) { dev_err(&fn_dev->dev, "%s: missing report type.\n", __func__); retval = -EINVAL; goto error_exit; } retval = do_set_report_mode(f05, (u8)tmpbuf[1]); if (retval < 0) goto error_exit; break; case F05_REPORT_START: /* Overwrite and store interrupts */ mutex_lock(&f05->status_mutex); if (f05->status == F05_STATE_READY) { if (driver->store_irq_mask) { u8 irq_bits[driver_data->num_of_irq_regs]; f01_dev = driver_data->f01_container; u8_or(irq_bits, f01_dev->irq_mask, fn_dev->irq_mask, driver_data->irq_count); driver->store_irq_mask(fn_dev->rmi_dev, irq_bits); } f05->data_ready = false; set_status(f05, F05_STATE_RUN); mutex_unlock(&f05->status_mutex); request_next_report(f05); } else { dev_err(&fn_dev->dev, "%s: cannot start report in state %d.\n", __func__, f05->status); mutex_unlock(&f05->status_mutex); retval = -EINVAL; goto error_exit; } break; case F05_REPORT_PAUSE: do_pause(f05); break; case F05_REPORT_STOP: do_stop(f05); break; case F05_REPORT_FORCE_ZERO: mutex_lock(&f05->status_mutex); if (f05->status == F05_STATE_READY) { f05->data_ready = false; f05->dev_command.get_image = 0; f05->dev_command.force_zero = 1; retval = rmi_write_block(f05->fn_dev->rmi_dev, f05->fn_dev->fd.command_base_addr, (u8 *) &f05->dev_command, sizeof(f05->dev_command)); mutex_unlock(&f05->status_mutex); if (retval < 0) { dev_err(&fn_dev->dev, "%s: Could not write command register, code: %d.\n", __func__, retval); goto error_exit; } } else { dev_err(&fn_dev->dev, "%s: cannot force zero in state %d.\n", __func__, f05->status); mutex_unlock(&f05->status_mutex); retval = -EINVAL; goto error_exit; } break; default: dev_err(&fn_dev->dev, "%s: invalid command %d.\n", __func__, command); retval = -EINVAL; goto error_exit; } retval = count; error_exit: return retval; }
static void enemy_tag_loop() { update_caption = tag_update_caption; tag_enemy_current_route = 0; tag_enemy_current_shot = 0; tag_enemy_spawnline = map_spawn_line; tag_enemy_y = 0; tag_enemy_upscrolled = 0; reset_tag_enemy(); tag_enemy_id = init_enemy(&tag_enemy); SDL_Event sdl_event; while(1) { if(!obj_slot_used[tag_enemy_id]) update_tag_enemy(0); //tag_enemy_id = init_enemy(&tag_enemy); unsigned need_redraw = 1; while (SDL_PollEvent(&sdl_event)) { need_redraw = 0; int dir = -1; switch (sdl_event.type) { case SDL_KEYUP: switch(sdl_event.key.keysym.sym) { case SDLK_e: dump_enemy(); return; case SDLK_g: toggle_gun(); break; case SDLK_d: enter_direction(); break; case SDLK_i: insert_steps(); break; case SDLK_s: insert_shot(); break; case SDLK_p: do_pause(); break; case SDLK_c: clear_screen(); video_update(); need_redraw = 1; break; case SDLK_SPACE: update_tag_enemy(1); break; case SDLK_PAGEUP: scrollup(); break; case SDLK_KP_PLUS: dir = 1; case SDLK_KP_MINUS: if((sdl_event.key.keysym.mod & KMOD_RSHIFT) || (sdl_event.key.keysym.mod & KMOD_LSHIFT)) toggle_shape(dir); else if((sdl_event.key.keysym.mod & KMOD_RALT) || (sdl_event.key.keysym.mod & KMOD_LALT)) toggle_route(dir); else if((sdl_event.key.keysym.mod & KMOD_RCTRL) || (sdl_event.key.keysym.mod & KMOD_LCTRL)) toggle_shot(dir); else toggle_vel(dir); break; default: break; } case SDL_KEYDOWN: switch(sdl_event.key.keysym.sym) { case SDLK_RIGHT: dir = 1; case SDLK_LEFT: if((sdl_event.key.keysym.mod & KMOD_RSHIFT) || (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4; tag_enemy.x += dir; update_tag_enemy(1); break; case SDLK_DOWN: dir = 1; case SDLK_UP: if((sdl_event.key.keysym.mod & KMOD_RSHIFT) || (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4; tag_enemy_y += dir; update_tag_enemy(1); break; default: ; } break; default: ; } } game_tick(need_redraw); } }
static void send_space (void) { do_pause (MORSE_SPACE_DURATION_MS); }
static void send_pause (void) { do_pause (MORSE_PAUSE_DURATION_MS); }