Loading...
Searching...
No Matches
Task.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/process/Task.h
22
23 \brief Abstraction that represents a Task that can be executed
24 */
25
26#ifndef __TERRALIB_PROCESS_INTERNAL_TASK_H
27#define __TERRALIB_PROCESS_INTERNAL_TASK_H
28
29 // TerraLib
30#include "Config.h"
31
32#include "../common/AbstractFactory.h"
33
34#include <map>
35#include <memory>
36#include <string>
37#include <vector>
38
39namespace te
40{
41 namespace process
42 {
43 class Connector;
44 class ParameterValue;
45 class TaskCapabilities;
46 class TaskParameters;
47
48 /*!
49 \class Task
50
51 \brief Abstraction that represents a Task that can be executed
52 */
54 {
55 public:
56
57 enum class State
58 {
59 NOT_INITIALIZED, MISSING_PARAMETERS, READY_TO_RUN, RUNNING, FINISHED, FINISHED_WITH_ERRORS
60 };
61
62 /*!
63 \brief It initializes the Task
64 */
65 Task(const std::string& taskType);
66
67 /*! \brief Virtual destructor. */
68 virtual ~Task();
69
70 //!< Gets the id of the task
71 const std::string& getId() const;
72
73 //< Sets the id of the task. Generally used only of a deserialization
74 void setId(const std::string& id);
75
76 //!< Gets the type of the task
77 const std::string& getType() const;
78
79 //!< Gets the capabilities of the task
81
82 //!< Gets the current execution state of the task
83 State getState() const;
84
85 //!< Gets the index-th parameter
86 const te::process::ParameterValue* getParameter(std::size_t index) const;
87
88 //!< Sets the index-th parameter. This object will optionally take the ownership of the value pointer
89 void setParameter(std::size_t index, te::process::ParameterValue* value, bool takeOwnership);
90
91 //!< Gets the task paramters
93
94 //!< Sets the task paramters. This class will take the ownership of the given pointer
95 void setTaskParameters(TaskParameters* taskParameters);
96
97 //!< Adds a parameter connector to this class
98 void addConnector(Connector* connector);
99
100 //!< Removes a parameter connector to this class
101 void removeConnector(Connector* connector);
102
103 //!< Gets all the input connectors
104 std::vector<Connector*> getInputConnectors() const;
105
106 //!< Gets all the output connectors
107 std::vector<Connector*> getOutputConnectors() const;
108
109 //!< Checks if the task is valid, that is, if all the required input parameters have values OR connectors associated to them
110 bool isValid(std::string& errorMessage) const;
111
112 //!< Runs the task
113 void run();
114
115 protected:
116
117 //!< Initializes the task. This function must be called by any class that extends this abstraction. The abstraction will take the ownership of the pointer
119
120 //!< Checks if all the input connectors are ready. If at least one connector is not ready, it returns FALSE.
122
123 //!< Pushes the parameters into the output connectors
125
126 //!< This function is called whenever the parameters are changed and is responsible for checking the parameters are valid. If they are, change the task state to Ready to Run
128
129 //!< Runs the task
130 virtual void runImpl() = 0;
131
132 protected:
133 std::string m_taskType; //!< The type of the task. Used by the factory
134 std::string m_id; //!< The ID of the task
136 std::unique_ptr<TaskCapabilities> m_capabilities;
137 std::unique_ptr<TaskParameters> m_parameters;
138 std::vector<Connector*> m_connectors;
139 };
140
141 //Typedef
142 class TEPROCESSEXPORT TaskPtr : public std::unique_ptr<Task>
143 {
144 public:
145 explicit TaskPtr(te::process::Task* task = nullptr);
147 };
148
149 class TEPROCESSEXPORT TaskSharedPtr : public std::shared_ptr<Task>
150 {
151 public:
152 explicit TaskSharedPtr(te::process::Task* task = nullptr);
154 };
155
156 /*!
157 \class TaskFactory
158
159 \brief Abstract factory used to create Tasks.
160 */
161 class TEPROCESSEXPORT TaskFactory : public te::common::AbstractFactory < te::process::Task, std::string >
162 {
163 public:
164
165 /*!
166 \brief Constructor.
167
168 \param factoryKey The key that identifies the factory.
169 */
170 TaskFactory(const std::string& taskType, const std::string& category);
171
172 //!< Destructor
173 virtual ~TaskFactory();
174
175 //!< Gets all registered categories
176 static std::vector<std::string> getCategories();
177
178 //!< Gets all tasks from the give category
179 static std::vector<std::string> getTasksFromCategory(const std::string& category);
180
181 protected:
182
183 static std::map<std::string, std::vector<std::string> > m_mapCategories;
184 };
185
186 //!< Wrapper function used to create taks. Used to avoid C++ to create multiple instances of the factory singleton on Windows
187 TEPROCESSEXPORT Task* CreateTask(const std::string& taskType);
188
189 } // end namespace process
190} // end namespace te
191
192#endif // __TERRALIB_PROCESS_INTERNAL_TASK_H
193
te::da::DataSourceCapabilities capabilities
This class defines the interface of abstract factories without initializing parameters.
Abstraction that represents a Connector between parameters of a Task.
Definition: Connector.h:48
Represents the capabilities of a task.
Wrapper function used to create taks. Used to avoid C++ to create multiple instances of the factory s...
Definition: Task.h:162
virtual ~TaskFactory()
Gets all registered categories.
static std::vector< std::string > getTasksFromCategory(const std::string &category)
TaskFactory(const std::string &taskType, const std::string &category)
Constructor.
static std::map< std::string, std::vector< std::string > > m_mapCategories
Definition: Task.h:183
static std::vector< std::string > getCategories()
Gets all tasks from the give category.
TaskPtr(te::process::Task *task=nullptr)
TaskSharedPtr(te::process::Task *task=nullptr)
This class represents the description of a parameter.
Definition: Task.h:54
std::string m_id
The ID of the task.
Definition: Task.h:134
std::vector< Connector * > getInputConnectors() const
Gets all the output connectors.
virtual ~Task()
Virtual destructor.
std::vector< Connector * > m_connectors
Definition: Task.h:138
const TaskParameters * getTaskParameters() const
Sets the task paramters. This class will take the ownership of the given pointer.
std::unique_ptr< TaskParameters > m_parameters
Definition: Task.h:137
virtual void runImpl()=0
State getState() const
Gets the index-th parameter.
bool checkConnectorsAreReady()
Pushes the parameters into the output connectors.
void setParameter(std::size_t index, te::process::ParameterValue *value, bool takeOwnership)
Gets the task paramters.
const TaskCapabilities * getCapabilities() const
Gets the current execution state of the task.
void addConnector(Connector *connector)
Removes a parameter connector to this class.
void setId(const std::string &id)
Gets the type of the task.
void setTaskParameters(TaskParameters *taskParameters)
Adds a parameter connector to this class.
void pushParametersToConnectors()
This function is called whenever the parameters are changed and is responsible for checking the param...
std::unique_ptr< TaskCapabilities > m_capabilities
Definition: Task.h:136
void checkForReadyToRun()
Runs the task.
const std::string & getType() const
Gets the capabilities of the task.
std::vector< Connector * > getOutputConnectors() const
Checks if the task is valid, that is, if all the required input parameters have values OR connectors ...
void removeConnector(Connector *connector)
Gets all the input connectors.
State m_state
Definition: Task.h:135
const std::string & getId() const
void init(TaskCapabilities *capabilities)
< Initializes the task. This function must be called by any class that extends this abstraction....
bool isValid(std::string &errorMessage) const
Runs the task.
const te::process::ParameterValue * getParameter(std::size_t index) const
Sets the index-th parameter. This object will optionally take the ownership of the value pointer.
std::string m_taskType
The type of the task. Used by the factory.
Definition: Task.h:133
Task(const std::string &taskType)
It initializes the Task.
TEPROCESSEXPORT Task * CreateTask(const std::string &taskType)
TerraLib.
#define TEPROCESSEXPORT
Definition: Config.h:47
Proxy configuration file for TerraView (see terraview_config.h).