File: tasks.h

package info (click to toggle)
vdr-plugin-live 2.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,608 kB
  • sloc: cpp: 5,859; makefile: 254; sh: 129; awk: 39
file content (163 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef VDR_LIVE_TASKS_H
#define VDR_LIVE_TASKS_H

// STL headers need to be before VDR tools.h (included by <vdr/channels.h>)
#include <string>
#include <vector>

#include <vdr/channels.h>
#include <vdr/thread.h>

namespace vdrlive {

class Task;

class TaskManager: public cMutex
{
	friend TaskManager& LiveTaskManager();
	friend class StickyTask;

	typedef std::vector< Task* > TaskList;

public:
	bool Execute( Task& task );

	// may only be called from Plugin::MainThreadHook
	void DoScheduledTasks();

private:
	TaskManager();
	TaskManager( TaskManager const& );

	void AddStickyTask( Task& task );
	void RemoveStickyTask( Task& task );

	TaskList m_taskQueue;
	TaskList m_stickyTasks;
	cCondVar m_scheduleWait;
};

class Task
{
	friend void TaskManager::DoScheduledTasks();

public:
	virtual ~Task() {}

	bool Result() const { return m_result; }
	std::string const& Error() const { return m_error; }

protected:
	explicit Task()
		: m_result( true )
		{}
	Task( Task const& );

	void SetError( std::string const& error ) { m_result = false; m_error = error; }

private:
	bool m_result;
	std::string m_error;

	virtual void Action() = 0;
};

class StickyTask: public Task
{
protected:
	explicit StickyTask();
	virtual ~StickyTask();
};

class SwitchChannelTask: public Task
{
public:
	explicit SwitchChannelTask( tChannelID channel ): m_channel( channel ) {}

private:
	tChannelID m_channel;

	virtual void Action();
};

class RecordingTask: public Task
{
protected:
	explicit RecordingTask(std::string const& recording)
		: m_recording(recording)
	{}

	std::string m_recording;
};

class PlayRecordingTask: public RecordingTask
{
public:
	explicit PlayRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();
};

class PauseRecordingTask: public RecordingTask
{
public:
	explicit PauseRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();
};

class StopRecordingTask: public RecordingTask
{
public:
	explicit StopRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();
};

class ForwardRecordingTask: public RecordingTask
{
public:
	explicit ForwardRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();
};

class BackwardRecordingTask: public RecordingTask
{
public:
	explicit BackwardRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();
};

class RemoveRecordingTask: public RecordingTask
{
public:
	explicit RemoveRecordingTask( std::string const& recording )
		: RecordingTask(recording)
	{}

	virtual void Action();

	std::string const & RecName() const { return m_recName; }

private:
	std::string m_recName;
};


TaskManager& LiveTaskManager();

} // namespace vdrlive

#endif // VDR_LIVE_TASKS_H