📄 evapicmanager.cpp
字号:
if(currentIndex == -1) doRequestStart(); else doSendFileInfo(); } break; case QQ_REQUEST_AGENT_REPLY_REDIRECT: printf("EvaPicManager::processRequestAgentReply -- redirect\n"); initConnection(packet->getRedirectIP(), packet->getRedirectPort()); break; case QQ_REQUEST_AGENT_REPLY_TOO_LONG: default: clearManager(); std::string str = packet->getMessage(); printf("EvaPicManager::processRequestAgentReply -- agent error:%s\n", packet->getMessage().c_str()); emit sendErrorMessage(qunID, codec->toUnicode(str.c_str())); break; } delete packet;}// We are not interested in this, so just ignore it :)void EvaPicManager::processRequestFaceReply(const EvaPicInPacket * /*in*/){ //printf("EvaPicManager::processRequestFaceReply -- got request face reply\n");}void EvaPicManager::processTransferReply(const EvaPicInPacket *in){ EvaPicTransferReplyPacket *packet = new EvaPicTransferReplyPacket(in->getRawBody(), in->getRawBodyLength()); packet->parse(); if(packet->getLength() == 0) { fprintf(stderr, "EvaPicManager::processTransferReply -- bodyLength is Zero!!!\n"); delete packet; return; } if(packet->getData()){ if(!isSend){ if(currentFile.lastPacketSeq!=0xffff && currentFile.lastPacketSeq >= packet->getSequence()){ delete packet; return; } if(!currentFile.buf){ delete packet; doRequestNextPic(); return; } currentFile.lastPacketSeq = packet->getSequence(); memcpy(currentFile.buf + currentFile.offset, packet->getData(), packet->getDataLength()); currentFile.offset += packet->getDataLength(); if(currentFile.offset >= currentFile.length){ doSaveFile(); doRequestNextPic(); delete packet; return; } doRequestData(currentPic, true); } else { doSendNextFragment(); } } else{ currentFile.filename = codec->toUnicode(packet->getFileName().c_str()); currentFile.length = packet->getImageLength(); currentFile.buf = new unsigned char [ currentFile.length ]; memset(currentFile.buf, 0, currentFile.length); currentFile.offset = 0; currentFile.lastPacketSeq = 0xffff; doRequestData(currentPic, false); } delete packet;}void EvaPicManager::processRequestStartReply(const EvaPicInPacket *in){ EvaRequestStartReplyPacket *packet = new EvaRequestStartReplyPacket(in->getRawBody(), in->getRawBodyLength()); packet->parse(); if(sessionID != packet->getSessionID()){ delete packet; return; } if(isSend){ currentIndex++;// now we start doSendFileInfo(); } delete packet;}void EvaPicManager::doRequestNextPic(){ currentIndex++; if(currentIndex >= (int)picList.size()){ picList.clear(); doProcessEvent(); return; } currentFile.offset = 0; if(currentFile.buf) delete currentFile.buf; currentFile.buf = NULL; currentFile.lastPacketSeq = 0xffff; int index = 0; std::list<CustomizedPic>::iterator iter; for(iter = picList.begin(); iter!=picList.end(); ++iter){ if(index == currentIndex){ break; } index++; } if(iter != picList.end()){ currentPic = *iter; doRequestPic(currentPic); }}void EvaPicManager::doSaveFile(){ QString fileName = user->getSetting()->getPictureCacheDir() + "/" + currentFile.filename; QFile file(fileName); if(!file.open(IO_WriteOnly | IO_Raw )){ printf("EvaPicManager::doSaveFile -- cannot open file \'%s\'!\n", fileName.ascii()); return; } QDataStream stream(&file); stream.writeRawBytes((char *)currentFile.buf, currentFile.offset); file.close(); if(currentFile.buf) delete currentFile.buf; currentFile.buf = NULL; currentFile.offset = 0; currentFile.lastPacketSeq = 0xffff; emit pictureReady(qunID, fileName, currentPic.tmpFileName);}void EvaPicManager::doRequestAgent(){ EvaRequestAgentPacket *packet = new EvaRequestAgentPacket(Packet::getFileAgentToken(), Packet::getFileAgentTokenLength()); packet->setQunID(qunID); packet->setMd5(currentOutPic.md5); packet->setImageLength(currentOutPic.imageLength); packet->setFileName(std::string((codec->fromUnicode(currentOutPic.fileName)).data())); expectedSequence = packet->getSequence(); append(packet);}void EvaPicManager::doRequestStart( ){ EvaRequestStartPacket *packet = new EvaRequestStartPacket(); packet->setSessionID(sessionID); packet->setMd5(currentOutPic.md5); append(packet);}void EvaPicManager::doSendFileInfo( ){ currentFile.filename = currentOutPic.fileName.right(currentOutPic.fileName.length() - currentOutPic.fileName.findRev("/") -1); currentFile.length = currentOutPic.imageLength; currentFile.offset = 0; currentFile.buf = new unsigned char[currentFile.length]; QFile file(currentOutPic.fileName); if(!file.open(IO_ReadOnly | IO_Raw )){ printf("EvaPicManager::doSendFileInfo -- cannot open file \'%s\' !\n", currentOutPic.fileName.ascii()); return; } QDataStream stream(&file); stream.readRawBytes((char *)currentFile.buf, currentFile.length); file.close(); EvaPicTransferPacket *packet = new EvaPicTransferPacket(false, false); packet->setSessionID(sessionID); packet->setMd5(currentOutPic.md5); packet->setImageLength(currentFile.length); packet->setFileName(std::string((codec->fromUnicode(currentFile.filename)).data())); expectedSequence = packet->getSequence(); append(packet);}void EvaPicManager::doProcessOutEvent( ){ if(!sendList.size()) { isBusy = false; if(downloadList.size()) doProcessEvent(); return; } isBusy = true; isSend = true; OutSession session = sendList.front(); sendList.pop_front(); qunID = session.qunID; outList = session.list; if(!outList.size()){ isBusy = false; doProcessOutEvent( ); return; } currentIndex = -1; if(!Packet::getFileAgentKey()) { clearManager(); return; } EvaPicPacket::setFileAgentKey(Packet::getFileAgentKey()); currentOutPic = *(outList.begin()); initConnection(-1, 443);}void EvaPicManager::doSendNextFragment(){ if(currentFile.length <= currentFile.offset){ currentIndex++; if(currentIndex >= (int)(outList.size())){ doProcessOutEvent(); return; } currentFile.offset = 0; if(currentFile.buf) delete currentFile.buf; currentFile.buf = NULL; int index = 0; std::list<OutCustomizedPic>::iterator iter; for(iter = outList.begin(); iter!=outList.end(); ++iter){ if(index == currentIndex){ break; } index++; } if(iter != outList.end()){ currentOutPic = *iter; doSendFileInfo(); } } for(int i=0; i<10; i++){ bool isLast = ( (currentFile.length - currentFile.offset) <= 1024 ); unsigned int len = isLast?((currentFile.length - currentFile.offset)):1024; EvaPicTransferPacket *packet = new EvaPicTransferPacket(true, isLast); packet->setSessionID(sessionID); packet->setFragment(currentFile.buf + currentFile.offset, len); currentFile.offset += len; append(packet); if(isLast) { if((currentIndex+1) == (int)(outList.size())){ outList.clear(); emit pictureSent(qunID, sessionID, sendIP, sendPort); return; } break; } }}void EvaPicManager::clearManager(){ outPool.clear(); outList.clear(); currentIndex = -1; bufLength = 0; isSend = false; isBusy = false; if(connecter){ connecter->close(); delete connecter; connecter = NULL; }}void EvaPicManager::removePacket( const int hashCode ){ isRemoving = true; QMutex mutex; mutex.lock(); EvaPicOutPacket *packet; for(packet=outPool.first(); packet; packet = outPool.next()){ if(packet->hashCode() == hashCode) outPool.remove(); } mutex.unlock(); isRemoving = false;}void EvaPicManager::packetMonitor( ){ if(isAppending || isRemoving ) return; for ( uint i=0; i < outPool.count(); i++ ){ if(outPool.at(i)->needResend()){ sendPacket(outPool.at(i)); }else{ removePacket(outPool.at(i)->hashCode()); isBusy = false; fprintf(stderr, "EvaPicManager::packetMonitor -- time out\n"); return; } if(isAppending || isRemoving ) break; }}void EvaPicManager::stop( ){ if(timer->isActive()) timer->stop(); clearManager();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -