MythTV master
mythsystem.h
Go to the documentation of this file.
1/* -*- Mode: c++ -*-
2 * Class MythSystem
3 *
4 * Copyright (C) Daniel Kristjansson 2013
5 * Copyright (C) Gavin Hurlbut 2012
6 * Copyright (C) Issac Richards 2008
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef MYTHSYSTEM_H_
24#define MYTHSYSTEM_H_
25
26// Qt headers
27#include <QIODevice>
28#include <QString>
29
30// MythTV headers
31#include "mythbaseexp.h"
32#include "mythchrono.h"
33
35 kMSNone = 0x00000000,
36 kMSDontBlockInputDevs = 0x00000001,
37 kMSDontDisableDrawing = 0x00000002,
38 kMSRunBackground = 0x00000004,
39 kMSProcessEvents = 0x00000008,
40 kMSStdIn = 0x00000020,
41 kMSStdOut = 0x00000040,
42 kMSStdErr = 0x00000080,
43 kMSRunShell = 0x00000200,
44 kMSAnonLog = 0x00000800,
45 kMSAutoCleanup = 0x00004000,
47 kMSLowExitVal = 0x00008000,
48 // ^ FIXME Eliminate? appears to be a hack for some "ubuntu", but
49 // doesn't appear to be needed with ubuntu 12.04
50 kMSDisableUDPListener = 0x00010000,
52 kMSPropagateLogs = 0x00020000,
54};
55
56enum MythSignal : std::uint8_t {
69};
70
81{
82 public:
84 enum Priority : std::uint8_t {
85 kIdlePriority = 0,
93 };
94
95 static MythSystem *Create(
96 const QStringList &args,
97 uint flags = kMSNone,
98 const QString& startPath = QString(),
99 Priority cpuPriority = kInheritPriority,
100 Priority diskPriority = kInheritPriority);
101
102 static MythSystem *Create(
103 const QString& args,
104 uint flags = kMSNone,
105 const QString& startPath = QString(),
106 Priority cpuPriority = kInheritPriority,
107 Priority diskPriority = kInheritPriority);
108
109 virtual ~MythSystem(void) = default;
110
111 // Deleted functions should be public.
112 MythSystem(const MythSystem&) = delete; // no-implementation
113 MythSystem& operator= (const MythSystem&) = delete; // no-implementation
114
116 virtual uint GetFlags(void) const = 0;
117
119 virtual QString GetStartingPath(void) const = 0;
120
122 virtual Priority GetCPUPriority(void) const = 0;
123
125 virtual Priority GetDiskPriority(void) const = 0;
126
132 virtual bool Wait(std::chrono::milliseconds timeout = 0ms) = 0;
133
137 virtual QIODevice *GetStandardInputStream(void) = 0;
138
142 virtual QIODevice *GetStandardOutputStream(void) = 0;
143
147 virtual QIODevice *GetStandardErrorStream(void) = 0;
148
150 virtual void Signal(MythSignal) = 0;
151
158 virtual int GetExitCode(void) const = 0;
159
160 protected:
161 MythSystem() = default;
162};
163
164#endif // MYTHSYSTEM_H_
165
166/* vim:ts=4:sw=4:ai:et:si:sts=4 */
class for managing sub-processes.
Definition: mythsystem.h:81
virtual bool Wait(std::chrono::milliseconds timeout=0ms)=0
Blocks until child process is collected or timeout reached.
virtual QString GetStartingPath(void) const =0
Returns the starting path of the program.
MythSystem(const MythSystem &)=delete
virtual uint GetFlags(void) const =0
Returns the flags passed to the constructor.
virtual QIODevice * GetStandardErrorStream(void)=0
Returns the standard error stream for the program if the kMSStdErr flag was passed to the constructor...
MythSystem()=default
virtual QIODevice * GetStandardOutputStream(void)=0
Returns the standard output stream for the program if the kMSStdOut flag was passed to the constructo...
Priority
Priorities that can be used for cpu and disk usage of child process.
Definition: mythsystem.h:84
@ kHighestPriority
Definition: mythsystem.h:90
@ kLowestPriority
Definition: mythsystem.h:86
@ kHighPriority
Definition: mythsystem.h:89
@ kNormalPriority
run as a normal program
Definition: mythsystem.h:88
@ kInheritPriority
Use parent priority.
Definition: mythsystem.h:92
@ kTimeCriticalPriority
Definition: mythsystem.h:91
@ kLowPriority
Definition: mythsystem.h:87
virtual Priority GetCPUPriority(void) const =0
Return the CPU Priority of the program.
virtual void Signal(MythSignal)=0
Sends the selected signal to the program.
virtual int GetExitCode(void) const =0
returns the exit code, if any, that the program returned.
virtual ~MythSystem(void)=default
virtual Priority GetDiskPriority(void) const =0
Return the Disk Priority of the program.
virtual QIODevice * GetStandardInputStream(void)=0
Returns the standard input stream for the program if the kMSStdIn flag was passed to the constructor.
unsigned int uint
Definition: freesurround.h:24
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythSignal
Definition: mythsystem.h:56
@ kSignalContinue
Definition: mythsystem.h:61
@ kSignalSegfault
Definition: mythsystem.h:63
@ kSignalUser1
Definition: mythsystem.h:65
@ kSignalQuit
Definition: mythsystem.h:62
@ kSignalInterrupt
Definition: mythsystem.h:60
@ kSignalHangup
Definition: mythsystem.h:59
@ kSignalNone
Definition: mythsystem.h:57
@ kSignalUser2
Definition: mythsystem.h:66
@ kSignalUnknown
Definition: mythsystem.h:58
@ kSignalStop
Definition: mythsystem.h:68
@ kSignalKill
Definition: mythsystem.h:64
@ kSignalTerm
Definition: mythsystem.h:67
MythSystemFlag
Definition: mythsystem.h:34
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:36
@ kMSProcessEvents
process events while waiting
Definition: mythsystem.h:39
@ kMSStdIn
allow access to stdin
Definition: mythsystem.h:40
@ kMSStdErr
allow access to stderr
Definition: mythsystem.h:42
@ kMSPropagateLogs
add arguments for MythTV log propagation
Definition: mythsystem.h:52
@ kMSStdOut
allow access to stdout
Definition: mythsystem.h:41
@ kMSLowExitVal
allow exit values 0-127 only
Definition: mythsystem.h:47
@ kMSNone
Definition: mythsystem.h:35
@ kMSRunShell
run process through shell
Definition: mythsystem.h:43
@ kMSDisableUDPListener
disable MythMessage UDP listener for the duration of application.
Definition: mythsystem.h:50
@ kMSAnonLog
anonymize the logs
Definition: mythsystem.h:44
@ kMSRunBackground
run child in the background
Definition: mythsystem.h:38
@ kMSDontDisableDrawing
avoid disabling UI drawing
Definition: mythsystem.h:37
@ kMSAutoCleanup
automatically delete if backgrounded
Definition: mythsystem.h:45