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 <QObject>
25 #include <QtCore/QtCore>
26 
27 #include <atomic>
28 #include <condition_variable>
29 
30 class MythExternControl;
31 
32 class MythExternRecApp : public QObject
33 {
34  Q_OBJECT
35 
36  public:
37  MythExternRecApp(QString command, QString conf_file,
38  QString log_file, QString logging);
39  ~MythExternRecApp(void) override;
40 
41  bool Open(void);
42  void Run(void);
43 
44  QString Desc(void) const;
45  void MythLog(const QString & msg)
46  { SendMessage("", "0", QString("STATUS:%1").arg(msg)); }
47  void SetErrorMsg(const QString & msg) { emit ErrorMessage(msg); }
48 
49  signals:
50  void SetDescription(const QString & desc);
51  void SendMessage(const QString & func, const QString & serial,
52  const QString & msg);
53  void ErrorMessage(const QString & msg);
54  void Opened(void);
55  void Done(void);
56  void Streaming(bool val);
57  void Fill(const QByteArray & buffer);
58 
59  public slots:
60  void ProcStarted(void);
61  void ProcFinished(int exitCode, QProcess::ExitStatus exitStatus);
62  void ProcStateChanged(QProcess::ProcessState newState);
63  void ProcError(QProcess::ProcessError error);
64  void ProcReadStandardError(void);
65  void ProcReadStandardOutput(void);
66 
67  void Close(void);
68  void StartStreaming(const QString & serial);
69  void StopStreaming(const QString & serial, bool silent);
70  void LockTimeout(const QString & serial);
71  void HasTuner(const QString & serial);
72  void Cleanup(void);
73  void DataStarted(void);
74  void LoadChannels(const QString & serial);
75  void FirstChannel(const QString & serial);
76  void NextChannel(const QString & serial);
77 
78  void NewEpisodeStarting(const QString & channum);
79  void TuneChannel(const QString & serial, const QString & channum);
80  void TuneStatus(const QString & serial);
81  void HasPictureAttributes(const QString & serial);
82  void SetBlockSize(const QString & serial, int blksz);
83 
84  protected:
85  void GetChannel(const QString & serial, const QString & func);
86  void TerminateProcess(QProcess & proc, const QString & desc) const;
87 
88  private:
89  bool config(void);
90 
91  bool m_fatal { false };
92 
93  std::atomic<bool> m_run { true };
94  std::condition_variable m_runCond;
95  std::mutex m_runMutex;
96  std::atomic<bool> m_streaming { false };
97  int m_result { 0 };
98 
99  uint m_bufferMax { 188 * 10000 };
101 
102  QProcess m_proc;
103  QString m_command;
104  QString m_cleanup;
105 
106  QString m_recCommand;
107  QString m_recDesc;
108 
109  QMap<QString, QString> m_appEnv;
110 
111  QProcess m_tuneProc;
112  QString m_tuneCommand;
113  QString m_onDataStart;
115  QString m_channelsIni;
117 
118  QString m_scanCommand;
119  uint m_scanTimeout { 120000 };
120 
121  QString m_logFile;
122  QString m_logging;
123  QString m_configIni;
124  QString m_desc;
125 
127  QString m_tunedChannel;
128 
129  // Channel scanning
130  QSettings *m_chanSettings { nullptr };
131  QStringList m_channels;
132  int m_channelIdx { -1 };
133 
134 };
135 
136 #endif // MYTHTVEXTERNRECAPP_H
MythExternRecApp::SetDescription
void SetDescription(const QString &desc)
MythExternRecApp::HasTuner
void HasTuner(const QString &serial)
Definition: MythExternRecApp.cpp:663
MythExternRecApp::m_runMutex
std::mutex m_runMutex
Definition: MythExternRecApp.h:95
MythExternRecApp::m_recCommand
QString m_recCommand
Definition: MythExternRecApp.h:106
MythExternRecApp::m_onDataStart
QString m_onDataStart
Definition: MythExternRecApp.h:113
error
static void error(const char *str,...)
Definition: vbi.cpp:42
MythExternRecApp::StopStreaming
void StopStreaming(const QString &serial, bool silent)
Definition: MythExternRecApp.cpp:735
MythExternRecApp::Streaming
void Streaming(bool val)
MythExternRecApp::MythExternRecApp
MythExternRecApp(QString command, QString conf_file, QString log_file, QString logging)
Definition: MythExternRecApp.cpp:35
MythExternRecApp::ProcFinished
void ProcFinished(int exitCode, QProcess::ExitStatus exitStatus)
Definition: MythExternRecApp.cpp:773
MythExternRecApp::m_blockSize
uint m_blockSize
Definition: MythExternRecApp.h:100
MythExternRecApp::m_run
std::atomic< bool > m_run
Definition: MythExternRecApp.h:93
MythExternRecApp::m_command
QString m_command
Definition: MythExternRecApp.h:103
MythExternRecApp::TerminateProcess
void TerminateProcess(QProcess &proc, const QString &desc) const
Definition: MythExternRecApp.cpp:184
MythExternRecApp::m_tuneProc
QProcess m_tuneProc
Definition: MythExternRecApp.h:111
MythExternRecApp::MythLog
void MythLog(const QString &msg)
Definition: MythExternRecApp.h:45
MythExternRecApp::Run
void Run(void)
Definition: MythExternRecApp.cpp:235
arg
arg(title).arg(filename).arg(doDelete))
MythExternRecApp::Done
void Done(void)
slots
unsigned int slots[4]
Definition: element.cpp:38
MythExternRecApp::m_channels
QStringList m_channels
Definition: MythExternRecApp.h:131
MythExternRecApp::Open
bool Open(void)
Definition: MythExternRecApp.cpp:125
MythExternRecApp::NewEpisodeStarting
void NewEpisodeStarting(const QString &channum)
Definition: MythExternRecApp.cpp:463
MythExternRecApp::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
Definition: MythExternRecApp.cpp:675
MythExternRecApp::m_tuneCommand
QString m_tuneCommand
Definition: MythExternRecApp.h:112
MythExternRecApp::m_recDesc
QString m_recDesc
Definition: MythExternRecApp.h:107
MythExternRecApp::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
Definition: MythExternRecApp.cpp:670
MythExternRecApp::TuneStatus
void TuneStatus(const QString &serial)
Definition: MythExternRecApp.cpp:609
MythExternRecApp::TuneChannel
void TuneChannel(const QString &serial, const QString &channum)
Definition: MythExternRecApp.cpp:496
MythExternRecApp::LockTimeout
void LockTimeout(const QString &serial)
Definition: MythExternRecApp.cpp:639
MythExternRecApp::m_cleanup
QString m_cleanup
Definition: MythExternRecApp.h:104
MythExternRecApp::Close
void Close(void)
Definition: MythExternRecApp.cpp:209
MythExternRecApp::m_streaming
std::atomic< bool > m_streaming
Definition: MythExternRecApp.h:96
MythExternRecApp::SetErrorMsg
void SetErrorMsg(const QString &msg)
Definition: MythExternRecApp.h:47
MythExternRecApp::m_logging
QString m_logging
Definition: MythExternRecApp.h:122
MythExternRecApp::Opened
void Opened(void)
MythExternRecApp::m_newEpisodeCommand
QString m_newEpisodeCommand
Definition: MythExternRecApp.h:114
MythExternRecApp::LoadChannels
void LoadChannels(const QString &serial)
Definition: MythExternRecApp.cpp:337
MythExternRecApp::m_tuningChannel
QString m_tuningChannel
Definition: MythExternRecApp.h:126
MythExternRecApp::m_result
int m_result
Definition: MythExternRecApp.h:97
MythExternRecApp::Cleanup
void Cleanup(void)
Definition: MythExternRecApp.cpp:268
MythExternRecApp::m_configIni
QString m_configIni
Definition: MythExternRecApp.h:123
MythExternRecApp::m_lockTimeout
uint m_lockTimeout
Definition: MythExternRecApp.h:116
MythExternRecApp::ProcReadStandardOutput
void ProcReadStandardOutput(void)
Definition: MythExternRecApp.cpp:839
MythExternRecApp
Definition: MythExternRecApp.h:32
MythExternRecApp::ProcReadStandardError
void ProcReadStandardError(void)
Definition: MythExternRecApp.cpp:822
MythExternRecApp::ErrorMessage
void ErrorMessage(const QString &msg)
MythExternRecApp::GetChannel
void GetChannel(const QString &serial, const QString &func)
Definition: MythExternRecApp.cpp:407
uint
unsigned int uint
Definition: compat.h:140
MythExternRecApp::NextChannel
void NextChannel(const QString &serial)
Definition: MythExternRecApp.cpp:458
MythExternRecApp::m_chanSettings
QSettings * m_chanSettings
Definition: MythExternRecApp.h:130
MythExternRecApp::ProcError
void ProcError(QProcess::ProcessError error)
Definition: MythExternRecApp.cpp:815
MythExternRecApp::~MythExternRecApp
~MythExternRecApp(void) override
Definition: MythExternRecApp.cpp:61
MythExternRecApp::m_desc
QString m_desc
Definition: MythExternRecApp.h:124
MythExternRecApp::m_logFile
QString m_logFile
Definition: MythExternRecApp.h:121
MythExternRecApp::m_bufferMax
uint m_bufferMax
Definition: MythExternRecApp.h:99
MythExternRecApp::m_channelIdx
int m_channelIdx
Definition: MythExternRecApp.h:132
MythExternControl
Definition: MythExternControl.h:120
MythExternRecApp::m_tunedChannel
QString m_tunedChannel
Definition: MythExternRecApp.h:127
MythExternRecApp::FirstChannel
void FirstChannel(const QString &serial)
Definition: MythExternRecApp.cpp:452
MythExternRecApp::config
bool config(void)
Definition: MythExternRecApp.cpp:76
MythExternRecApp::m_fatal
bool m_fatal
Definition: MythExternRecApp.h:91
MythExternRecApp::SendMessage
void SendMessage(const QString &func, const QString &serial, const QString &msg)
MythExternRecApp::DataStarted
void DataStarted(void)
Definition: MythExternRecApp.cpp:302
MythExternRecApp::Desc
QString Desc(void) const
Definition: MythExternRecApp.cpp:66
MythExternRecApp::StartStreaming
void StartStreaming(const QString &serial)
Definition: MythExternRecApp.cpp:681
MythExternRecApp::m_scanCommand
QString m_scanCommand
Definition: MythExternRecApp.h:118
MythExternRecApp::m_channelsIni
QString m_channelsIni
Definition: MythExternRecApp.h:115
MythExternRecApp::ProcStarted
void ProcStarted(void)
Definition: MythExternRecApp.cpp:766
MythExternRecApp::m_appEnv
QMap< QString, QString > m_appEnv
Definition: MythExternRecApp.h:109
MythExternRecApp::m_runCond
std::condition_variable m_runCond
Definition: MythExternRecApp.h:94
MythExternRecApp::m_proc
QProcess m_proc
Definition: MythExternRecApp.h:102
MythExternRecApp::m_scanTimeout
uint m_scanTimeout
Definition: MythExternRecApp.h:119
MythExternRecApp::Fill
void Fill(const QByteArray &buffer)
MythExternRecApp::ProcStateChanged
void ProcStateChanged(QProcess::ProcessState newState)
Definition: MythExternRecApp.cpp:789