t_axe_variable * getVariable (t_program_infos *program, char *ID) { t_axe_variable search_pattern; t_list *elementFound; /* preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); if (ID == NULL) notifyError(AXE_VARIABLE_ID_UNSPECIFIED); /* initialize the pattern */ search_pattern.ID = ID; /* search inside the list of variables */ elementFound = CustomfindElement (program->variables, &search_pattern, compareVariables); /* if the element is found return it to the caller. Otherwise return NULL. */ if (elementFound != NULL) return (t_axe_variable *) LDATA(elementFound); return NULL; }
/* reserve a new label identifier for future uses */ t_axe_label * newLabel(t_program_infos *program) { /* test the preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); if (program->lmanager == NULL) notifyError(AXE_INVALID_LABEL_MANAGER); return newLabelID(program->lmanager); }
/* assign a new label identifier to the next instruction */ t_axe_label * assignLabel(t_program_infos *program, t_axe_label *label) { /* test the preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); if (program->lmanager == NULL) notifyError(AXE_INVALID_LABEL_MANAGER); /* fix the label */ return assignLabelID(program->lmanager, label); }
void TimedTextPlayer::doRead(MediaSource::ReadOptions* options) { int64_t startTimeUs = 0; int64_t endTimeUs = 0; sp<ParcelEvent> parcelEvent = new ParcelEvent(); CHECK(mSource != NULL); status_t err = mSource->read(&startTimeUs, &endTimeUs, &(parcelEvent->parcel), options); if (err == WOULD_BLOCK) { sp<AMessage> msg = new AMessage(kWhatRetryRead, id()); if (options != NULL) { int64_t seekTimeUs = kInvalidTimeUs; MediaSource::ReadOptions::SeekMode seekMode = MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC; CHECK(options->getSeekTo(&seekTimeUs, &seekMode)); msg->setInt64("seekTimeUs", seekTimeUs); msg->setInt32("seekMode", seekMode); } msg->setInt32("generation", mSendSubtitleGeneration); msg->post(kWaitTimeUsToRetryRead); return; } else if (err != OK) { notifyError(err); return; } postTextEvent(parcelEvent, startTimeUs); if (endTimeUs > 0) { CHECK_GE(endTimeUs, startTimeUs); // send an empty timed text to clear the subtitle when it reaches to the // end time. postTextEvent(NULL, endTimeUs); } }
/* assign the given label identifier to the next instruction. Returns * NULL if an error occurred; otherwise the assigned label */ t_axe_label * assignLabelID(t_axe_label_manager *lmanager, t_axe_label *label) { /* precondition: lmanager must be different from NULL */ assert(lmanager != NULL); /* precondition: label must be different from NULL and * must always carry a valid identifier */ if ( (label == NULL) || (label->labelID == LABEL_UNSPECIFIED) || (label->labelID >= lmanager->current_label_ID)) { notifyError(AXE_INVALID_LABEL); } /* test if the next instruction has already a label */ if ( (lmanager->label_to_assign != NULL) && ((lmanager->label_to_assign)->labelID != LABEL_UNSPECIFIED) ) { label->labelID = (lmanager->label_to_assign)->labelID; } else lmanager->label_to_assign = label; /* all went good */ return label; }
//=========================================================================== // Deregister a WPS class by removing its data from OS2SYS.INI. // Parameters -------------------------------------------------------------- // HWND hwnd : window handle // PSWPCLASSLIST pClassList : WPS class list data previously retrieved // from OS2SYS.INI. // PSZ pClassName : name of the WPS to be removed. // Return value ------------------------------------------------------------ // BOOL : TRUE/FALSE (success/error) //=========================================================================== static BOOL deleteWPSClassData(HWND hwnd, PWPSCLASSLIST pClassList, PSZ pClassName) { PWPSCLASSENTRY pClass, pNextClass; PBYTE pEnd; ULONG cbDel; pEnd = (PBYTE)pClassList + pClassList->cbData; // loop through the whole class list for (pClass = &pClassList->aClass[0]; (PBYTE)pClass < pEnd; pClass = (PWPSCLASSENTRY)((PBYTE)pClass + pClass->offNext)) { // match found if (!strcmp(pClass->achClass, pClassName)) { cbDel = pClass->offNext; pNextClass = PNEXTCLASS(pClass); // remove all the data of the current class memmove(pClass, pNextClass, (ULONG)pEnd - (ULONG)pNextClass); pClassList->cbData -= cbDel; // update OS2SYS.INI if (PrfWriteProfileData(HINI_SYSTEM, PRF_WPSCLASSESAPP, PRF_WPSCLASSESKEY, pClassList, pClassList->cbData)) { return TRUE; } else { notifyError(hwnd, SZERR_UPDATEOS2SYSINI); } /* endif */ } /* endif */ } /* endfor */ return FALSE; }
//=========================================================================== // // Parameters -------------------------------------------------------------- // HWND hwnd : window handle // VOID // Return value ------------------------------------------------------------ // BOOL : TRUE/FALSE (success/error) // VOID //=========================================================================== static PWPSCLASSLIST getWPSClassData(HWND hwnd) { PWPSCLASSLIST p; ULONG cb = 0x10000; if (NULL == (p = malloc(cb))) { notifyError(hwnd, SZERR_ALLOC); return NULL; } /* endif */ if (!PrfQueryProfileData(HINI_SYSTEM, PRF_WPSCLASSESAPP, PRF_WPSCLASSESKEY, p, &cb)) { notifyError(hwnd, SZERR_GETCLASSLISTDATA); free(p); return NULL; } /* endif */ return p; }
//=========================================================================== // Register a new class. // Parameters -------------------------------------------------------------- // HWND hwnd : window handle // Return value ------------------------------------------------------------ // VOID //=========================================================================== static VOID addItem(HWND hwnd) { PWPSCLASSLIST pClassList; ULONG cbClassList = 0; CHAR className[64]; CHAR moduleName[CCHMAXPATH]; CHAR buf[1024]; DlgItemText(hwnd, EF_CLASSNAME, sizeof(className), className); DlgItemText(hwnd, EF_MODULENAME, sizeof(moduleName), moduleName); sprintf(buf, SZ_CONFIRMADD, className, moduleName); if (NULL != (pClassList = getWPSClassData(hwnd))) { cbClassList = pClassList->cbData; free(pClassList); } /* endif */ if (userConfirmAction(hwnd, buf)) { if (!WinRegisterObjectClass(className, moduleName)) { buf[0] = 0; if (cbClassList && (NULL != (pClassList = getWPSClassData(hwnd)))) { if (cbClassList != pClassList->cbData) sprintf(buf, SZERR_ADD2, className, moduleName); free(pClassList); } /* endif */ if (!buf[0]) sprintf(buf, SZERR_ADD, className, moduleName); notifyError(hwnd, buf); } else { sprintf(buf, SZ_FORMATSTR, className, moduleName); dLbxItemIns(hwnd, LBOX_CLASS, LIT_SORTASCENDING, buf); } /* endif */ } /* endif */ }
QString AbstractDb::attach(Db* otherDb, bool silent) { QWriteLocker locker(&dbOperLock); if (!isOpenInternal()) return QString::null; if (attachedDbMap.containsRight(otherDb)) { attachCounter[otherDb]++; return attachedDbMap.valueByRight(otherDb); } QString attName = generateUniqueDbName(false); SqlQueryPtr results = exec(getAttachSql(otherDb, attName), Flag::NO_LOCK); if (results->isError()) { if (!silent) notifyError(tr("Error attaching database %1: %2").arg(otherDb->getName()).arg(results->getErrorText())); else qDebug() << QString("Error attaching database %1: %2").arg(otherDb->getName()).arg(results->getErrorText()); return QString::null; } attachedDbMap.insert(attName, otherDb); emit attached(otherDb); return attName; }
bool AsyncExecuteStatements::executeStatement(sqlite3_stmt *aStatement) { mMutex.AssertNotCurrentThreadOwns(); while (true) { int rc = ::sqlite3_step(aStatement); // Stop if we have no more results. if (rc == SQLITE_DONE) return false; // If we got results, we can return now. if (rc == SQLITE_ROW) return true; // Some errors are not fatal, and we can handle them and continue. if (rc == SQLITE_BUSY) { // Yield, and try again (void)::PR_Sleep(PR_INTERVAL_NO_WAIT); continue; } // Set an error state. mState = ERROR; // And notify. sqlite3 *db = ::sqlite3_db_handle(aStatement); (void)notifyError(rc, ::sqlite3_errmsg(db)); // Finally, indicate that we should stop processing. return false; } }
int SharedMemory::getSharedMemoryId(unsigned int id, unsigned int size) { int sharedMemoryIdTemp; key_t key = ftok(PATH, id); if (key == -1) { notifyError(id, "getSharedMemoryId - ftok"); exit(EXIT_FAILURE); } else { sharedMemoryIdTemp = shmget(key, size, 0660); if (sharedMemoryIdTemp == -1) { notifyError(id, "getSharedMemoryId - shmget"); exit(EXIT_FAILURE); } } return sharedMemoryIdTemp; }
void WorkerScriptLoader::didReceiveResponse( unsigned long identifier, const ResourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) { DCHECK(!handle); if (response.httpStatusCode() / 100 != 2 && response.httpStatusCode()) { notifyError(); return; } m_identifier = identifier; m_responseURL = response.url(); m_responseEncoding = response.textEncodingName(); m_appCacheID = response.appCacheID(); m_referrerPolicy = response.httpHeaderField(HTTPNames::Referrer_Policy); processContentSecurityPolicy(response); m_originTrialTokens = OriginTrialContext::parseHeaderValue( response.httpHeaderField(HTTPNames::Origin_Trial)); if (NetworkUtils::isReservedIPAddress(response.remoteIPAddress())) { m_responseAddressSpace = SecurityOrigin::create(m_responseURL)->isLocalhost() ? WebAddressSpaceLocal : WebAddressSpacePrivate; } if (m_responseCallback) (*m_responseCallback)(); }
virtual bool doWork() { bool ret; for (size_t i = 0; i < saves.size(); i++) { if (publish) ret = PublishSave(saves[i]); else ret = UnpublishSave(saves[i]); if (!ret) { std::stringstream error; if (publish) // uses html page so error message will be spam error << "Failed to publish [" << saves[i] << "], is this save yours?"; else error << "Failed to unpublish [" << saves[i] << "]: " + Client::Ref().GetLastError(); notifyError(error.str()); c->Refresh(); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } c->Refresh(); return true; }
void SharedMemory::destroy(int id, unsigned int size){ int sharedMemoryId = getSharedMemoryId(id, size); int removeResult = shmctl(sharedMemoryId, IPC_RMID, (struct shmid_ds*) 0); bool removeFailed = removeResult == -1; if (removeFailed) { notifyError(id, "destroy"); } }
/* add an instruction at the tail of the list `program->instructions'. * Returns an error code. */ void addInstruction(t_program_infos *program, t_axe_instruction *instr) { /* test the preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); if (instr == NULL) notifyError(AXE_INVALID_INSTRUCTION); if (program->lmanager == NULL) notifyError(AXE_INVALID_LABEL_MANAGER); instr->labelID = assign_label(program->lmanager); /* update the list of instructions */ program->instructions = addElement(program->instructions, instr, -1); }
void SharedMemory::dettach() { if (attached){ if (shmdt(attachAddress) == -1){ notifyError(id, "dettach"); } attached = false; } }
void* SharedMemory::create(unsigned int id, unsigned int size){ SharedMemory* newSharedMemory = new SharedMemory(); key_t key = ftok(PATH, id); if (key == -1) { notifyError(id, "create - ftok"); exit(EXIT_FAILURE); } else { int sharedMemoryId = shmget(key, size, IPC_CREAT | IPC_EXCL | 0660); if (sharedMemoryId == -1) { notifyError(id, "create - shmget"); exit(EXIT_FAILURE); } newSharedMemory->setId(id); newSharedMemory->setSharedMemoryId(sharedMemoryId); } return newSharedMemory->attach(); }
void SocketServer::runAt(int port) { m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(m_socket, (sockaddr*)&addr, sizeof(addr))==-1){ notifyError(BindFail); return; } if(listen(m_socket, 5)==-1){ notifyError(ListenFail); return; } std::thread t(serverWaitClientThread); t.detach(); }
void writeAssembly(t_program_infos *program, char *output_file) { FILE *fp; int _error; /* test the preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); /* If necessary, set the value of `output_file' to "output.asm" */ if (output_file == NULL) { /* set "output.o" as output file name */ output_file = "output.asm"; } #ifndef NDEBUG fprintf(stdout, "\n\n*******************************************\n"); fprintf(stdout, "INITIALIZING OUTPUT FILE: %s. \n", output_file); fprintf(stdout, "CODE SEGMENT has a size of %d instructions \n" , getLength(program->instructions)); fprintf(stdout, "DATA SEGMENT has a size of %d elements \n" , getLength(program->data)); fprintf(stdout, "NUMBER OF LABELS : %d. \n" , get_number_of_labels(program->lmanager)); fprintf(stdout, "*******************************************\n\n"); #endif /* open a new file */ fp = fopen(output_file, "w"); if (fp == NULL) notifyError(AXE_FOPEN_ERROR); /* print the data segment */ translateDataSegment(program, fp); /* print the code segment */ translateCodeSegment(program, fp); /* close the file and return */ _error = fclose(fp); if (_error == EOF) notifyError(AXE_FCLOSE_ERROR); }
void DownloadOperation::notifyFailedToDownload(const TCHAR *errorDescription) { StringStorage message; message.format(_T("Error: failed to download '%s' (%s)"), m_pathToSourceFile.getString(), errorDescription); notifyError(message.getString()); }
void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error) { if (!m_client) return; m_didFail = true; m_error = WebURLError(error); if (m_enableErrorNotifications) notifyError(&m_errorTimer); }
void* SharedMemory::attach() { if (!attached) { attachAddress = shmat(sharedMemoryId, 0, 0); if (attachAddress == (void *) - 1) { notifyError(id, "attach"); } attached = true; } return attachAddress; }
/* * sysAccept */ void NSocketX::sysAccept() { char new_ipaddress[NI_MAXHOST]; char new_port[NI_MAXSERV]; NSocket * newcon; SOCKET new_fd; sockaddr_storage new_ssaddr; socklen_t slen = sizeof(new_ssaddr); new_fd = accept(fd,(struct sockaddr *) &new_ssaddr, &slen); if ( new_fd == INVALID_SOCKET ) { error=GET_NET_ERROR(); switch (error) { // Notify on BAD errors, the rest are ignorable // Note that this errors are NSocket errors #ifdef _WIN32 // for windows case WSAENOTSOCK: case WSAEOPNOTSUPP: case WSAEINVAL: case WSAEFAULT: case WSANOTINITIALISED: #else // for others case EBADF: case ENOTSOCK: case EOPNOTSUPP: case EINVAL: // not in macosx, should test if this compiles in it case EFAULT: #endif notifyError(); // on this errors this socket should be closed } return; // nothing more to do } sockaddr_to_ip(&new_ssaddr,slen,new_ipaddress,new_port); newcon=onNewConnection(new_ipaddress, new_port); if (newcon) { newcon->fd = new_fd; newcon->has_socket = true; strcpy(newcon->ipaddress, new_ipaddress); strcpy(newcon->port, new_port); //NSocketManager::add_to_list(newcon); newcon->onSocketReady(); } else { closesocket(new_fd); } }
/* create a new variable */ void createVariable(t_program_infos *program, char *ID , int type, int isArray, int arraySize, int init_val) { t_axe_variable *var; /* test the preconditions */ if (program == NULL) notifyError(AXE_PROGRAM_NOT_INITIALIZED); /* initialize a new variable */ var = alloc_variable(ID, type, isArray, arraySize, init_val); if (var == NULL) notifyError(AXE_OUT_OF_MEMORY); /* assign a new label to the newly created variable `var' */ var->labelID = newLabel(program); /* add the new variable to program */ addVariable(program, var); }
void UploadOperation::notifyFailedToUpload(const TCHAR *errorDescription) { StringStorage message; message.format(_T("Error: failed to upload '%s' %s (%s)"), m_pathToSourceFile.getString(), m_toCopy->getFileInfo()->isDirectory() ? _T("folder") : _T("file"), errorDescription); notifyError(message.getString()); }
bool NSocketX::setReuseAddr() { int v=1; sys_result = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, SETSOCKOPT_TYPE &v, sizeof(v)); if (sys_result == SOCKET_ERROR) { error=GET_NET_ERROR(); notifyError(); } return true; }
bool AsyncExecuteStatements::executeAndProcessStatement(sqlite3_stmt *aStatement, bool aLastStatement) { mMutex.AssertNotCurrentThreadOwns(); // Execute our statement bool hasResults; do { hasResults = executeStatement(aStatement); // If we had an error, bail. if (mState == ERROR) return false; // If we have been canceled, there is no point in going on... { MutexAutoLock lockedScope(mMutex); if (mCancelRequested) { mState = CANCELED; return false; } } // Build our result set and notify if we got anything back and have a // callback to notify. if (mCallback && hasResults && NS_FAILED(buildAndNotifyResults(aStatement))) { // We had an error notifying, so we notify on error and stop processing. mState = ERROR; // Notify, and stop processing statements. (void)notifyError(mozIStorageError::ERROR, "An error occurred while notifying about results"); return false; } } while (hasResults); #ifdef DEBUG // Check to make sure that this statement was smart about what it did. checkAndLogStatementPerformance(aStatement); #endif // If we are done, we need to set our state accordingly while we still hold // our mutex. We would have already returned if we were canceled or had // an error at this point. if (aLastStatement) mState = COMPLETED; return true; }
void WorkerScriptLoader::didFinishLoading(unsigned long identifier, double) { if (m_failed) { notifyError(); return; } if (m_decoder) m_script += m_decoder->flush(); m_identifier = identifier; notifyFinished(); }
void RemoteFolderCreateOperation::onLastRequestFailedReply() { // Logging StringStorage message; message.format(_T("Error: failed to create remote folder '%s'"), m_pathToTargetFile.getString()); notifyError(message.getString()); // Notify all that operation have ended notifyFinish(); }
bool AsyncExecuteStatements::executeStatement(sqlite3_stmt *aStatement) { mMutex.AssertNotCurrentThreadOwns(); Telemetry::AutoTimer<Telemetry::MOZ_STORAGE_ASYNC_REQUESTS_MS> finallySendExecutionDuration(mRequestStartDate); while (true) { // lock the sqlite mutex so sqlite3_errmsg cannot change SQLiteMutexAutoLock lockedScope(mDBMutex); int rc = mConnection->stepStatement(mNativeConnection, aStatement); // Stop if we have no more results. if (rc == SQLITE_DONE) { Telemetry::Accumulate(Telemetry::MOZ_STORAGE_ASYNC_REQUESTS_SUCCESS, true); return false; } // If we got results, we can return now. if (rc == SQLITE_ROW) { Telemetry::Accumulate(Telemetry::MOZ_STORAGE_ASYNC_REQUESTS_SUCCESS, true); return true; } // Some errors are not fatal, and we can handle them and continue. if (rc == SQLITE_BUSY) { // Don't hold the lock while we call outside our module. SQLiteMutexAutoUnlock unlockedScope(mDBMutex); // Yield, and try again (void)::PR_Sleep(PR_INTERVAL_NO_WAIT); continue; } // Set an error state. mState = ERROR; Telemetry::Accumulate(Telemetry::MOZ_STORAGE_ASYNC_REQUESTS_SUCCESS, false); // Construct the error message before giving up the mutex (which we cannot // hold during the call to notifyError). nsCOMPtr<mozIStorageError> errorObj( new Error(rc, ::sqlite3_errmsg(mNativeConnection)) ); // We cannot hold the DB mutex while calling notifyError. SQLiteMutexAutoUnlock unlockedScope(mDBMutex); (void)notifyError(errorObj); // Finally, indicate that we should stop processing. return false; } }