ProgressManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/progress/ProgressManager.h
22 
23  \brief A singleton class used to manage tasks progresses and their viewers.
24 */
25 
26 #ifndef __TERRALIB_COMMON_PROGRESS_INTERNAL_PROGRESSMANAGER_H
27 #define __TERRALIB_COMMON_PROGRESS_INTERNAL_PROGRESSMANAGER_H
28 
29 // TerraLib
30 #include "../Config.h"
31 #include "../Singleton.h"
32 #include "../ThreadingPolicies.h"
33 
34 // STL
35 #include <map>
36 #include <string>
37 
38 namespace te
39 {
40  namespace common
41  {
42 // Forward declarations
44  class TaskProgress;
45 
46  /*!
47  \class ProgressManager
48 
49  \brief A singleton class used to manage tasks progresses and their viewers.
50 
51  This singleton is used to store all tasks created and their
52  progress viewers. If one or more viewers is attached,
53  all instances will be used to display the tasks progresses.
54 
55  \ingroup common
56 
57  \sa AbstractProgressViewer, TaskProgress
58  */
60  ::boost::recursive_mutex,
61  ::boost::lock_guard< ::boost::recursive_mutex>,
62  ::boost::lock_guard< ::boost::recursive_mutex> >,
63  public te::common::Singleton<ProgressManager>
64  {
66 
67  public:
68 
69  /*!
70  \brief Attach a progress viewer
71 
72  \param apv Progress viewer instance
73 
74  \note
75  */
77 
78  /*!
79  \brief Dettach a progress viewer (AbstractProgressViewer destructor calls this method).
80 
81  \param viewerId Progress viewer identifier
82  */
83  void removeViewer(int viewerId);
84 
85  /*!
86  \brief Used in TaskProgress constructor, register this task generating a task id.
87 
88  \param tp TaskProgress instance
89 
90  \return Task identifier
91 
92  \note Thread-safe!
93  */
95 
96  /*!
97  \brief Used in TaskProgress destructor, remove task from singleton.
98 
99  \param taskId Task identifier.
100 
101  \note Thread-safe!
102  */
103  void removeTask(int taskId);
104 
105  /*!
106  \brief Inform all viewers that a task was canceled.
107 
108  \param taskId Task identifier.
109  */
110  void cancelTask(int taskId);
111 
112  /*!
113  \brief Cancels the task with the given task type and inform all viewers that a task was canceled.
114 
115  \param type The task type.
116  */
117  void cancelTasks(unsigned int type);
118 
119  /*!
120  \brief Inform all viewers that a task set the total values.
121 
122  \param taskId Task identifier.
123  */
124  void setTotalValues(int taskId);
125 
126  /*!
127  \brief Inform all viewers that a task set the current step.
128 
129  \param taskId Task identifier.
130  */
131  void updateValue(int taskId);
132 
133  /*!
134  \brief Inform all viewers that a task set the message.
135 
136  \param taskId Task identifier.
137  */
138  void updateMessage(int taskId);
139 
140  /*!
141  \brief Removes references for Viewers and tasks.
142  */
143  void clearAll();
144 
145  void setSuspendViewers(bool flag) { m_suspendViewers = flag; }
146 
147  protected:
148 
149  /*! \brief Default constructor. */
151 
152  /*! \brief Destructor. */
154 
155  /*!
156  \brief Used to generate a new viewer id (use internal counter).
157 
158  \return Viewer identification as integer value.
159  */
161 
162  /*!
163  \brief Used to generate a new task id (use internal counter).
164 
165  \return Task identification as integer value.
166  */
168 
169  protected:
170 
171  int m_taskCounter; //!< Counter used to generate a task id.
172  int m_viewerCounter; //!< Counter used to generate a viewer id.
173  std::map<int, TaskProgress*> m_tasks; //!< Container with tasks.
174  std::map<int, AbstractProgressViewer*> m_viewers; //!< Container with viewers.
175 
177 
178  };
179 
180  } // end namespace common
181 } // end namespace te
182 
183 #endif //__TERRALIB_COMMON_PROGRESS_INTERNAL_PROGRESSMANAGER_H
te::common::ProgressManager::generateViewerId
int generateViewerId()
Used to generate a new viewer id (use internal counter).
te::common::ProgressManager::addTask
int addTask(TaskProgress *tp)
Used in TaskProgress constructor, register this task generating a task id.
te::common::ProgressManager::m_taskCounter
int m_taskCounter
Counter used to generate a task id.
Definition: ProgressManager.h:171
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::common::ProgressManager::updateValue
void updateValue(int taskId)
Inform all viewers that a task set the current step.
te::common::ProgressManager::clearAll
void clearAll()
Removes references for Viewers and tasks.
te::common::ProgressManager::setTotalValues
void setTotalValues(int taskId)
Inform all viewers that a task set the total values.
TECOMMONEXPORT
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:66
te::common::ProgressManager::removeViewer
void removeViewer(int viewerId)
Dettach a progress viewer (AbstractProgressViewer destructor calls this method).
te::common::ProgressManager::addViewer
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
te::common::ProgressManager::m_suspendViewers
bool m_suspendViewers
Definition: ProgressManager.h:176
te::common::ProgressManager::m_viewers
std::map< int, AbstractProgressViewer * > m_viewers
Container with viewers.
Definition: ProgressManager.h:174
te::common::ProgressManager
A singleton class used to manage tasks progresses and their viewers.
Definition: ProgressManager.h:64
te::common::ProgressManager::ProgressManager
ProgressManager()
Default constructor.
te::common::ProgressManager::removeTask
void removeTask(int taskId)
Used in TaskProgress destructor, remove task from singleton.
te::common::ProgressManager::generateTaskId
int generateTaskId()
Used to generate a new task id (use internal counter).
te::common::ProgressManager::~ProgressManager
~ProgressManager()
Destructor.
te::common::ProgressManager::m_tasks
std::map< int, TaskProgress * > m_tasks
Container with tasks.
Definition: ProgressManager.h:173
te::common::Singleton
Template support for singleton pattern.
Definition: Singleton.h:101
te::common::ProgressManager::m_viewerCounter
int m_viewerCounter
Counter used to generate a viewer id.
Definition: ProgressManager.h:172
te::common::ObjectLevelLockable
This policy assures an object-level locking scheme for a derived class.
Definition: ThreadingPolicies.h:152
te::common::ProgressManager::updateMessage
void updateMessage(int taskId)
Inform all viewers that a task set the message.
te::common::AbstractProgressViewer
A class that defines the interface of an abstract progress viewer.
Definition: AbstractProgressViewer.h:49
te::common::ProgressManager::setSuspendViewers
void setSuspendViewers(bool flag)
Definition: ProgressManager.h:145
te::common::TaskProgress
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:54
te::common::ProgressManager::cancelTasks
void cancelTasks(unsigned int type)
Cancels the task with the given task type and inform all viewers that a task was canceled.
te::common::ProgressManager::cancelTask
void cancelTask(int taskId)
Inform all viewers that a task was canceled.