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());
129 m_guiContext(guicontext),
130 m_appBinaryVersion(
std::move(binversion)),
132 m_uiThread(QThread::currentThread())
138 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
139 QMutexLocker &locker,
141 QMutexLocker<QMutex> &locker,
186 GetMythDB()->GetDBManager()->CloseDatabases();
201 std::chrono::milliseconds timeout_remaining =
timeout;
204 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Wake-On-LAN in progress, waiting...");
206 std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
208 timeout_remaining -= max_wait;
224 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Out-of-memory");
230 LOG(VB_GENERAL, LOG_CRIT,
231 QString(
"Application binary version (%1) does not "
232 "match libraries (%2)")
235 QString warning = tr(
"This application is not compatible with the "
236 "installed MythTV libraries. Please recompile "
237 "after a make distclean");
238 LOG(VB_GENERAL, LOG_WARNING, warning);
244 static const QRegularExpression utf8
245 {
"utf-?8", QRegularExpression::CaseInsensitiveOption };
246 QString lang_variables(
"");
247 QString lc_value = setlocale(LC_CTYPE,
nullptr);
248 if (lc_value.isEmpty())
252 lc_value = qEnvironmentVariable(
"LC_ALL");
253 if (lc_value.isEmpty())
254 lc_value = qEnvironmentVariable(
"LC_CTYPE");
256 if (!lc_value.contains(utf8))
257 lang_variables.append(
"LC_ALL or LC_CTYPE");
258 lc_value = qEnvironmentVariable(
"LANG");
259 if (!lc_value.contains(utf8))
261 if (!lang_variables.isEmpty())
262 lang_variables.append(
", and ");
263 lang_variables.append(
"LANG");
265 LOG(VB_GENERAL, LOG_INFO, QString(
"Assumed character encoding: %1")
267 if (!lang_variables.isEmpty())
269 LOG(VB_GENERAL, LOG_WARNING, QString(
"This application expects to "
270 "be running a locale that specifies a UTF-8 codeset, and many "
271 "features may behave improperly with your current language "
272 "settings. Please set the %1 variable(s) in the environment "
273 "in which this program is executed to include a UTF-8 codeset "
274 "(such as 'en_US.UTF-8').").arg(lang_variables));
303 const QString &announcement,
304 [[maybe_unused]] std::chrono::milliseconds
timeout,
305 bool &proto_mismatch)
307 proto_mismatch =
false;
309 #ifndef IGNORE_PROTO_VER_MISMATCH
312 proto_mismatch =
true;
317 QStringList strlist(announcement);
321 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Connecting server socket to "
322 "master backend, socket write failed");
327 strlist.empty() || (strlist[0] ==
"ERROR"))
329 if (!strlist.empty())
331 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Problem connecting "
332 "server socket to master backend");
336 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Timeout connecting "
337 "server socket to master backend");
347 bool openEventSocket)
358 bool openEventSocket)
364 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ERROR: Master backend tried to connect back "
372 if (server.isEmpty())
376 bool proto_mismatch =
false;
386 QString
type =
IsFrontend() ?
"Frontend" : (blockingClient ?
"Playback" :
"Monitor");
387 QString ann = QString(
"ANN %1 %2 %3")
390 server, port, ann, &proto_mismatch);
398 if (!openEventSocket)
417 QCoreApplication::postEvent(
428 const QString &
hostname,
int port,
const QString &announce,
429 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
443 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
445 std::chrono::seconds WOLsleepTime = 0s;
446 int WOLmaxConnTry = 0;
447 if (!WOLcmd.isEmpty())
449 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
450 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
451 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
454 bool we_attempted_wol =
false;
456 if (setup_timeout <= 0ms)
459 bool proto_mismatch =
false;
460 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
462 LOG(VB_GENERAL, LOG_INFO,
LOC +
463 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
464 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
468 std::chrono::microseconds sleepus = 0us;
472 serverSock, announce, setup_timeout, proto_mismatch))
479 if (p_proto_mismatch)
480 *p_proto_mismatch =
true;
483 serverSock =
nullptr;
487 setup_timeout += setup_timeout / 2;
489 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
491 if (!we_attempted_wol)
505 sleepus = WOLsleepTime;
509 serverSock =
nullptr;
513 QCoreApplication::postEvent(
518 usleep(sleepus.count());
521 if (we_attempted_wol)
528 if (!serverSock && !proto_mismatch)
530 LOG(VB_GENERAL, LOG_ERR,
531 "Connection to master server timed out.\n\t\t\t"
532 "Either the server is down or the master server settings"
534 "in mythtv-settings does not contain the proper IP address\n");
538 QCoreApplication::postEvent(
552 if (!eventSock->ConnectToHost(
hostname, port))
554 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
555 "socket to master backend");
556 eventSock->DecrRef();
560 QString str = QString(
"ANN Monitor %1 %2")
562 QStringList strlist(str);
563 eventSock->WriteStringList(strlist);
565 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
566 (strlist[0] ==
"ERROR"))
568 if (!strlist.empty())
570 LOG(VB_GENERAL, LOG_ERR,
LOC +
571 "Problem connecting event socket to master backend");
575 LOG(VB_GENERAL, LOG_ERR,
LOC +
576 "Timeout connecting event socket to master backend");
583 eventSock->DecrRef();
604 strlist <<
"BLOCK_SHUTDOWN";
618 strlist <<
"ALLOW_SHUTDOWN";
680 if (addr.toLower() == host.toLower())
682 QHostAddress addrfix(addr);
683 addrfix.setScopeId(QString());
684 QString addrstr = addrfix.toString();
685 if (addrfix.isNull())
689 return !addrstr.isEmpty()
690 && ((addrstr == thisip) || (addrstr == thisip6));
692 return GetSetting(
"MasterServerName") == host;
702 #if defined(Q_OS_DARWIN) || defined(__FreeBSD__) || defined(__OpenBSD__)
703 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
705 const char *command =
"%systemroot%\\system32\\tasklist.exe "
706 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
708 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
728 if (addr.toLower() == host.toLower())
731 QHostAddress addrfix(addr);
732 addrfix.setScopeId(QString());
733 QString addrstr = addrfix.toString();
735 if (addrfix.isNull())
742 return !addrstr.isEmpty() && ((addrstr == thisip));
748 bool backendOnLocalhost =
false;
750 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
755 backendOnLocalhost = strlist[0] !=
"FALSE";
757 return !backendOnLocalhost;
766 QHostAddress addr(host);
769 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
770 "IP address instead of hostname "
771 "(ID). This is invalid.").arg(host, path));
777 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
778 m_host =
"[" + addr.toString().toLower() +
"]";
780 ret.setScheme(
"myth");
781 if (!storageGroup.isEmpty())
782 ret.setUserName(storageGroup);
784 if (port > 0 && port != 6543)
786 if (!path.startsWith(
"/"))
787 path = QString(
"/") + path;
791 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
792 QString(
"GenMythURL returning %1").arg(ret.toString()));
795 return ret.toString();
818 QStringList strlist(
"QUERY_HOSTNAME");
850 int &width,
int &height,
851 double &forced_aspect,
852 double &refresh_rate,
855 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
856 refresh_rate, index);
892 const QString &newValue,
895 return d->
m_database->SaveSettingOnHost(key, newValue, host);
899 const QString &defaultval)
908 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
916 return d->
m_database->GetNumSetting(key, defaultval);
923 return d->
m_database->GetFloatSetting(key, defaultval);
928 const QString &defaultval)
932 return d->
m_database->GetSettingOnHost(key, host, defaultval);
949 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
958 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
983 (
"MasterServerName");
985 (
"BackendServerPort", masterserver, 6543);
1111 QHostAddress addr1 = addr;
1112 addr1.setScopeId(QString());
1113 QString addrstr = addr1.toString();
1131 QHostAddress addr1 = addr;
1132 addr1.setScopeId(QString());
1135 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1145 QHostAddress addr1 = addr;
1146 addr1.setScopeId(QString());
1149 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1164 const QString &host,
1195 QHostAddress addr(host);
1197 if (!host.isEmpty() && addr.isNull())
1200 QHostInfo info = QHostInfo::fromName(host);
1201 QList<QHostAddress> list = info.addresses();
1205 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1206 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1213 for (
const auto& item : std::as_const(list))
1216 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1218 if (prot == QAbstractSocket::IPv4Protocol)
1224 else if (prot == QAbstractSocket::IPv6Protocol)
1234 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1237 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1240 addr = v6.isNull() ?
1241 (v4.isNull() ? QHostAddress::LocalHostIPv6 : v4) : v6;
1245 else if (host.isEmpty())
1252 addr.setScopeId(QString());
1254 return addr.toString();
1270 QHostAddress peer = socket->peerAddress();
1287 static const QHostAddress
kLinkLocal(
"fe80::");
1294 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1295 QString(
"Repeat denied connection from ip address: %1")
1296 .arg(peer.toString()));
1308 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1309 for (
const auto & qni : std::as_const(IFs))
1311 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1314 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1315 for (
const auto & qnai : std::as_const(IPs))
1317 int pfxlen = qnai.prefixLength();
1322 if (peer.isInSubnet(qnai.ip(),pfxlen))
1330 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1331 QString(
"Denied connection from ip address: %1")
1332 .arg(peer.toString()));
1338 const QString &value)
1340 d->
m_database->OverrideSettingForSession(key, value);
1345 d->
m_database->ClearOverrideSettingForSession(key);
1372 QStringList &strlist,
bool quickTimeout,
bool block)
1377 msg =
"SendReceiveStringList(";
1378 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1379 msg += (i?
",":
"") + strlist[i];
1380 msg += (strlist.size() > 2) ?
"...)" :
")";
1381 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1384 QString query_type =
"UNKNOWN";
1386 if (!strlist.isEmpty())
1387 query_type = strlist[0];
1401 std::chrono::milliseconds
timeout = quickTimeout ?
1407 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1408 QString(
"Connection to backend server lost"));
1431 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1434 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1435 QString message = strlist[1];
1436 strlist.pop_front(); strlist.pop_front();
1452 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1453 QString(
"Reconnection to backend server failed"));
1456 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1462 if (strlist.isEmpty())
1464 else if (strlist[0] ==
"ERROR")
1466 if (strlist.size() == 2)
1468 LOG(VB_GENERAL, LOG_INFO,
LOC +
1469 QString(
"Protocol query '%1' responded with the error '%2'")
1470 .arg(query_type, strlist[1]));
1474 LOG(VB_GENERAL, LOG_INFO,
LOC +
1475 QString(
"Protocol query '%1' responded with an error, but "
1476 "no error message.") .arg(query_type));
1481 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1483 LOG(VB_GENERAL, LOG_ERR,
LOC +
1484 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1506 QStringList strlist(
"MESSAGE");
1555 const QString &
args)
1565 QStringList strlist;
1569 if (strlist.size() < 2)
1572 QString
prefix = strlist[0];
1573 QString message = strlist[1];
1574 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1579 else if (
prefix !=
"BACKEND_MESSAGE")
1581 LOG(VB_NETWORK, LOG_ERR,
LOC +
1582 QString(
"Received a: %1 message from the backend "
1583 "but I don't know what to do with it.")
1586 else if (message ==
"CLEAR_SETTINGS_CACHE")
1589 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1592 else if (message.startsWith(
"FILE_WRITTEN"))
1598 if (tokens.size() == NUMTOKENS)
1601 size = tokens[2].toULongLong();
1605 LOG(VB_NETWORK, LOG_ERR,
LOC +
1606 QString(
"FILE_WRITTEN event received "
1607 "with invalid number of arguments, "
1608 "%1 expected, %2 actual")
1610 .arg(tokens.size()-1));
1614 LOG(VB_NETWORK, LOG_INFO,
LOC +
1615 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1618 else if (message.startsWith(
"FILE_CLOSED"))
1623 if (tokens.size() == NUMTOKENS)
1629 LOG(VB_NETWORK, LOG_ERR,
LOC +
1630 QString(
"FILE_CLOSED event received "
1631 "with invalid number of arguments, "
1632 "%1 expected, %2 actual")
1634 .arg(tokens.size()-1));
1638 LOG(VB_NETWORK, LOG_INFO,
LOC +
1639 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1644 strlist.pop_front();
1645 strlist.pop_front();
1655 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1656 "Event socket closed. No connection to the backend.");
1662 std::chrono::milliseconds
timeout,
1663 bool error_dialog_desired)
1668 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1669 .arg(MYTH_PROTO_VERSION,
1670 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1675 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1676 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1677 "This happens when the backend is too busy to respond,\n\t\t\t"
1678 "or has deadlocked due to bugs or hardware failure.");
1682 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1684 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1685 "(frontend=%1/%2,backend=%3/\?\?)\n")
1686 .arg(MYTH_PROTO_VERSION,
1687 QString::fromUtf8(MYTH_PROTO_TOKEN),
1692 QStringList list(strlist[1]);
1693 QCoreApplication::postEvent(
1699 if (strlist[0] ==
"ACCEPT")
1704 LOG(VB_GENERAL, LOG_INFO,
LOC +
1705 QString(
"Using protocol version %1 %2")
1706 .arg(MYTH_PROTO_VERSION,
1707 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1713 LOG(VB_GENERAL, LOG_ERR,
LOC +
1714 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1721 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1815 LOG(VB_AUDIO, LOG_DEBUG,
LOC + QString(
"audio language:%1 menu language:%2")
1829 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1856 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1869 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1889 LOG(VB_GENERAL, LOG_INFO,
1896 LOG(VB_GENERAL, LOG_ERR,
LOC +
1897 "No locale defined! We weren't able to set locale defaults.");
1919 QEventLoop eventLoop;
1920 for (
const auto& s : sigs)
1922 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1923 QString(
"Waiting for signal %1")
1928 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1939 if (!sender || !method)
1949 Qt::BlockingQueuedConnection);
1985 QThread *currentThread = QThread::currentThread();
1990 if (it.key() == sender)
1993 QThread *thread = it.key()->thread();
1995 if (thread != currentThread)
2017 Qt::BlockingQueuedConnection);
2022 if (it.key() == sender)
2025 QThread *thread = it.key()->thread();
2027 if (thread != currentThread)
2031 it.key(), it.value());
2033 it.key(), it.value(), Qt::BlockingQueuedConnection);
2068 return intvplayback;
2080 const QString &libversion,
2081 const QString &pluginversion)
2083 if (libversion == pluginversion)
2086 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2087 QString(
"Plugin %1 (%2) binary version does not "
2088 "match libraries (%3)")
2089 .arg(name, pluginversion, libversion));
2126 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2131 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2136 LOG(VB_FILE, LOG_DEBUG,
LOC +
2137 QString(
"%1").arg(
file));
2148 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2153 LOG(VB_FILE, LOG_DEBUG,
LOC +
2154 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.
QString GetAudioLanguage(void)
Returns two character ISO-639 language descriptor for audio language.
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)
void ResetAudioLanguage(void)
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)
QString GetAudioLanguageAndVariant(void)
Returns the user-set audio language and variant.
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="")