| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #include "AsyncTask.h"
- #include "core/oxygine.h"
- #include <typeinfo>
- namespace oxygine
- {
- AsyncTask::AsyncTask() : _status(status_not_started), _mainThreadSync(false)
- {
- }
- AsyncTask::~AsyncTask()
- {
- }
- void AsyncTask::run()
- {
- _prerun();
- log::messageln("AsyncTask::run %d - %s", getObjectID(), typeid(*this).name());
- OX_ASSERT(_status == status_not_started);
- _status = status_inprogress;
- sync([ = ]()
- {
- _run();
- });
- }
- void AsyncTask::_complete()
- {
- log::messageln("AsyncTask::_complete %d - %s", getObjectID(), typeid(*this).name());
- _status = status_completed;
- _onFinal(false);
- _finalize(false);
- _onComplete();
- _dispatchComplete();
- }
- void AsyncTask::_dispatchComplete()
- {
- AsyncTaskEvent ev(COMPLETE, this);
- dispatchEvent(&ev);
- }
- void AsyncTask::_error()
- {
- log::messageln("AsyncTask::_error %d - %s", getObjectID(), typeid(*this).name());
- _status = status_failed;
- _onFinal(true);
- _finalize(true);
- _onError();
- AsyncTaskEvent ev(ERROR, this);
- dispatchEvent(&ev);
- }
- void AsyncTask::onComplete()
- {
- sync([ = ]()
- {
- _complete();
- });
- }
- void AsyncTask::onError()
- {
- sync([ = ]()
- {
- _error();
- });
- }
- }
|