void CntServiceProviderOld::CompleteServiceAndCloseApp(const QVariant& retValue) { CNT_ENTRY connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit())); if ( mCurrentRequestIndex != 0 ) { bool success = false; if (!mOverriddenReturnValue.isNull() && retValue.value<int>() != KCntServicesReturnValueContactDeleted) { CNT_LOG_ARGS(mOverriddenReturnValue.value<int>()); success = completeRequest(mCurrentRequestIndex, mOverriddenReturnValue); } else { CNT_LOG_ARGS(retValue.value<int>()); success = completeRequest(mCurrentRequestIndex, retValue); } if ( !success ) { CNT_LOG_ARGS("Failed to complete highway request."); } mCurrentRequestIndex = 0; } CNT_EXIT }
bool V4L2Camera::enqueueRequestBuffers() { // Get a request from the queue (blocks this thread until one is available). std::shared_ptr<default_camera_hal::CaptureRequest> request = dequeueRequest(); // Assume request validated before being added to the queue // (For now, always exactly 1 output buffer, no inputs). // Setting and getting settings are best effort here, // since there's no way to know through V4L2 exactly what // settings are used for a buffer unless we were to enqueue them // one at a time, which would be too slow. // Set the requested settings int res = metadata_->SetRequestSettings(request->settings); if (res) { HAL_LOGE("Failed to set settings."); completeRequest(request, res); return true; } // Replace the requested settings with a snapshot of // the used settings/state immediately before enqueue. res = metadata_->FillResultMetadata(&request->settings); if (res) { // Note: since request is a shared pointer, this may happen if another // thread has already decided to complete the request (e.g. via flushing), // since that locks the metadata (in that case, this failing is fine, // and completeRequest will simply do nothing). HAL_LOGE("Failed to fill result metadata."); completeRequest(request, res); return true; } // Actually enqueue the buffer for capture. res = device_->EnqueueRequest(request); if (res) { HAL_LOGE("Device failed to enqueue buffer."); completeRequest(request, res); return true; } // Make sure the stream is on (no effect if already on). res = device_->StreamOn(); if (res) { HAL_LOGE("Device failed to turn on stream."); // Don't really want to send an error for only the request here, // since this is a full device error. // TODO: Should trigger full flush. return true; } std::unique_lock<std::mutex> lock(in_flight_lock_); in_flight_buffer_count_++; buffers_in_flight_.notify_one(); return true; }
void BtxqAddrService::handleshowBTAddrCompleted() { // The dialog has been closed. // Complete the service request. QVariant retVal(mError); completeRequest(mCurrentRequestIndex, retVal); }
bool V4L2Camera::dequeueRequestBuffers() { // Dequeue a buffer. std::shared_ptr<default_camera_hal::CaptureRequest> request; int res; { std::unique_lock<std::mutex> lock(in_flight_lock_); res = device_->DequeueRequest(&request); if (!res) { if (request) { completeRequest(request, res); in_flight_buffer_count_--; } return true; } } if (res == -EAGAIN) { // EAGAIN just means nothing to dequeue right now. // Wait until something is available before looping again. std::unique_lock<std::mutex> lock(in_flight_lock_); while (in_flight_buffer_count_ == 0) { buffers_in_flight_.wait(lock); } } else { HAL_LOGW("Device failed to dequeue buffer: %d", res); } return true; }
/*! * Destructor. */ CxuiServiceProvider::~CxuiServiceProvider() { CX_DEBUG_ENTER_FUNCTION(); if (mRequestIndex != -1) { CX_DEBUG(("Request still active...")); // Complete request now, this will return error to client completeRequest(mRequestIndex, QString()); } CX_DEBUG_EXIT_FUNCTION(); }
// virtual S32 LLWorkerThread::update(U32 max_time_ms) { S32 res = LLQueuedThread::update(max_time_ms); // Delete scheduled workers std::vector<LLWorkerClass*> delete_list; std::vector<LLWorkerClass*> abort_list; mDeleteMutex->lock(); for (delete_list_t::iterator iter = mDeleteList.begin(); iter != mDeleteList.end(); ) { delete_list_t::iterator curiter = iter++; LLWorkerClass* worker = *curiter; if (worker->deleteOK()) { if (worker->getFlags(LLWorkerClass::WCF_WORK_FINISHED)) { delete_list.push_back(worker); mDeleteList.erase(curiter); } else if (!worker->getFlags(LLWorkerClass::WCF_ABORT_REQUESTED)) { abort_list.push_back(worker); } } } mDeleteMutex->unlock(); // abort and delete after releasing mutex for (std::vector<LLWorkerClass*>::iterator iter = abort_list.begin(); iter != abort_list.end(); ++iter) { (*iter)->abortWork(false); } LLWorkerClass::sDeleteLock = TRUE ; for (std::vector<LLWorkerClass*>::iterator iter = delete_list.begin(); iter != delete_list.end(); ++iter) { LLWorkerClass* worker = *iter; if (worker->mRequestHandle) { // Finished but not completed completeRequest(worker->mRequestHandle); worker->mRequestHandle = LLWorkerThread::nullHandle(); worker->clearFlags(LLWorkerClass::WCF_HAVE_WORK); } delete *iter; } LLWorkerClass::sDeleteLock = FALSE ; // delete and aborted entries mean there's still work to do res += delete_list.size() + abort_list.size(); return res; }
S32 LLVFSThread::readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, U8* buffer, S32 offset, S32 numbytes) { handle_t handle = generateHandle(); Request* req = new Request(handle, PRIORITY_IMMEDIATE, 0, FILE_READ, vfs, file_id, file_type, buffer, offset, numbytes); S32 res = addRequest(req) ? 1 : 0; if (res == 0) { LL_ERRS() << "LLVFSThread::read called after LLVFSThread::cleanupClass()" << LL_ENDL; req->deleteRequest(); } else { llverify(waitForResult(handle, false) == true); res = req->getBytesRead(); completeRequest(handle); } return res; }
/*! * Sends filename of captured image/video to client and exits camera app. */ void CxuiServiceProvider::sendFilenameToClientAndExit(QString filename) { CX_DEBUG_ENTER_FUNCTION(); if (mRequestIndex == -1) { CX_DEBUG(("CxuiServiceProvider: no request in progress")); QCoreApplication::instance()->quit(); CX_DEBUG_EXIT_FUNCTION(); return; } connect(this, SIGNAL(returnValueDelivered()), QCoreApplication::instance(), SLOT(quit())); CX_DEBUG(("CxuiServiceProvider: completing request")); if (!completeRequest(mRequestIndex, QVariant(filename))) { // if request completion fails call quit immediately because signal is not coming CX_DEBUG(("completeRequest() failed, quitting now")); QCoreApplication::instance()->quit(); } mRequestIndex = -1; CX_DEBUG_EXIT_FUNCTION(); }
/* * Proxy for all I/O with a device * @author Dan Streetman */ JNIEXPORT void JNICALL Java_com_ibm_jusb_os_linux_JavaxUsb_nativeDeviceProxy ( JNIEnv *env, jclass JavaxUsb, jobject linuxDeviceProxy ) { int fd = 0; struct usbdevfs_urb *urb; int loop_count = 0; jclass LinuxDeviceProxy; jobject linuxRequest; jstring jkey; jmethodID startCompleted, isRequestWaiting, getReadyRequest, getCancelRequest; jmethodID getKey; LinuxDeviceProxy = (*env)->GetObjectClass( env, linuxDeviceProxy ); startCompleted = (*env)->GetMethodID( env, LinuxDeviceProxy, "startCompleted", "(I)V" ); isRequestWaiting = (*env)->GetMethodID( env, LinuxDeviceProxy, "isRequestWaiting", "()Z" ); getReadyRequest = (*env)->GetMethodID( env, LinuxDeviceProxy, "getReadyRequest", "()Lcom/ibm/jusb/os/linux/LinuxRequest;" ); getCancelRequest = (*env)->GetMethodID( env, LinuxDeviceProxy, "getCancelRequest", "()Lcom/ibm/jusb/os/linux/LinuxRequest;" ); getKey = (*env)->GetMethodID( env, LinuxDeviceProxy, "getKey", "()Ljava/lang/String;" ); jkey = (*env)->CallObjectMethod( env, linuxDeviceProxy, getKey ); (*env)->DeleteLocalRef( env, LinuxDeviceProxy ); errno = 0; fd = open_device( env, jkey, O_RDWR ); (*env)->DeleteLocalRef( env, jkey ); if (0 > fd) { dbg( MSG_ERROR, "nativeDeviceProxy : Could not open node for device!\n" ); (*env)->CallVoidMethod( env, linuxDeviceProxy, startCompleted, errno ); return; } (*env)->CallVoidMethod( env, linuxDeviceProxy, startCompleted, 0 ); /* run forever...? */ while (1) { /* FIXME - stop using polling! */ if ( loop_count > 20 ) { usleep( 0 ); loop_count = 0; } loop_count ++; if (JNI_TRUE == (*env)->CallBooleanMethod( env, linuxDeviceProxy, isRequestWaiting )) { if ((linuxRequest = (*env)->CallObjectMethod( env, linuxDeviceProxy, getReadyRequest ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got Request\n" ); submitRequest( env, fd, linuxRequest ); (*env)->DeleteLocalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Completed Request\n" ); } if ((linuxRequest = (*env)->CallObjectMethod( env, linuxDeviceProxy, getCancelRequest ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got Abort Request\n" ); cancelRequest( env, fd, linuxRequest ); (*env)->DeleteLocalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Completed Abort Request\n" ); } } if (!(ioctl( fd, USBDEVFS_REAPURBNDELAY, &urb ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got completed URB\n" ); linuxRequest = urb->usercontext; completeRequest( env, linuxRequest ); (*env)->DeleteGlobalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Finished completed URB\n" ); } } dbg( MSG_ERROR, "nativeDeviceProxy : Proxy exiting! ERROR!\n" ); close( fd ); }
// Give libcurl some cycles, invoke it's callbacks, process // completed requests finalizing or issuing retries as needed. // // If active list goes empty *and* we didn't queue any // requests for retry, we return a request for a hard // sleep otherwise ask for a normal polling interval. HttpService::ELoopSpeed HttpLibcurl::processTransport() { HttpService::ELoopSpeed ret(HttpService::REQUEST_SLEEP); // Give libcurl some cycles to do I/O & callbacks for (int policy_class(0); policy_class < mPolicyCount; ++policy_class) { if (! mMultiHandles[policy_class]) { // No handle, nothing to do. continue; } if (! mActiveHandles[policy_class]) { // If we've gone quiet and there's a dirty update, apply it, // otherwise we're done. if (mDirtyPolicy[policy_class]) { policyUpdated(policy_class); } continue; } int running(0); CURLMcode status(CURLM_CALL_MULTI_PERFORM); do { running = 0; status = curl_multi_perform(mMultiHandles[policy_class], &running); } while (0 != running && CURLM_CALL_MULTI_PERFORM == status); // Run completion on anything done CURLMsg * msg(NULL); int msgs_in_queue(0); while ((msg = curl_multi_info_read(mMultiHandles[policy_class], &msgs_in_queue))) { if (CURLMSG_DONE == msg->msg) { CURL * handle(msg->easy_handle); CURLcode result(msg->data.result); completeRequest(mMultiHandles[policy_class], handle, result); handle = NULL; // No longer valid on return ret = HttpService::NORMAL; // If anything completes, we may have a free slot. // Turning around quickly reduces connection gap by 7-10mS. } else if (CURLMSG_NONE == msg->msg) { // Ignore this... it shouldn't mean anything. ; } else { LL_WARNS_ONCE(LOG_CORE) << "Unexpected message from libcurl. Msg code: " << msg->msg << LL_ENDL; } msgs_in_queue = 0; } } if (! mActiveOps.empty()) { ret = HttpService::NORMAL; } return ret; }