Go to the documentation of this file.
3 #include <QCoreApplication>
10 #include <QWaitCondition>
11 #include <QAbstractSocket>
12 #include <QHostAddress>
14 #include <QNetworkInterface>
15 #include <QNetworkAddressEntry>
18 #include <QRegularExpression>
44 #include "mythversion.h"
53 #define LOC QString("MythCoreContext::%1(): ").arg(__func__)
64 bool WaitForWOL(std::chrono::milliseconds
timeout = std::chrono::milliseconds::max());
128 m_guiContext(guicontext),
129 m_appBinaryVersion(
std::move(binversion)),
131 m_uiThread(QThread::currentThread())
137 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
138 QMutexLocker &locker,
140 QMutexLocker<QMutex> &locker,
185 GetMythDB()->GetDBManager()->CloseDatabases();
200 std::chrono::milliseconds timeout_remaining =
timeout;
203 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Wake-On-LAN in progress, waiting...");
205 std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
207 timeout_remaining -= max_wait;
223 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Out-of-memory");
229 LOG(VB_GENERAL, LOG_CRIT,
230 QString(
"Application binary version (%1) does not "
231 "match libraries (%2)")
234 QString warning = tr(
"This application is not compatible with the "
235 "installed MythTV libraries. Please recompile "
236 "after a make distclean");
237 LOG(VB_GENERAL, LOG_WARNING, warning);
243 static const QRegularExpression utf8
244 {
"utf-?8", QRegularExpression::CaseInsensitiveOption };
245 QString lang_variables(
"");
246 QString lc_value = setlocale(LC_CTYPE,
nullptr);
247 if (lc_value.isEmpty())
251 lc_value = qEnvironmentVariable(
"LC_ALL");
252 if (lc_value.isEmpty())
253 lc_value = qEnvironmentVariable(
"LC_CTYPE");
255 if (!lc_value.contains(utf8))
256 lang_variables.append(
"LC_ALL or LC_CTYPE");
257 lc_value = qEnvironmentVariable(
"LANG");
258 if (!lc_value.contains(utf8))
260 if (!lang_variables.isEmpty())
261 lang_variables.append(
", and ");
262 lang_variables.append(
"LANG");
264 LOG(VB_GENERAL, LOG_INFO, QString(
"Assumed character encoding: %1")
266 if (!lang_variables.isEmpty())
268 LOG(VB_GENERAL, LOG_WARNING, QString(
"This application expects to "
269 "be running a locale that specifies a UTF-8 codeset, and many "
270 "features may behave improperly with your current language "
271 "settings. Please set the %1 variable(s) in the environment "
272 "in which this program is executed to include a UTF-8 codeset "
273 "(such as 'en_US.UTF-8').").arg(lang_variables));
302 const QString &announcement,
303 [[maybe_unused]] std::chrono::milliseconds
timeout,
304 bool &proto_mismatch)
306 proto_mismatch =
false;
308 #ifndef IGNORE_PROTO_VER_MISMATCH
311 proto_mismatch =
true;
316 QStringList strlist(announcement);
320 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Connecting server socket to "
321 "master backend, socket write failed");
326 strlist.empty() || (strlist[0] ==
"ERROR"))
328 if (!strlist.empty())
330 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Problem connecting "
331 "server socket to master backend");
335 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Timeout connecting "
336 "server socket to master backend");
346 bool openEventSocket)
357 bool openEventSocket)
363 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ERROR: Master backend tried to connect back "
371 if (server.isEmpty())
375 bool proto_mismatch =
false;
385 QString
type =
IsFrontend() ?
"Frontend" : (blockingClient ?
"Playback" :
"Monitor");
386 QString ann = QString(
"ANN %1 %2 %3")
389 server, port, ann, &proto_mismatch);
397 if (!openEventSocket)
416 QCoreApplication::postEvent(
427 const QString &
hostname,
int port,
const QString &announce,
428 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
442 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
444 std::chrono::seconds WOLsleepTime = 0s;
445 int WOLmaxConnTry = 0;
446 if (!WOLcmd.isEmpty())
448 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
449 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
450 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
453 bool we_attempted_wol =
false;
455 if (setup_timeout <= 0ms)
458 bool proto_mismatch =
false;
459 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
461 LOG(VB_GENERAL, LOG_INFO,
LOC +
462 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
463 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
467 std::chrono::microseconds sleepus = 0us;
471 serverSock, announce, setup_timeout, proto_mismatch))
478 if (p_proto_mismatch)
479 *p_proto_mismatch =
true;
482 serverSock =
nullptr;
486 setup_timeout += setup_timeout / 2;
488 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
490 if (!we_attempted_wol)
504 sleepus = WOLsleepTime;
508 serverSock =
nullptr;
512 QCoreApplication::postEvent(
517 usleep(sleepus.count());
520 if (we_attempted_wol)
527 if (!serverSock && !proto_mismatch)
529 LOG(VB_GENERAL, LOG_ERR,
530 "Connection to master server timed out.\n\t\t\t"
531 "Either the server is down or the master server settings"
533 "in mythtv-settings does not contain the proper IP address\n");
537 QCoreApplication::postEvent(
551 if (!eventSock->ConnectToHost(
hostname, port))
553 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
554 "socket to master backend");
555 eventSock->DecrRef();
559 QString str = QString(
"ANN Monitor %1 %2")
561 QStringList strlist(str);
562 eventSock->WriteStringList(strlist);
564 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
565 (strlist[0] ==
"ERROR"))
567 if (!strlist.empty())
569 LOG(VB_GENERAL, LOG_ERR,
LOC +
570 "Problem connecting event socket to master backend");
574 LOG(VB_GENERAL, LOG_ERR,
LOC +
575 "Timeout connecting event socket to master backend");
582 eventSock->DecrRef();
603 strlist <<
"BLOCK_SHUTDOWN";
617 strlist <<
"ALLOW_SHUTDOWN";
679 if (addr.toLower() == host.toLower())
681 QHostAddress addrfix(addr);
682 addrfix.setScopeId(QString());
683 QString addrstr = addrfix.toString();
684 if (addrfix.isNull())
688 return !addrstr.isEmpty()
689 && ((addrstr == thisip) || (addrstr == thisip6));
691 return GetSetting(
"MasterServerName") == host;
701 #if defined(Q_OS_DARWIN) || defined(__FreeBSD__) || defined(__OpenBSD__)
702 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
704 const char *command =
"%systemroot%\\system32\\tasklist.exe "
705 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
707 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
727 if (addr.toLower() == host.toLower())
730 QHostAddress addrfix(addr);
731 addrfix.setScopeId(QString());
732 QString addrstr = addrfix.toString();
734 if (addrfix.isNull())
741 return !addrstr.isEmpty() && ((addrstr == thisip));
747 bool backendOnLocalhost =
false;
749 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
754 backendOnLocalhost = strlist[0] !=
"FALSE";
756 return !backendOnLocalhost;
765 QHostAddress addr(host);
768 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
769 "IP address instead of hostname "
770 "(ID). This is invalid.").arg(host, path));
776 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
777 m_host =
"[" + addr.toString().toLower() +
"]";
779 ret.setScheme(
"myth");
780 if (!storageGroup.isEmpty())
781 ret.setUserName(storageGroup);
783 if (port > 0 && port != 6543)
785 if (!path.startsWith(
"/"))
786 path = QString(
"/") + path;
790 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
791 QString(
"GenMythURL returning %1").arg(ret.toString()));
794 return ret.toString();
817 QStringList strlist(
"QUERY_HOSTNAME");
849 int &width,
int &height,
850 double &forced_aspect,
851 double &refresh_rate,
854 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
855 refresh_rate, index);
891 const QString &newValue,
894 return d->
m_database->SaveSettingOnHost(key, newValue, host);
898 const QString &defaultval)
907 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
915 return d->
m_database->GetNumSetting(key, defaultval);
922 return d->
m_database->GetFloatSetting(key, defaultval);
927 const QString &defaultval)
931 return d->
m_database->GetSettingOnHost(key, host, defaultval);
948 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
957 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
982 (
"MasterServerName");
984 (
"BackendServerPort", masterserver, 6543);
1110 QHostAddress addr1 = addr;
1111 addr1.setScopeId(QString());
1112 QString addrstr = addr1.toString();
1130 QHostAddress addr1 = addr;
1131 addr1.setScopeId(QString());
1134 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1144 QHostAddress addr1 = addr;
1145 addr1.setScopeId(QString());
1148 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1163 const QString &host,
1194 QHostAddress addr(host);
1196 if (!host.isEmpty() && addr.isNull())
1199 QHostInfo info = QHostInfo::fromName(host);
1200 QList<QHostAddress> list = info.addresses();
1204 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1205 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1212 for (
const auto& item : qAsConst(list))
1215 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1217 if (prot == QAbstractSocket::IPv4Protocol)
1223 else if (prot == QAbstractSocket::IPv6Protocol)
1233 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1236 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1239 addr = v6.isNull() ?
1240 (v4.isNull() ? QHostAddress::LocalHostIPv6 : v4) : v6;
1244 else if (host.isEmpty())
1251 addr.setScopeId(QString());
1253 return addr.toString();
1269 QHostAddress peer = socket->peerAddress();
1286 static const QHostAddress
kLinkLocal(
"fe80::");
1293 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1294 QString(
"Repeat denied connection from ip address: %1")
1295 .arg(peer.toString()));
1307 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1308 for (
const auto & qni : qAsConst(IFs))
1310 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1313 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1314 for (
const auto & qnai : qAsConst(IPs))
1316 int pfxlen = qnai.prefixLength();
1321 if (peer.isInSubnet(qnai.ip(),pfxlen))
1329 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1330 QString(
"Denied connection from ip address: %1")
1331 .arg(peer.toString()));
1337 const QString &value)
1339 d->
m_database->OverrideSettingForSession(key, value);
1344 d->
m_database->ClearOverrideSettingForSession(key);
1371 QStringList &strlist,
bool quickTimeout,
bool block)
1376 msg =
"SendReceiveStringList(";
1377 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1378 msg += (i?
",":
"") + strlist[i];
1379 msg += (strlist.size() > 2) ?
"...)" :
")";
1380 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1383 QString query_type =
"UNKNOWN";
1385 if (!strlist.isEmpty())
1386 query_type = strlist[0];
1400 std::chrono::milliseconds
timeout = quickTimeout ?
1406 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1407 QString(
"Connection to backend server lost"));
1430 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1433 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1434 QString message = strlist[1];
1435 strlist.pop_front(); strlist.pop_front();
1451 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1452 QString(
"Reconnection to backend server failed"));
1455 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1461 if (strlist.isEmpty())
1463 else if (strlist[0] ==
"ERROR")
1465 if (strlist.size() == 2)
1467 LOG(VB_GENERAL, LOG_INFO,
LOC +
1468 QString(
"Protocol query '%1' responded with the error '%2'")
1469 .arg(query_type, strlist[1]));
1473 LOG(VB_GENERAL, LOG_INFO,
LOC +
1474 QString(
"Protocol query '%1' responded with an error, but "
1475 "no error message.") .arg(query_type));
1480 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1482 LOG(VB_GENERAL, LOG_ERR,
LOC +
1483 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1505 QStringList strlist(
"MESSAGE");
1554 const QString &
args)
1564 QStringList strlist;
1568 if (strlist.size() < 2)
1571 QString
prefix = strlist[0];
1572 QString message = strlist[1];
1573 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
1574 QStringList tokens = message.split(
" ", QString::SkipEmptyParts);
1576 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1582 else if (
prefix !=
"BACKEND_MESSAGE")
1584 LOG(VB_NETWORK, LOG_ERR,
LOC +
1585 QString(
"Received a: %1 message from the backend "
1586 "but I don't know what to do with it.")
1589 else if (message ==
"CLEAR_SETTINGS_CACHE")
1592 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1595 else if (message.startsWith(
"FILE_WRITTEN"))
1601 if (tokens.size() == NUMTOKENS)
1604 size = tokens[2].toULongLong();
1608 LOG(VB_NETWORK, LOG_ERR,
LOC +
1609 QString(
"FILE_WRITTEN event received "
1610 "with invalid number of arguments, "
1611 "%1 expected, %2 actual")
1613 .arg(tokens.size()-1));
1617 LOG(VB_NETWORK, LOG_INFO,
LOC +
1618 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1621 else if (message.startsWith(
"FILE_CLOSED"))
1626 if (tokens.size() == NUMTOKENS)
1632 LOG(VB_NETWORK, LOG_ERR,
LOC +
1633 QString(
"FILE_CLOSED event received "
1634 "with invalid number of arguments, "
1635 "%1 expected, %2 actual")
1637 .arg(tokens.size()-1));
1641 LOG(VB_NETWORK, LOG_INFO,
LOC +
1642 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1647 strlist.pop_front();
1648 strlist.pop_front();
1658 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1659 "Event socket closed. No connection to the backend.");
1665 std::chrono::milliseconds
timeout,
1666 bool error_dialog_desired)
1671 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1672 .arg(MYTH_PROTO_VERSION,
1673 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1678 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1679 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1680 "This happens when the backend is too busy to respond,\n\t\t\t"
1681 "or has deadlocked due to bugs or hardware failure.");
1685 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1687 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1688 "(frontend=%1/%2,backend=%3/\?\?)\n")
1689 .arg(MYTH_PROTO_VERSION,
1690 QString::fromUtf8(MYTH_PROTO_TOKEN),
1695 QStringList list(strlist[1]);
1696 QCoreApplication::postEvent(
1702 if (strlist[0] ==
"ACCEPT")
1707 LOG(VB_GENERAL, LOG_INFO,
LOC +
1708 QString(
"Using protocol version %1 %2")
1709 .arg(MYTH_PROTO_VERSION,
1710 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1716 LOG(VB_GENERAL, LOG_ERR,
LOC +
1717 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1724 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1798 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1825 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1838 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1858 LOG(VB_GENERAL, LOG_INFO,
1865 LOG(VB_GENERAL, LOG_ERR,
LOC +
1866 "No locale defined! We weren't able to set locale defaults.");
1888 QEventLoop eventLoop;
1889 for (
const auto& s : sigs)
1891 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1892 QString(
"Waiting for signal %1")
1897 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1908 if (!sender || !method)
1918 Qt::BlockingQueuedConnection);
1954 QThread *currentThread = QThread::currentThread();
1959 if (it.key() == sender)
1962 QThread *thread = it.key()->thread();
1964 if (thread != currentThread)
1986 Qt::BlockingQueuedConnection);
1991 if (it.key() == sender)
1994 QThread *thread = it.key()->thread();
1996 if (thread != currentThread)
2000 it.key(), it.value());
2002 it.key(), it.value(), Qt::BlockingQueuedConnection);
2037 return intvplayback;
2049 const QString &libversion,
2050 const QString &pluginversion)
2052 if (libversion == pluginversion)
2055 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2056 QString(
"Plugin %1 (%2) binary version does not "
2057 "match libraries (%3)")
2058 .arg(name, pluginversion, libversion));
2095 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2100 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2105 LOG(VB_FILE, LOG_DEBUG,
LOC +
2106 QString(
"%1").arg(
file));
2117 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2122 LOG(VB_FILE, LOG_DEBUG,
LOC +
2123 QString(
"%1").arg(
file));
QString resolveSettingAddress(const QString &name, const QString &host=QString(), ResolveType type=ResolveAny, bool keepscope=false)
Retrieve IP setting "name" for "host".
void SetPluginManager(MythPluginManager *pmanager)
void loggingDeregisterThread(void)
Deregister the current thread's name.
void SetWOLAllowed(bool allow)
bool WaitForWOL(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
If another thread has already started WOL process, wait on them...
void SendMessage(const QString &message)
QString GetMasterHostName(void)
QMap< QString, QPair< int64_t, uint64_t > > m_fileswritten
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
This is an generic interface to a program scheduler.
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
MythScheduler * GetScheduler(void)
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
bool IsBlockingClient(void) const
is this client blocking shutdown
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
QMutex m_masterHostLock
Locking for m_masterHostname.
MDBManager * GetDBManager(void)
void UnregisterFileForWrite(const QString &file)
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
MythSocket * m_eventSock
socket events arrive on
MythLocale * GetLocale(void) const
~MythCoreContext() override
void ShutdownMythDownloadManager(void)
Deletes the running MythDownloadManager at program exit.
void SetScheduler(MythScheduler *sched)
int GetBackendStatusPort(void)
Returns the locally defined backend status port.
void OverrideSettingForSession(const QString &key, const QString &value)
DB connection pool, used by MSqlQuery. Do not use directly.
QLocale ToQLocale() const
static QHash< QString, int > s_serverPortCache
This class is used as a container for messages.
QString m_appBinaryVersion
void RegisterFileForWrite(const QString &file, uint64_t size=0LL)
bool IsDatabaseIgnored(void) const
/brief Returns true if database is being ignored.
QObject * GetGUIObject(void)
QString GetFilePrefix(void)
void connectionClosed(MythSocket *sock) override
void DisconnectFromHost(void)
bool CheckProtoVersion(MythSocket *socket, std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
bool is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
@ GENERIC_EXIT_OK
Exited with no error.
bool GetScopeForAddress(QHostAddress &addr) const
Return the cached scope Id for the given address.
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
void setTestStringSettings(QMap< QString, QString > &overrides)
void InitPower(bool Create=true)
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
const QString & Message() const
bool IsConnected(void) const
QWaitCondition m_wolInProgressWaitCondition
int GetMasterServerStatusPort(void)
Returns the Master Backend status port If no master server status port has been defined in the databa...
QMutex m_scopesLock
Locking for m_masterHostname.
SendAsyncMessage(QString msg, QStringList extra)
static constexpr const char * MYTH_APPNAME_MYTHTV_SETUP
void SendHostSystemEvent(const QString &msg, const QString &hostname, const QString &args)
MythPluginManager * m_pluginmanager
Class for communcating between myth backends and frontends.
void ClearOverrideSettingForSession(const QString &key)
bool IsConnectedToMaster(void)
MythCoreContext(const QString &binversion, QObject *guiContext)
static void ShutdownAllPools(void)
void UnregisterForPlayback(QObject *sender)
bool IsRegisteredFileForWrite(const QString &file)
bool IsMasterBackend(void)
is this the actual MBE process
QString m_localHostname
hostname from config.xml or gethostname()
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
QObject * GetGUIContext(void)
static bool BackendIsRunning(void)
a backend process is running on this host
bool WriteStringList(const QStringList &list)
void SetAsFrontend(bool frontend)
static void StopAllPools(void)
int GetBackendServerPort(void)
Returns the locally defined backend control port.
void SendSystemEvent(const QString &msg)
void SendEvent(const MythEvent &event)
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
void WaitUntilSignals(std::vector< CoreWaitInfo > &sigs) const
Wait until any of the provided signals have been received.
MythCoreContext * m_parent
static MythPower * AcquireRelease(void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s)
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
MythSessionManager * m_sessionManager
bool IsFrontend(void) const
is this process a frontend process
void readyRead(MythSocket *sock) override
bool MythWakeup(const QString &wakeUpCommand, uint flags, std::chrono::seconds timeout)
int GetNumSettingOnHost(const QString &key, const QString &host, int defaultval=0)
QList< QHostAddress > m_approvedIps
QMutex m_wolInProgressLock
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
void RegisterForPlayback(QObject *sender, PlaybackStartCb method)
QString GetBackendServerIP4(void)
Returns the IPv4 address defined for the current host see GetBackendServerIP4(host)
QMap< QString, QString > m_testOverrideStrings
void TVPlaybackAboutToStart(void)
static constexpr std::chrono::milliseconds kShortTimeout
MythSocket * ConnectCommandSocket(const QString &hostname, int port, const QString &announcement, bool *proto_mismatch=nullptr, int maxConnTry=-1, std::chrono::milliseconds setup_timeout=-1ms)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
~MythCoreContextPrivate() override
MythSocket * ConnectEventSocket(const QString &hostname, int port)
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
int GetNumSetting(const QString &key, int defaultval=0)
void logStop(void)
Entry point for stopping logging for an application.
void SaveLocaleDefaults(bool overwrite=false)
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 SetLocalHostname(const QString &hostname)
bool GetBoolSetting(const QString &key, bool defaultval=false)
const QStringList & ExtraDataList() const
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
QMap< QObject *, MythCoreContext::PlaybackStartCb > m_playbackClients
bool InWantingPlayback(void)
Returns true if a client has requested playback.
This class contains the runtime context for MythTV.
void setTestIntSettings(QMap< QString, int > &overrides)
QMap< QString, double > m_testOverrideFloats
bool IsBackend(void) const
is this process a backend process
static QPair< QHostAddress, int > kLinkLocal
QString m_masterHostname
master backend hostname
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
QMap< QString, QString > m_scopes
Scope Id cache for Link-Local addresses.
@ kMSProcessEvents
process events while waiting
QString GetLanguageAndVariant(void)
Returns the user-set language and variant.
MythSocket * m_serverSock
socket for sending MythProto requests
bool IsDataAvailable(void)
static void ClearBackendServerPortCache()
void TVInWantingPlayback(bool b)
Let the TV class tell us if we was interrupted following a call to WantingPlayback().
MythCoreContextPrivate * d
SendAsyncMessage(QString msg)
void ActivateSettingsCache(bool activate=true)
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...
QMutex m_sockLock
protects both m_serverSock and m_eventSock
QString GetLocaleCode() const
Name of language in that language.
void WantingPlayback(QObject *sender)
All the objects that have registered using MythCoreContext::RegisterForPlayback but sender will be ca...
void MBASE_PUBLIC ShutdownMythSystemLegacy(void)
QString GetHostName(void)
MythScheduler * m_scheduler
static void ThreadSetup(const QString &name)
This is to be called on startup in those few threads that haven't been ported to MThread.
QList< QHostAddress > m_deniedIps
bool GetBoolSettingOnHost(const QString &key, const QString &host, bool defaultval=false)
void ClearSettingsCache(const QString &myKey=QString(""))
bool IsThisHost(const QString &addr)
is this address mapped to this host
bool IsMasterHost(void)
is this the same host as the master
QMutex m_localHostLock
Locking for m_localHostname.
bool IsWOLAllowed() const
double GetFloatSetting(const QString &key, double defaultval=0.0)
@ kMSDontDisableDrawing
avoid disabling UI drawing
void SaveSetting(const QString &key, int newValue)
QString GetMasterHostPrefix(const QString &storageGroup=QString(), const QString &path=QString())
MythSessionManager * GetSessionManager(void)
QString GetBackendServerIP6(void)
Returns the IPv6 address defined for the current host see GetBackendServerIP6(host)
static void delete_sock(QMutexLocker< QMutex > &locker, MythSocket **s)
static MThreadPool * globalInstance(void)
MythPluginManager * GetPluginManager(void)
void SetScopeForAddress(const QHostAddress &addr)
Record the scope Id of the given IP address.
static constexpr std::chrono::milliseconds kLongTimeout
bool SetupCommandSocket(MythSocket *serverSock, const QString &announcement, std::chrono::milliseconds timeout, bool &proto_mismatch)
bool CheckSubnet(const QAbstractSocket *socket)
Check if a socket is connected to an approved peer.
void SaveLocaleDefaults(void)
void dispatch(const MythEvent &event)
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
bool ReadStringList(QStringList &list, std::chrono::milliseconds timeoutMS=kShortTimeout)
void SetAsBackend(bool backend)
QMap< QString, int > m_testOverrideInts
void(QObject::*)(void) PlaybackStartCb
bool IsThisBackend(const QString &addr)
is this address mapped to this backend host
void setTestFloatSettings(QMap< QString, double > &overrides)
double GetFloatSettingOnHost(const QString &key, const QString &host, double defaultval=0.0)
void start(QRunnable *runnable, const QString &debugName, int priority=0)
void SetExiting(bool exiting=true)
void SetGUIObject(QObject *gui)
bool SendReceiveStringList(QStringList &list, uint min_reply_length=0, std::chrono::milliseconds timeoutMS=kLongTimeout)
MythCoreContextPrivate(MythCoreContext *lparent, QString binversion, QObject *guicontext)
QString GetSetting(const QString &key, const QString &defaultval="")