void Session_Service::onRemoteObjectComplete(qi::Future<void> future, long requestId) { qiLogDebug() << "Got metaobject"; boost::recursive_mutex::scoped_lock l(_requestsMutex); ServiceRequest *sr = serviceRequest(requestId); if (!sr) return; if (future.hasError()) { sr->promise.setError(future.error()); removeRequest(requestId); return; } { boost::recursive_mutex::scoped_lock sl(_remoteObjectsMutex); RemoteObjectMap::iterator it = _remoteObjects.find(sr->name); if (it != _remoteObjects.end()) { //another object have been registered before us, return it //the new socket will be closed when the request is deleted qiLogVerbose() << "A request for the service " << sr->name << " have been discarded, " << "the remoteobject on the service was already available."; sr->promise.setValue(it->second); } else { AnyObject o = makeDynamicAnyObject(sr->remoteObject); //register the remote object in the cache addService(sr->name, o); sr->promise.setValue(o); sr->remoteObject = 0; } } removeRequest(requestId); }
MojErr MojLunaService::dispatchReplyImpl(MojServiceRequest* req, MojServiceMessage *msg, MojObject& payload, MojErr errCode) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(req); MojAssertMutexUnlocked(m_mutex); // don't automatically cancel a subscription if the payload has "subscribed":true bool subscribed = false; payload.get(_T("subscribed"), subscribed); // remove if there are more responses coming. due to the vagaries of the luna-service protocol, // we never really know for sure, but this is a good guess. bool remove = (req->numReplies() + 1 >= req->numRepliesExpected()) || (errCode != MojErrNone && !subscribed); MojErr err = req->dispatchReply(msg, payload, errCode); MojErrCatchAll(err) { remove = true; } if (remove) { if (req->numRepliesExpected() == 1) { bool found = false; err = removeRequest(req, found); MojErrCheck(err); } else { err = cancel(req); MojErrCheck(err); } } return MojErrNone; }
void FileTreeView::remove ( void ) { emit removeRequest( selectionModel()->selectedIndexes() ); }
void RealTimeStationSearchModelPrivate::slotStationsRegistered(const QString & request, const QList<Station> &stations) { if (!requestRunning(request)) { return; } AbstractBackendWrapper *backend = qobject_cast<AbstractBackendWrapper *>(sender()); if (!backend) { return; } debug("realtime-station-search-model") << "Request" << request << "finished"; removeRequest(request); bool support = backend->capabilities().contains(CAPABILITY_REAL_TIME_RIDES_FROM_STATION); ModelDataList addedData; foreach (Station station, stations) { ModelData data; data.insert(Qt::UserRole + STATION_INDEX, QVariant::fromValue(station)); data.insert(Qt::UserRole + BACKEND_IDENTIFIER_INDEX, backend->identifier()); data.insert(RealTimeStationSearchModel::NameRole, station.name()); // TODO ProviderNameRole data.insert(RealTimeStationSearchModel::SupportRidesFromStationRole, support); addedData.append(data); }
void MiniFieldWidget::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { /* if(event->modifiers().testFlag(Qt::ControlModifier)) MainWindow::dataManager()->toggleAddSelection(reinterpret_cast<ulong>(volume)); else MainWindow::dataManager()->setSelection(reinterpret_cast<ulong>(volume)); updateStyleSheet(); */ } else if(event->button() == Qt::RightButton) { if(m_field) { QMenu contextMenu; QAction *removeAction = contextMenu.addAction("Remove Field"); QAction *selectedItem = contextMenu.exec(mapToGlobal(event->pos())); if(selectedItem) { if(selectedItem == removeAction) { emit removeRequest(m_field); } } } } }
void Session_Service::onTransportSocketResult(qi::Future<TransportSocketPtr> value, long requestId) { qiLogDebug() << "Got transport socket for service"; { boost::recursive_mutex::scoped_lock sl(_requestsMutex); ServiceRequest *sr = serviceRequest(requestId); if (!sr) return; if (value.hasError()) { sr->promise.setError(value.error()); removeRequest(requestId); return; } } TransportSocketPtr socket = value.value(); // If true, this socket came from the socket cache and has already been identified. // This typically happens when two services are behind the same endpoint. // We forge a message that just shows we've authenticated successfully. if (socket->hasReceivedRemoteCapabilities()) { Message dummy; CapabilityMap cm; cm[AuthProvider::State_Key] = AnyValue::from(AuthProvider::State_Done); dummy.setType(Message::Type_Reply); dummy.setFunction(qi::Message::ServerFunction_Authenticate); dummy.setValue(AnyValue::from(cm), typeOf<CapabilityMap>()->signature()); onAuthentication(TransportSocket::SocketEventData(dummy), requestId, socket, ClientAuthenticatorPtr(new NullClientAuthenticator), SignalSubscriberPtr()); return; } ClientAuthenticatorPtr authenticator = _authFactory->newAuthenticator(); CapabilityMap authCaps; { CapabilityMap tmp = authenticator->initialAuthData(); for (CapabilityMap::iterator it = tmp.begin(), end = tmp.end(); it != end; ++it) authCaps[AuthProvider::UserAuthPrefix + it->first] = it->second; } SignalSubscriberPtr protSubscriber(new SignalSubscriber); *protSubscriber = socket->socketEvent.connect(&Session_Service::onAuthentication, this, _1, requestId, socket, authenticator, protSubscriber); Message msgCapabilities; msgCapabilities.setFunction(Message::ServerFunction_Authenticate); msgCapabilities.setService(Message::Service_Server); msgCapabilities.setType(Message::Type_Call); TransportSocketPtr sdSocket = _sdClient->socket(); CapabilityMap socketCaps; if (sdSocket) { socketCaps = sdSocket->localCapabilities(); socket->advertiseCapabilities(socketCaps); } socketCaps.insert(authCaps.begin(), authCaps.end()); msgCapabilities.setValue(socketCaps, typeOf<CapabilityMap>()->signature()); socket->send(msgCapabilities); }
void FileTreeView::setModel ( FileTreeModel * model ) { QTreeView::setModel( model ); connect( this, SIGNAL( expanded( QModelIndex ) ), model, SLOT( expand( QModelIndex ) ) ); connect( this, SIGNAL( collapsed( QModelIndex ) ), model, SLOT( collapse( QModelIndex ) ) ); connect( this, SIGNAL( removeRequest( QModelIndexList ) ), model, SLOT( remove( QModelIndexList ) ) ); }
void FileTreeView::keyPressEvent ( QKeyEvent * event ) { if ( ( event->key() == Qt::Key_Delete ) && selectionModel()->hasSelection() ) { emit removeRequest( selectionModel()->selectedIndexes() ); } QTreeView::keyPressEvent( event ); }
//aIndexs need Traversall from start to end, so use foreach void IRParallelDownloadSession::removeRequest(const QList<int> &aIndexList) { LOG_METHOD; Qt::HANDLE threadid = QThread::currentThreadId(); LOG_FORMAT(" !!!thread IRParallelDownloadSession::removeRequest_QList id=%d",(int)threadid); //NonRecursive Lock. locked in removeRequest(inputIndex), mMutex.lock() is not necessary here. //foreach is OK here. loop index by aIndexList, but the removed container is mReqMap. It's Safe!! foreach (int inputIndex, aIndexList) { removeRequest(inputIndex); }
MojErr MojService::cancel(MojServiceRequest* req) { MojAssert(req); MojAssertMutexUnlocked(m_mutex); MojLogTrace(s_log); bool found = false; MojErr err = removeRequest(req, found); MojErrCheck(err); if (found) { err = cancelImpl(req); MojErrCheck(err); } return MojErrNone; }
void Session_Service::onTransportSocketResult(qi::Future<TransportSocketPtr> value, long requestId) { qiLogDebug() << "Got transport socket for service"; qi::Future<void> fut; { boost::recursive_mutex::scoped_lock sl(_requestsMutex); ServiceRequest *sr = serviceRequest(requestId); if (!sr) return; if (value.hasError()) { sr->promise.setError(value.error()); removeRequest(requestId); return; } sr->remoteObject = new qi::RemoteObject(sr->serviceId, value.value()); //ask the remoteObject to fetch the metaObject fut = sr->remoteObject->fetchMetaObject(); } fut.connect(&Session_Service::onRemoteObjectComplete, this, _1, requestId); }
void recvReadReply(trfs_pkt_t *rq) { trfs_fio_t *fio = &(rq->readReply.info); void *data = rq->readReply.data; SHOW_FLOW( 2, "read reply for fid %d ioid %d nSect %d start %ld", fio->fileId, fio->ioId, fio->nSectors, fio->startSector); trfs_queue_t *qe = findRequest( fio, TRFS_QEL_TYPE_READ ); if( qe == 0 ) { SHOW_ERROR0( 0, "TRFS: No request for read reply"); return; } trfs_process_received_data(qe, fio, data); trfs_mark_recombine_map(qe, fio->startSector, fio->nSectors); if( trfs_request_complete(qe) ) { removeRequest(qe); trfs_signal_done(qe); } }
ImageManager::ImageRequest* ImageManager::RequestQueue::popNext() { QueueType::iterator it = m_queues.end(); // m_queues is initialized to non-zero size do { --it; while ( ! it->empty() ) { ImageRequest* request = it->dequeue(); if ( ! request->stillNeeded() ) { removeRequest( request ); request->setLoadedOK( false ); CancelEvent* event = new CancelEvent( request ); QApplication::postEvent( AsyncLoader::instance(), event ); } else { const ImageRequestReference ref(request); m_uniquePending.remove( ref ); return request; } } } while ( it != m_queues.begin() ); return nullptr; }
void Session_Service::onAuthentication(const TransportSocket::SocketEventData& data, long requestId, TransportSocketPtr socket, ClientAuthenticatorPtr auth, SignalSubscriberPtr old) { static const std::string cmsig = typeOf<CapabilityMap>()->signature().toString(); boost::recursive_mutex::scoped_lock sl(_requestsMutex); ServiceRequest *sr = serviceRequest(requestId); if (!sr) return; if (data.which() == TransportSocket::Event_Error) { if (old) socket->socketEvent.disconnect(*old); sr->promise.setError(boost::get<std::string>(data)); removeRequest(requestId); return; } #if BOOST_VERSION < 105800 const Message& msg = boost::get<const Message&>(data); #else const Message& msg = boost::relaxed_get<const Message&>(data); #endif int function = msg.function(); bool failure = msg.type() == Message::Type_Error || msg.service() != Message::Service_Server || function != Message::ServerFunction_Authenticate; if (failure) { if (old) socket->socketEvent.disconnect(*old); if (_enforceAuth) { std::stringstream error; if (msg.type() == Message::Type_Error) error << "Error while authenticating: " << msg.value("s", socket).to<std::string>(); else error << "Expected a message for function #" << Message::ServerFunction_Authenticate << " (authentication), received a message for function " << function; sr->promise.setError(error.str()); removeRequest(requestId); } else { session_service_private::sendCapabilities(socket); qi::Future<void> metaObjFut; sr->remoteObject = new qi::RemoteObject(sr->serviceId, socket); metaObjFut = sr->remoteObject->fetchMetaObject(); metaObjFut.connect(&Session_Service::onRemoteObjectComplete, this, _1, requestId); } return; } AnyReference cmref = msg.value(typeOf<CapabilityMap>()->signature(), socket); CapabilityMap authData = cmref.to<CapabilityMap>(); CapabilityMap::iterator authStateIt = authData.find(AuthProvider::State_Key); cmref.destroy(); if (authStateIt == authData.end() || authStateIt->second.to<unsigned int>() < AuthProvider::State_Error || authStateIt->second.to<unsigned int>() > AuthProvider::State_Done) { if (old) socket->socketEvent.disconnect(*old); std::string error = "Invalid authentication state token."; sr->promise.setError(error); removeRequest(requestId); qiLogInfo() << error; return; } if (authData[AuthProvider::State_Key].to<unsigned int>() == AuthProvider::State_Done) { qi::Future<void> metaObjFut; if (old) socket->socketEvent.disconnect(*old); sr->remoteObject = new qi::RemoteObject(sr->serviceId, socket); //ask the remoteObject to fetch the metaObject metaObjFut = sr->remoteObject->fetchMetaObject(); metaObjFut.connect(&Session_Service::onRemoteObjectComplete, this, _1, requestId); return; } CapabilityMap nextData = auth->processAuth(authData); Message authMsg; authMsg.setService(Message::Service_Server); authMsg.setType(Message::Type_Call); authMsg.setValue(nextData, cmsig); authMsg.setFunction(Message::ServerFunction_Authenticate); socket->send(authMsg); }
void OutgoingContactRequest::accept() { setStatus(Accepted); removeRequest(); emit accepted(); }
// We received a ServiceInfo, and want to establish a connection void Session_Service::onServiceInfoResult(qi::Future<qi::ServiceInfo> result, long requestId, std::string protocol) { qiLogDebug() << "Got serviceinfo message"; { boost::recursive_mutex::scoped_lock sl(_requestsMutex); ServiceRequest *sr = serviceRequest(requestId); if (!sr) return; if (result.hasError()) { sr->promise.setError(result.error()); removeRequest(requestId); return; } const qi::ServiceInfo &si = result.value(); sr->serviceId = si.serviceId(); if (_sdClient->isLocal()) { // Wait! If sd is local, we necessarily have an open socket // on which service was registered, whose lifetime is bound // to the service TransportSocketPtr s = _sdClient->_socketOfService(sr->serviceId); if (!s) // weird qiLogVerbose() << "_socketOfService returned 0"; else { // check if the socket support that capability if (s->remoteCapability("ClientServerSocket", false)) { qiLogVerbose() << "sd is local and service is capable, going through socketOfService"; onTransportSocketResult(qi::Future<TransportSocketPtr>(s), requestId); return; } } } //empty serviceInfo if (!si.endpoints().size()) { std::stringstream ss; ss << "No endpoints returned for service:" << sr->name << " (id:" << sr->serviceId << ")"; qiLogVerbose() << ss.str(); sr->promise.setError(ss.str()); removeRequest(requestId); return; } if (protocol != "") { std::vector<qi::Url>::const_iterator it = si.endpoints().begin(); for (; it != si.endpoints().end() && it->protocol() != protocol; it++) { continue; } if (it == si.endpoints().end()) { std::stringstream ss; ss << "No " << protocol << " endpoint available for service:" << sr->name << " (id:" << sr->serviceId << ")"; qiLogVerbose() << ss.str(); sr->promise.setError(ss.str()); } } } qiLogDebug() << "Requesting socket from cache"; qi::Future<qi::TransportSocketPtr> fut = _socketCache->socket(result.value(), protocol); fut.connect(&Session_Service::onTransportSocketResult, this, _1, requestId); }
/** Function which handles the server process management. The function polls the requests directory for new requests generated by the client processes. The server process management function requires max_restarts as a limitation for graceful degradation. */ int server(int max_restarts) { /**Directory pointer used to point to the directory location requests.*/ DIR *dirp; /**Storage variable for return variable for usleep function call.*/ int ret_val_usleep; /**Directory entry pointer.*/ struct dirent *dp; printf("Server Process has begun processing the requests...\n"); /**Check for Failure in generation of backup process.*/ if(backup(max_restarts)==EXIT_SUCCESS) { printf("successfully executed...\n"); } /**If backup process cannot be created. The parent process takes control.(Graceful Degradation)*/ else { fprintf(stderr, "Error:Backup cannot be created.\nParent server process PID:%d taking control.\n",getpid()); } while(1) { /**Open the requests directory.*/ dirp = opendir("./requests"); /**Condition to check if the opendir function has failed or not.*/ if(dirp==NULL) { fprintf(stderr, "Error:Open Directory function failed.\n"); /**Process returns and terminates with error.*/ return EXIT_FAILURE; } while(dirp) { /**Storage variable to generate the absolute path for the request file name.*/ char request_name[100]="requests/"; /** Condition to check if the readdir function has reached end of the directory or not. It is a condition to detect even failures for the readdir function calls. readdir() returns the directory entry pointer to the next directory file inside the given directory location. */ if ((dp = readdir(dirp)) != NULL) { /** Check if the request file name contains req_ as the substring in the file name. And if the type of the file is Regular file or not. */ if ((strstr(dp->d_name,"req_")!=NULL)&&(dp->d_type == DT_REG)) { /**Generating the absolute path of the request file name.*/ if(strcat(request_name,dp->d_name)==NULL) { fprintf(stderr, "Error:String Concatenation function failed.\n"); return EXIT_FAILURE; } /** Performing readRequest Call with requesting file name and failure chance. Condition checks if the readRequest call failed or not. */ if(readRequest(request_name)==EXIT_FAILURE) { fprintf(stderr, "Error:readRequest function failed.\n"); return EXIT_FAILURE; } /** Performing removeRequest Call with requesting file name. Condition checks if the removeRequest call failed or not. */ if(removeRequest(request_name)==EXIT_FAILURE) { fprintf(stderr, "Error:removeRequest function failed.\n"); return EXIT_FAILURE; } /**Sleeping the process for 500ms.*/ ret_val_usleep = usleep(500000); /**Failure in usleep call*/ if(ret_val_usleep<0) { fprintf(stderr, "Error:Usleep function failed.\n"); /**Process returns and terminates with error*/ return EXIT_FAILURE; } } } else { /**Directory end reached.*/ break; } } /**Close the requests directory. Check if the close operation was successful or not.*/ if(closedir(dirp)<0) { fprintf(stderr, "Error:Usleep function failed.\n"); /**Process returns and terminates with error*/ return EXIT_FAILURE; } } /**Process returns and terminates with success.*/ return EXIT_SUCCESS; }
void OutgoingContactRequest::cancel() { removeRequest(); }