void SsdbDriver::handleDisconnectEvent(events::DisconnectRequestEvent* ev) { QObject* sender = ev->sender(); notifyProgress(sender, 0); events::DisconnectResponceEvent::value_type res(ev->value()); notifyProgress(sender, 50); common::Error er = impl_->disconnect(); if (er && er->isError()) { res.setErrorInfo(er); } reply(sender, new events::DisconnectResponceEvent(this, res)); notifyProgress(sender, 100); }
status_t SimpleSocketConnection::notifyWritable() { assert(sending_); ulong_t toSend = requestLenLeft_; if (requestLenLeft_ > chunkSize_) toSend = chunkSize_; uint_t dataSize = 0; status_t error = socket().send(dataSize, request_ + requestSent_, requestLenLeft_, transferTimeout()); if (errNone==error || netErrWouldBlock==error) { registerEvent(SocketSelector::eventRead); requestSent_ += dataSize; assert( requestLenLeft_ >= dataSize ); requestLenLeft_ -= dataSize; if (0 == requestLenLeft_) { sending_ = false; error = socket().shutdown(netSocketDirOutput); if (error) LogStrUlong(eLogDebug, _T("notifyWritable(): Socket::shutdown() returned error: "), error); } else registerEvent(SocketSelector::eventWrite); error = notifyProgress(); } else LogStrUlong(eLogError, _T("notifyWritable(): Socket::send() returned error: "), error); return error; }
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 Tool::print(const std::string &msg) { _internalPrint(_print_udata, msg.c_str()); // We notify of progress here // This way, almost all tools will be able to exit gracefully (as they print stuff) notifyProgress(false); }
virtual bool doWork() { std::vector<ByteString> files = Client::Ref().DirectorySearch(directory, search, ".cps"); std::sort(files.rbegin(), files.rend(), [](ByteString a, ByteString b) { return a.ToLower() < b.ToLower(); }); notifyProgress(-1); for(std::vector<ByteString>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter) { SaveFile * saveFile = new SaveFile(*iter); try { std::vector<unsigned char> data = Client::Ref().ReadFile(*iter); GameSave * tempSave = new GameSave(data); saveFile->SetGameSave(tempSave); saveFiles.push_back(saveFile); ByteString filename = (*iter).SplitFromEndBy(PATH_SEP).After(); filename = filename.SplitBy('.').Before(); saveFile->SetDisplayName(filename.FromUtf8()); } catch(std::exception & e) { //:( } } return true; }
void SsdbDriver::handleExecuteEvent(events::ExecuteRequestEvent* ev) { QObject* sender = ev->sender(); notifyProgress(sender, 0); events::ExecuteResponceEvent::value_type res(ev->value()); const char *inputLine = common::utils::c_strornull(res.text); common::Error er; if (inputLine) { size_t length = strlen(inputLine); int offset = 0; RootLocker lock = make_locker(sender, inputLine); FastoObjectIPtr outRoot = lock.root_; double step = 100.0f/length; for (size_t n = 0; n < length; ++n) { if (interrupt_) { er.reset(new common::ErrorValue("Interrupted exec.", common::ErrorValue::E_INTERRUPTED)); res.setErrorInfo(er); break; } if (inputLine[n] == '\n' || n == length-1) { notifyProgress(sender, step * n); char command[128] = {0}; if (n == length - 1) { strcpy(command, inputLine + offset); } else { strncpy(command, inputLine + offset, n - offset); } offset = n + 1; FastoObjectCommand* cmd = createCommand<SsdbCommand>(outRoot, command, common::Value::C_USER); er = execute(cmd); if (er && er->isError()) { res.setErrorInfo(er); break; } } } } else { er.reset(new common::ErrorValue("Empty command line.", common::ErrorValue::E_ERROR)); res.setErrorInfo(er); } reply(sender, new events::ExecuteResponceEvent(this, res)); notifyProgress(sender, 100); }
bool Task::doWork() { notifyStatus("Fake progress"); for(int i = 0; i < 100; i++) { notifyProgress(i); } return true; }
void SsdbDriver::handleConnectEvent(events::ConnectRequestEvent *ev) { QObject* sender = ev->sender(); notifyProgress(sender, 0); events::ConnectResponceEvent::value_type res(ev->value()); SsdbConnectionSettings *set = dynamic_cast<SsdbConnectionSettings*>(settings_.get()); if (set) { impl_->config_ = set->info(); impl_->sinfo_ = set->sshInfo(); notifyProgress(sender, 25); common::Error er = impl_->connect(); if (er && er->isError()) { res.setErrorInfo(er); } notifyProgress(sender, 75); } reply(sender, new events::ConnectResponceEvent(this, res)); notifyProgress(sender, 100); }
void SsdbDriver::handleLoadDatabaseContentEvent(events::LoadDatabaseContentRequestEvent *ev) { QObject* sender = ev->sender(); notifyProgress(sender, 0); events::LoadDatabaseContentResponceEvent::value_type res(ev->value()); char patternResult[1024] = {0}; common::SNPrintf(patternResult, sizeof(patternResult), GET_KEYS_PATTERN_1ARGS_I, res.count_keys); FastoObjectIPtr root = FastoObject::createRoot(patternResult); notifyProgress(sender, 50); FastoObjectCommand* cmd = createCommand<SsdbCommand>(root, patternResult, common::Value::C_INNER); common::Error er = execute(cmd); if (er && er->isError()) { res.setErrorInfo(er); } else { FastoObject::child_container_type rchildrens = cmd->childrens(); if (rchildrens.size()) { DCHECK_EQ(rchildrens.size(), 1); FastoObjectArray* array = dynamic_cast<FastoObjectArray*>(rchildrens[0]); if (!array) { goto done; } common::ArrayValue* ar = array->array(); if (!ar) { goto done; } for (size_t i = 0; i < ar->size(); ++i) { std::string key; bool isok = ar->getString(i, &key); if (isok) { NKey k(key); NDbKValue ress(k, NValue()); res.keys.push_back(ress); } } } } done: notifyProgress(sender, 75); reply(sender, new events::LoadDatabaseContentResponceEvent(this, res)); notifyProgress(sender, 100); }
bool doWork() override { for (size_t i = 0; i < saves.size(); i++) { notifyStatus(String::Build("Deleting stamp [", saves[i].FromUtf8(), "] ...")); Client::Ref().DeleteStamp(saves[i]); notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
virtual bool doWork() { for(int i = 0; i < saves.size(); i++) { std::stringstream saveName; saveName << "Deleting stamp [" << saves[i] << "] ..."; notifyStatus(saveName.str()); Client::Ref().DeleteStamp(saves[i]); notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
void Tool::print(const char *format, ...) { char buf[4096] = ""; va_list va; va_start(va, format); vsnprintf(buf, 4096, format, va); va_end(va); _internalPrint(_print_udata, buf); // We notify of progress here // This way, almost all tools will be able to exit gracefully (as they print stuff) notifyProgress(false); }
bool doWork() override { for (size_t i = 0; i < saves.size(); i++) { notifyStatus(String::Build("Unfavouring save [", saves[i], "]")); if (Client::Ref().FavouriteSave(saves[i], false)!=RequestOkay) { notifyError(String::Build("Failed to unfavourite [", saves[i], "]: " + Client::Ref().GetLastError())); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
void SsdbDriver::handleCommandRequestEvent(events::CommandRequestEvent* ev) { QObject* sender = ev->sender(); notifyProgress(sender, 0); events::CommandResponceEvent::value_type res(ev->value()); std::string cmdtext; common::Error er = commandByType(res.cmd, &cmdtext); if (er && er->isError()) { res.setErrorInfo(er); reply(sender, new events::CommandResponceEvent(this, res)); notifyProgress(sender, 100); return; } RootLocker lock = make_locker(sender, cmdtext); FastoObjectIPtr root = lock.root_; FastoObjectCommand* cmd = createCommand<SsdbCommand>(root, cmdtext, common::Value::C_INNER); notifyProgress(sender, 50); er = execute(cmd); if (er && er->isError()) { res.setErrorInfo(er); } reply(sender, new events::CommandResponceEvent(this, res)); notifyProgress(sender, 100); }
bool doWork() override { for (size_t i = 0; i < saves.size(); i++) { notifyStatus(String::Build("Deleting save [", saves[i], "] ...")); if (Client::Ref().DeleteSave(saves[i])!=RequestOkay) { notifyError(String::Build("Failed to delete [", saves[i], "]: ", Client::Ref().GetLastError())); c->Refresh(); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } c->Refresh(); return true; }
virtual bool doWork() { for(int i = 0; i < saves.size(); i++) { std::stringstream saveID; saveID << "Unfavouring save [" << saves[i] << "] ..."; notifyStatus(saveID.str()); if(Client::Ref().FavouriteSave(saves[i], false)!=RequestOkay) { std::stringstream saveIDF; saveIDF << "\boFailed to remove [" << saves[i] << "] ..."; notifyStatus(saveIDF.str()); } notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
virtual bool doWork() { for(int i = 0; i < saves.size(); i++) { std::stringstream saveID; saveID << "Hiding save [" << saves[i] << "] ..."; notifyStatus(saveID.str()); if(Client::Ref().UnpublishSave(saves[i])!=RequestOkay) { std::stringstream saveIDF; saveIDF << "\boFailed to hide [" << saves[i] << "] ..."; notifyStatus(saveIDF.str()); } notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
virtual bool doWork() { for (size_t i = 0; i < saves.size(); i++) { std::stringstream saveID; saveID << "Unfavouring save [" << saves[i] << "]"; notifyStatus(saveID.str()); if (Client::Ref().FavouriteSave(saves[i], false)!=RequestOkay) { std::stringstream saveIDF; saveIDF << "Failed to unfavourite [" << saves[i] << "]: " + Client::Ref().GetLastError(); notifyError(saveIDF.str()); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } return true; }
virtual bool doWork() { for (size_t i = 0; i < saves.size(); i++) { std::stringstream saveID; saveID << "Deleting save [" << saves[i] << "] ..."; notifyStatus(saveID.str()); if (Client::Ref().DeleteSave(saves[i])!=RequestOkay) { std::stringstream saveIDF; saveIDF << "Failed to delete [" << saves[i] << "]: " << Client::Ref().GetLastError(); notifyError(saveIDF.str()); c->Refresh(); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } c->Refresh(); return true; }
virtual bool doWork() { std::vector<std::string> files = Client::Ref().DirectorySearch(directory, search, ".cps"); std::sort(files.rbegin(), files.rend(), [](std::string a, std::string b) { std::transform(a.begin(), a.end(), a.begin(), ::tolower); std::transform(b.begin(), b.end(), b.begin(), ::tolower); return a < b; }); notifyProgress(-1); for(std::vector<std::string>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter) { SaveFile * saveFile = new SaveFile(*iter); try { std::vector<unsigned char> data = Client::Ref().ReadFile(*iter); GameSave * tempSave = new GameSave(data); saveFile->SetGameSave(tempSave); saveFiles.push_back(saveFile); std::string filename = *iter; size_t folderPos = filename.rfind(PATH_SEP); if(folderPos!=std::string::npos && folderPos+1 < filename.size()) { filename = filename.substr(folderPos+1); } size_t extPos = filename.rfind("."); if(extPos!=std::string::npos) { filename = filename.substr(0, extPos); } saveFile->SetDisplayName(filename); } catch(std::exception & e) { //:( } } return true; }
bool doWork() override { bool ret; for (size_t i = 0; i < saves.size(); i++) { if (publish) ret = PublishSave(saves[i]); else ret = UnpublishSave(saves[i]); if (!ret) { if (publish) // uses html page so error message will be spam notifyError(String::Build("Failed to publish [", saves[i], "], is this save yours?")); else notifyError(String::Build("Failed to unpublish [", saves[i], "]: " + Client::Ref().GetLastError())); c->Refresh(); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); } c->Refresh(); return true; }
status_t SimpleSocketConnection::notifyReadable() { uint_t dataSize = 0; ulong_t curResponseSize; if (sending_) Log(eLogDebug, _T("notifyReadable(): called while sending data, probably some connection error occured"), true); status_t status = errNone; status_t error = getSocketErrorStatus(status); if (errNone == error) error = status; else { LogStrUlong(eLogInfo, _T("notifyReadable(): getSocketErrorStatus() returned error (ignored): "), error); error = errNone; } if (errNone != error) goto Exit; curResponseSize = responseLen_; if (curResponseSize >= maxResponseSize_ - chunkSize_) { error = errResponseTooLong; goto Exit; } if (NULL == chunk_) chunk_ = (char*)malloc(chunkSize_); if (NULL == chunk_) { error = memErrNotEnoughSpace; goto Exit; } dataSize = 0; error = socket().receive(dataSize, chunk_, chunkSize_, transferTimeout()); if (errNone != error) goto Exit; totalReceived_ += dataSize; assert(dataSize <= chunkSize_); response_ = StrAppend(response_, responseLen_, chunk_, dataSize); if (NULL == response_) { error = memErrNotEnoughSpace; goto Exit; } responseLen_ += dataSize; if (0 == dataSize) { // Log(eLogInfo, _T("notifyReadable(): 0 == dataSize (server shut socket down?)"), true); // TODO: if we use chunkSize_ != dataSize condition, we also need // to notifyProgress(); //error=notifyProgress(); //if (error) // goto Exit; error = notifyFinished(); abortConnection(); } else { registerEvent(SocketSelector::eventRead); error = notifyProgress(); } Exit: if (errNone!=error) LogStrUlong(eLogError, _T("notifyReadable(): Socket::receive() returned error: "), error); return error; }
virtual bool doWork() { notifyProgress(-1); return Client::Ref().UploadSave(save) == RequestOkay; }
void FeatureController::emitProgress(int counter, int total){ double percentage = (double)counter / (double)total; percentage *= 100.0; emit notifyProgress((int) floor(percentage)); }