#include "stallsgetwork.h"
#include "event/fmapplication.h"
#include "event/posevent.h"
#include "QsLog.h"

StallsGetWork::StallsGetWork(WorkObject *parent) : WorkObject(parent)
{
    FMApplication::subscibeEvent(this, PosEvent::s_token_change);
}

StallsGetWork::~StallsGetWork()
{
    qDebug() << "";
    while(!_stoped)
    {
        _stopflag = true;
        emit quit();
        EVENTWAIT(10);
    }
}

bool StallsGetWork::event(QEvent *e)
{
    if(e->type() == PosEvent::s_token_change)
    {
        QString token;

        GETEVENTINFO(token, e, QString);

        QLOG_DEBUG() << "StallsGetWork::event::PosEvent::s_token_chang:" << token;

        _token = token;

        emit quit();

        return true;
    }

    return WorkObject::event(e);
}

void StallsGetWork::workstart()
{
    if(_token.isEmpty())
    {
        QEventLoop loop;
        connect(this, &StallsGetWork::quit, &loop, &QEventLoop::quit);
        loop.exec();
    }

    while(_stopflag)
    {
        //获取档口信息

        //获取档口信息完成后检擦是否退出表示
        if(_stopflag)
            break;

        QEventLoop loop;
        connect(this, &StallsGetWork::quit, &loop, &QEventLoop::quit);
        loop.exec();
    }
}

