void FbReadHandler::RootHandler::writeHeader() { writer().writeStartElement("head"); writeScript("qrc:/js/jquery.js"); writeScript("qrc:/js/location.js"); if (!m_style.isEmpty()) { writer().writeStartElement("style"); writer().writeAttribute("type", "text/css"); writer().writeCharacters(m_style); writer().writeEndElement(); } writer().writeEndElement(); writer().writeStartElement("body"); }
/** * Run an external script. */ static rpmRC runExtScript(rpmPlugins plugins, ARGV_const_t prefixes, const char *sname, rpmlogLvl lvl, FD_t scriptFd, ARGV_t * argvp, const char *script, int arg1, int arg2) { FD_t out = NULL; char * fn = NULL; pid_t pid, reaped; int status; rpmRC rc = RPMRC_FAIL; rpmlog(RPMLOG_DEBUG, "%s: scriptlet start\n", sname); if (script) { fn = writeScript(*argvp[0], script); if (fn == NULL) { rpmlog(RPMLOG_ERR, _("Couldn't create temporary file for %s: %s\n"), sname, strerror(errno)); goto exit; } argvAdd(argvp, fn); if (arg1 >= 0) { argvAddNum(argvp, arg1); } if (arg2 >= 0) { argvAddNum(argvp, arg2); } } if (scriptFd != NULL) { if (rpmIsVerbose()) { out = fdDup(Fileno(scriptFd)); } else { out = Fopen("/dev/null", "w.fdio"); if (Ferror(out)) { out = fdDup(Fileno(scriptFd)); } } } else { out = fdDup(STDOUT_FILENO); } if (out == NULL) { rpmlog(RPMLOG_ERR, _("Couldn't duplicate file descriptor: %s: %s\n"), sname, strerror(errno)); goto exit; } pid = fork(); if (pid == (pid_t) -1) { rpmlog(RPMLOG_ERR, _("Couldn't fork %s: %s\n"), sname, strerror(errno)); goto exit; } else if (pid == 0) {/* Child */ rpmlog(RPMLOG_DEBUG, "%s: execv(%s) pid %d\n", sname, *argvp[0], (unsigned)getpid()); /* Run scriptlet post fork hook for all plugins */ if (rpmpluginsCallScriptletForkPost(plugins, *argvp[0], RPMSCRIPTLET_FORK | RPMSCRIPTLET_EXEC) != RPMRC_FAIL) { doScriptExec(*argvp, prefixes, scriptFd, out); } else { _exit(126); /* exit 126 for compatibility with bash(1) */ } } do { reaped = waitpid(pid, &status, 0); } while (reaped == -1 && errno == EINTR); rpmlog(RPMLOG_DEBUG, "%s: waitpid(%d) rc %d status %x\n", sname, (unsigned)pid, (unsigned)reaped, status); if (reaped < 0) { rpmlog(lvl, _("%s scriptlet failed, waitpid(%d) rc %d: %s\n"), sname, pid, reaped, strerror(errno)); } else if (!WIFEXITED(status) || WEXITSTATUS(status)) { if (WIFSIGNALED(status)) { rpmlog(lvl, _("%s scriptlet failed, signal %d\n"), sname, WTERMSIG(status)); } else { rpmlog(lvl, _("%s scriptlet failed, exit status %d\n"), sname, WEXITSTATUS(status)); } } else { /* if we get this far we're clear */ rc = RPMRC_OK; } exit: if (out) Fclose(out); /* XXX dup'd STDOUT_FILENO */ if (fn) { if (!rpmIsDebug()) unlink(fn); free(fn); } return rc; }
void RaceAnalyzerComm::writeConfig(RaceCaptureConfig *config, RaceAnalyzerCommCallback * callback){ try{ wxDateTime start = wxDateTime::UNow(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); int updateCount = 0; for (int i = 0; i < CONFIG_ANALOG_CHANNELS;i++){ AnalogConfig &cfg = config->analogConfigs[i]; wxString cmd = "setAnalogCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.scalingMode); cmd = AppendFloatParam(cmd, cfg.linearScaling); ScalingMap &map = (cfg.scalingMap); for (int m=0; m < CONFIG_ANALOG_SCALING_BINS;m++){ cmd = AppendIntParam(cmd, map.rawValues[m]); } for (int m=0; m < CONFIG_ANALOG_SCALING_BINS;m++){ cmd = AppendFloatParam(cmd, map.scaledValue[m]); } wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_TIMER_CHANNELS; i++){ TimerConfig &cfg = config->timerConfigs[i]; wxString cmd = "setTimerCfg"; cmd = AppendIntParam(cmd, i); AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.slowTimerEnabled); cmd = AppendIntParam(cmd, cfg.mode); cmd = AppendIntParam(cmd, cfg.pulsePerRev); cmd = AppendIntParam(cmd, cfg.timerDivider); cmd = AppendIntParam(cmd, cfg.scaling); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_ACCEL_CHANNELS; i++){ AccelConfig &cfg = config->accelConfigs[i]; wxString cmd = "setAccelCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.mode); cmd = AppendIntParam(cmd, cfg.channel); cmd = AppendIntParam(cmd, cfg.zeroValue); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_ANALOG_PULSE_CHANNELS; i++){ PwmConfig &cfg = config->pwmConfigs[i]; wxString cmd = "setPwmCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.outputMode); cmd = AppendIntParam(cmd, cfg.loggingMode); cmd = AppendIntParam(cmd, cfg.startupDutyCycle); cmd = AppendIntParam(cmd, cfg.startupPeriod); cmd = AppendFloatParam(cmd, cfg.voltageScaling); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_GPIO_CHANNELS; i++){ GpioConfig &cfg = config->gpioConfigs[i]; wxString cmd = "setGpioCfg"; cmd = AppendIntParam(cmd,i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.mode); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { GpsConfig &cfg = config->gpsConfig; { wxString cmd = "setGpsCfg"; cmd = AppendIntParam(cmd, cfg.gpsInstalled); cmd = AppendChannelConfig(cmd, cfg.latitudeCfg); cmd = AppendChannelConfig(cmd, cfg.longitudeCfg); cmd = AppendChannelConfig(cmd, cfg.speedCfg); cmd = AppendChannelConfig(cmd, cfg.timeCfg); cmd = AppendChannelConfig(cmd, cfg.satellitesCfg); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { wxString cmd = "setStartFinishCfg"; cmd = AppendChannelConfig(cmd, cfg.lapCountCfg); cmd = AppendChannelConfig(cmd, cfg.lapTimeCfg); cmd = AppendChannelConfig(cmd, cfg.splitTimeCfg); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.latitude); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.longitude); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.targetRadius); cmd = AppendFloatParam(cmd, cfg.splitTarget.latitude); cmd = AppendFloatParam(cmd, cfg.splitTarget.longitude); cmd = AppendFloatParam(cmd, cfg.splitTarget.targetRadius); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } } { ConnectivityConfig &cfg = config->connectivityConfig; wxString cmd = "setOutputCfg"; cmd = AppendIntParam(cmd, cfg.sdLoggingMode); cmd = AppendIntParam(cmd, cfg.connectivityMode); cmd = AppendUIntParam(cmd, cfg.p2pConfig.destinationAddrHigh); cmd = AppendUIntParam(cmd, cfg.p2pConfig.destinationAddrLow); cmd = AppendStringParam(cmd, cfg.telemetryConfig.telemetryServer); cmd = AppendStringParam(cmd, cfg.telemetryConfig.telemetryDeviceId); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); cmd = "setCellCfg"; cmd = AppendStringParam(cmd, cfg.cellularConfig.apnHost); cmd = AppendStringParam(cmd, cfg.cellularConfig.apnUser); cmd = AppendStringParam(cmd, cfg.cellularConfig.apnPass); result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { writeScript(config->luaScript); updateWriteConfigPct(++updateCount,callback); } wxTimeSpan dur = wxDateTime::UNow() - start; VERBOSE(FMT("write config in %f",dur.GetMilliseconds().ToDouble())); callback->WriteConfigComplete(true,""); } catch(CommException &e){ callback->WriteConfigComplete(false, e.GetErrorMessage()); } CloseSerialPort(); }