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

Go to the SVN repository for this file.

1 /* $Id: data_mining_service.cpp 39591 2017-10-13 14:45:28Z 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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
37 
40 
43 
44 #include <algorithm>
45 
46 
48 
49 
51  "Data Mining Service - search tools");
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 // CDMSearchResult
55 
57  : m_OLTModel(0),
58  m_IsIncomplete(false),
59  m_MaxSearchResult(0)
60 {
61 }
62 
64 {
65  delete m_OLTModel;
66 }
67 
68 
69 CDMSearchResult::CDMSearchResult(const string& query_descr,
70  CObjectListTableModel* olt_model,
71  CObjectList* obj_list
72  )
73  : m_QueryDescr(query_descr),
74  m_OLTModel(olt_model),
75  m_ObjectList(obj_list),
76  m_IsIncomplete(false)
77 {
78 }
79 
81 {
83  m_OLTModel = 0;
84  return olt;
85 }
86 
87 
88 ///////////////////////////////////////////////////////////////////////////////
89 /// CDataMiningService
91 {
92 public:
93  virtual bool Select(const IUITool& tool)
94  {
95  return dynamic_cast<const IDMSearchTool*>(&tool) != NULL;
96  }
97 };
98 
99 
101  m_ServiceLocator(NULL),
102  m_LastActiveContext(NULL)
103 {
104 }
105 
106 
108 {
109 }
110 
112 {
114 }
115 
117 {
118  LOG_POST(Info << "Initializing Data Mining Service...");
119 
120  // get all tools from extension point
121  vector< CIRef<IDMSearchTool> > tools;
122  GetExtensionAsInterface("data_mining_tool", tools);
123 
124  for( size_t i = 0; i < tools.size(); ++i ) {
125  IDMSearchTool* dm_tool = tools[i].GetPointer();
126  RegisterTool(dm_tool);
127  }
128 
129  LoadSettings();
130 
131  LOG_POST(Info << "Finished initializing Data Mining Service");
132 }
133 
134 
136 {
137  LOG_POST(Info << "Shutting down Data Mining Service...");
138 
139  SaveSettings();
140 
142 
143  m_Contributors.clear();
144 
145  LOG_POST(Info << "Finished shutting down Data Mining Service");
146 }
147 
148 
150 {
151  m_ServiceLocator = srv_locator;
152 }
153 
154 
155 #define REG_ERR_PREFIX "CDataMiningService::RegisterTool() - "
156 
158 {
159  if(tool) {
160  const string& name = tool->GetName();
161  if(name.empty()) {
162  ERR_POST(REG_ERR_PREFIX << "Tool name is empty");
163  } else {
165  if(it != m_NameToTool.end()) {
166  ERR_POST(REG_ERR_PREFIX << name << " tool already registered");
167  } else {
168  m_NameToTool[name] = tool;
169 
170  IServiceLocatorConsumer* consumer =
171  dynamic_cast<IServiceLocatorConsumer*>(tool);
172  if(consumer) {
174  }
175  LOG_POST(Info << " DataMiningTool " << name << " registered.");
176  return true;
177  }
178  }
179  } else {
180  ERR_POST(REG_ERR_PREFIX << "NULL argument");
181  }
182  return false;
183 }
184 
185 
187 {
189  IDMSearchTool& tool = *it->second;
190 
191  IServiceLocatorConsumer* consumer =
192  dynamic_cast<IServiceLocatorConsumer*>(&tool);
193  if(consumer) {
194  consumer->SetServiceLocator(NULL);
195  }
196  }
197 
199 }
200 
201 
203 {
204  string name = (m_NameToTool.size()) ? m_NameToTool.begin()->first : "";
205  return name;
206 }
207 
208 
209 void CDataMiningService::GetToolNames(vector<string>& names) const
210 {
212  names.push_back(it->first);
213  }
214 }
215 
216 
218 {
220  return (it == m_NameToTool.end()) ? CIRef<IDMSearchTool>(NULL)
221  : it->second;
222 }
223 
224 
226 {
227  TContexts::const_iterator it = std::find(m_Contexts.begin(), m_Contexts.end(), &context);
228  if(it == m_Contexts.end()) {
229  m_Contexts.push_back(&context);
231  } else {
232  ERR_POST("CDataMiningService::AttachContext() - client already registered");
233  }
234 }
235 
236 
238 {
239  TContexts::iterator it = std::find(m_Contexts.begin(), m_Contexts.end(), &context);
240  if(it != m_Contexts.end()) {
241  m_Contexts.erase(it);
242  if(m_LastActiveContext == &context) {
244  }
246  } else {
247  ERR_POST("CDataMiningService::DetachContext() - client is not attached");
248  }
249 }
250 
251 
253 {
254  return m_LastActiveContext;
255 }
256 
257 
259 {
260  if(active != m_LastActiveContext && active) {
261  m_LastActiveContext = active;
263  }
264 }
265 
266 
268 {
269  contexts = m_Contexts;
270 }
271 
272 
274 {
275 }
276 
277 
279 {
280 }
281 
282 void CDataMiningService::SetRegistryPath(const string& path)
283 {
284  m_RegPath = path;
285 }
286 
287 
289 {
290  _ASSERT(contributor);
291 
292  if(contributor == NULL) {
293  ERR_POST("CDataMiningService::AddContributor() - NULL contributor.");
294  } else {
295  TContributors::const_iterator it =
296  std::find(m_Contributors.begin(), m_Contributors.end(), contributor);
297  if(it == m_Contributors.end()) {
298  m_Contributors.push_back(contributor);
299  //contributor->SetMenuService(this);
300  } else {
301  ERR_POST("CDataMiningService::AddContributor() - contributor already added");
302  }
303  }
304 }
305 
306 
308 {
309  _ASSERT(contributor);
310 
311  if(contributor == NULL) {
312  ERR_POST("CDataMiningService::AddContributor() - NULL contributor.");
313  } else {
314  TContributors::iterator it =
315  std::find(m_Contributors.begin(), m_Contributors.end(), contributor);
316  if(it == m_Contributors.end()) {
317  ERR_POST("CDataMiningService::RemoveContributor() - not found");
318  } else {
319  // do not delete Contributors, they have their own life management
320  //contributor->SetMenuService(NULL);
321  m_Contributors.erase(it);
322  }
323  }
324 }
325 
326 
#define false
Definition: bool.h:36
CObjectListTableModel * DetachOLTModel()
Return OLT model and forget the ptr.association (ownership transfer)
CObjectListTableModel * m_OLTModel
CDataMiningService.
virtual bool Select(const IUITool &tool)
virtual void SaveSettings() const
IDataMiningContext * m_LastActiveContext
virtual IDataMiningContext * GetLastActiveContext()
virtual void DetachContext(IDataMiningContext &context)
virtual string GetDefaultToolName() const
virtual void OnActiveContextChanged(IDataMiningContext *active)
this function is called by GUI components to notify server
virtual void ShutDownService()
virtual void GetToolNames(vector< string > &names) const
void AddContributor(IDMContextMenuContributor *contributor)
the service does NOT assume ownership of the contributor
virtual void SetServiceLocator(IServiceLocator *locator)
IServiceLocator * m_ServiceLocator
void RemoveContributor(IDMContextMenuContributor *contributor)
vector< IDataMiningContext * > TContexts
virtual CIRef< IDMSearchTool > GetToolByName(const string &name)
virtual void AttachContext(IDataMiningContext &context)
virtual void SetRegistryPath(const string &path)
virtual void GetContexts(TContexts &contexts)
virtual bool RegisterTool(IDMSearchTool *tool)
CExtensionPointDeclaration - static declaration helper.
CObjectListTableModel.
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
IDMContextMenuContributor - contributes menu to Data Mining Service.
IDMSearchTool interface representing a single search tool in Data Mining Service.
virtual string GetName() const =0
returns unique name of the method that is used in UI to identify it
IDataMiningContext IDataMiningContext represents an abstract context for a Search.
IServiceLocatorConsumer - classes that need IServiceLocator should implement this interface.
Definition: service.hpp:103
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IUITool represents an abstract algorithm that is bound to a UI component.
Definition: ui_tool.hpp:59
size_type size() const
Definition: map.hpp:148
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
#define REG_ERR_PREFIX
static CExtensionPointDeclaration decl(EXT_POINT__DATA_MINING_TOOL, "Data Mining Service - search tools")
static const struct name_t names[]
#define EXT_POINT__DATA_MINING_TOOL
Extension Point ID for Data Mining Tools Components that need to add new search tools to Data Mining ...
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#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 Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
virtual void SetServiceLocator(IServiceLocator *locator)=0
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
void Post(CRef< CEvent > evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Handles an event asynchronously (process and/or dispatch).
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
#define _ASSERT
Modified on Tue Nov 28 02:29:47 2023 by modify_doxy.py rev. 669887