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

Go to the SVN repository for this file.

1 /* $Id: edit_job.cpp 30185 2014-04-11 19:13:34Z 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: Colleen Bollin, based on a file by Andrey Yazhuk
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
33 
35 
40 
41 #include <objects/general/Date.hpp>
42 
43 #include <corelib/ncbi_system.hpp>
44 
45 #include <wx/dirdlg.h>
46 
49 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// CDataLoadingAppJob
54 : m_Service(service)
55 {
56 }
57 
58 
60 {
61 }
62 
63 
65 {
66  return m_Service.GetPointer();
67 }
68 
69 
71 {
72  static const char* kLogMsg = "CEditAppJob::Run() - exception in x_Run() ";
73 
74  //LOG_POST("CEditAppJob::Run() Started " << m_Descr);
75 
76  x_ResetState(); // reset state before execution
77 
78  string err_msg;
79  try {
80  x_Run();
81  }
82  catch (CException& e) {
83  err_msg = kLogMsg + GetDescr() + ". " + e.GetMsg();
84  LOG_POST(Error << err_msg);
85  LOG_POST(Error << e.ReportAll());
86  } catch (std::exception& ee) {
87  err_msg = kLogMsg + GetDescr() + ". " + ee.what();
88  LOG_POST(Error << err_msg);
89  }
90 
92 
93  if(err_msg.empty()) {
94  LOG_POST(Info << "CEditAppJob::Run() Finished " << m_Descr);
95  return eCompleted;
96  } else {
97  m_Error.Reset(new CAppJobError(err_msg));
98  return eFailed;
99  }
100 }
101 
102 
104 {
105  CFastMutexGuard lock(m_Mutex);
106 
108  m_Error.Reset();
109 
110  m_Status = "Starting...";
111 }
112 
113 
115 {
116 
117  x_MakeChanges ();
118 
119 }
120 
121 
123 {
124  CRef<CObject> res;
125  CFastMutexGuard lock(m_Mutex);
126  if( ! m_TextResult.empty()) {
128  }
129  return res;
130 }
131 
132 
133 ///////////////////////////////////////////////////////////////////////////////
134 /// CEditAppTask
135 
136 CEditAppTask::CEditAppTask(CEditAppJob& job, const string& descr)
137 : CAppJobTask(job, true, descr)
138 {
139  if(descr == kEmptyStr) {
140  m_Descr = job.GetDescr();
141  }
142 }
143 
144 
146 {
148 
149  if(state == eCompleted) {
150  IAppJob* job = GetJob().GetPointer();
151  CEditAppJob* data_job = dynamic_cast<CEditAppJob*>(job);
152  _ASSERT(data_job);
153  }
154  return state;
155 }
156 
157 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define true
Definition: bool.h:35
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
CAppJobTextResult Default implementation for result object - encapsulates a text error message.
string m_Descr
task description
CEditAppJob - a base class for Jobs modifying existing data in projects.
Definition: edit_job.hpp:59
virtual void x_ResetState()
prepares job for execution by clearing state variables
Definition: edit_job.cpp:103
CProjectService * GetProjectService()
Definition: edit_job.cpp:64
string m_TextResult
Definition: edit_job.hpp:90
virtual ~CEditAppJob()
Definition: edit_job.cpp:59
virtual CRef< CObject > GetResult()
Returns the Job Result.
Definition: edit_job.cpp:122
virtual void x_MakeChanges()=0
override this function in derived classes, populate m_TextResult
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
Definition: edit_job.cpp:70
CIRef< CProjectService > m_Service
Definition: edit_job.hpp:88
CEditAppJob(CProjectService *service)
constructor for derived classes
Definition: edit_job.cpp:53
virtual void x_Run()
Definition: edit_job.cpp:114
CEditAppTask(CEditAppJob &job, const string &descr=kEmptyStr)
CEditAppTask.
Definition: edit_job.cpp:136
virtual ETaskState Run()
we override this function because our logic is a bit more complex than one implemented in CAppJobTask...
Definition: edit_job.cpp:145
CProjectService - a service providing API for operations with Workspaces and Projects.
IAppJob.
Definition: app_job.hpp:82
USING_SCOPE(objects)
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
CIRef< IAppJob > GetJob()
ETaskState
List of task states defining the task management FSM.
Definition: app_task.hpp:87
virtual ETaskState Run()
execute the task, this function is called on the main UI thread if a task needs to execute in backgro...
@ eCompleted
successfully finished
Definition: app_task.hpp:92
CRef< CAppJobError > m_Error
string m_Descr
mutex to sync our internals
CFastMutex m_Mutex
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
string m_Status
Current status of the Job.
virtual string GetDescr() const override
Returns a human readable description of the Job (optional)
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 kEmptyStr
Definition: ncbistr.hpp:123
#define _ASSERT
Modified on Tue Nov 28 02:26:58 2023 by modify_doxy.py rev. 669887