NCBI C++ ToolKit
job_adapter.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: job_adapter.cpp 40279 2018-01-19 17:48:49Z katargir $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Roman Katargin
27 *
28 * File Description:
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 
35 
37 
41 
42 void CJobAdapter::Start(IAppJob& job)
43 {
44  x_CancelJob();
45  m_JobId = CAppJobDispatcher::GetInstance().StartJob(job, "ObjManagerEngine", *this, -1, true);
46 }
47 
49 {
50  m_Callback = 0;
51  x_CancelJob();
52 }
53 
55 {
59  }
60 }
61 
63 {
64  CAppJobNotification* notn = dynamic_cast<CAppJobNotification*>(evt);
65  _ASSERT(notn);
66  if (!notn) return;
67 
68  switch (notn->GetState()) {
69  case IAppJob::eCompleted :
71 
72  if (m_Callback) {
73  CRef<CObject> result = notn->GetResult();
74  m_Callback->OnJobResult(result.GetPointerOrNull(), *this);
75  return;
76  }
77  break;
78  case IAppJob::eFailed:
80 
81  if (m_Callback) {
83  string errMsg = error ? error->GetText() : string();
84  m_Callback->OnJobFailed(errMsg, *this);
85  return;
86  }
87  break;
88  case IAppJob::eCanceled:
90  break;
91  default:
92  break;
93  }
94 }
95 
CAppJobNotification Notification send by CAppJobEventTranslator.
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
IAppJob.
Definition: app_job.hpp:82
string
Definition: cgiapp.hpp:687
CConstIRef< IAppJobError > GetError() const
returns non-null pointer only if job Failed
static CAppJobDispatcher & GetInstance()
CRef< CObject > GetResult() const
returns non-null pointer only if Completed or Running and has temporary results available
CAppJobDispatcher::TJobID m_JobId
Definition: job_adapter.hpp:75
IJobCallback * m_Callback
Definition: job_adapter.hpp:74
void Cancel()
Definition: job_adapter.cpp:48
virtual void OnJobResult(CObject *result, CJobAdapter &adapter)=0
bool DeleteJob(TJobID job_id)
when a Job is deleted the listener is not notified
TJobID StartJob(IAppJob &job, const string &engine_name, IEngineParams *params=NULL)
Starts a Job on the specified engine in "passive mode" - no notifications or progress reports will be...
#define ON_EVENT(type, id, handler)
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
void x_CancelJob()
Definition: job_adapter.cpp:54
void x_OnJobNotification(CEvent *evt)
Definition: job_adapter.cpp:62
TJobState GetState() const
virtual void OnJobFailed(const string &errMsg, CJobAdapter &adapter)=0
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define _ASSERT
else result
Definition: token2.c:20
Modified on Sat Jul 13 13:38:54 2024 by modify_doxy.py rev. 669887