MFC Grid manual

Task-oriented threading model

// MyAutomat.h file
class CMyAutomat : public Dapfor::Common::CAutomat
{
public:
    CMyAutomat(const std::string& name);
};

// MyAutomat.cpp file
CMyAutomat::CMyAutomat(const std::string& name) : CAutomat(name)
{
}



// PrintJob.h file

//The job that will be processed in the automat's thread.
class CPrintJob : public Dapfor::Common::CJob
{
public:
    CPrintJob(int count);

protected:
    virtual void ProcessJob(Dapfor::Common::CAutomat* automat);

private:
    int m_Count;
};



// PrintJob.cpp file
CPrintJob::CPrintJob(int count) : m_Count(count)
{
}

void CPrintJob::ProcessJob(Dapfor::Common::CAutomat* automat)
{
    //Do some work...
    for(int i = 0; i < m_Count; ++i)
    {
        std::cout << automat->GetThreadName() << ": value = " << i << std::endl;
        Sleep(100);
    }
}



//Using sample

  ...

    //Create the automat
    CMyAutomat automat("Automat");

    //Start the automat
    automat.Start();

    //Create and push a new job and push it to the automat.
    //Job object will be destroyed upon processing.
    automat.PushJob(new CPrintJob(10));

    //Wait for job processed in the automat
    Sleep(2000);

    //Stop the automat
    automat.Stop();
    automat.Wait();