MythTV master
MythExternRecApp.h
Go to the documentation of this file.
1/* -*- Mode: c++ -*-
2 *
3 * Copyright (C) John Poet 2018
4 *
5 * This file is part of MythTV
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef MYTHTVEXTERNRECAPP_H
22#define MYTHTVEXTERNRECAPP_H
23
24#include <QDir>
25#include <QMap>
26#include <QObject>
27#include <QProcess>
28#include <QSettings>
29#include <QString>
30#include <QVariantMap>
31
32#include <atomic>
33#include <condition_variable>
34
36
37class MythExternRecApp : public QObject
38{
39 Q_OBJECT
40
41 public:
42 MythExternRecApp(QString command, QString conf_file,
43 QString log_file, QString logging);
44 ~MythExternRecApp(void) override;
45
46 bool Open(void);
47 void Run(void);
48
49 void ReplaceVariables(QString & cmd) const;
50 QString Desc(void) const;
51 void MythLog(const QString & msg)
52 { emit SendMessage("", "0", "STATUS", msg); }
53 void SetErrorMsg(const QString & msg) { emit ErrorMessage(msg); }
54
55 signals:
56 void SetDescription(const QString & desc);
57 void SendMessage(const QString & command,
58 const QString & serial,
59 const QString & message,
60 const QString & status = "");
61 void ErrorMessage(const QString & msg);
62 void Opened(void);
63 void Done(void);
64 void Streaming(bool val);
65 void Fill(const QByteArray & buffer);
66
67 public slots:
68 void ProcStarted(void);
69 void ProcFinished(int exitCode, QProcess::ExitStatus exitStatus);
70 void ProcStateChanged(QProcess::ProcessState newState);
71 void ProcError(QProcess::ProcessError error);
72 void ProcReadStandardError(void);
73 void ProcReadStandardOutput(void);
74
75 void Close(void);
76 void StartStreaming(const QString & serial);
77 void StopStreaming(const QString & serial, bool silent);
78 void LockTimeout(const QString & serial);
79 void HasTuner(const QString & serial);
80 void Cleanup(void);
81 void DataStarted(void);
82 void LoadChannels(const QString & serial);
83 void FirstChannel(const QString & serial);
84 void NextChannel(const QString & serial);
85
86 void NewEpisodeStarting(void);
87 void TuneChannel(const QString & serial, const QVariantMap & chaninfo);
88 void TuneStatus(const QString & serial);
89 void HasPictureAttributes(const QString & serial);
90 void SetBlockSize(const QString & serial, int blksz);
91
92 protected:
93 void GetChannel(const QString & serial, const QString & func);
94 void TerminateProcess(QProcess & proc, const QString & desc) const;
95
96 private:
97 bool config(void);
98 static QString sanitize_var(const QString & var);
99 QString replace_extra_args(const QString & var,
100 const QVariantMap & extra_args) const;
101
102 mutable bool m_terminating { false };
103 bool m_fatal { false };
104 QString m_fatalMsg;
105
106 std::atomic<bool> m_run { true };
107 std::condition_variable m_runCond;
108 std::mutex m_runMutex;
109 std::atomic<bool> m_streaming { false };
110 int m_result { 0 };
111
112 uint m_bufferMax { 188 * 10000 };
114
115 QProcess m_proc;
116 QString m_command;
117 QString m_cleanup;
118
120 QString m_recDesc;
121
122 QMap<QString, QString> m_appEnv;
123 QMap<QString, QString> m_settingVars;
124 QVariantMap m_chaninfo;
125
126 QProcess m_tuneProc;
133
135 uint m_scanTimeout { 120000 };
136
137 QString m_logFile;
138 QString m_logging;
139 QString m_configIni;
140 QString m_desc;
141
144
145 // Channel scanning
146 QSettings *m_chanSettings { nullptr };
147 QStringList m_channels;
148 int m_channelIdx { -1 };
149
150};
151
152#endif // MYTHTVEXTERNRECAPP_H
void LockTimeout(const QString &serial)
QString replace_extra_args(const QString &var, const QVariantMap &extra_args) const
std::atomic< bool > m_run
void StartStreaming(const QString &serial)
void TerminateProcess(QProcess &proc, const QString &desc) const
void ProcFinished(int exitCode, QProcess::ExitStatus exitStatus)
void SetDescription(const QString &desc)
void ProcReadStandardError(void)
void Streaming(bool val)
void NewEpisodeStarting(void)
std::condition_variable m_runCond
void Done(void)
void GetChannel(const QString &serial, const QString &func)
MythExternRecApp(QString command, QString conf_file, QString log_file, QString logging)
void ProcReadStandardOutput(void)
~MythExternRecApp(void) override
QMap< QString, QString > m_settingVars
QStringList m_channels
QMap< QString, QString > m_appEnv
void TuneChannel(const QString &serial, const QVariantMap &chaninfo)
void Opened(void)
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
QVariantMap m_chaninfo
void MythLog(const QString &msg)
void ProcStateChanged(QProcess::ProcessState newState)
void HasTuner(const QString &serial)
void FirstChannel(const QString &serial)
void Fill(const QByteArray &buffer)
void StopStreaming(const QString &serial, bool silent)
std::atomic< bool > m_streaming
void LoadChannels(const QString &serial)
QSettings * m_chanSettings
void NextChannel(const QString &serial)
QString Desc(void) const
void ErrorMessage(const QString &msg)
void TuneStatus(const QString &serial)
void ProcError(QProcess::ProcessError error)
void SetBlockSize(const QString &serial, int blksz)
static QString sanitize_var(const QString &var)
void ReplaceVariables(QString &cmd) const
void HasPictureAttributes(const QString &serial)
void SetErrorMsg(const QString &msg)
unsigned int uint
Definition: freesurround.h:24
def error(message)
Definition: smolt.py:409