1 #ifndef GUI_OBJUTILS___JOB_FUTURE__HPP
2 #define GUI_OBJUTILS___JOB_FUTURE__HPP
125 bool IsRunning()
const;
128 void x_OnJobNotification(
CEvent* evt);
144 std::rethrow_exception(m_Exception);
149 virtual string GetText()
const {
return ""; };
167 m_State = rhs.m_State;
168 m_Canceled = rhs.m_Canceled;
169 m_Result = std::move(rhs.m_Result);
170 m_Error = std::move(rhs.m_Error);
171 m_JobAdapter = std::move(rhs.m_JobAdapter);
174 m_JobAdapter->SetCallback(
this);
177 rhs.m_Canceled =
false;
187 m_State = rhs.m_State;
188 m_Canceled = rhs.m_Canceled;
189 m_Result = std::move(rhs.m_Result);
190 m_Error = std::move(rhs.m_Error);
191 m_JobAdapter = std::move(rhs.m_JobAdapter);
194 m_JobAdapter->SetCallback(
this);
197 rhs.m_Canceled =
false;
204 bool IsRunning()
const {
return m_JobAdapter ? m_JobAdapter->IsRunning() :
false; }
213 m_JobAdapter->Cancel();
220 virtual void OnJobCanceled();
234 bool m_Canceled =
false;
288 m_Canceled =
result->GetCanceled();
291 throw std::runtime_error(m_BadJobResponse);
359 template<
class _Fty,
typename _Rty>
366 result.SetData() = m_Farg(*x_GetICanceled());
368 catch (
const std::exception&) {
406 catch (
const std::exception&) {
432 return typename tr::future(*job);
466 template<
class _Fty,
typename _Rty>
478 if (
future.IsComplete()) {
492 template<
class _Fty,
class _Fty2>
497 async_job_type* job =
new async_job_type(_Fnarg2,
job_async(_Fnarg, descr));
CEvent - generic event implementation TODO TODO - Attachments.
Base class to build jobs with cancel functionality.
virtual void OnJobResult(CObject *result)=0
virtual void OnJobCanceled()=0
virtual void OnJobFailed(const IAppJobError *error)=0
Here is set of classes to implement launching jobs (to execute code on a worker thread using C++ Tool...
IJobCallback * m_Callback
CAppJobDispatcher::TJobID m_JobId
void SetCallback(IJobCallback *callback)
std::exception_ptr m_Exception
virtual string GetText() const
returns a string describing the error
virtual bool IsUserLevel() const
CJobFutureError(const std::exception_ptr &ex)
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
CJobFutureJobBase(const string &descr)
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
virtual CRef< CObject > GetResult()
Returns the Job Result.
CConstRef< CJobFutureError > m_Error
virtual string x_GetJobName() const
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
CJobFutureJob(const _Fty &_Fnarg, const string &descr)
CJobFutureResultRet< _Rty > TResult
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
CJobFutureJob(const _Fty &_Fnarg, const string &descr)
list< async_job * > m_Jobs
void AddJob(async_job *job)
static CJobHandler & Instance()
void x_RemoveJob(async_job *job)
async_job_impl(const _Fty &_Fnres, job_future< _Rty > &&_future)
job_future< _Rty > future
virtual bool complete()=0
virtual bool canceled()=0
job_future & operator=(job_future &&rhs)
job_future(job_future &&rhs)
virtual ~job_future_base()
job_future_base & operator=(job_future_base const &)=delete
CRef< CJobFutureAdapter > m_JobAdapter
CConstRef< CJobFutureError > m_Error
job_future_base(job_future_base const &)=delete
job_future_base(job_future_base &&rhs)
job_future_base & operator=(job_future_base &&rhs)
static const char * m_BadJobResponse
job_future_base
job_future(job_future &&rhs)
job_future & operator=(job_future &&rhs)
ICanceled * x_GetICanceled()
virtual bool IsCanceled() const override
EJobState
Job states (describe FSM)
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
void Reset(void)
Reset reference object.
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
virtual void Process(SOCK sock)=0
Runs asynchronously (from a separate thread) for each request.
#define NCBI_GUIUTILS_EXPORT
Defines to provide correct exporting from DLLs in Windows.
job_function_traits< _Fty >::future job_async(const _Fty &_Fnarg, const string &descr)
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CJobFutureJob< _Fty, result > job
job_future< result > future
std::invoke_result< _Fty, ICanceled & >::type result