NCBI C++ ToolKit
loading_app_job.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_CORE_DEMO___LOADING_APP_JOB__HPP
2 #define GUI_CORE_DEMO___LOADING_APP_JOB__HPP
3 
4 /* $Id: loading_app_job.hpp 45881 2021-01-05 03:10:02Z rudnev $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk, Liangshou Wu
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 #include <corelib/ncbimtx.hpp>
37 
40 
42 
44 
46 
47 #include <objmgr/scope.hpp>
48 
49 #include <wx/string.h>
50 
51 #include <mutex>
52 
53 
55 
56 
58 {
59 public:
61  CDataLoadingAppJobProgress(const TData& data, float done, const string& text);
62 
63  const TData& GetData() const { return m_Data; }
64 private:
66 };
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 /// CDataLoadingAppJob - a base class for Jobs loading data into projects.
70 
72 {
73 public:
74  /// constructor for derived classes
76  virtual ~CDataLoadingAppJob();
77 
78  /// @name IAppJob implementation
79  /// @{
80  virtual EJobState Run();
81  virtual CRef<CObject> GetResult();
82  virtual CConstIRef<IAppJobProgress> GetProgress();
83  /// @}
84 
85  const CSelectProjectOptions::TData& GetData() const { return m_Data; }
86  const objects::CScope& GetScope() const { _ASSERT(m_Scope); return *m_Scope; }
87 
88  virtual void GetHTMLResults( wxString& /*title*/, wxString& /*html*/ ) {}
89 
90  void AddProjectItem(objects::CProjectItem& item);
91  void AddProjectItem(objects::CProjectItem& item, objects::CLoaderDescriptor& loader);
92  void AddDataLoader(objects::CLoaderDescriptor& loader);
93  void ClearItems();
94 
95 protected:
96 
97  /// prepares job for execution by clearing state variables
98  virtual void x_ResetState();
99 
100  virtual void x_Run();
101 
102  /// override this function in derived classes and populate m_Items.
103  /// If data loaders are needed, they should be created here too.
104  virtual void x_CreateProjectItems() = 0;
105 
106  void x_SetTextResult( const string& result );
107 
108 protected:
109  string m_TextResult;
110 
112 
113 private:
115  std::mutex m_DataMutex;
116 };
117 
118 ///////////////////////////////////////////////////////////////////////////////
119 /// CDataLoadingAppTask - a task that executes CDataLoadingAppJob.
121 {
122 public:
123  CDataLoadingAppTask(CProjectService* service, CSelectProjectOptions& options, CDataLoadingAppJob& job, const string& descr = kEmptyStr);
124 
125  /// @name IAppTask interface implementation
126  /// @{
127 
128  /// we override this function because our logic is a bit more complex than
129  /// one implemented in CAppJobTask::Run() - under some circumstances
130  /// we may need to show a dialog and then relaunch the job.
131  virtual ETaskState Run();
132  /// @}
133 
134  void SetOptions(const CSelectProjectOptions& options) { m_Options = options; }
135 
136 protected:
137  void x_OnAppJobProgress(const IAppJobProgress& progress);
138 
139 protected:
142 };
143 
145 
146 
147 #endif
148 // GUI_CORE_DEMO___LOADING_APP_JOB__HPP
static CRef< CScope > m_Scope
User-defined methods of the data storage class.
CAppJobProgress Default implementation for IAppJobProgress - the class encapsulates a text message an...
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
CAppJob - default implementation of IAppJob that could be used as a base class.
const TData & GetData() const
CDataLoadingAppJob - a base class for Jobs loading data into projects.
void AddProjectItem(objects::CProjectItem &item)
void AddProjectItem(objects::CProjectItem &item, objects::CLoaderDescriptor &loader)
CRef< objects::CScope > m_Scope
virtual void x_CreateProjectItems()=0
override this function in derived classes and populate m_Items.
CSelectProjectOptions::TData m_Data
const objects::CScope & GetScope() const
virtual void GetHTMLResults(wxString &, wxString &)
const CSelectProjectOptions::TData & GetData() const
CDataLoadingAppTask - a task that executes CDataLoadingAppJob.
CIRef< CProjectService > m_Service
CSelectProjectOptions m_Options
void SetOptions(const CSelectProjectOptions &options)
CProjectService - a service providing API for operations with Workspaces and Projects.
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
map< TLoaderRef, TItems > TData
IAppJobProgress.
Definition: app_job.hpp:50
char data[12]
Definition: iconv.c:80
ETaskState
List of task states defining the task management FSM.
Definition: app_task.hpp:87
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
#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
void Run(void)
Enter the main loop.
#define NCBI_GUICORE_EXPORT
Definition: gui_export.h:508
static void text(MDB_val *v)
Definition: mdb_dump.c:62
Multi-threading – mutexes; rw-locks; semaphore.
The NCBI C++/STL use hints.
#define _ASSERT
done
Definition: token1.c:1
else result
Definition: token2.c:20
Modified on Wed Apr 17 13:09:50 2024 by modify_doxy.py rev. 669887