kodi
PltThreadTask.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - Thread Tasks
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
39 #ifndef _PLT_THREADTASK_H_
40 #define _PLT_THREADTASK_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltTaskManager.h"
47 
48 /*----------------------------------------------------------------------
49 | PLT_ThreadTask class
50 +---------------------------------------------------------------------*/
57 {
58 public:
59  friend class PLT_TaskManager;
60 
65  NPT_Result Kill();
66 
67 protected:
73  virtual bool IsAborting(NPT_Timeout timeout) {
74  return NPT_SUCCEEDED(m_Abort.WaitUntilEquals(1, timeout));
75  }
76 
84  NPT_Result Start(PLT_TaskManager* task_manager = NULL,
85  NPT_TimeInterval* delay = NULL,
86  bool auto_destroy = true);
91  NPT_Result Stop(bool blocking = true);
92 
97  virtual void DoInit() {}
98 
103  virtual void DoAbort() {}
104 
108  virtual void DoRun() {}
109 
113  PLT_ThreadTask();
114 
119  ~PLT_ThreadTask() override;
120 
121 private:
122  NPT_Result StartThread();
123 
124  // NPT_Thread methods
125  void Run() override;
126 
127 protected:
128  // members
129  PLT_TaskManager* m_TaskManager;
130 
131 private:
132  // members
133  NPT_SharedVariable m_Started;
134  NPT_SharedVariable m_Abort;
135  NPT_Thread* m_Thread;
136  bool m_AutoDestroy;
137  NPT_TimeInterval m_Delay;
138 };
139 
140 #endif /* _PLT_THREADTASK_H_ */
Definition: NptThreads.h:234
virtual void DoInit()
This method to override in derived classes is called when the task is about to start.
Definition: PltThreadTask.h:97
NPT_Result Start(PLT_TaskManager *task_manager=NULL, NPT_TimeInterval *delay=NULL, bool auto_destroy=true)
Start a task by associating it with a task manager.
Definition: PltThreadTask.cpp:65
Definition: NptThreads.h:209
~PLT_ThreadTask() override
The task manager will destroy the task when finished if m_AutoDestroy is true otherwise the owner of ...
Definition: PltThreadTask.cpp:56
virtual void DoAbort()
This method to override in derived classes is called when the task is about to stop.
Definition: PltThreadTask.h:103
NPT_Result Stop(bool blocking=true)
Stop the task.
Definition: PltThreadTask.cpp:116
The PLT_TaskManager class maintains a list of runnable tasks.
Definition: PltTaskManager.h:60
Definition: NptTime.h:50
Definition: NptThreads.h:149
virtual void DoRun()
This method to override in derived classes is the main task loop.
Definition: PltThreadTask.h:108
virtual bool IsAborting(NPT_Timeout timeout)
Return whether this task is in the process of stopping.
Definition: PltThreadTask.h:73
NPT_Result Kill()
When a task is not managed by a PLT_TaskManager, the owner must call this to stop and destroy it...
Definition: PltThreadTask.cpp:139
Runnable Tasks Manager.
PLT_ThreadTask()
A PLT_ThreadTask base class is never instantiated directly.
Definition: PltThreadTask.cpp:46
The PLT_ThreadTask class is a base class for executing a given task in a worker thread.
Definition: PltThreadTask.h:56