FAIF - Active Object

The active object design pattern gives the possibility to run the commands synchronously or asynchronously, it use the thread pool (from boost::thread) and command queue.

Fast start

The user command must define operator()
#include <faif/utils/actobj/Command.h>

using namespace faif;

struct DummyCmd : public Command {

    DummyCmd() {}
    virtual ~DummyCmd() {}

    virtual void operator()(Progress& progress) {

            progress.setProgress(0.5); //send the message about the progress

    }

};
The command should be executed asynchronously (in another thread, the calling thread will not wait for finish):
#include <faif/utils/actobj/Scheduler.h>

using namespace faif;

Scheduler& scheduler = Scheduler::getInstance();
PCommand cmd(new DummyCmd );
scheduler.executeAsynchronously( cmd );
or synchronously (the calling thread is waiting for finish or break the command)
scheduler.executeSynchronously( cmd );

return to the main page