File: timer_thread.c

package info (click to toggle)
vdr-plugin-epgsearch 2.4.0%2Bgit20191101-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,992 kB
  • sloc: ansic: 22,373; perl: 1,330; sh: 630; makefile: 226
file content (112 lines) | stat: -rw-r--r-- 3,126 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
/*                                                                  -*- c++ -*-
Copyright (C) 2004-2013 Christian Wieninger

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

The author can be reached at cwieninger@gmx.de

The project's page is at http://winni.vdr-developer.org/epgsearch
*/

#include <string>
#include <list>
#ifdef __FreeBSD__
#include <netinet/in.h>
#endif
#include "timer_thread.h"
#include "epgsearchcfg.h"
#include "epgsearchtools.h"
#include "services.h"
#include "svdrpclient.h"
#include "timerstatus.h"

#include <vdr/tools.h>
#include <vdr/plugin.h>

cTimerThread *cTimerThread::m_Instance = NULL;
TimerThreadStatus cTimerThread::m_Status = TimerThreadReady;
int gl_TimerProgged = 0; // Flag that indicates, when programming is finished

cTimerThread::cTimerThread()
    : cThread("EPGSearch: timer")
{
    m_Active = false;
}

cTimerThread::~cTimerThread()
{
    if (m_Active)
        Stop();
    cTimerThread::m_Instance = NULL;
}

void cTimerThread::Init(cString cmd)
{
    if (m_Instance == NULL) {
        m_Instance = new cTimerThread;
        m_Instance->m_cmd = cmd;
        m_Instance->Start();
    }
}

void cTimerThread::Exit(void)
{
    if (m_Instance != NULL) {
        m_Instance->Stop();
        DELETENULL(m_Instance);
    }

}

void cTimerThread::Stop(void)
{
    m_Active = false;
    Cancel(3);
}

void cTimerThread::Action(void)
{
    m_Active = true;
    if (EPGSearchConfig.useExternalSVDRP && !epgsSVDRP::cSVDRPClient::SVDRPSendCmd) {
        LogFile.eSysLog("ERROR - SVDRPSend script not specified or does not exist (use -f option)");
        m_Active = false;
        return;
    }
    while (m_Active) {
        if (!Running()) {
            m_Active = false;
            break;
        }
        {
            LOCK_TIMERS_WRITE;
            Timers->SetExplicitModify();
        }
        bool bSuccess = SendViaSVDRP(m_cmd);
        if (!bSuccess) {
            Epgsearch_osdmessage_v1_0* service_data = new Epgsearch_osdmessage_v1_0;
            service_data->message = strdup(tr("Programming timer failed!"));
            service_data->type = mtError;
            cPluginManager::CallFirstService("Epgsearch-osdmessage-v1.0", service_data);
            delete service_data;
        } else {
            gl_TimerProgged = 1;
            if (gl_timerStatusMonitor) gl_timerStatusMonitor->SetConflictCheckAdvised();
        }
        m_Active = false;
    };
}