bool MBus::SendNKE() { // Empty the buffer while (Serial.available()) Serial.read(); byte vRequest[5] = { 0x10, 0x40, this->address, 0x00, 0x16 }; vRequest[3] = Telegram::checkSum(vRequest, 1, 3); Serial.write(vRequest, 5); debug("Wrote to serial: ", vRequest, 5); unsigned long time = millis(); while (!Serial.available() && (millis() - time) < 2000); if (Serial.read() == 0xe5 || this->Debug) { return true; } else { if ((millis() - time) >= 2000) errorCallback("NKE timeout"); else errorCallback("NKE response error"); return false; } }
void AsyncAudioDecoder::DecodingTask::notifyComplete() { if (audioBuffer() && successCallback()) successCallback()->handleEvent(audioBuffer()); else if (errorCallback()) errorCallback()->handleEvent(audioBuffer()); // Our ownership was given up in AsyncAudioDecoder::runLoop() // Make sure to clean up here. delete this; }
void AudioSoundIo::writeCallback(int frameCountMin, int frameCountMax) { const struct SoundIoChannelLayout *layout = &m_outstream->layout; SoundIoChannelArea *areas; int bytesPerSample = m_outstream->bytes_per_sample; int err; const float gain = mixer()->masterGain(); int framesLeft = frameCountMax; while (framesLeft > 0) { int frameCount = framesLeft; if ((err = soundio_outstream_begin_write(m_outstream, &areas, &frameCount))) { errorCallback(err); return; } if (!frameCount) break; for (int frame = 0; frame < frameCount; frame += 1) { if (m_outBufFrameIndex >= m_outBufFramesTotal) { m_outBufFramesTotal = getNextBuffer(m_outBuf); m_outBufFrameIndex = 0; } for (int channel = 0; channel < layout->channel_count; channel += 1) { float sample = gain * m_outBuf[m_outBufFrameIndex][channel]; memcpy(areas[channel].ptr, &sample, bytesPerSample); areas[channel].ptr += areas[channel].step; } m_outBufFrameIndex += 1; } if ((err = soundio_outstream_end_write(m_outstream))) { errorCallback(err); return; } framesLeft -= frameCount; } }
// Run a Lua command. // This function is currently used by luaUqm_debug_interactive, but should // also be suitable if we have some graphical console, when different // callback functions than luaUqm_debug_outputCallback() and // luaUqm_debug_errorCallback are used. void luaUqm_debug_runLine(const char *exprBuf, void (*outputCallback)(void *extra, const char *format, ...), void (*errorCallback)(void *extra, const char *format, ...), void *extra) { int resultType; const char *resultStr; const char *resultTypeStr; // Compile the string to a Lua function. { if (luaL_loadstring (luaUqm_debugState, exprBuf) != LUA_OK) { // An error occurred during parsing. errorCallback(extra, "Syntax error: %s\n", lua_tostring (luaUqm_debugState, -1)); lua_pop(luaUqm_debugState, 1); // Pop the error. return; } } // Call the Lua function. if (lua_pcall (luaUqm_debugState, 0, 1, 0) != 0) { // An error occurred during execution. errorCallback(extra, "Runtime error: %s\n", lua_tostring (luaUqm_debugState, -1)); lua_pop(luaUqm_debugState, 1); // Pop the error. return; } // Success. Result is on the stack. // Convert the result to a string. resultType = lua_type(luaUqm_debugState, -1); resultTypeStr = lua_typename(luaUqm_debugState, resultType); resultStr = lua_tolstring (luaUqm_debugState, -1, NULL); // Memory for 'resultStr' lasts until the lua_pop(). if (resultStr == NULL) { // Not a string and not convertable to a string. // The command was executed ok though, and we treat this as such. outputCallback(extra, "(%s)\n", resultTypeStr); } else { outputCallback(extra, "(%s) %s\n", resultTypeStr, resultStr); } // Pop the result from the stack. lua_pop (luaUqm_debugState, 1); }
void DirectoryEntry::getDirectory(const String& path, const Dictionary& options, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) { FileSystemFlags flags(options); RefPtr<ErrorCallback> errorCallback(errorCallbackRef); if (!m_fileSystem->getDirectory(this, path, flags, successCallback, errorCallback)) filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR)); }
void WebGetter::update() { lock_guard<mutex>{m}; Connection::run(); auto it = sessions.begin(); while(it != sessions.end()) { auto s = *it; if(s->gotHeaders() && s->isRedirect()) { auto location = s->getHeader("Location"); if(!startsWith(location, "http://")) { location = format("http://%s:%d%s", s->getHost(), s->getPort(), urlencode(location, ":\\?;+ ")); } LOGD("Redirecting to '%s'", location); auto callback = s->getCallback(); it = sessions.erase(it); auto s = make_shared<HttpSession>(location); sessions.push_back(s); s->connect(); s->stream(callback); it = sessions.end(); continue; } if(s->error()) { errorCallback(0, ""); } if(s->done()) { it = sessions.erase(it); LOGD("Session done"); } else it++; } }
// Loads quadKey. void loadQuadKey(const char* styleFile, const utymap::QuadKey& quadKey, OnMeshBuilt* meshCallback, OnElementLoaded* elementCallback, OnError* errorCallback) { try { auto& eleProvider = quadKey.levelOfDetail <= SrtmElevationLodStart ? flatEleProvider_ : (utymap::heightmap::ElevationProvider&) srtmEleProvider_; // TODO: preloading is not thread safe: extract separate API function eleProvider.preload(utymap::utils::GeoUtils::quadKeyToBoundingBox(quadKey)); utymap::mapcss::StyleProvider& styleProvider = *getStyleProvider(styleFile); QuadKeyElementVisitor elementVisitor(stringTable_, styleProvider, quadKey.levelOfDetail, elementCallback); quadKeyBuilder_.build(quadKey, styleProvider, eleProvider, [&meshCallback](const utymap::meshing::Mesh& mesh) { meshCallback(mesh.name.data(), mesh.vertices.data(), mesh.vertices.size(), mesh.triangles.data(), mesh.triangles.size(), mesh.colors.data(), mesh.colors.size()); }, [&elementVisitor](const utymap::entities::Element& element) { element.accept(elementVisitor); }); } catch (std::exception& ex) { errorCallback(ex.what()); } }
void EXPORT_API connect(const char *indexPath, OnError *errorCallback) { try { applicationPtr = new Application(indexPath); } catch (std::exception &ex) { errorCallback(ex.what()); } }
/* * ======== UARTMSP432_hwiIntFxn ======== * Hwi function that processes UART interrupts. * * @param(arg) The UART_Handle for this Hwi. */ void UARTMSP432_hwiIntFxn(uintptr_t arg) { bool readSuccess = true; uint8_t status; uintptr_t errorFlags; UARTMSP432_Object *object = ((UART_Handle) arg)->object; UARTMSP432_HWAttrs const *hwAttrs = ((UART_Handle) arg)->hwAttrs; /* Clear interrupts */ status = MAP_UART_getEnabledInterruptStatus(hwAttrs->baseAddr); MAP_UART_clearInterruptFlag(hwAttrs->baseAddr, status); if (status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) { readSuccess = object->readFxns.readIsrFxn((UART_Handle)arg); } if (status & EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) { writeData((UART_Handle)arg); } if (status & (EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT | EUSCI_A_UART_BREAKCHAR_INTERRUPT) || !readSuccess) { errorFlags = MAP_UART_queryStatusFlags(hwAttrs->baseAddr, EUSCI_A_UART_OVERRUN_ERROR | EUSCI_A_UART_BREAK_DETECT | EUSCI_A_UART_PARITY_ERROR | EUSCI_A_UART_FRAMING_ERROR); errorCallback((UART_Handle)arg, errorFlags); } }
// Adds data to persistent store. void addToPersistentStore(const char* styleFile, const char* path, const utymap::LodRange& range, OnError* errorCallback) { try { geoStore_.add(PersistentStorageKey, path, range, *getStyleProvider(styleFile).get()); } catch (std::exception& ex) { errorCallback(ex.what()); } }
// Adds data to in-memory store. void addToInMemoryStore(const char* styleFile, const char* path, const utymap::QuadKey& quadKey, OnError* errorCallback) { try { geoStore_.add(InMemoryStorageKey, path, quadKey, *getStyleProvider(styleFile).get()); } catch (std::exception& ex) { errorCallback(ex.what()); } }
// Adds data to in-memory store. void addToInMemoryStore(const char* styleFile, const char* path, const utymap::BoundingBox& bbox, const utymap::LodRange& range, OnError* errorCallback) { try { geoStore_.add(InMemoryStorageKey, path, bbox, range, *getStyleProvider(styleFile).get()); } catch (std::exception& ex) { errorCallback(ex.what()); } }
// Adds element to in-memory store. void addInMemoryStore(const char* styleFile, const utymap::entities::Element& element, const utymap::LodRange& range, OnError* errorCallback) { try { geoStore_.add(InMemoryStorageKey, element, range, *getStyleProvider(styleFile).get()); } catch (std::exception& ex) { errorCallback(ex.what()); } }
void safeExecute(const std::function<void()>& action, OnError* errorCallback) { try { action(); } catch (std::exception& ex) { errorCallback(ex.what()); } }
std::shared_ptr<RuntimeScene> SceneStack::Push(std::string newSceneName) { auto newScene = std::make_shared<RuntimeScene>(window, &game); if (!newScene->LoadFromScene(game.GetLayout(newSceneName))) { if (errorCallback) errorCallback("Unable to load scene \"" + newSceneName + "\"."); return std::shared_ptr<RuntimeScene>(); } if (!newScene->GetCodeExecutionEngine()->LoadFromDynamicLibrary(codeLibraryName, "GDSceneEvents"+gd::SceneNameMangler::GetMangledSceneName(newScene->GetName()))) { if (errorCallback) errorCallback("Unable to setup execution engine for scene \"" + newScene->GetName() + "\"."); return std::shared_ptr<RuntimeScene>(); } newScene->ChangeRenderWindow(window); stack.push_back(newScene); return newScene; }
void DynamicAddress::get() { QList<QVariant> arguments; arguments.push_back(QVariant(QString::fromLatin1(MaliitServerInterface))); arguments.push_back(QVariant(QString::fromLatin1(MaliitServerAddressProperty))); QDBusMessage message = QDBusMessage::createMethodCall(MaliitServerName, MaliitServerObjectPath, DBusPropertiesInterface, DBusPropertiesGetMethod); message.setArguments(arguments); QDBusConnection::sessionBus().callWithCallback(message, this, SLOT(successCallback(QDBusVariant)), SLOT(errorCallback(QDBusError))); }
void MBus::ReadDevice(int pMaxTelegrams) { Serial.begin(2400, SERIAL_8E1); while (!Serial) {} if (SendNKE()) { errorCallback("NKE OK!!"); delay(1000); int vRemaining = pMaxTelegrams; bool vMoreTelegrams = true; this->FCB = 0x20; while (vRemaining-- != 0 && RequestTelegram()) { errorCallback("Telegram OK!!"); Telegram *t = new Telegram(); if (t->parse(buffer)) { errorCallback("Telegram parsed OK!!"); telegramCallback(*t); vMoreTelegrams = t->MoreTelegrams; } else { vMoreTelegrams = false; } delete(t); } } else { errorCallback("Error sending NKE"); } }
void InspectorDatabaseAgent::executeSQL(long databaseId, const String& query, bool* success, long* transactionId) { Database* database = databaseForId(databaseId); if (!database) { *success = false; return; } *transactionId = ++lastTransactionId; RefPtr<SQLTransactionCallback> callback(TransactionCallback::create(query, *transactionId, m_frontendProvider)); RefPtr<SQLTransactionErrorCallback> errorCallback(TransactionErrorCallback::create(*transactionId, m_frontendProvider)); RefPtr<VoidCallback> successCallback(TransactionSuccessCallback::create()); database->transaction(callback.release(), errorCallback.release(), successCallback.release()); *success = true; }
static int EraseObject(char *nameP, int force) { struct stat src_stat; int rc = 0; if (periodicCallback) if (periodicCallback() != 0) return -1; if (lstat(nameP, &src_stat) < 0) rc = errno; else if ((src_stat.st_mode & S_IFMT) == S_IFDIR) { if (access(nameP, X_OK|W_OK)) return errno; rc = EmptyDir(nameP, 1, force); } else { if (!force && access(nameP, W_OK)) return errno; if (unlink(nameP)) rc = errno; } /* * Return code zero means everything is ok; * return code -1 means the operation is aborted. * In either case, propagated the return code up. */ if (rc <= 0) return rc; /* * Return code > 0 means an error occurred in the last operation. * Call the the error callback function. If the callback returns * zero, we return zero; this will cause the error to be ignored. * Otherwise we return -1 to signal that the operation is aborted. */ if (!errorCallback) return rc; else if (errorCallback(nameP, rc) == 0) return 0; else return -1; }
void InspectorDatabaseAgent::executeSQL(ErrorString&, const String& databaseId, const String& query, Ref<ExecuteSQLCallback>&& requestCallback) { if (!m_enabled) { requestCallback->sendFailure("Database agent is not enabled"); return; } Database* database = databaseForId(databaseId); if (!database) { requestCallback->sendFailure("Database not found"); return; } Ref<SQLTransactionCallback> callback(TransactionCallback::create(query, requestCallback.get())); Ref<SQLTransactionErrorCallback> errorCallback(TransactionErrorCallback::create(requestCallback.get())); Ref<VoidCallback> successCallback(TransactionSuccessCallback::create()); database->transaction(WTF::move(callback), WTF::move(errorCallback), WTF::move(successCallback)); }
void InspectorDatabaseAgent::executeSQL(ErrorString*, const String& databaseId, const String& query, PassRefPtr<ExecuteSQLCallback> prpRequestCallback) { RefPtr<ExecuteSQLCallback> requestCallback = prpRequestCallback; if (!m_enabled) { requestCallback->sendFailure("Database agent is not enabled"); return; } Database* database = databaseForId(databaseId); if (!database) { requestCallback->sendFailure("Database not found"); return; } RefPtr<SQLTransactionCallback> callback(TransactionCallback::create(query, requestCallback.get())); RefPtr<SQLTransactionErrorCallback> errorCallback(TransactionErrorCallback::create(requestCallback.get())); RefPtr<VoidCallback> successCallback(TransactionSuccessCallback::create()); database->transaction(callback.release(), errorCallback.release(), successCallback.release()); }
bool Server::openNewPutty() { if(!this->isOn()) { emit error(tr("The machine is not connected. " \ "It's not possible execute any command !")); return false; } if(this->putty != NULL) { emit error(tr("A command has already been launched on this machine ! "\ "Please wait !")); return false; } this->putty = new Putty(this->getIp(), this->getUser(), this->getPassword(), this->os); QObject::connect(this->putty, SIGNAL(error(QString)), this, SLOT(errorCallback(QString))); QObject::connect(this->putty, SIGNAL(output(QString)), this, SLOT(outputCallback(QString))); QObject::connect(this->putty, SIGNAL(finished()), this, SLOT(deletePutty())); return true; }
bool SceneStack::Step() { if (stack.empty()) return false; auto scene = stack.back(); if (scene->RenderAndStep()) { auto request = scene->GetRequestedChange(); if (request.change == RuntimeScene::SceneChange::STOP_GAME) { return false; } else if (request.change == RuntimeScene::SceneChange::POP_SCENE) { Pop(); } else if (request.change == RuntimeScene::SceneChange::PUSH_SCENE) { Push(request.requestedScene); } else if (request.change == RuntimeScene::SceneChange::REPLACE_SCENE) { Replace(request.requestedScene); } else { if (errorCallback) errorCallback("Unrecognized change in scene stack."); return false; } } return true; }
static int CopyObject(char *sourceP, char *targetP, int repl, int link) /* copy a directory, file, or symbolic link */ { struct stat src_stat; int rc; if (progressCallback) if (progressCallback(sourceP) != 0) return -1; if (periodicCallback) if (periodicCallback() != 0) return -1; if (lstat(sourceP, &src_stat) < 0) rc = errno; else { copy_switch: switch(src_stat.st_mode & S_IFMT) { case S_IFDIR: rc = CopyDir(sourceP, targetP, repl, link, &src_stat); break; case S_IFREG: rc = CopyFile(sourceP, targetP, repl, &src_stat); break; case S_IFLNK: if (link) rc = CopyLink(sourceP, targetP, repl, &src_stat); else if (stat(sourceP, &src_stat) < 0) rc = errno; else goto copy_switch; break; default: rc = EINVAL; } } /* * Return code zero means everything is ok; * return code -1 means the operation is aborted. * In either case, propagated the return code up. */ if (rc <= 0) return rc; /* * Return code > 0 means an error occurred in the last operation. * Call the the error callback function. If the callback returns * zero, we return zero; this will cause the error to be ignored. * Otherwise we return -1 to signal that the operation is aborted. */ if (!errorCallback) return rc; else if (errorCallback(sourceP, rc) == 0) return 0; else return -1; }
void DirectoryEntry::getFile(const String& path, PassRefPtr<WebKitFlags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) { RefPtr<ErrorCallback> errorCallback(errorCallbackRef); if (!m_fileSystem->getFile(this, path, flags, successCallback, errorCallback)) filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR)); }
void DirectoryEntry::removeRecursively(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { RefPtr<ErrorCallback> errorCallback(errorCallbackRef); if (!m_fileSystem->removeRecursively(this, successCallback, errorCallback)) filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR)); }
void Entry::copyTo(PassRefPtr<DirectoryEntry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { RefPtr<ErrorCallback> errorCallback(errorCallbackRef); if (!m_fileSystem->copy(this, parent.get(), name, successCallback, errorCallback)) filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR)); }
void Entry::getParent(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { RefPtr<ErrorCallback> errorCallback(errorCallbackRef); if (!m_fileSystem->getParent(this, successCallback, errorCallback)) filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR)); }