5#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
6#include <QtSystemDetection>
8#include <QCoreApplication>
15#include <QWaitCondition>
16#include <QAbstractSocket>
17#include <QHostAddress>
19#include <QNetworkInterface>
20#include <QNetworkAddressEntry>
23#include <QRegularExpression>
49#include "mythversion.h"
58#define LOC QString("MythCoreContext::%1(): ").arg(__func__)
69 bool WaitForWOL(std::chrono::milliseconds
timeout = std::chrono::milliseconds::max());
135 m_guiContext(guicontext),
136 m_appBinaryVersion(
std::move(binversion)),
138 m_uiThread(QThread::currentThread())
144#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
145 QMutexLocker &locker,
147 QMutexLocker<QMutex> &locker,
192 GetMythDB()->GetDBManager()->CloseDatabases();
207 std::chrono::milliseconds timeout_remaining =
timeout;
210 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Wake-On-LAN in progress, waiting...");
212 std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
214 timeout_remaining -= max_wait;
230 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Out-of-memory");
236 LOG(VB_GENERAL, LOG_CRIT,
237 QString(
"Application binary version (%1) does not "
238 "match libraries (%2)")
241 QString warning = tr(
"This application is not compatible with the "
242 "installed MythTV libraries. Please recompile "
243 "after a make distclean");
244 LOG(VB_GENERAL, LOG_WARNING, warning);
250 static const QRegularExpression utf8
251 {
"utf-?8", QRegularExpression::CaseInsensitiveOption };
252 QString lang_variables(
"");
253 QString lc_value = setlocale(LC_CTYPE,
nullptr);
254 if (lc_value.isEmpty())
258 lc_value = qEnvironmentVariable(
"LC_ALL");
259 if (lc_value.isEmpty())
260 lc_value = qEnvironmentVariable(
"LC_CTYPE");
262 if (!lc_value.contains(utf8))
263 lang_variables.append(
"LC_ALL or LC_CTYPE");
264 lc_value = qEnvironmentVariable(
"LANG");
265 if (!lc_value.contains(utf8))
267 if (!lang_variables.isEmpty())
268 lang_variables.append(
", and ");
269 lang_variables.append(
"LANG");
271 LOG(VB_GENERAL, LOG_INFO, QString(
"Assumed character encoding: %1")
273 if (!lang_variables.isEmpty())
275 LOG(VB_GENERAL, LOG_WARNING, QString(
"This application expects to "
276 "be running a locale that specifies a UTF-8 codeset, and many "
277 "features may behave improperly with your current language "
278 "settings. Please set the %1 variable(s) in the environment "
279 "in which this program is executed to include a UTF-8 codeset "
280 "(such as 'en_US.UTF-8').").arg(lang_variables));
309 const QString &announcement,
310 [[maybe_unused]] std::chrono::milliseconds
timeout,
311 bool &proto_mismatch)
313 proto_mismatch =
false;
315#ifndef IGNORE_PROTO_VER_MISMATCH
318 proto_mismatch =
true;
323 QStringList strlist(announcement);
327 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Connecting server socket to "
328 "master backend, socket write failed");
333 strlist.empty() || (strlist[0] ==
"ERROR"))
335 if (!strlist.empty())
337 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Problem connecting "
338 "server socket to master backend");
342 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Timeout connecting "
343 "server socket to master backend");
353 bool openEventSocket)
364 bool openEventSocket)
370 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ERROR: Master backend tried to connect back "
378 if (server.isEmpty())
382 bool proto_mismatch =
false;
392 QString
type {
"Monitor" };
395 else if (blockingClient)
397 QString ann = QString(
"ANN %1 %2 %3")
400 server, port, ann, &proto_mismatch);
408 if (!openEventSocket)
427 QCoreApplication::postEvent(
438 const QString &
hostname,
int port,
const QString &announce,
439 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
453 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
455 std::chrono::seconds WOLsleepTime = 0s;
456 int WOLmaxConnTry = 0;
457 if (!WOLcmd.isEmpty())
459 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
460 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
461 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
464 bool we_attempted_wol =
false;
466 if (setup_timeout <= 0ms)
469 bool proto_mismatch =
false;
470 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
472 LOG(VB_GENERAL, LOG_INFO,
LOC +
473 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
474 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
478 std::chrono::microseconds sleepus = 0us;
482 serverSock, announce, setup_timeout, proto_mismatch))
489 if (p_proto_mismatch)
490 *p_proto_mismatch =
true;
493 serverSock =
nullptr;
497 setup_timeout += setup_timeout / 2;
499 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
501 if (!we_attempted_wol)
515 sleepus = WOLsleepTime;
519 serverSock =
nullptr;
523 QCoreApplication::postEvent(
528 usleep(sleepus.count());
531 if (we_attempted_wol)
538 if (!serverSock && !proto_mismatch)
540 LOG(VB_GENERAL, LOG_ERR,
541 "Connection to master server timed out.\n\t\t\t"
542 "Either the server is down or the master server settings"
544 "in mythtv-settings does not contain the proper IP address\n");
548 QCoreApplication::postEvent(
562 if (!eventSock->ConnectToHost(
hostname, port))
564 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
565 "socket to master backend");
566 eventSock->DecrRef();
570 QString str = QString(
"ANN Monitor %1 %2")
572 QStringList strlist(str);
573 eventSock->WriteStringList(strlist);
575 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
576 (strlist[0] ==
"ERROR"))
578 if (!strlist.empty())
580 LOG(VB_GENERAL, LOG_ERR,
LOC +
581 "Problem connecting event socket to master backend");
585 LOG(VB_GENERAL, LOG_ERR,
LOC +
586 "Timeout connecting event socket to master backend");
593 eventSock->DecrRef();
614 strlist <<
"BLOCK_SHUTDOWN";
628 strlist <<
"ALLOW_SHUTDOWN";
690 if (addr.toLower() == host.toLower())
692 QHostAddress addrfix(addr);
693 addrfix.setScopeId(QString());
694 QString addrstr = addrfix.toString();
695 if (addrfix.isNull())
699 return !addrstr.isEmpty()
700 && ((addrstr == thisip) || (addrstr == thisip6));
702 return GetSetting(
"MasterServerName") == host;
713 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
714#elif defined(Q_OS_WINDOWS)
715 const char *command =
"%systemroot%\\system32\\tasklist.exe "
716 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
718 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
738 if (addr.toLower() == host.toLower())
741 QHostAddress addrfix(addr);
742 addrfix.setScopeId(QString());
743 QString addrstr = addrfix.toString();
745 if (addrfix.isNull())
752 return !addrstr.isEmpty() && ((addrstr == thisip));
758 bool backendOnLocalhost =
false;
760 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
765 backendOnLocalhost = strlist[0] !=
"FALSE";
767 return !backendOnLocalhost;
776 QHostAddress addr(host);
779 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
780 "IP address instead of hostname "
781 "(ID). This is invalid.").arg(host, path));
787 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
788 m_host =
"[" + addr.toString().toLower() +
"]";
790 ret.setScheme(
"myth");
791 if (!storageGroup.isEmpty())
792 ret.setUserName(storageGroup);
794 if (port > 0 && port != 6543)
796 if (!path.startsWith(
"/"))
797 path = QString(
"/") + path;
801 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
802 QString(
"GenMythURL returning %1").arg(ret.toString()));
805 return ret.toString();
828 QStringList strlist(
"QUERY_HOSTNAME");
860 int &width,
int &height,
861 double &forced_aspect,
862 double &refresh_rate,
865 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
866 refresh_rate, index);
902 const QString &newValue,
905 return d->
m_database->SaveSettingOnHost(key, newValue, host);
909 const QString &defaultval)
918 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
926 return d->
m_database->GetNumSetting(key, defaultval);
933 return d->
m_database->GetFloatSetting(key, defaultval);
938 const QString &defaultval)
942 return d->
m_database->GetSettingOnHost(key, host, defaultval);
959 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
968 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
993 (
"MasterServerName");
995 (
"BackendServerPort", masterserver, 6543);
1121 QHostAddress addr1 = addr;
1122 addr1.setScopeId(QString());
1123 QString addrstr = addr1.toString();
1141 QHostAddress addr1 = addr;
1142 addr1.setScopeId(QString());
1145 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1155 QHostAddress addr1 = addr;
1156 addr1.setScopeId(QString());
1159 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1174 const QString &host,
1205 QHostAddress addr(host);
1207 if (!host.isEmpty() && addr.isNull())
1210 QHostInfo
info = QHostInfo::fromName(host);
1211 QList<QHostAddress> list =
info.addresses();
1215 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1216 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1223 for (
const auto& item : std::as_const(list))
1226 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1228 if (prot == QAbstractSocket::IPv4Protocol)
1234 else if (prot == QAbstractSocket::IPv6Protocol)
1244 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1247 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1252 else if (!v4.isNull())
1255 addr = QHostAddress::LocalHostIPv6;
1259 else if (host.isEmpty())
1266 addr.setScopeId(QString());
1268 return addr.toString();
1284 QHostAddress peer = socket->peerAddress();
1316 static const QHostAddress
kLinkLocal(
"fe80::");
1324 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1325 QString(
"Repeat denied connection from ip address: %1")
1326 .arg(peer.toString()));
1338 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1339 for (
const auto & qni : std::as_const(IFs))
1341 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1344 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1345 for (
const auto & qnai : std::as_const(IPs))
1347 int pfxlen = qnai.prefixLength();
1352 if (peer.isInSubnet(qnai.ip(),pfxlen))
1361 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1362 QString(
"Denied connection from ip address: %1")
1363 .arg(peer.toString()));
1369 const QString &value)
1371 d->
m_database->OverrideSettingForSession(key, value);
1376 d->
m_database->ClearOverrideSettingForSession(key);
1403 QStringList &strlist,
bool quickTimeout,
bool block)
1408 msg =
"SendReceiveStringList(";
1409 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1410 msg += (i?
",":
"") + strlist[i];
1411 msg += (strlist.size() > 2) ?
"...)" :
")";
1412 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1415 QString query_type =
"UNKNOWN";
1417 if (!strlist.isEmpty())
1418 query_type = strlist[0];
1432 std::chrono::milliseconds
timeout = quickTimeout ?
1438 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1439 QString(
"Connection to backend server lost"));
1462 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1465 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1466 QString message = strlist[1];
1467 strlist.pop_front(); strlist.pop_front();
1483 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1484 QString(
"Reconnection to backend server failed"));
1487 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1493 if (strlist.isEmpty())
1495 else if (strlist[0] ==
"ERROR")
1497 if (strlist.size() == 2)
1499 LOG(VB_GENERAL, LOG_INFO,
LOC +
1500 QString(
"Protocol query '%1' responded with the error '%2'")
1501 .arg(query_type, strlist[1]));
1505 LOG(VB_GENERAL, LOG_INFO,
LOC +
1506 QString(
"Protocol query '%1' responded with an error, but "
1507 "no error message.") .arg(query_type));
1512 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1514 LOG(VB_GENERAL, LOG_ERR,
LOC +
1515 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1537 QStringList strlist(
"MESSAGE");
1586 const QString &
args)
1596 QStringList strlist;
1600 if (strlist.size() < 2)
1603 QString
prefix = strlist[0];
1604 QString message = strlist[1];
1605 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1610 else if (
prefix !=
"BACKEND_MESSAGE")
1612 LOG(VB_NETWORK, LOG_ERR,
LOC +
1613 QString(
"Received a: %1 message from the backend "
1614 "but I don't know what to do with it.")
1617 else if (message ==
"CLEAR_SETTINGS_CACHE")
1620 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1623 else if (message.startsWith(
"FILE_WRITTEN"))
1629 if (tokens.size() == NUMTOKENS)
1632 size = tokens[2].toULongLong();
1636 LOG(VB_NETWORK, LOG_ERR,
LOC +
1637 QString(
"FILE_WRITTEN event received "
1638 "with invalid number of arguments, "
1639 "%1 expected, %2 actual")
1641 .arg(tokens.size()-1));
1645 LOG(VB_NETWORK, LOG_INFO,
LOC +
1646 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1649 else if (message.startsWith(
"FILE_CLOSED"))
1654 if (tokens.size() == NUMTOKENS)
1660 LOG(VB_NETWORK, LOG_ERR,
LOC +
1661 QString(
"FILE_CLOSED event received "
1662 "with invalid number of arguments, "
1663 "%1 expected, %2 actual")
1665 .arg(tokens.size()-1));
1669 LOG(VB_NETWORK, LOG_INFO,
LOC +
1670 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1675 strlist.pop_front();
1676 strlist.pop_front();
1685 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1686 "Event socket closed. No connection to the backend.");
1692 std::chrono::milliseconds
timeout,
1693 bool error_dialog_desired)
1698 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1699 .arg(MYTH_PROTO_VERSION,
1700 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1705 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1706 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1707 "This happens when the backend is too busy to respond,\n\t\t\t"
1708 "or has deadlocked due to bugs or hardware failure.");
1712 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1714 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1715 "(frontend=%1/%2,backend=%3/\?\?)\n")
1716 .arg(MYTH_PROTO_VERSION,
1717 QString::fromUtf8(MYTH_PROTO_TOKEN),
1722 QStringList list(strlist[1]);
1723 QCoreApplication::postEvent(
1729 if (strlist[0] ==
"ACCEPT")
1734 LOG(VB_GENERAL, LOG_INFO,
LOC +
1735 QString(
"Using protocol version %1 %2")
1736 .arg(MYTH_PROTO_VERSION,
1737 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1743 LOG(VB_GENERAL, LOG_ERR,
LOC +
1744 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1751 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1845 LOG(VB_AUDIO, LOG_DEBUG,
LOC + QString(
"audio language:%1 menu language:%2")
1859 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1886 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1899 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1919 LOG(VB_GENERAL, LOG_INFO,
1926 LOG(VB_GENERAL, LOG_ERR,
LOC +
1927 "No locale defined! We weren't able to set locale defaults.");
1949 QEventLoop eventLoop;
1950 for (
const auto& s : sigs)
1952 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1953 QString(
"Waiting for signal %1")
1958 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1969 if (!sender || !method)
1979 Qt::BlockingQueuedConnection);
2015 QThread *currentThread = QThread::currentThread();
2020 if (it.key() == sender)
2023 QThread *thread = it.key()->thread();
2025 if (thread != currentThread)
2047 Qt::BlockingQueuedConnection);
2052 if (it.key() == sender)
2055 QThread *thread = it.key()->thread();
2057 if (thread != currentThread)
2061 it.key(), it.value());
2063 it.key(), it.value(), Qt::BlockingQueuedConnection);
2098 return intvplayback;
2114 const QString &libversion,
2115 const QString &pluginversion)
2117 if (libversion == pluginversion)
2120 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2121 QString(
"Plugin %1 (%2) binary version does not "
2122 "match libraries (%3)")
2123 .arg(name, pluginversion, libversion));
2160 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2165 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2170 LOG(VB_FILE, LOG_DEBUG,
LOC +
2171 QString(
"%1").arg(
file));
2182 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2187 LOG(VB_FILE, LOG_DEBUG,
LOC +
2188 QString(
"%1").arg(
file));
DB connection pool, used by MSqlQuery. Do not use directly.
static void StopAllPools(void)
static MThreadPool * globalInstance(void)
void start(QRunnable *runnable, const QString &debugName, int priority=0)
static void ShutdownAllPools(void)
static void Cleanup(void)
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total...
static void ThreadSetup(const QString &name)
This is to be called on startup in those few threads that haven't been ported to MThread.
MythSocket * m_eventSock
socket events arrive on
~MythCoreContextPrivate() override
MythCoreContextPrivate(MythCoreContext *lparent, QString binversion, QObject *guicontext)
MythCoreContext * m_parent
QMutex m_sockLock
protects both m_serverSock and m_eventSock
MythSocket * m_serverSock
socket for sending MythProto requests
QMap< QObject *, MythCoreContext::PlaybackStartCb > m_playbackClients
QString m_masterHostname
master backend hostname
QString m_localHostname
hostname from config.xml or gethostname()
QWaitCondition m_wolInProgressWaitCondition
MythSessionManager * m_sessionManager
MythPluginManager * m_pluginmanager
bool WaitForWOL(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
If another thread has already started WOL process, wait on them...
QMutex m_wolInProgressLock
QMutex m_masterHostLock
Locking for m_masterHostname.
MythScheduler * m_scheduler
QMutex m_scopesLock
Locking for m_masterHostname.
QMutex m_localHostLock
Locking for m_localHostname.
QString m_appBinaryVersion
QMap< QString, QPair< int64_t, uint64_t > > m_fileswritten
QList< QHostAddress > m_deniedIps
QMap< QString, QString > m_scopes
Scope Id cache for Link-Local addresses.
QList< QHostAddress > m_approvedIps
This class contains the runtime context for MythTV.
void TVPlaybackAboutToStart(void)
bool IsFrontend(void) const
is this process a frontend process
void ResetAudioLanguage(void)
void UnregisterForPlayback(QObject *sender)
Unregister sender from being called when TVPlaybackAboutToStart signal is emitted.
bool IsConnectedToMaster(void)
void setTestIntSettings(QMap< QString, int > &overrides)
void ClearSettingsCache(const QString &myKey=QString(""))
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
QString resolveSettingAddress(const QString &name, const QString &host=QString(), ResolveType type=ResolveAny, bool keepscope=false)
Retrieve IP setting "name" for "host".
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
int GetNumSettingOnHost(const QString &key, const QString &host, int defaultval=0)
QMap< QString, QString > m_testOverrideStrings
void readyRead(MythSocket *sock) override
QMap< QString, double > m_testOverrideFloats
void ActivateSettingsCache(bool activate=true)
bool IsLocalSubnet(const QHostAddress &peer, bool log)
Check if peer is on local subnet.
void SetWOLAllowed(bool allow)
void SendHostSystemEvent(const QString &msg, const QString &hostname, const QString &args)
bool IsDatabaseIgnored(void) const
/brief Returns true if database is being ignored.
QString GetHostName(void)
void SetScopeForAddress(const QHostAddress &addr)
Record the scope Id of the given IP address.
MythCoreContextPrivate * d
static bool BackendIsRunning(void)
a backend process is running on this host
bool GetScopeForAddress(QHostAddress &addr) const
Return the cached scope Id for the given address.
void ClearOverrideSettingForSession(const QString &key)
static QHash< QString, int > s_serverPortCache
void TVInWantingPlayback(bool b)
Let the TV class tell us if we was interrupted following a call to WantingPlayback().
void connectionClosed(MythSocket *sock) override
QString GetBackendServerIP4(void)
Returns the IPv4 address defined for the current host see GetBackendServerIP4(host)
void SaveSetting(const QString &key, int newValue)
MythSocket * ConnectCommandSocket(const QString &hostname, int port, const QString &announcement, bool *proto_mismatch=nullptr, int maxConnTry=-1, std::chrono::milliseconds setup_timeout=-1ms)
void setTestFloatSettings(QMap< QString, double > &overrides)
void SetLocalHostname(const QString &hostname)
void SetExiting(bool exiting=true)
static QString resolveAddress(const QString &host, ResolveType type=ResolveAny, bool keepscope=false)
if host is an IP address, it will be returned or resolved otherwise.
void SetAsBackend(bool backend)
void RegisterForPlayback(QObject *sender, PlaybackStartCb method)
Register sender for TVPlaybackAboutToStart signal.
bool IsThisHost(const QString &addr)
is this address mapped to this host
MythScheduler * GetScheduler(void)
MythCoreContext(const QString &binversion, QObject *guiContext)
QString GetMasterHostPrefix(const QString &storageGroup=QString(), const QString &path=QString())
MythSessionManager * GetSessionManager(void)
QString GetSetting(const QString &key, const QString &defaultval="")
void SendSystemEvent(const QString &msg)
QString GetAudioLanguageAndVariant(void)
Returns the user-set audio language and variant.
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
bool IsRegisteredFileForWrite(const QString &file)
bool CheckProtoVersion(MythSocket *socket, std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
QString GetAudioLanguage(void)
Returns two character ISO-639 language descriptor for audio language.
QObject * GetGUIContext(void)
bool CheckSubnet(const QAbstractSocket *socket)
Check if a socket is connected to an approved peer.
void setTestStringSettings(QMap< QString, QString > &overrides)
MythPluginManager * GetPluginManager(void)
bool InWantingPlayback(void)
Returns true if a client has requested playback.
int GetBackendServerPort(void)
Returns the locally defined backend control port.
void OverrideSettingForSession(const QString &key, const QString &value)
void RegisterFileForWrite(const QString &file, uint64_t size=0LL)
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
QObject * GetGUIObject(void)
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
void WantingPlayback(QObject *sender)
All the objects that have registered using MythCoreContext::RegisterForPlayback but sender will be ca...
int GetBackendStatusPort(void)
Returns the locally defined backend status port.
bool IsBackend(void) const
is this process a backend process
double GetFloatSetting(const QString &key, double defaultval=0.0)
bool IsThisBackend(const QString &addr)
is this address mapped to this backend host
int GetMasterServerStatusPort(void)
Returns the Master Backend status port If no master server status port has been defined in the databa...
~MythCoreContext() override
QString GetBackendServerIP6(void)
Returns the IPv6 address defined for the current host see GetBackendServerIP6(host)
void SetScheduler(MythScheduler *sched)
QString GetFilePrefix(void)
void dispatch(const MythEvent &event)
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
void SendMessage(const QString &message)
bool SetupCommandSocket(MythSocket *serverSock, const QString &announcement, std::chrono::milliseconds timeout, bool &proto_mismatch)
bool IsMasterHost(void)
is this the same host as the master
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
void SetPluginManager(MythPluginManager *pmanager)
bool IsWOLAllowed() const
void SetGUIObject(QObject *gui)
void SaveLocaleDefaults(void)
int GetNumSetting(const QString &key, int defaultval=0)
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
void(QObject::*)(void) PlaybackStartCb
double GetFloatSettingOnHost(const QString &key, const QString &host, double defaultval=0.0)
void SetAsFrontend(bool frontend)
QString GetMasterHostName(void)
QMap< QString, int > m_testOverrideInts
bool IsMasterBackend(void)
is this the actual MBE process
MythSocket * ConnectEventSocket(const QString &hostname, int port)
static void ClearBackendServerPortCache()
void UnregisterFileForWrite(const QString &file)
bool IsBlockingClient(void) const
is this client blocking shutdown
MDBManager * GetDBManager(void)
void InitPower(bool Create=true)
bool GetBoolSettingOnHost(const QString &key, const QString &host, bool defaultval=false)
void WaitUntilSignals(std::vector< CoreWaitInfo > &sigs) const
Wait until any of the provided signals have been received.
void SendEvent(const MythEvent &event)
QString GetLanguageAndVariant(void)
Returns the user-set language and variant.
bool GetBoolSetting(const QString &key, bool defaultval=false)
MythLocale * GetLocale(void) const
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
This class is used as a container for messages.
const QString & Message() const
const QStringList & ExtraDataList() const
QLocale ToQLocale() const
QString GetLocaleCode() const
Name of language in that language.
void SaveLocaleDefaults(bool overwrite=false)
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
static MythPower * AcquireRelease(void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s)
This is an generic interface to a program scheduler.
We use digest authentication because it protects the password over unprotected networks.
static void UnlockSessions()
static void LockSessions()
Class for communcating between myth backends and frontends.
static constexpr std::chrono::milliseconds kLongTimeout
bool SendReceiveStringList(QStringList &list, uint min_reply_length=0, std::chrono::milliseconds timeoutMS=kLongTimeout)
bool ReadStringList(QStringList &list, std::chrono::milliseconds timeoutMS=kShortTimeout)
bool IsConnected(void) const
bool IsDataAvailable(void)
static constexpr std::chrono::milliseconds kShortTimeout
void DisconnectFromHost(void)
bool WriteStringList(const QStringList &list)
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
SendAsyncMessage(QString msg)
SendAsyncMessage(QString msg, QStringList extra)
@ GENERIC_EXIT_OK
Exited with no error.
void loggingDeregisterThread(void)
Deregister the current thread's name.
void logStop(void)
Entry point for stopping logging for an application.
bool is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
static constexpr const char * MYTH_APPNAME_MYTHTV_SETUP
static void delete_sock(QMutexLocker< QMutex > &locker, MythSocket **s)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void ShutdownMythDownloadManager(void)
Deletes the running MythDownloadManager at program exit.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
bool MythWakeup(const QString &wakeUpCommand, uint flags, std::chrono::seconds timeout)
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
@ kMSProcessEvents
process events while waiting
@ kMSDontDisableDrawing
avoid disabling UI drawing
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
void MBASE_PUBLIC ShutdownMythSystemLegacy(void)
None log(str msg, int level=LOGDEBUG)
static QPair< QHostAddress, int > kLinkLocal