SimpleHttpResult* SimpleHttpClient::request (int method, const string& location, const char* body, size_t bodyLength, const map<string, string>& headerFields) { _result = new SimpleHttpResult; _errorMessage = ""; // set body to all connections setRequest(method, location, body, bodyLength, headerFields); double endTime = now() + _requestTimeout; double remainingTime = _requestTimeout; while (isWorking() && remainingTime > 0.0) { switch (_state) { case (IN_CONNECT): handleConnect(); break; case (IN_WRITE): handleWrite(remainingTime); break; case (IN_READ_HEADER): case (IN_READ_BODY): case (IN_READ_CHUNKED_HEADER): case (IN_READ_CHUNKED_BODY): handleRead(remainingTime); break; default: break; } remainingTime = endTime - now(); } if (isWorking() && _errorMessage=="" ) { if (_warn) { LOGGER_WARNING << "Request timeout reached."; } _errorMessage = "Request timeout reached."; } // set result type in getResult() SimpleHttpResult* result = getResult(); _result = 0; return result; }
void IntEngine::sendLevelBuffer() { if(isWorking()) { LogDebug("Attempt to send LVLX buffer"); QString output; FileFormats::WriteExtendedLvlFileRaw(testBuffer, output); QString sendLvlx; if(!testBuffer.meta.path.isEmpty()) sendLvlx = QString("SEND_LVLX: %1/%2\n") .arg(testBuffer.meta.path) .arg(testBuffer.meta.filename + ".lvlx"); else sendLvlx = QString("SEND_LVLX: %1/%2\n") .arg(ApplicationPath) .arg("_untitled.lvlx"); if(output.size() <= 0) output = "HEAD\nEMPTY:1\nHEAD_END\n"; //#ifdef DEBUG_BUILD // qDebug() << "Sent File data BEGIN >>>>>>>>>>>\n" << output << "\n<<<<<<<<<<<<Sent File data END"; //#endif sendMessage(sendLvlx); QByteArray output_e; base64_encode(output_e, output); output_e.append('\n'); engine->write(output_e); sendMessage("PARSE_LVLX"); LogDebug("LVLX buffer sent"); } }
void IntEngine::onData() { if(isWorking()) { QByteArray strData = engine->readAllStandardOutput(); QByteArray msg = QByteArray::fromBase64(strData); if(msg.startsWith("CMD:")) { char *msgP = msg.data() + 4; //"CMD:" LogDebug("ENGINE COMMAND: >>"); LogDebug(msgP); LogDebug("<<ENGINE COMMAND END"); if(strcmp(msgP, "CONNECT_TO_ENGINE") == 0) sendLevelBuffer(); else if(strcmp(msgP, "ENGINE_CLOSED") == 0) { MainWinConnect::pMainWin->show(); MainWinConnect::pMainWin->raise(); } } else emit engineInputMsg(QString::fromUtf8(msg)); } }
virtual void dispose() { #if 0 // sample code; do this right with the API Q_ASSERT(!isWorking()); #endif delete this; }
void IntEngine::init() { if(!isWorking()) { if(engineSocket!=NULL) delete engineSocket; engineSocket = new EngineClient(); engineSocket->start(); } }
void IntEngine::quit() { if(isWorking()) { engineSocket->exit(); delete engineSocket; engineSocket = NULL; } }
//============================================================================= // METHOD: SPELLipcTrash::run //============================================================================= void SPELLipcTrash::run() { while(isWorking()) { if (haveData()) clearData(); usleep(250000); } if (haveData()) clearData(); m_finishEvent.set(); }
bool IntEngine::sendMessage(QString &msg) { if(!isWorking()) return false; QByteArray output_e; base64_encode(output_e, msg); output_e.append('\n'); return (engine->write(output_e) > 0); }
//============================================================================= // METHOD: SPELLipcTrash::run //============================================================================= void SPELLipcTrash::run() { DEBUG( NAME + "Thread started" ); while(isWorking()) { if (haveData()) clearData(); usleep(350000); } if (haveData()) clearData(); m_trashFinishEvent.set(); DEBUG( NAME + "Thread finished" ); }
bool IntEngine::sendItemPlacing(QString _args) { if(isWorking()) { LogDebug("ENGINE: Place item command: " + _args); QString out = QString("PLACEITEM: %1").arg(_args); bool ret = sendMessage(out); return ret; } return false; }
void FileGathererThread::abortGathering() { if ( !isRunning() || !isWorking() ) { return; } QMutexLocker k(&_imp->abortRequestsMutex); ++_imp->abortRequests; while (_imp->abortRequests > 0) { _imp->abortRequestsCond.wait(&_imp->abortRequestsMutex); } }
main() { int foo; oneHop testPath[NUMSEGMENTS]; int genPath[NUMSEGMENTS]; init_schedular(); testPath[0].thisNode.module = A; testPath[0].thisNode.sensorNum = 1; testPath[0].distance = 200; testPath[1].thisNode.module = C; testPath[1].thisNode.sensorNum = 13; testPath[1].distance = 400; testPath[2].thisNode.module = E; testPath[2].thisNode.sensorNum = 7; testPath[2].distance = NIL; init('a'); foo = router(genPath, 52, testPath); if (foo > 0) { foo = router(genPath, 55, testPath); foo = isWorking(testPath[0].thisNode); foo = isWorking(testPath[1].thisNode); foo = isWorking(testPath[2].thisNode); } }
Strategy::statusType Balancer::doStrategy() { if(balance == 0) { startBalacing(); } else { trySaveVon(); if(getBalanceTime() > maxBalanceTime) { setBalance(0); } } if((!isWorking()) && done) return Strategy::COMPLETE; return Strategy::RUNNING; }
bool IntEngine::sendMessageBox(QString _args) { if(isWorking()) { if(_args.isEmpty()) return false; _args.replace('\n', "\\n"); QString out = QString("MSGBOX: %1").arg(_args); return sendMessage(out); } else return false; }
Strategy::statusType Balancer::doStrategy() { LogDebug("minCell=", minCell, " balance=", balance, " conCells=", connectedCells); if(balance == 0) { startBalacing(); } else { trySaveVon(); if(getBalanceTime() > maxBalanceTime) { setBalance(0); } } if((!isWorking()) && done) return Strategy::COMPLETE; return Strategy::RUNNING; }
bool MessageQueue::Receive(char *message,bool wait){ if (!isWorking()){ std::cout << "[Error] Not working!\n"; return false; } if (!isReceiver()){ std::cout << "[Error] I am not receiver! ["<<type<<"]\n"; return false; } int readSize=-1; if (readSize = msgrcv(MessageQueueId, &Buffer, MSG_SIZE, 1,(wait ? 0 : IPC_NOWAIT) ) < 0){ return false; } LastReadSize = readSize; for (int i=0;i<MSG_SIZE+1;i++){ message[i] = Buffer.mtext[i]; } return true; }
int main() { FILE *rep_file = NULL; int *pad_errs = NULL; dword i; char c, choice = '\0'; if((rep_file = fopen("list_report.txt", "w+")) == NULL) { printf("**Error, unable to create report_list.txt**\n"); return EXIT_FAILURE; } /* Printing on the screen and in the report file */ fprintf(rep_file, "====================================\n"); fprintf(rep_file, "** Report for list.c test drivers **\n"); fprintf(rep_file, "====================================\n\n"); fprintf(rep_file, "# Driver's Name \t\t\tStatus\n"); fprintf(rep_file, "-----------------------------------------------\n"); printf("\n\n*******************************\n"); printf(" <BEGIN of list.c Testing>\n"); printf("*******************************\n\n"); if(openFile()) { fprintf(rep_file, "1. openFile() \t\t\t\tSUCCESS\n"); } else { fprintf(rep_file, "1. openFile() \t\t\t\tFAILURE\n"); } if(readFile()) { fprintf(rep_file, "2. readFile() \t\t\t\tSUCCESS\n"); } else { fprintf(rep_file, "2. readFile() \t\t\t\tFAILURE\n"); } if(isBM()) { fprintf(rep_file, "3. isBM() \t\t\t\tSUCCESS\n"); } else { fprintf(rep_file, "3. isBM() \t\t\t\tFAILURE\n"); } if(hasCompress()) { fprintf(rep_file, "4. hasCompress() \t\t\tSUCCESS\n"); } else { fprintf(rep_file, "4. hasCompress() \t\t\tFAILURE\n"); } if(isPixel24bit()) { fprintf(rep_file, "5. isPixel24bit() \t\t\tSUCCESS\n"); } else { fprintf(rep_file, "5. isPixel24bit() \t\t\tFAILURE\n"); } if((pad_errs = paddingCases()) == NULL) { fprintf(rep_file, "6. paddingCases() - Padding Bytes: 0\tSUCCESS\n"); fprintf(rep_file, "6. paddingCases() - Padding Bytes: 1\tSUCCESS\n"); fprintf(rep_file, "6. paddingCases() - Padding Bytes: 2\tSUCCESS\n"); fprintf(rep_file, "6. paddingCases() - Padding Bytes: 3\tSUCCESS\n"); } else { for(i=0; i<4; i++) { if(pad_errs[i] == -1) { fprintf(rep_file, "7. paddingCases() - Padding Bytes: %d\tFAILURE\n", i); } } free(pad_errs); } if(isWorking()) { fprintf(rep_file, "6. isWorking() \t\t\t\tSUCCESS\n"); } else { fprintf(rep_file, "6. isWorking() \t\t\t\tFAILURE\n"); } rewind(rep_file); printf("\n"); while((c = getc(rep_file)) != EOF) { printf("%c", c); } fclose(rep_file); // Dialogue message for a choice to keep the report file or delete it. printf("\n>> Do you want to keep the report file? (y/n): "); scanf(" %c", &choice); // Validation check for choice variable - only 'y' or 'n' are accepted. while(choice != 'y' && choice != 'n') { printf("**Error, %c is an invalid choice, 'y' for YES -- 'n' for NO**\n",choice); printf(">> Do you want to keep the report file? (y/n): "); scanf(" %c", &choice); } if(choice == 'n') { if(remove("list_report.txt")) { printf("**Error, unable to remove the report file**"); return EXIT_FAILURE; } } printf("\n\n******************************\n"); printf(" </END of list.c Testing>\n"); printf("******************************\n\n"); return EXIT_SUCCESS; }
SimpleHttpResult* SimpleHttpClient::request (rest::HttpRequest::HttpRequestType method, const string& location, const char* body, size_t bodyLength, const map<string, string>& headerFields) { assert(_result == 0); _result = new SimpleHttpResult; _errorMessage = ""; // set body to all connections setRequest(method, location, body, bodyLength, headerFields); double endTime = now() + _requestTimeout; double remainingTime = _requestTimeout; while (isWorking() && remainingTime > 0.0) { switch (_state) { case (IN_CONNECT): { handleConnect(); break; } case (IN_WRITE): { size_t bytesWritten = 0; TRI_set_errno(TRI_ERROR_NO_ERROR); if (! _connection->handleWrite(remainingTime, (void*) (_writeBuffer.c_str() + _written), _writeBuffer.length() - _written, &bytesWritten)) { setErrorMessage(TRI_last_error(), false); this->close(); } else { _written += bytesWritten; if (_written == _writeBuffer.length()) { _state = IN_READ_HEADER; } } break; } case (IN_READ_HEADER): case (IN_READ_BODY): case (IN_READ_CHUNKED_HEADER): case (IN_READ_CHUNKED_BODY): { TRI_set_errno(TRI_ERROR_NO_ERROR); if (_connection->handleRead(remainingTime, _readBuffer)) { switch (_state) { case (IN_READ_HEADER): readHeader(); break; case (IN_READ_BODY): readBody(); break; case (IN_READ_CHUNKED_HEADER): readChunkedHeader(); break; case (IN_READ_CHUNKED_BODY): readChunkedBody(); break; default: break; } } else { setErrorMessage(TRI_last_error(), false); this->close(); } break; } default: break; } remainingTime = endTime - now(); } if (isWorking() && _errorMessage == "" ) { setErrorMessage("Request timeout reached"); } // set result type in getResult() SimpleHttpResult* result = getResult(); _result = 0; return result; }