//! Program a range of flash from buffer //! //! Returns an error if the security location is to be programmed //! to permanently lock the device //! void programRange(FlashData_t *flashData) { FlashController *controller = flashData->controller; uint32_t address = flashData->address; const uint32_t *data = flashData->data; uint32_t numWords = flashData->size/4; int rc = FLASH_ERR_OK; if ((flashData->flags&DO_PROGRAM_RANGE) == 0) { return; } if ((address & 0x03) != 0) { setErrorCode(FLASH_ERR_ILLEGAL_PARAMS); } // Program words while (numWords-- > 0) { if (address == (NV_FSEC_ADDRESS&~3)) { // Check for permanent secure value if ((*data & (FTFL_FSEC_MEEN_MASK)) == (FTFL_FSEC_MEEN_DISABLE)) { setErrorCode(FLASH_ERR_ILLEGAL_SECURITY); } } controller->fccob0_3 = (F_PGM4 << 24) | address; controller->fccob4_7 = *data; rc = executeCommand(controller); if (rc != FLASH_ERR_OK) { setErrorCode(rc); } address += 4; data++; } flashData->flags &= ~DO_PROGRAM_RANGE; }
//! Main C entry point //! //! Assumes ramBuffer is set up beforehand //! void entry(void) { FlashData_t *flashData; // Handle on programming data // Disable COP *(gFlashProgramHeader.soptAddress+0x0A) = 0x00; // Handle on programming data flashData = gFlashProgramHeader.flashData; // Indicate not complete flashData->flags &= ~IS_COMPLETE; // No errors so far flashData->errorCode = FLASH_ERR_OK; if (flashData->controller == NULL) { setErrorCode(FLASH_ERR_ILLEGAL_PARAMS); } // Clear invalid/unused address bits // A23 is used for Flash block number flashData->address &= 0x008FFFFFUL; initFlash(flashData); eraseFlashBlock(flashData); programPartition(flashData) ; eraseRange(flashData); blankCheckRange(flashData); programRange(flashData); verifyRange(flashData); // Indicate completed setErrorCode(FLASH_ERR_OK); }
//! Check that a range of flash is blank (=0xFFFF) //! void blankCheckRange(FlashData_t *flashData) { static const uint32_t elementSize = 4; // Size of element verified FlashController *controller = flashData->controller; uint32_t address = flashData->address; uint32_t numElements = (flashData->size+elementSize-1)/elementSize; if ((flashData->flags&DO_BLANK_CHECK_RANGE) == 0) { return; } if ((address & (elementSize-1)) != 0) { setErrorCode(FLASH_ERR_ILLEGAL_PARAMS); } while (numElements>0) { int rc; uint16_t num = 0x8000; if (num>numElements) { num = (uint16_t)numElements; } controller->fccob0_3 = (F_RD1SEC << 24) | address; controller->fccob4_7 = (num <<16) | (F_USER_MARGIN<<8) | 0; rc = executeCommand(controller); if (rc != FLASH_ERR_OK) { if (rc == FLASH_ERR_PROG_MGSTAT0) { rc = FLASH_ERR_ERASE_FAILED; } // flashData->frequency = controller->fccob0_3; // debug // flashData->address = controller->fccob4_7; setErrorCode(rc); } numElements -= num; address += elementSize*num; } flashData->flags &= ~DO_BLANK_CHECK_RANGE; }
/** * Program a range of flash from buffer * * Returns an error if the security location is to be programmed * to permanently lock the device */ void programRange(FlashData_t *flashData) { uint32_t address = fixAddress(flashData->address); uint32_t endAddress = flashData->address+flashData->dataSize; const uint32_t *data = flashData->dataAddress; if ((flashData->flags&DO_PROGRAM_RANGE) == 0) { return; } if ((address & 0x07) != 0) { setErrorCode(FLASH_ERR_ILLEGAL_PARAMS); } // Program words while (address < endAddress) { if (address == (NV_FSEC_ADDRESS&~3)) { // Check for permanent secure value if ((*data & (FTFL_FSEC_MEEN_MASK)) == (FTFL_FSEC_MEEN_DISABLE)) { setErrorCode(FLASH_ERR_ILLEGAL_SECURITY); } } flashData->controller->fccob0_3 = (F_PGM8 << 24) | address; flashData->controller->fccob4_7 = *data++; flashData->controller->fccob8_B = *data++; executeCommand(flashData->controller); address += 8; } flashData->flags &= ~DO_PROGRAM_RANGE; }
ConfigErrorCode Config::parseStream(FILE *stream) { confin = stream; confdebug = _debug ? 1 : 0; int status = confparse(this); if (status != 0) return setErrorCode(kConfigParseStreamErr); return setErrorCode(kConfigNoErr); }
ConfigErrorCode Config::getValue(const char *key, char *& value) { DictItem *item = findDictItem(key); if (item == NULL) return setErrorCode(kConfigNoValueForKey); value = item->getStringValue(); if (item->lastError() != kDictNoErr) return setErrorCode(kConfigValueWrongType); return setErrorCode(kConfigNoErr); }
bool HttpClient::doMultipartPost() { //如果有Fields段 已经写入了body内 直接发送 if (!sendBody()) { setErrorCode(HTTPERROR_TRANSPORT); return false; } //发送文件 const std::vector<HttpFile*>& post_files = _request->getFiles(); const std::string& boundary = _request->getBoundary(); for (size_t i = 0; i < post_files.size(); i++) { const std::string name = post_files[i]->_name; IHttpPostFile* post_file = post_files[i]->_post_file; std::string file_header = "--" + boundary + "\r\n" "content-disposition: form-data; name=\"" + name + "\"; filename=\"" + post_file->getFilename() + "\"\r\n" + "content-type: " + post_file->getContentType() + "\r\n" + "\r\n"; bool send_file_header = _proxy_socket->writeAll(file_header.c_str(),file_header.size()); if (!send_file_header) { setErrorCode(HTTPERROR_TRANSPORT); return false; } bool post_file_success = uploadFile(post_file); if (!post_file_success) { setErrorCode(HTTPERROR_TRANSPORT); return false; } std::string file_tailer = "\r\n"; bool send_file_tailer = _proxy_socket->writeAll(file_tailer.c_str(),file_tailer.size()); if (!send_file_tailer) { setErrorCode(HTTPERROR_TRANSPORT); return false; } } //发送boundary结束标记 std::string post_tailer = "--" + boundary + "--\r\n"; bool send_post_tailer = _proxy_socket->writeAll(post_tailer.c_str(),post_tailer.size()); return send_post_tailer ? getResponse() : setErrorCode(HTTPERROR_TRANSPORT) , false; }
ConfigErrorCode Config::parseStream(FILE *stream) { confin = stream; confdebug = _debug ? 1 : 0; #if defined(OF_ANDROID) || defined(OPENFRAMEWORKS) int status = 0; #else int status = confparse(this); #endif if (status != 0) return setErrorCode(kConfigParseStreamErr); return setErrorCode(kConfigNoErr); }
/* * SHM IN: * fname : * * operation: DBG_GET_SHADER_CODE * SHM out: * fname : * * result : DBG_ERROR_CODE */ void restoreActiveShader(void) { int error; ORIG_GL(glUseProgram)(g.storedShader.programHandle); error = glError(); if (error) { setErrorCode(error); return; } freeShaderProgram(&g.storedShader); setErrorCode(DBG_NO_ERROR); }
void LitResPasswordRecoveryDataParser::processTag(const std::string &tag) { if (TAG_PASSWORD_RECOVERY_FAILED == tag) { const std::string &error = attributes()["error"]; if ("1" == error) { setErrorCode(NetworkErrors::ERROR_NO_USER_EMAIL); } else if ("2" == error) { setErrorCode(NetworkErrors::ERROR_EMAIL_WAS_NOT_SPECIFIED); } else { setErrorCode(NetworkErrors::ERROR_INTERNAL); } } else if (TAG_PASSWORD_RECOVERY_OK == tag) { // NOP } }
CameraException::CameraException(const error_code aCode, const string& aFile, const string& aFunc, int aLine) : Exception("",aFile,aFunc,aLine){ setErrorCode(aCode); }
bool HttpClient::downloadHeader(std::string& body_header) { body_header.clear(); char buff[kmax_buffer_size] = {0}; std::string header; bool complete = false; while(!complete) { int ret = _proxy_socket->read(buff,kmax_buffer_size); if (ret <= 0) { setErrorCode(HTTPERROR_TRANSPORT); break; } header.append(buff,ret); //因为Header往往很短,基本一次可以收完 size_t end_index = header.find("\r\n\r\n"); //所以也不需要计算偏移来提高搜索速度 if (end_index != std::string::npos) { complete = true; size_t length = header.length() ; body_header = header.substr(end_index + 4,length - end_index - 4); _response->setHeader(header.substr(0,end_index + 4)); } } return complete; }
DirException::DirException(const error_code aCode, const string& aPath, const string& aFile, const string& aFunc) :Exception("",aFile,aFunc){ setErrorCode(aCode,aPath); }
//! Erase a range of flash //! void eraseRange(FlashData_t *flashData) { FlashController *controller = flashData->controller; uint32_t address = flashData->address; uint32_t endAddress = address + flashData->size - 1; // Inclusive uint32_t pageMask = flashData->sectorSize-1U; int rc; if ((flashData->flags&DO_ERASE_RANGE) == 0) { return; } // Check for empty range before block rounding if (flashData->size == 0) { return; } // Round start address to start of block (inclusive) address &= ~pageMask; // Round end address to end of block (inclusive) endAddress |= pageMask; // Erase each block/page while (address <= endAddress) { controller->fccob0_3 = (F_ERSSCR << 24) | address; rc = executeCommand(controller); if (rc != FLASH_ERR_OK) { if (rc == FLASH_ERR_PROG_MGSTAT0) { rc = FLASH_ERR_ERASE_FAILED; } setErrorCode(rc); } // Advance to start of next block address += flashData->sectorSize; } flashData->flags &= ~DO_ERASE_RANGE; }
ConfigErrorCode Config::parseFile(const char *fileName) { FILE *stream = fopen(fileName, "r"); if (stream == NULL) { if (errno == ENOENT || errno == ENOTDIR) return setErrorCode(kConfigFileMissingErr); else if (errno == EACCES) return setErrorCode(kConfigFileNoAccessErr); return setErrorCode(kConfigOpenFileErr); } ConfigErrorCode status = parseStream(stream); if (status == kConfigParseStreamErr) status = setErrorCode(kConfigParseFileErr); fclose(stream); return status; }
TransferReport::TransferReport( std::vector<TransferStats>& transferredSourceStats, std::vector<TransferStats>& failedSourceStats, std::vector<TransferStats>& threadStats, std::vector<std::string>& failedDirectories, double totalTime, int64_t totalFileSize, int64_t numDiscoveredFiles) : transferredSourceStats_(std::move(transferredSourceStats)), failedSourceStats_(std::move(failedSourceStats)), threadStats_(std::move(threadStats)), failedDirectories_(std::move(failedDirectories)), totalTime_(totalTime), totalFileSize_(totalFileSize) { for (const auto& stats : threadStats_) { summary_ += stats; } ErrorCode summaryErrorCode = summary_.getErrorCode(); bool atLeastOneOk = false; for (auto& stats : threadStats_) { if (stats.getErrorCode() == OK) { atLeastOneOk = true; break; } } LOG(INFO) << "Error code summary " << errorCodeToStr(summaryErrorCode); // none of the files or directories failed bool possiblyOk = true; if (!failedDirectories_.empty()) { possiblyOk = false; summaryErrorCode = getMoreInterestingError(summaryErrorCode, BYTE_SOURCE_READ_ERROR); } for (const auto& sourceStat : failedSourceStats_) { possiblyOk = false; summaryErrorCode = getMoreInterestingError(summaryErrorCode, sourceStat.getErrorCode()); } if (possiblyOk && atLeastOneOk) { if (summaryErrorCode != OK) { LOG(WARNING) << "WDT successfully recovered from error " << errorCodeToStr(summaryErrorCode); } summaryErrorCode = OK; } setErrorCode(summaryErrorCode); if (summary_.getEffectiveDataBytes() != totalFileSize_) { // sender did not send all the bytes LOG(INFO) << "Could not send all the bytes " << totalFileSize_ << " " << summary_.getEffectiveDataBytes(); WDT_CHECK(summaryErrorCode != OK) << "BUG: All threads OK yet sized based error detected"; } std::set<std::string> failedFilesSet; for (auto& stats : failedSourceStats_) { failedFilesSet.insert(stats.getId()); } int64_t numTransferredFiles = numDiscoveredFiles - failedFilesSet.size(); summary_.setNumFiles(numTransferredFiles); }
void SkAnimateMaker::setScriptError(const SkScriptEngine& engine) { SkString errorString; #ifdef SK_DEBUG engine.getErrorString(&errorString); #endif setErrorNoun(errorString); setErrorCode(SkDisplayXMLParserError::kErrorInScript); }
bool FileLogHandler::createNewFile() { bool rc = true; int fileNo = 1; char newName[PATH_MAX]; time_t newMtime, preMtime = 0; do { if (fileNo >= m_maxNoFiles) { fileNo = 1; BaseString::snprintf(newName, sizeof(newName), "%s.%d", m_pLogFile->getName(), fileNo); break; } BaseString::snprintf(newName, sizeof(newName), "%s.%d", m_pLogFile->getName(), fileNo++); newMtime = File_class::mtime(newName); if (newMtime < preMtime) { break; } else { preMtime = newMtime; } } while (File_class::exists(newName)); m_pLogFile->close(); if (!File_class::rename(m_pLogFile->getName(), newName)) { setErrorCode(errno); rc = false; } // Open again if (!m_pLogFile->open()) { setErrorCode(errno); rc = false; } return rc; }
int NdbOperation::init(const NdbTableImpl* tab, NdbTransaction* myConnection){ NdbApiSignal* tSignal; theStatus = Init; theError.code = 0; theErrorLine = 1; m_currentTable = m_accessTable = tab; theNdbCon = myConnection; for (Uint32 i=0; i<NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY; i++) for (int j=0; j<3; j++) theTupleKeyDefined[i][j] = 0; theFirstATTRINFO = NULL; theCurrentATTRINFO = NULL; theLastKEYINFO = NULL; theTupKeyLen = 0; theNoOfTupKeyLeft = tab->getNoOfPrimaryKeys(); theTotalCurrAI_Len = 0; theAI_LenInCurrAI = 0; theStartIndicator = 0; theCommitIndicator = 0; theSimpleIndicator = 0; theDirtyIndicator = 0; theInterpretIndicator = 0; theDistrKeyIndicator_ = 0; theScanInfo = 0; theTotalNrOfKeyWordInSignal = 8; theMagicNumber = 0xABCDEF01; theBlobList = NULL; m_abortOption = -1; m_noErrorPropagation = false; m_no_disk_flag = 1; tSignal = theNdb->getSignal(); if (tSignal == NULL) { setErrorCode(4000); return -1; } theTCREQ = tSignal; theTCREQ->setSignal(m_tcReqGSN); theAI_LenInCurrAI = 20; TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend()); tcKeyReq->scanInfo = 0; theKEYINFOptr = &tcKeyReq->keyInfo[0]; theATTRINFOptr = &tcKeyReq->attrInfo[0]; if (theReceiver.init(NdbReceiver::NDB_OPERATION, this)) { // theReceiver sets the error code of its owner return -1; } return 0; }
void LitResLoginDataParser::processTag(const std::string &tag) { if (TAG_AUTHORIZATION_FAILED == tag) { setErrorCode(NetworkErrors::ERROR_AUTHENTICATION_FAILED); } else if (TAG_AUTHORIZATION_OK == tag) { myFirstName = attributes()["first-name"]; myLastName = attributes()["first-name"]; mySid = attributes()["sid"]; } }
void WeatherDataSource::requestMoreDataFromNetwork(const QString region, const QString city, const QString date, bool requestOlderItems) { // Only request data if there is currently no request being done. if (mReply == 0) { int dayOffset = 0; QString encodedCity = QUrl(city).toEncoded(); QString encodedRegion = QUrl(region).toEncoded(); QUrl path = AppSettings::prepareServerUrl("resources/cities/" + encodedRegion + "/" + encodedCity, true); // An empty date string mean request data with 0 days offset. if (!date.isEmpty()) { // Server requests is made with an offset as compared to today QDate today = QDate::currentDate(); QDate compareDate = QDate::fromString(date, "yyyy-MM-dd"); dayOffset = compareDate.daysTo(today); if (requestOlderItems) { // Add one to day offset to begin at the next date after the "date" parameter. dayOffset += 1; } else { // For newer items than date we need to know how many items are set to be requested each time. uint chunkSize = AppSettings::loadSize(); dayOffset -= chunkSize; if (dayOffset <= 0) { // A negative offset means future data, which is not possible, we have to // adjust the chunksize and set the dayOffset to 0 i.e. today. chunkSize = chunkSize + dayOffset; dayOffset = 0; if (chunkSize == 0) { // If the adjusted chunk size become 0, all data up to current date has been received and we are done. emit noMoreWeather(); return; } // Request a new path with the custom chunksize. path = AppSettings::prepareServerUrl("resources/cities/" + encodedRegion + "/" + encodedCity, true, chunkSize); } } } // Add the offset for the server request, corresponds to from which day in the pas the request is made. path.addQueryItem("start", QString("%1").arg(dayOffset)); // Reset the error code. setErrorCode(WeatherError::NoError); qDebug() << "GET " << path.toString(); mReply = mAccessManager.get(QNetworkRequest(path)); // Connect to the reply finished signal to httpFinsihed() Slot function. connect(mReply, SIGNAL(finished()), this, SLOT(onHttpFinished())); mCursor.index = dayOffset; } }
bool HttpClient::sendHeader() { std::string header; int header_length = _request->generateHeader(header); bool send = _proxy_socket->writeAll(header.c_str(),header_length); if (!send) { setErrorCode(HTTPERROR_TRANSPORT); } return send; }
/** Create a BPN object from filename. @param filename The name of the file to load this object from. */ BPN::BPN(string filename) : NeuralNetwork(), id(BPNTYPE), learningRate(0.25f), momentum(0.7f), epochsCompleted(0), errorCode(NONE), lastPatternTest(0), patternsCompleted(0), saveVersion(2), dynamicLearningRate(false), dynamicMomentum(false), inputFieldShape(IFS_SQUARE) { activationFunction.push_back(SIGMOID); if(!load(filename)) { setErrorCode(BPN_ERROR); throw "BPN constructor failed to load file!"; } }
bool FileLogHandler::close() { bool rc = true; if (!m_pLogFile->close()) { setErrorCode(errno); rc = false; } return rc; }
/** * Launch & wait for Flash command to complete */ void executeCommand(volatile FlashController *controller) { // Clear any existing errors controller->fstat = FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL; // Launch command controller->fstat = FTFA_FSTAT_CCIF; // Wait for command complete while ((controller->fstat & FTFA_FSTAT_CCIF) == 0) { } // Handle any errors if ((controller->fstat & FTFA_FSTAT_FPVIOL ) != 0) { setErrorCode(FLASH_ERR_PROG_FPVIOL); } if ((controller->fstat & FTFA_FSTAT_ACCERR ) != 0) { setErrorCode(FLASH_ERR_PROG_ACCERR); } if ((controller->fstat & FTFA_FSTAT_MGSTAT0 ) != 0) { setErrorCode(FLASH_ERR_PROG_MGSTAT0); } }
//! Verify a range of flash against buffer //! void verifyRange(FlashData_t *flashData) { FlashController *controller = flashData->controller; uint32_t address = flashData->address; const uint32_t *data = flashData->data; uint32_t numLongwords = flashData->size/4; if ((flashData->flags&DO_VERIFY_RANGE) == 0) { return; } if ((address & 0x03) != 0) { setErrorCode(FLASH_ERR_ILLEGAL_PARAMS); } // // Initialise CRC // CRC_CTRL = CRC_CTRL_TCRC; // CRC_GPOLY = 0x13451234; // CRC_CTRL = CRC_CTRL_TCRC|CRC_CTRL_WAS; // CRC_CRC = 0xFFFFFFFF; // CRC_CTRL = CRC_CTRL_TCRC; // Verify words while (numLongwords-- > 0) { int rc; controller->fccob0_3 = (F_PGMCHK << 24) | address; controller->fccob4_7 = (F_USER_MARGIN<<24) | 0; controller->fccob8_B = *data; // CRC_CRC = *data; rc = executeCommand(controller); if (rc != FLASH_ERR_OK) { if (rc == FLASH_ERR_PROG_MGSTAT0) { rc = FLASH_ERR_VERIFY_FAILED; } setErrorCode(rc); } address += 4; data++; } // flashCommandTable->crc = CRC_CRC; flashData->flags &= ~DO_VERIFY_RANGE; }
void LitResPurchaseDataParser::processTag(const std::string &tag) { if (TAG_AUTHORIZATION_FAILED == tag) { setErrorCode(NetworkErrors::ERROR_AUTHENTICATION_FAILED); } else { myAccount = attributes()["account"]; myBookId = attributes()["art"]; if (TAG_PURCHASE_OK == tag) { // nop } else if (TAG_PURCHASE_FAILED == tag) { const std::string &error = attributes()["error"]; if ("1" == error) { setErrorCode(NetworkErrors::ERROR_PURCHASE_NOT_ENOUGH_MONEY); } else if ("2" == error) { setErrorCode(NetworkErrors::ERROR_PURCHASE_MISSING_BOOK); } else if ("3" == error) { setErrorCode(NetworkErrors::ERROR_PURCHASE_ALREADY_PURCHASED); } else { setErrorCode(NetworkErrors::ERROR_INTERNAL); } } } }
NdbBlob* NdbOperation::getBlobHandle(Uint32 anAttrId) { const NdbColumnImpl* col = m_currentTable->getColumn(anAttrId); if (col == NULL) { setErrorCode(4004); return NULL; } else { return getBlobHandle(theNdbCon, col); } }
bool HttpClient::httpGet() { //发送HTTP头请求 if (sendHeader()) { //接受反馈 return getResponse(); } else { setErrorCode(HTTPERROR_TRANSPORT); return false; } }
//! Partition FlexNVM/EEPROM //! void programPartition(FlashData_t *flashData) { int rc; FlashController *controller = flashData->controller; if ((flashData->flags&DO_PARTITION_FLEXNVM) == 0) { return; } controller->fccob0_3 = (F_PGMPART << 24)|0; controller->fccob4_7 = flashData->frequency; rc = executeCommand(controller); if (rc != FLASH_ERR_OK) { setErrorCode(rc); } flashData->flags &= ~DO_PARTITION_FLEXNVM; }