1 #ifndef MYTHCORECONTEXT_H_
2 #define MYTHCORECONTEXT_H_
6 #include <QHostAddress>
19 #define MYTH_APPNAME_MYTHBACKEND "mythbackend"
20 #define MYTH_APPNAME_MYTHJOBQUEUE "mythjobqueue"
21 #define MYTH_APPNAME_MYTHFRONTEND "mythfrontend"
22 #define MYTH_APPNAME_MYTHTV_SETUP "mythtv-setup"
23 #define MYTH_APPNAME_MYTHFILLDATABASE "mythfilldatabase"
24 #define MYTH_APPNAME_MYTHCOMMFLAG "mythcommflag"
25 #define MYTH_APPNAME_MYTHCCEXTRACTOR "mythccextractor"
26 #define MYTH_APPNAME_MYTHPREVIEWGEN "mythpreviewgen"
27 #define MYTH_APPNAME_MYTHTRANSCODE "mythtranscode"
28 #define MYTH_APPNAME_MYTHWELCOME "mythwelcome"
29 #define MYTH_APPNAME_MYTHSHUTDOWN "mythshutdown"
30 #define MYTH_APPNAME_MYTHLCDSERVER "mythlcdserver"
31 #define MYTH_APPNAME_MYTHAVTEST "mythavtest"
32 #define MYTH_APPNAME_MYTHMEDIASERVER "mythmediaserver"
33 #define MYTH_APPNAME_MYTHMETADATALOOKUP "mythmetadatalookup"
34 #define MYTH_APPNAME_MYTHUTIL "mythutil"
35 #define MYTH_APPNAME_MYTHSCREENWIZARD "mythscreenwizard"
36 #define MYTH_APPNAME_MYTHFFPROBE "mythffprobe"
37 #define MYTH_APPNAME_MYTHEXTERNRECORDER "mythexternrecorder"
71 void SetLocalHostname(
const QString &
hostname);
76 bool SafeConnectToMasterServer(
bool blockingClient =
true,
77 bool openEventSocket =
true);
78 bool ConnectToMasterServer(
bool blockingClient =
true,
79 bool openEventSocket =
true);
82 const QString &announcement,
83 bool *proto_mismatch =
nullptr,
85 std::chrono::milliseconds setup_timeout = -1ms);
89 bool SetupCommandSocket(
MythSocket *serverSock,
const QString &announcement,
90 std::chrono::milliseconds
timeout,
bool &proto_mismatch);
94 bool error_dialog_desired =
false);
96 static QString GenMythURL(
const QString& host = QString(),
int port = 0,
97 QString path = QString(),
98 const QString& storageGroup = QString());
100 QString GetMasterHostPrefix(
const QString &storageGroup = QString(),
101 const QString &path = QString());
102 QString GetMasterHostName(
void);
103 QString GetHostName(
void);
104 QString GetFilePrefix(
void);
106 bool IsConnectedToMaster(
void);
107 void SetAsBackend(
bool backend);
108 bool IsBackend(
void)
const;
109 void SetAsFrontend(
bool frontend);
110 bool IsFrontend(
void)
const;
111 bool IsFrontendOnly(
void);
112 bool IsMasterHost(
void);
114 bool IsMasterHost(
const QString &host);
116 static bool BackendIsRunning(
void);
118 bool IsThisBackend(
const QString &addr);
119 bool IsThisHost(
const QString &addr);
120 bool IsThisHost(
const QString &addr,
const QString &host);
122 void BlockShutdown(
void);
123 void AllowShutdown(
void);
124 bool IsBlockingClient(
void)
const;
126 void SetWOLAllowed(
bool allow);
127 bool IsWOLAllowed()
const;
129 bool SendReceiveStringList(QStringList &strlist,
bool quickTimeout =
false,
134 void SendHostSystemEvent(
const QString &msg,
const QString &
hostname,
135 const QString &
args);
137 void SetGUIObject(QObject *gui);
138 QObject *GetGUIObject(
void);
139 QObject *GetGUIContext(
void);
140 bool HasGUI(
void)
const;
141 bool IsUIThread(
void);
147 bool IsDatabaseIgnored(
void)
const;
149 {
return GetDB()->GetDatabaseParams(); }
151 void SaveSetting(
const QString &key,
int newValue);
152 void SaveSetting(
const QString &key,
const QString &newValue);
153 QString GetSetting(
const QString &key,
const QString &defaultval =
"");
155 template <
typename T>
156 typename std::enable_if_t<std::chrono::__is_duration<T>::value,
void>
158 { SaveSetting(key,
static_cast<int>(newValue.count())); }
160 bool SaveSettingOnHost(
const QString &key,
const QString &newValue,
161 const QString &host);
163 { SaveSetting(key,
static_cast<int>(newValue)); }
166 bool GetBoolSetting(
const QString &key,
bool defaultval =
false);
167 int GetNumSetting(
const QString &key,
int defaultval = 0);
168 template <
typename T>
169 typename std::enable_if_t<std::chrono::__is_duration<T>::value, T>
171 {
return T(GetNumSetting(key,
static_cast<int>(defaultval.count()))); }
172 int GetBoolSetting(
const QString &key,
int defaultval) =
delete;
173 bool GetNumSetting(
const QString &key,
bool defaultvalue) =
delete;
174 double GetFloatSetting(
const QString &key,
double defaultval = 0.0);
175 void GetResolutionSetting(
const QString &
type,
int &width,
int &height,
176 double& forced_aspect,
double &refresh_rate,
178 void GetResolutionSetting(
const QString &
type,
int &width,
int &height,
181 QString GetSettingOnHost(
const QString &key,
const QString &host,
182 const QString &defaultval =
"");
183 bool GetBoolSettingOnHost(
const QString &key,
const QString &host,
184 bool defaultval =
false);
185 int GetNumSettingOnHost(
const QString &key,
const QString &host,
187 int GetBoolSettingOnHost(
const QString &key,
const QString &host,
188 int defaultval) =
delete;
189 bool GetNumSettingOnHost(
const QString &key,
const QString &host,
190 bool defaultval =
false) =
delete;
191 double GetFloatSettingOnHost(
const QString &key,
const QString &host,
192 double defaultval = 0.0);
194 QString GetBackendServerIP(
void);
195 QString GetBackendServerIP(
const QString &host);
196 QString GetBackendServerIP4(
void);
197 QString GetBackendServerIP4(
const QString &host);
198 QString GetBackendServerIP6(
void);
199 QString GetBackendServerIP6(
const QString &host);
200 QString GetMasterServerIP(
void);
201 static int GetMasterServerPort(
void);
202 int GetMasterServerStatusPort(
void);
203 int GetBackendServerPort(
void);
204 int GetBackendServerPort(
const QString &host);
205 int GetBackendStatusPort(
void);
206 int GetBackendStatusPort(
const QString &host);
208 bool GetScopeForAddress(QHostAddress &addr)
const;
209 void SetScopeForAddress(
const QHostAddress &addr);
210 void SetScopeForAddress(
const QHostAddress &addr,
int scope);
211 enum ResolveType { ResolveAny = -1, ResolveIPv4 = 0, ResolveIPv6 = 1 };
212 QString resolveSettingAddress(
const QString &name,
213 const QString &host = QString(),
214 ResolveType
type = ResolveAny,
215 bool keepscope =
false);
216 static QString resolveAddress(
const QString &host,
217 ResolveType
type = ResolveAny,
218 bool keepscope =
false) ;
219 bool CheckSubnet(
const QAbstractSocket *socket);
220 bool CheckSubnet(
const QHostAddress &peer);
223 void ActivateSettingsCache(
bool activate =
true);
224 void OverrideSettingForSession(
const QString &key,
const QString &value);
225 void ClearOverrideSettingForSession(
const QString &key);
229 void InitPower(
bool Create =
true);
230 void InitLocale(
void);
231 void ReInitLocale(
void);
233 QLocale GetQLocale(
void);
234 void SaveLocaleDefaults(
void);
235 QString GetLanguage(
void);
236 QString GetLanguageAndVariant(
void);
237 void ResetLanguage(
void);
238 void ResetSockets(
void);
250 template <
class OBJ,
typename SLOT>
251 typename std::enable_if_t<std::is_member_function_pointer_v<SLOT>,
void>
254 RegisterForPlayback(qobject_cast<QObject*>(sender),
258 void UnregisterForPlayback(QObject *sender);
259 void WantingPlayback(QObject *sender);
260 bool InWantingPlayback(
void);
261 void TVInWantingPlayback(
bool b);
266 static bool TestPluginVersion(
const QString &name,
const QString &libversion,
267 const QString &pluginversion);
273 void SetExiting(
bool exiting =
true);
274 bool IsExiting(
void);
276 void RegisterFileForWrite(
const QString &
file, uint64_t size = 0LL);
277 void UnregisterFileForWrite(
const QString &
file);
278 bool IsRegisteredFileForWrite(
const QString &
file);
281 void setTestIntSettings(QMap<QString,int>& overrides);
282 void setTestFloatSettings(QMap<QString,double>& overrides);
283 void setTestStringSettings(QMap<QString,QString>& overrides);
286 void WaitUntilSignals(std::vector<CoreWaitInfo> & sigs)
const;
290 emit TVPlaybackSought();}
298 void TVPlaybackStarted(
void);
301 void TVPlaybackStopped(
void);
302 void TVPlaybackSought(qint64 position);
303 void TVPlaybackSought(
void);
304 void TVPlaybackPaused(
void);
305 void TVPlaybackUnpaused(
void);
306 void TVPlaybackAborted(
void);
307 void TVPlaybackAboutToStart(
void);
308 void TVPlaybackPlaying(
void);
319 QMap<QString,int> m_testOverrideInts {};
320 QMap<QString,double> m_testOverrideFloats {};
321 QMap<QString,QString> m_testOverrideStrings {};
324 bool m_dvbv3 {
false};