void pimpl<PortalsImporterJob>::run() { m_result.reset(); m_status = String::EMPTY; if(m_stream != nullptr) { shared_ptr<Portal> portal = m_portal.lock(); if(portal == nullptr || m_stream == nullptr) return; m_status = "importing"; m_serializer->setStopped(false); m_result = m_serializer->importStream(portal, m_stream); m_stream->close(); m_stream.reset(); } else { m_status = "download"; shared_ptr<boost::asio::io_service> service = createAsioService(); shared_ptr<TCPSocket> socket = Engine::instance()->createTCPSocket(service, true, true); shared_ptr<HttpClient> httpClient(OS_NEW HttpClient(service, socket)); HttpUrl url(m_url.to_ascii()); bool result = httpClient->perform(url); if(result) { shared_ptr<HttpResponse> response = httpClient->getResponse(); //shared_ptr<HttpContent> responseContent = response->getContent(); if(response->getStatusCode() == 200) { m_status = "importing"; shared_ptr<MemFile> content(OS_NEW MemFile(response->getContent()->getContentPtr())); shared_ptr<Portal> portal = m_portal.lock(); if(portal == nullptr) return; m_serializer->setStopped(false); m_result = m_serializer->importStream(portal, content); } m_status = "completed"; } else { m_status = "failed"; } } //Engine::instance()->addBackgroundJob(shared_ptr<PortalsOptimizerJob>(OS_NEW PortalsOptimizerJob(Engine::instance()->peekBackgroundJobID(), portal))); }
NetworkService::NetworkService(boost::optional<uint32> workerThreadsCount) { if(workerThreadsCount) m_impl->workerThreadsCount = workerThreadsCount.get(); else m_impl->workerThreadsCount = PlatformManager::instance()->getOptimalHardwareConcurrency(); m_impl->service = createAsioService(); m_impl->connectionsManager.reset(OS_NEW ConnectionsManager(m_impl->service)); m_impl->connectionsManager->addListener(boost::bind(&NetworkService::connectionsCallback, this, _1, _2)); }