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  \note
75  */
76  int addViewer(AbstractProgressViewer* apv);
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  */
94  int addTask(TaskProgress* tp);
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. */
150  ProgressManager();
151 
152  /*! \brief Destructor. */
153  ~ProgressManager();
154 
155  /*!
156  \brief Used to generate a new viewer id (use internal counter).
157 
158  \return Viewer identification as integer value.
159  */
160  int generateViewerId();
161 
162  /*!
163  \brief Used to generate a new task id (use internal counter).
164 
165  \return Task identification as integer value.
166  */
167  int generateTaskId();
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
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:66
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