bool ThreadPool::removeJob (ThreadPoolJob* const job, const bool interruptIfRunning, const int timeOutMs) { bool dontWait = true; OwnedArray<ThreadPoolJob> deletionList; if (job != nullptr) { const ScopedLock sl (lock); if (jobs.contains (job)) { if (job->isActive) { if (interruptIfRunning) job->signalJobShouldExit(); dontWait = false; } else { jobs.removeFirstMatchingValue (job); addToDeleteList (deletionList, job); } } } return dontWait || waitForJobToFinish (job, timeOutMs); }
json_object* OGRAmigoCloudDataSource::RunPOST(const char*pszURL, const char *pszPostData, const char *pszHeaders) { CPLString osURL(pszURL); /* -------------------------------------------------------------------- */ /* Provide the API Key */ /* -------------------------------------------------------------------- */ if( !osAPIKey.empty() ) { if(osURL.find("?") == std::string::npos) osURL += "?token="; else osURL += "&token="; osURL += osAPIKey; } char** papszOptions=nullptr; CPLString osPOSTFIELDS("POSTFIELDS="); if (pszPostData) osPOSTFIELDS += pszPostData; papszOptions = CSLAddString(papszOptions, osPOSTFIELDS); papszOptions = CSLAddString(papszOptions, pszHeaders); papszOptions = CSLAddString(papszOptions, GetUserAgentOption().c_str()); CPLHTTPResult * psResult = CPLHTTPFetch( osURL.c_str(), papszOptions); CSLDestroy(papszOptions); if( psResult == nullptr ) return nullptr; if (psResult->pszContentType && strncmp(psResult->pszContentType, "text/html", 9) == 0) { CPLDebug( "AMIGOCLOUD", "RunPOST HTML Response: %s", psResult->pabyData ); CPLError(CE_Failure, CPLE_AppDefined, "HTML error page returned by server: %s", psResult->pabyData); CPLHTTPDestroyResult(psResult); return nullptr; } if (psResult->pszErrBuf != nullptr && psResult->pabyData != nullptr ) { CPLError( CE_Failure, CPLE_AppDefined, "POST Response: %s", psResult->pabyData ); } else if (psResult->nStatus != 0) { CPLDebug( "AMIGOCLOUD", "RunPOST Error Status:%d", psResult->nStatus ); } if( psResult->pabyData == nullptr ) { CPLHTTPDestroyResult(psResult); return nullptr; } json_object* poObj = nullptr; const char* pszText = reinterpret_cast<const char*>(psResult->pabyData); if( !OGRJSonParse(pszText, &poObj, true) ) { CPLHTTPDestroyResult(psResult); return nullptr; } CPLHTTPDestroyResult(psResult); if( poObj != nullptr ) { if( json_object_get_type(poObj) == json_type_object ) { json_object* poError = CPL_json_object_object_get(poObj, "error"); if( poError != nullptr && json_object_get_type(poError) == json_type_array && json_object_array_length(poError) > 0 ) { poError = json_object_array_get_idx(poError, 0); if( poError != nullptr && json_object_get_type(poError) == json_type_string ) { CPLError(CE_Failure, CPLE_AppDefined, "Error returned by server : %s", json_object_get_string(poError)); json_object_put(poObj); return nullptr; } } json_object* poJob = CPL_json_object_object_get(poObj, "job"); if (poJob != nullptr) { const char *job = json_object_get_string(poJob); if (job != nullptr) { waitForJobToFinish(job); } } } else { json_object_put(poObj); return nullptr; } } return poObj; }