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 
35 class MythExternControl;
36 
37 class 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 
119  QString m_recCommand;
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;
128  QString m_tuneCommand;
129  QString m_onDataStart;
131  QString m_channelsIni;
133 
134  QString m_scanCommand;
135  uint m_scanTimeout { 120000 };
136 
137  QString m_logFile;
138  QString m_logging;
139  QString m_configIni;
140  QString m_desc;
141 
143  QString m_tunedChannel;
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
MythExternRecApp::SetDescription
void SetDescription(const QString &desc)
MythExternRecApp::HasTuner
void HasTuner(const QString &serial)
Definition: MythExternRecApp.cpp:881
MythExternRecApp::m_chaninfo
QVariantMap m_chaninfo
Definition: MythExternRecApp.h:124
MythExternRecApp::TuneChannel
void TuneChannel(const QString &serial, const QVariantMap &chaninfo)
Definition: MythExternRecApp.cpp:682
MythExternRecApp::m_runMutex
std::mutex m_runMutex
Definition: MythExternRecApp.h:108
MythExternRecApp::m_recCommand
QString m_recCommand
Definition: MythExternRecApp.h:119
MythExternRecApp::m_onDataStart
QString m_onDataStart
Definition: MythExternRecApp.h:129
error
static void error(const char *str,...)
Definition: vbi.cpp:37
MythExternRecApp::StopStreaming
void StopStreaming(const QString &serial, bool silent)
Definition: MythExternRecApp.cpp:954
MythExternRecApp::Streaming
void Streaming(bool val)
MythExternRecApp::MythExternRecApp
MythExternRecApp(QString command, QString conf_file, QString log_file, QString logging)
Definition: MythExternRecApp.cpp:40
MythExternRecApp::ProcFinished
void ProcFinished(int exitCode, QProcess::ExitStatus exitStatus)
Definition: MythExternRecApp.cpp:992
MythExternRecApp::m_blockSize
uint m_blockSize
Definition: MythExternRecApp.h:113
MythExternRecApp::NewEpisodeStarting
void NewEpisodeStarting(void)
Definition: MythExternRecApp.cpp:632
MythExternRecApp::m_run
std::atomic< bool > m_run
Definition: MythExternRecApp.h:106
MythExternRecApp::m_command
QString m_command
Definition: MythExternRecApp.h:116
MythExternRecApp::TerminateProcess
void TerminateProcess(QProcess &proc, const QString &desc) const
Definition: MythExternRecApp.cpp:328
MythExternRecApp::m_tuneProc
QProcess m_tuneProc
Definition: MythExternRecApp.h:126
MythExternRecApp::MythLog
void MythLog(const QString &msg)
Definition: MythExternRecApp.h:51
MythExternRecApp::Run
void Run(void)
Definition: MythExternRecApp.cpp:374
MythExternRecApp::Done
void Done(void)
MythExternRecApp::m_channels
QStringList m_channels
Definition: MythExternRecApp.h:147
MythExternRecApp::Open
bool Open(void)
Definition: MythExternRecApp.cpp:269
MythExternRecApp::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
Definition: MythExternRecApp.cpp:892
MythExternRecApp::m_tuneCommand
QString m_tuneCommand
Definition: MythExternRecApp.h:128
MythExternRecApp::m_recDesc
QString m_recDesc
Definition: MythExternRecApp.h:120
MythExternRecApp::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
Definition: MythExternRecApp.cpp:887
MythExternRecApp::TuneStatus
void TuneStatus(const QString &serial)
Definition: MythExternRecApp.cpp:829
MythExternRecApp::LockTimeout
void LockTimeout(const QString &serial)
Definition: MythExternRecApp.cpp:858
MythExternRecApp::m_cleanup
QString m_cleanup
Definition: MythExternRecApp.h:117
MythExternRecApp::Close
void Close(void)
Definition: MythExternRecApp.cpp:348
MythExternRecApp::m_streaming
std::atomic< bool > m_streaming
Definition: MythExternRecApp.h:109
MythExternRecApp::SetErrorMsg
void SetErrorMsg(const QString &msg)
Definition: MythExternRecApp.h:53
MythExternRecApp::m_logging
QString m_logging
Definition: MythExternRecApp.h:138
MythExternRecApp::Opened
void Opened(void)
MythExternRecApp::m_newEpisodeCommand
QString m_newEpisodeCommand
Definition: MythExternRecApp.h:130
MythExternRecApp::LoadChannels
void LoadChannels(const QString &serial)
Definition: MythExternRecApp.cpp:511
MythExternRecApp::m_tuningChannel
QString m_tuningChannel
Definition: MythExternRecApp.h:142
MythExternRecApp::m_result
int m_result
Definition: MythExternRecApp.h:110
MythExternRecApp::Cleanup
void Cleanup(void)
Definition: MythExternRecApp.cpp:407
MythExternRecApp::SendMessage
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
MythExternRecApp::m_configIni
QString m_configIni
Definition: MythExternRecApp.h:139
MythExternRecApp::m_lockTimeout
uint m_lockTimeout
Definition: MythExternRecApp.h:132
MythExternRecApp::ProcReadStandardOutput
void ProcReadStandardOutput(void)
Definition: MythExternRecApp.cpp:1087
MythExternRecApp
Definition: MythExternRecApp.h:37
MythExternRecApp::m_terminating
bool m_terminating
Definition: MythExternRecApp.h:102
MythExternRecApp::ProcReadStandardError
void ProcReadStandardError(void)
Definition: MythExternRecApp.cpp:1049
MythExternRecApp::ErrorMessage
void ErrorMessage(const QString &msg)
MythExternRecApp::GetChannel
void GetChannel(const QString &serial, const QString &func)
Definition: MythExternRecApp.cpp:578
MythExternRecApp::sanitize_var
static QString sanitize_var(const QString &var)
Definition: MythExternRecApp.cpp:73
uint
unsigned int uint
Definition: compat.h:81
MythExternRecApp::NextChannel
void NextChannel(const QString &serial)
Definition: MythExternRecApp.cpp:627
MythExternRecApp::m_chanSettings
QSettings * m_chanSettings
Definition: MythExternRecApp.h:146
MythExternRecApp::m_finishTuneProc
QProcess m_finishTuneProc
Definition: MythExternRecApp.h:127
MythExternRecApp::ProcError
void ProcError(QProcess::ProcessError error)
Definition: MythExternRecApp.cpp:1033
MythExternRecApp::~MythExternRecApp
~MythExternRecApp(void) override
Definition: MythExternRecApp.cpp:66
MythExternRecApp::m_desc
QString m_desc
Definition: MythExternRecApp.h:140
MythExternRecApp::m_logFile
QString m_logFile
Definition: MythExternRecApp.h:137
MythExternRecApp::m_bufferMax
uint m_bufferMax
Definition: MythExternRecApp.h:112
MythExternRecApp::m_channelIdx
int m_channelIdx
Definition: MythExternRecApp.h:148
MythExternControl
Definition: MythExternControl.h:124
MythExternRecApp::m_settingVars
QMap< QString, QString > m_settingVars
Definition: MythExternRecApp.h:123
MythExternRecApp::m_tunedChannel
QString m_tunedChannel
Definition: MythExternRecApp.h:143
MythExternRecApp::FirstChannel
void FirstChannel(const QString &serial)
Definition: MythExternRecApp.cpp:621
MythExternRecApp::config
bool config(void)
Definition: MythExternRecApp.cpp:158
MythExternRecApp::m_fatal
bool m_fatal
Definition: MythExternRecApp.h:103
MythExternRecApp::DataStarted
void DataStarted(void)
Definition: MythExternRecApp.cpp:443
MythExternRecApp::ReplaceVariables
void ReplaceVariables(QString &cmd) const
Definition: MythExternRecApp.cpp:124
MythExternRecApp::Desc
QString Desc(void) const
Definition: MythExternRecApp.cpp:145
MythExternRecApp::StartStreaming
void StartStreaming(const QString &serial)
Definition: MythExternRecApp.cpp:898
MythExternRecApp::m_scanCommand
QString m_scanCommand
Definition: MythExternRecApp.h:134
MythExternRecApp::replace_extra_args
QString replace_extra_args(const QString &var, const QVariantMap &extra_args) const
Definition: MythExternRecApp.cpp:101
MythExternRecApp::m_channelsIni
QString m_channelsIni
Definition: MythExternRecApp.h:131
MythExternRecApp::ProcStarted
void ProcStarted(void)
Definition: MythExternRecApp.cpp:985
MythExternRecApp::m_appEnv
QMap< QString, QString > m_appEnv
Definition: MythExternRecApp.h:122
MythExternRecApp::m_runCond
std::condition_variable m_runCond
Definition: MythExternRecApp.h:107
MythExternRecApp::m_proc
QProcess m_proc
Definition: MythExternRecApp.h:115
MythExternRecApp::m_fatalMsg
QString m_fatalMsg
Definition: MythExternRecApp.h:104
MythExternRecApp::m_scanTimeout
uint m_scanTimeout
Definition: MythExternRecApp.h:135
MythExternRecApp::Fill
void Fill(const QByteArray &buffer)
MythExternRecApp::ProcStateChanged
void ProcStateChanged(QProcess::ProcessState newState)
Definition: MythExternRecApp.cpp:1007