void ServiceRegistry::unregisterService(ServiceRef::Ptr pServiceRef) { if (pServiceRef) { unregisterService(pServiceRef->name()); } }
void ServiceDirectory::onSocketDisconnected(TransportSocketPtr socket, std::string error) { boost::recursive_mutex::scoped_lock lock(mutex); // clean from idxToSocket for (std::map<unsigned int, TransportSocketPtr>::iterator it = idxToSocket.begin(), iend = idxToSocket.end(); it != iend;) { std::map<unsigned int, TransportSocketPtr>::iterator next = it; ++next; if (it->second == socket) idxToSocket.erase(it); it = next; } // if services were connected behind the socket std::map<TransportSocketPtr, std::vector<unsigned int> >::iterator it; it = socketToIdx.find(socket); if (it == socketToIdx.end()) { return; } // Copy the vector, iterators will be invalidated. std::vector<unsigned int> ids = it->second; // Always start at the beginning since we erase elements on unregisterService // and mess up the iterator for (std::vector<unsigned int>::iterator it2 = ids.begin(); it2 != ids.end(); ++it2) { qiLogInfo() << "Service #" << *it2 << " disconnected"; try { unregisterService(*it2); } catch (std::runtime_error &) { qiLogWarning() << "Cannot unregister service #" << *it2; } } socketToIdx.erase(it); }
vvBonjourRegistrar::~vvBonjourRegistrar() { #ifdef HAVE_BONJOUR if (::serviceRef != NULL) { unregisterService(); } #endif }
void MprisPlayer::setServiceName(const QString &serviceName) { if (m_serviceName == serviceName) { return; } unregisterService(); m_serviceName = serviceName; registerService(); emit serviceNameChanged(); }
void ObjectRegistrar::close() { BoundServiceMap services; { boost::mutex::scoped_lock sl(_servicesMutex); services = _services; } for (BoundServiceMap::reverse_iterator iter = services.rbegin(); iter != services.rend(); ++iter) unregisterService(iter->first); Server::close(); }
void LinkLocalServiceBrowser::stop() { assert(isRunning()); if (isRegistered()) { unregisterService(); } for (ResolveQueryMap::const_iterator i = resolveQueries.begin(); i != resolveQueries.end(); ++i) { i->second->stop(); } resolveQueries.clear(); services.clear(); browseQuery->stopBrowsing(); browseQuery.reset(); onStopped(haveError); }
int main(int argc, char** argv) { PaymentGateService pg; ppg = &pg; try { if (!pg.init(argc, argv)) { return 0; //help message requested or so } Logging::LoggerRef(pg.getLogger(), "main")(Logging::INFO) << "walletd v" << PROJECT_VERSION_LONG; const auto& config = pg.getConfig(); if (config.gateConfiguration.generateNewContainer) { System::Dispatcher d; generateNewWallet(pg.getCurrency(), pg.getWalletConfig(), pg.getLogger(), d); return 0; } if (config.gateConfiguration.registerService) { return registerService(); } if (config.gateConfiguration.unregisterService) { return unregisterService(); } if (config.gateConfiguration.daemonize) { if (runDaemon() != 0) { throw std::runtime_error("Failed to start daemon"); } } else { pg.run(); } } catch (PaymentService::ConfigurationError& ex) { std::cerr << "Configuration error: " << ex.what() << std::endl; return 1; } catch (std::exception& ex) { std::cerr << "Fatal error: " << ex.what() << std::endl; return 1; } return 0; }
Controller::Controller() : _deviceNeedResolve(0), _lastTimeFocused(0), _service(&_udpDiscovery, this), _udpDiscoveryTimer(this) { _service.moveToThread(&_serviceThread); _serviceThread.start(); _view = new View(&_model); _bonjourBrowser = new BonjourServiceBrowser(this); connect(&_udpDiscovery, SIGNAL(devicesFound(const QList<Device *> &)), this, SLOT(updateDevices(const QList<Device *> &))); connect(&_udpDiscovery, SIGNAL(pongReceived(const QString&)), this, SLOT(onPong(const QString &))); connect(_bonjourBrowser, SIGNAL(currentBonjourRecordsChanged(const QList<BonjourRecord> &)), this, SLOT(updateRecords(const QList<BonjourRecord> &))); connect(_bonjourBrowser, SIGNAL(error(DNSServiceErrorType)), this, SLOT(error(DNSServiceErrorType))); connect(_view, SIGNAL(sendFile(const QString&, const QList<QUrl>&, DataType)), this, SLOT(onSendFile(const QString&, const QList<QUrl>&, DataType))); connect(_view, SIGNAL(sendText(const QString&, const QString&, DataType)), this, SLOT(onSendText(const QString&, const QString&, DataType))); connect(_view, SIGNAL(cancelTransfert(const QString&)), this, SLOT(onCancelTransfert(const QString&))); connect(_view, SIGNAL(focused()), this, SLOT(onWindowFocused())); connect(_view, SIGNAL(forceRefresh()), this, SLOT(onForceRefresh())); connect(_view, SIGNAL(registerService()), &_service, SLOT(serviceRegister())); connect(_view, SIGNAL(unregisterService()), &_service, SLOT(serviceUnregister())); connect(_view, SIGNAL(deleteFromHistory(int)), &_service, SLOT(onDeleteFromHistory(int))); connect(_view, SIGNAL(clearHistoryTriggered()), &_service, SLOT(onClearHistory())); connect(_view, SIGNAL(serviceNameChanged()), &_service, SLOT(onTimerOut())); connect(_view, SIGNAL(cancelIncomingTransfert()), &_service, SLOT(deleteFileReset())); connect(&_service, SIGNAL(historyChanged(const QList<HistoryElement>&)), _view, SLOT(onHistoryChanged(const QList<HistoryElement>&))); connect(&_service, SIGNAL(historyElementProgressUpdated(unsigned)), _view, SLOT(historyElementProgressUpdated(unsigned))); connect(&_service, SIGNAL(serviceError(ServiceErrorState,bool)), _view, SLOT(onServiceError(ServiceErrorState,bool))); connect(&_service, SIGNAL(receivingFile(const QString&,int)), _view, SLOT(onReceivingFile(const QString&,int))); connect(&_service, SIGNAL(receivingFolder(const QString&,int)), _view, SLOT(onReceivingFolder(const QString&,int))); connect(&_service, SIGNAL(receivingText(const QString&)), _view, SLOT(onReceivingText(const QString&))); connect(&_service, SIGNAL(receivingUrl(const QString&)), _view, SLOT(onReceivingUrl(const QString&))); connect(&_model, SIGNAL(newDeviceCreated(Device*)), this, SLOT(onNewDeviceCreated(Device*))); connect(&_model, SIGNAL(deviceRemoved()), _view, SLOT(updateDevices())); connect(&_updater, SIGNAL(updateNeeded(const QString&,const QString&)), _view, SLOT(onUpdateNeeded(const QString&,const QString&))); checkForBonjourState(); _view->updateDevices(); _view->onHistoryChanged(_service.getHistory()); _bonjourBrowser->browseForServiceType(QLatin1String("_fdnd._tcp.")); connect(&_udpDiscoveryTimer, SIGNAL(timeout()), &_udpDiscovery, SLOT(startDiscovery())); _udpDiscoveryTimer.start(UDP_DISCOVERY_INTERVAL); _udpDiscovery.startDiscovery(); createSendTo(); }
MprisPlayer::~MprisPlayer() { unregisterService(); }