summaryrefslogtreecommitdiff
path: root/timers.h
blob: 1400dab2d0dc0e4a8adfd4d571cd07a38a22920c (plain)
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
#ifndef VDR_LIVE_TIMERS_H
#define VDR_LIVE_TIMERS_H

#include <list>
#include <string>
#include <vdr/timers.h>
#include <vdr/thread.h>
#include "live.h"

namespace vdrlive {

class SortedTimers: public std::list< cTimer >
{
	friend class TimerManager;

public:
	std::string GetTimerId( cTimer const& timer );
	cTimer* GetByTimerId( std::string const& timerid );
	
private:
	SortedTimers();
	SortedTimers( SortedTimers const& );

	int m_state;
	
	void ReloadTimers( bool initial = false );
};

class TimerManager: public cMutex
{
	friend TimerManager& LiveTimerManager();

public:
	SortedTimers& GetTimers() { return m_timers; }

	std::string UpdateTimer( cTimer* timer, std::string const& timerString );

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

private:
	typedef std::pair< cTimer*, std::string > TimerPair;
	typedef std::pair< TimerPair, std::string > ErrorPair;
	typedef std::list< TimerPair > TimerList;
	typedef std::list< ErrorPair > ErrorList;
	
	TimerManager();
	TimerManager( TimerManager const& );

	SortedTimers m_timers;
	TimerList m_updateTimers;
	ErrorList m_failedUpdates;
	cCondVar m_updateWait;

	void DoUpdateTimers();
	void DoInsertTimer( TimerPair& timerData );
	void DoUpdateTimer( TimerPair& timerData );

	void StoreError( TimerPair const& timerData, std::string const& error );
	std::string GetError( TimerPair const& timerData );
};

TimerManager& LiveTimerManager();

} // namespace vdrlive

#endif // VDR_LIVE_TIMERS_H