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
43  class AbstractProgressViewer;
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  \return Progress viewer identifier
75 
76  \note
77  */
78  int addViewer(AbstractProgressViewer* apv);
79 
80  /*!
81  \brief Dettach a progress viewer
82 
83  \param viewerId Progress viewer identifier
84  */
85  void removeViewer(int viewerId);
86 
87  /*!
88  \brief Used in TaskProgress constructor, register this task generating a task id.
89 
90  \param tp TaskProgress instance
91 
92  \return Task identifier
93 
94  \note Thread-safe!
95  */
96  int addTask(TaskProgress* tp);
97 
98  /*!
99  \brief Used in TaskProgress destructor, remove task from singleton.
100 
101  \param taskId Task identifier.
102 
103  \note Thread-safe!
104  */
105  void removeTask(int taskId);
106 
107  /*!
108  \brief Inform all viewers that a task was canceled.
109 
110  \param taskId Task identifier.
111  */
112  void cancelTask(int taskId);
113 
114  /*!
115  \brief Cancels the task with the given task type and inform all viewers that a task was canceled.
116 
117  \param type The task type.
118  */
119  void cancelTasks(unsigned int type);
120 
121  /*!
122  \brief Inform all viewers that a task set the total values.
123 
124  \param taskId Task identifier.
125  */
126  void setTotalValues(int taskId);
127 
128  /*!
129  \brief Inform all viewers that a task set the current step.
130 
131  \param taskId Task identifier.
132  */
133  void updateValue(int taskId);
134 
135  /*!
136  \brief Inform all viewers that a task set the message.
137 
138  \param taskId Task identifier.
139  */
140  void updateMessage(int taskId);
141 
142  /*!
143  \brief Removes references for Viewers and tasks.
144  */
145  void clearAll();
146 
147  void setSuspendViewers(bool flag) { m_suspendViewers = flag; }
148 
149  protected:
150 
151  /*! \brief Default constructor. */
152  ProgressManager();
153 
154  /*! \brief Destructor. */
155  ~ProgressManager();
156 
157  /*!
158  \brief Used to generate a new viewer id (use internal counter).
159 
160  \return Viewer identification as integer value.
161  */
162  int generateViewerId();
163 
164  /*!
165  \brief Used to generate a new task id (use internal counter).
166 
167  \return Task identification as integer value.
168  */
169  int generateTaskId();
170 
171  protected:
172 
173  int m_taskCounter; //!< Counter used to generate a task id.
174  int m_viewerCounter; //!< Counter used to generate a viewer id.
175  std::map<int, TaskProgress*> m_tasks; //!< Container with tasks.
176  std::map<int, AbstractProgressViewer*> m_viewers; //!< Container with viewers.
177 
179 
180  };
181 
182  } // end namespace common
183 } // end namespace te
184 
185 #endif //__TERRALIB_COMMON_PROGRESS_INTERNAL_PROGRESSMANAGER_H
void setSuspendViewers(bool flag)
std::map< int, TaskProgress * > m_tasks
Container with tasks.
int m_taskCounter
Counter used to generate a task id.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
int m_viewerCounter
Counter used to generate a viewer id.
A class that defines the interface of an abstract progress viewer.
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
A singleton class used to manage tasks progresses and their viewers.
std::map< int, AbstractProgressViewer * > m_viewers
Container with viewers.
This policy assures an object-level locking scheme for a derived class.
Template support for singleton pattern.
Definition: Singleton.h:100