void Program::onTcpServerNewConnection() { QTcpSocket* socket = NULL; while ((socket = tcpServer_->nextPendingConnection()) != NULL) { QThread* thread = new HttpForwardJobThread(socket, contentTypePrefix_, transformCmd_, transformCmdArgs_); connect(thread, SIGNAL(finished()), this, SLOT(onThreadFinished())); thread->start(); } }
HPSThreadManager::HPSThreadManager(QObject *parent) : QObject(parent),mThreads(4+QThread::idealThreadCount()),mThreadsClosed(false) { QThread *t; for (int i = 0; i < mThreads.size(); ++i) { t = new QThread(); t->start(); connect(t,SIGNAL(finished()),this,SLOT(onThreadFinished())); mThreads[i] = t; } }
CRecieveTask_zakazrf_ru::~CRecieveTask_zakazrf_ru() { disconnect(m_signaller, SIGNAL(dataParsed(QUrl)), this, SLOT(removeData(QUrl))); delete m_signaller; for(int i=0; i<m_threads.count(); i++) { disconnect(m_threads.value(i), SIGNAL(dataReady(int/*,QByteArray*/)), this, SLOT(onDataReady(int/*,QByteArray*/))); disconnect(m_threads.value(i), SIGNAL(finished()), this, SLOT(onThreadFinished())); delete m_threads.value(i); } m_threads.clear(); m_activeDataStructures.clear(); QMultiMap<QUrl, CDataStructure*>::iterator dataStructuresIter; for(dataStructuresIter=m_dataStructures.begin(); dataStructuresIter!=m_dataStructures.end(); dataStructuresIter++) { delete dataStructuresIter.value(); } m_dataStructures.clear(); }
bool CRecieveTask_zakazrf_ru::run() { qDebug(); // m_signaller->onRecieveFinished(this); // return true; connect(m_signaller, SIGNAL(dataParsed(QUrl)), this, SLOT(removeData(QUrl))); #ifndef RUN_ALL_TASKS QUrl testUrl("http://zakazrf.ru/ViewReduction.aspx?id=4781"); CDataStructure* tmpdata = new CDataStructure(testUrl); tmpdata->setType(getUrlDataType(testUrl)); tmpdata->setRoot(); m_dataStructures.insert(testUrl, tmpdata); m_activeDataStructures.push_back(tmpdata); QUrl testUrl2("http://zakazrf.ru/ViewReduction.aspx?id=2943"); CDataStructure* tmpdata2 = new CDataStructure(testUrl2); tmpdata2->setType(getUrlDataType(testUrl2)); tmpdata2->setRoot(); m_dataStructures.insert(testUrl2, tmpdata2); m_activeDataStructures.push_back(tmpdata2); QUrl testUrl3("http://zakazrf.ru/ViewReduction.aspx?id=5319"); CDataStructure* tmpdata3 = new CDataStructure(testUrl3); tmpdata3->setType(getUrlDataType(testUrl3)); tmpdata3->setRoot(); m_dataStructures.insert(testUrl3, tmpdata3); m_activeDataStructures.push_back(tmpdata3); #else CDownloadManager_zakazrf_ru downloadManager; downloadManager.init(); QUrlList urls=downloadManager.getUrls(); if(urls.isEmpty()) { int min = getConfigurationValue("zakazrf/min_id",1).toUInt(); int max = getConfigurationValue("zakazrf/max_id",10000).toUInt(); if (max < min) { int tmp = max; max = min; min = tmp; } for(int i = min; i < max; i++) { QUrl testUrl(QString("http://zakazrf.ru/ViewReduction.aspx?id=%1").arg(i)); CDataStructure* tmpdata = new CDataStructure(testUrl); tmpdata->setType(getUrlDataType(testUrl)); tmpdata->setRoot(); m_dataStructures.insert(testUrl, tmpdata); m_activeDataStructures.push_back(tmpdata); } } else { for(int i=0; i<urls.count();i++) { CDataStructure* tmpdata = new CDataStructure(urls.at(i)); tmpdata->setType(getUrlDataType(urls.at(i))); tmpdata->setRoot(); m_dataStructures.insert(urls.at(i), tmpdata); m_activeDataStructures.push_back(tmpdata); } } #endif CDataStructure* data=NULL; QList<CDataStructure*>::iterator activeDataStructuresIter; for(activeDataStructuresIter = m_activeDataStructures.begin(); activeDataStructuresIter != m_activeDataStructures.end();) { if(m_threads.count()<(m_maxThreads+1)) { data=(*activeDataStructuresIter); CReciveThread *thread=new CReciveThread(data->url(), m_threadCounter++); thread->setDataStructure(data); m_threads.push_back(thread); connect(thread, SIGNAL(dataReady(int/*,QByteArray*/)), this, SLOT(onDataReady(int/*,QByteArray*/))); connect(thread, SIGNAL(finished()), this, SLOT(onThreadFinished())); thread->start(); activeDataStructuresIter=m_activeDataStructures.erase(activeDataStructuresIter); break; } break; }