| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "packinfoseed2server.h"
- #include <QTimer>
- PackInfoSeed2Server::PackInfoSeed2Server(PackInfoManger * manger, QObject *parent, bool autoSync) : QObject(parent),
- _manger(manger),_autoSync(autoSync)
- {
- connect(&_requst,&HttpRequest::request,this,&PackInfoSeed2Server::_requst);
- _failedCount = 0;
- }
- void PackInfoSeed2Server::send(QSharedPointer<PackInfo> & info)
- {
- if(_manger == nullptr) return;
- _queue.append(info);
- QTimer::singleShot(20,this,&PackInfoSeed2Server::doSend);
- }
- void PackInfoSeed2Server::doSend()
- {
- if(_current.isNull() && !_queue.isEmpty()){
- _current = _queue.first();
- // TODO:小宋, 发送 _current 到服务器
- }
- }
- void PackInfoSeed2Server::result(int code, const QJsonObject & body)
- {
- if(code != 200 || body.isEmpty()){
- _current.clear();
- QTimer::singleShot(500,this,&PackInfoSeed2Server::doSend);
- _failedCount ++;
- return;
- }
- auto error = body.value("code").toInt();
- if(error == 200){
- _queue.dequeue();
- _manger->setPackInfoSync(_current->codeSingle(),_current->time(),_autoSync);
- _current.clear();
- QTimer::singleShot(20,this,&PackInfoSeed2Server::doSend);
- _failedCount = 0;
- } else {
- // TODO: 判断错误,根据错误去处理下一步,例如重复了,就next的
- }
- }
|