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

Go to the SVN repository for this file.

1 #ifndef GUI_SERVICES___SEARCH_TOOL_BASE_HPP
2 #define GUI_SERVICES___SEARCH_TOOL_BASE_HPP
3 
4 /* $Id: search_tool_base.hpp 47029 2022-05-16 18:09:35Z asztalos $
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
30  *
31  * File Description:
32  *
33  */
34 
36 
37 #include <gui/utils/app_job.hpp>
39 #include <gui/utils/extension.hpp>
40 
42 
43 
45 
46 class IDMSearchForm;
47 class CAppJobDispatcher;
48 class CSearchJobBase;
49 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// CSearchToolBase
53 
55  public CObjectEx,
56  public IExtension,
57  public CEventHandler,
58  public IDMSearchTool
59 {
61 public:
62  enum EPatternType {
66  eNamed
67  };
68 
70  virtual ~CSearchToolBase();
71 
72  /// @name IUITool interface
73  /// @{
74  virtual IUITool* Clone() const = 0;
75  virtual string GetName() const = 0;
76  virtual string GetDescription() const = 0;
77  /// @}
78 
79  /// @name IDMSearchTool implementation
80  /// @{
83  virtual bool StartSearch(IDMSearchQuery& query, IDMSearchFormController& listener);
84  virtual bool CancelSearch(IDMSearchFormController& listener);
85  virtual bool PullSearch(IDMSearchQuery& query, IDMSearchFormController& listener);
86  virtual string GetJobDescr(IDMSearchFormController& form);
87  /// @}
88 
89  /// CAppJobDispatcher notification handler
90  void OnAJNotification(CEvent* evt);
91  void OnProgress(CEvent* evt);
92 
93  /// special flags
95 
96  // conversions
98 
99  // filters
100  virtual const IDMSearchTool::TFilters& GetFilters(void) const;
102 
103  /// String representation of pattern type
104  static string GetPatternTypeStr(EPatternType ptype);
105 
106 protected:
107  struct SSession {
110  int m_JobID;
111  string m_Descr;
112  };
113 
114  /// create a job based on the given query, override in derived classes
116 
117  int x_GetSessionIndexByID(int job_id);
118  int x_GetSessionIndexByQuery(IDMSearchQuery& query);
119  int x_GetSessionIndexByListener(IDMSearchFormController& listener);
120 
121  virtual void x_OnJobCompleted(CAppJobNotification& notify, SSession& session);
122  virtual void x_OnJobFailed(CAppJobNotification& notify, SSession& session);
123  virtual void x_OnJobCanceled(CAppJobNotification& notify, SSession& session);
124 
125 protected:
126  string m_Name;
127 
129  vector<SSession*> m_Sessions;
132 
134 };
135 
136 
137 ///////////////////////////////////////////////////////////////////////////////
138 /// CSearchQueryBase
140  public CObject,
141  public IDMSearchQuery
142 {
143 public:
144  struct SScopedLoc {
149  };
150  typedef vector<SScopedLoc> TScopedLocs;
151 
152  CSearchQueryBase(TScopedLocs& locs) { m_ScopedLocs = locs; }
153 
154  TScopedLocs& GetScopedLocs() { return m_ScopedLocs; }
155 
156 protected:
158 };
159 
160 
161 ///////////////////////////////////////////////////////////////////////////////
162 /// CSearchJobBase
163 ///
165 {
166 public:
168 
169  CSearchJobBase();
170  virtual ~CSearchJobBase();
171 
172  /// @name IAppJob implementation
173  /// @{
174  virtual EJobState Run();
175  virtual CConstIRef<IAppJobProgress> GetProgress();
176  virtual CRef<CObject> GetResult();
177  virtual CConstIRef<IAppJobError> GetError();
178  virtual string GetDescr() const;
179  /// @}
180 
181  void SetFilters(IDMSearchTool::TFilters & filters) {m_Filters = filters;}
182 
183  int GetResultsCount() const { return m_ResultsCount; }
184  int GetMaxResultsCount() const { return m_MaxResultsCount; }
185 
186 
187 protected:
188  /// returns true if Job params are correct, implement in derived classes
189  virtual bool x_ValidateParams() = 0;
190 
191  virtual void x_PrepareSearch();
192 
193  /// performs searching, assuming that params are correct;
194  /// Implement in derived classes
195  virtual EJobState x_DoSearch() = 0;
196 
197  /// add custom columns if needed
198  virtual void x_SetupColumns(CObjectList& obj_list);
199 
200  /// transfer data from Temp Results to Final
201  virtual void x_TransferResults();
202 
203  /// factory method creating new column handler for CObjectListWidget
204  //NCBI_DEPRECATED virtual IObjectColumnHandler* x_GetColumnHandler() const;
205 
206  /// factory method creating new model for CObjectListWidget
207  virtual CObjectListTableModel* x_GetNewOLTModel() const;
208 
209  // this function just needs info about OLT model
211 
212 
213 protected:
214  /// human-readable description of the Job
215  string m_Descr;
216 
217  /// synchronizes access to the Job members
219 
221 
222  /// total number of results
224  /// Max possible results count
226 
227  /// accumulates found objects before they are transferred to m_ResultList
229 
230  /// holds temporary results, guarded by Mutex
232 
233  string m_ProgressStr; /// guarded by Mutex
234 
235  CRef<CDMSearchResult> m_Result; /// holds the final results
236 
238 };
239 
240 
242 
243 #endif // GUI_SERVICES___SEARCH_TOOL_BASE_HPP
CAppJobDispatcher.
CAppJobNotification Notification send by CAppJobEventTranslator.
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
Base class to build jobs with cancel functionality.
CMutex –.
Definition: ncbimtx.hpp:749
CObjectEx –.
Definition: ncbiobj.hpp:2531
CObjectListTableModel.
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
CSearchJobBase.
int m_MaxResultsCount
Max possible results count.
CRef< CDMSearchResult > m_TempResult
holds temporary results, guarded by Mutex
string m_Descr
human-readable description of the Job
int m_ResultsCount
total number of results
int GetResultsCount() const
int GetMaxResultsCount() const
virtual bool x_ValidateParams()=0
returns true if Job params are correct, implement in derived classes
virtual EJobState x_DoSearch()=0
performs searching, assuming that params are correct; Implement in derived classes
void SetFilters(IDMSearchTool::TFilters &filters)
CRef< CDMSearchResult > m_Result
guarded by Mutex
IDMSearchTool::TFilters m_Filters
holds the final results
CSearchToolBase::EPatternType TPatternType
CMutex m_Mutex
synchronizes access to the Job members
CRef< CAppJobError > m_Error
CObjectList m_AccList
accumulates found objects before they are transferred to m_ResultList
CSearchQueryBase.
TScopedLocs & GetScopedLocs()
TScopedLocs m_ScopedLocs
CSearchQueryBase(TScopedLocs &locs)
vector< SScopedLoc > TScopedLocs
CSearchToolBase.
virtual CIRef< IDMSearchForm > CreateSearchForm()=0
factory method for creating a form representing the tool
virtual string GetName() const =0
returns unique name of the method that is used in UI to identify it
virtual IUITool * Clone() const =0
virtual bool IsCompatible(IDataMiningContext *context)=0
retuns true if the tool is compatible with the provided Search Context
virtual string GetDescription() const =0
returns a detailed description of the method that is used in UI
IDMSearchTool::TFilters m_Filters
virtual bool PullSearch(IDMSearchQuery &query, IDMSearchFormController &listener)
Pulls cached result from cache if possible (true)
virtual CRef< CSearchJobBase > x_CreateJob(IDMSearchQuery &query)=0
create a job based on the given query, override in derived classes
CRef< CObjectList > m_Cache
vector< SSession * > m_Sessions
IDMSearchTool::TConversions m_Conversions
IDMSearchFormController - interface representing an entity that controls the lifecycle of search Form...
IDMSearchForm - interface for abstract Search From.
IDMSearchQuery - abstract data mining query.
IDMSearchTool interface representing a single search tool in Data Mining Service.
virtual TFilters & SetFilters()=0
virtual TUIToolFlags GetFlags(void)=0
special flags
virtual const TFilters & GetFilters(void) const =0
list of all tool-provided filters
virtual TConversions & GetConversions(void)=0
list of acceptable feat types top convert and default type
virtual bool StartSearch(IDMSearchQuery &query, IDMSearchFormController &listener)=0
Starts search Job, the job is identified by the query object.
virtual string GetJobDescr(IDMSearchFormController &listener)=0
virtual bool PullSearch(IDMSearchQuery &query, IDMSearchFormController &listener)=0
Pulls cached result from cache if possible (true)
virtual bool CancelSearch(IDMSearchFormController &listener)=0
IDataMiningContext IDataMiningContext represents an abstract context for a Search.
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
IUITool represents an abstract algorithm that is bound to a UI component.
Definition: ui_tool.hpp:59
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
void Run(void)
Enter the main loop.
#define NCBI_GUICORE_EXPORT
Definition: gui_export.h:508
CRef< objects::CScope > m_Scope
CRef< objects::CSeq_loc > m_Loc
IDMSearchFormController * m_Listener
CIRef< IDMSearchQuery > m_Query
static string query
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Fri Jul 19 17:08:17 2024 by modify_doxy.py rev. 669887