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 {
"Monitor" };
389 else if (blockingClient)
391 QString ann = QString(
"ANN %1 %2 %3")
394 server, port, ann, &proto_mismatch);
402 if (!openEventSocket)
421 QCoreApplication::postEvent(
432 const QString &
hostname,
int port,
const QString &announce,
433 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
447 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
449 std::chrono::seconds WOLsleepTime = 0s;
450 int WOLmaxConnTry = 0;
451 if (!WOLcmd.isEmpty())
453 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
454 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
455 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
458 bool we_attempted_wol =
false;
460 if (setup_timeout <= 0ms)
463 bool proto_mismatch =
false;
464 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
466 LOG(VB_GENERAL, LOG_INFO,
LOC +
467 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
468 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
472 std::chrono::microseconds sleepus = 0us;
476 serverSock, announce, setup_timeout, proto_mismatch))
483 if (p_proto_mismatch)
484 *p_proto_mismatch =
true;
487 serverSock =
nullptr;
491 setup_timeout += setup_timeout / 2;
493 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
495 if (!we_attempted_wol)
509 sleepus = WOLsleepTime;
513 serverSock =
nullptr;
517 QCoreApplication::postEvent(
522 usleep(sleepus.count());
525 if (we_attempted_wol)
532 if (!serverSock && !proto_mismatch)
534 LOG(VB_GENERAL, LOG_ERR,
535 "Connection to master server timed out.\n\t\t\t"
536 "Either the server is down or the master server settings"
538 "in mythtv-settings does not contain the proper IP address\n");
542 QCoreApplication::postEvent(
556 if (!eventSock->ConnectToHost(
hostname, port))
558 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
559 "socket to master backend");
560 eventSock->DecrRef();
564 QString str = QString(
"ANN Monitor %1 %2")
566 QStringList strlist(str);
567 eventSock->WriteStringList(strlist);
569 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
570 (strlist[0] ==
"ERROR"))
572 if (!strlist.empty())
574 LOG(VB_GENERAL, LOG_ERR,
LOC +
575 "Problem connecting event socket to master backend");
579 LOG(VB_GENERAL, LOG_ERR,
LOC +
580 "Timeout connecting event socket to master backend");
587 eventSock->DecrRef();
608 strlist <<
"BLOCK_SHUTDOWN";
622 strlist <<
"ALLOW_SHUTDOWN";
684 if (addr.toLower() == host.toLower())
686 QHostAddress addrfix(addr);
687 addrfix.setScopeId(QString());
688 QString addrstr = addrfix.toString();
689 if (addrfix.isNull())
693 return !addrstr.isEmpty()
694 && ((addrstr == thisip) || (addrstr == thisip6));
696 return GetSetting(
"MasterServerName") == host;
706 #if defined(Q_OS_DARWIN) || defined(__FreeBSD__) || defined(__OpenBSD__)
707 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
709 const char *command =
"%systemroot%\\system32\\tasklist.exe "
710 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
712 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
732 if (addr.toLower() == host.toLower())
735 QHostAddress addrfix(addr);
736 addrfix.setScopeId(QString());
737 QString addrstr = addrfix.toString();
739 if (addrfix.isNull())
746 return !addrstr.isEmpty() && ((addrstr == thisip));
752 bool backendOnLocalhost =
false;
754 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
759 backendOnLocalhost = strlist[0] !=
"FALSE";
761 return !backendOnLocalhost;
770 QHostAddress addr(host);
773 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
774 "IP address instead of hostname "
775 "(ID). This is invalid.").arg(host, path));
781 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
782 m_host =
"[" + addr.toString().toLower() +
"]";
784 ret.setScheme(
"myth");
785 if (!storageGroup.isEmpty())
786 ret.setUserName(storageGroup);
788 if (port > 0 && port != 6543)
790 if (!path.startsWith(
"/"))
791 path = QString(
"/") + path;
795 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
796 QString(
"GenMythURL returning %1").arg(ret.toString()));
799 return ret.toString();
822 QStringList strlist(
"QUERY_HOSTNAME");
854 int &width,
int &height,
855 double &forced_aspect,
856 double &refresh_rate,
859 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
860 refresh_rate, index);
896 const QString &newValue,
899 return d->
m_database->SaveSettingOnHost(key, newValue, host);
903 const QString &defaultval)
912 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
920 return d->
m_database->GetNumSetting(key, defaultval);
927 return d->
m_database->GetFloatSetting(key, defaultval);
932 const QString &defaultval)
936 return d->
m_database->GetSettingOnHost(key, host, defaultval);
953 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
962 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
987 (
"MasterServerName");
989 (
"BackendServerPort", masterserver, 6543);
1115 QHostAddress addr1 = addr;
1116 addr1.setScopeId(QString());
1117 QString addrstr = addr1.toString();
1135 QHostAddress addr1 = addr;
1136 addr1.setScopeId(QString());
1139 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1149 QHostAddress addr1 = addr;
1150 addr1.setScopeId(QString());
1153 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1168 const QString &host,
1199 QHostAddress addr(host);
1201 if (!host.isEmpty() && addr.isNull())
1204 QHostInfo
info = QHostInfo::fromName(host);
1205 QList<QHostAddress> list =
info.addresses();
1209 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1210 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1217 for (
const auto& item : std::as_const(list))
1220 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1222 if (prot == QAbstractSocket::IPv4Protocol)
1228 else if (prot == QAbstractSocket::IPv6Protocol)
1238 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1241 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1246 else if (!v4.isNull())
1249 addr = QHostAddress::LocalHostIPv6;
1253 else if (host.isEmpty())
1260 addr.setScopeId(QString());
1262 return addr.toString();
1278 QHostAddress peer = socket->peerAddress();
1295 static const QHostAddress
kLinkLocal(
"fe80::");
1302 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1303 QString(
"Repeat denied connection from ip address: %1")
1304 .arg(peer.toString()));
1316 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1317 for (
const auto & qni : std::as_const(IFs))
1319 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1322 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1323 for (
const auto & qnai : std::as_const(IPs))
1325 int pfxlen = qnai.prefixLength();
1330 if (peer.isInSubnet(qnai.ip(),pfxlen))
1338 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1339 QString(
"Denied connection from ip address: %1")
1340 .arg(peer.toString()));
1346 const QString &value)
1348 d->
m_database->OverrideSettingForSession(key, value);
1353 d->
m_database->ClearOverrideSettingForSession(key);
1380 QStringList &strlist,
bool quickTimeout,
bool block)
1385 msg =
"SendReceiveStringList(";
1386 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1387 msg += (i?
",":
"") + strlist[i];
1388 msg += (strlist.size() > 2) ?
"...)" :
")";
1389 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1392 QString query_type =
"UNKNOWN";
1394 if (!strlist.isEmpty())
1395 query_type = strlist[0];
1409 std::chrono::milliseconds
timeout = quickTimeout ?
1415 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1416 QString(
"Connection to backend server lost"));
1439 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1442 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1443 QString message = strlist[1];
1444 strlist.pop_front(); strlist.pop_front();
1460 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1461 QString(
"Reconnection to backend server failed"));
1464 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1470 if (strlist.isEmpty())
1472 else if (strlist[0] ==
"ERROR")
1474 if (strlist.size() == 2)
1476 LOG(VB_GENERAL, LOG_INFO,
LOC +
1477 QString(
"Protocol query '%1' responded with the error '%2'")
1478 .arg(query_type, strlist[1]));
1482 LOG(VB_GENERAL, LOG_INFO,
LOC +
1483 QString(
"Protocol query '%1' responded with an error, but "
1484 "no error message.") .arg(query_type));
1489 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1491 LOG(VB_GENERAL, LOG_ERR,
LOC +
1492 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1514 QStringList strlist(
"MESSAGE");
1563 const QString &
args)
1573 QStringList strlist;
1577 if (strlist.size() < 2)
1580 QString
prefix = strlist[0];
1581 QString message = strlist[1];
1582 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1587 else if (
prefix !=
"BACKEND_MESSAGE")
1589 LOG(VB_NETWORK, LOG_ERR,
LOC +
1590 QString(
"Received a: %1 message from the backend "
1591 "but I don't know what to do with it.")
1594 else if (message ==
"CLEAR_SETTINGS_CACHE")
1597 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1600 else if (message.startsWith(
"FILE_WRITTEN"))
1606 if (tokens.size() == NUMTOKENS)
1609 size = tokens[2].toULongLong();
1613 LOG(VB_NETWORK, LOG_ERR,
LOC +
1614 QString(
"FILE_WRITTEN event received "
1615 "with invalid number of arguments, "
1616 "%1 expected, %2 actual")
1618 .arg(tokens.size()-1));
1622 LOG(VB_NETWORK, LOG_INFO,
LOC +
1623 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1626 else if (message.startsWith(
"FILE_CLOSED"))
1631 if (tokens.size() == NUMTOKENS)
1637 LOG(VB_NETWORK, LOG_ERR,
LOC +
1638 QString(
"FILE_CLOSED event received "
1639 "with invalid number of arguments, "
1640 "%1 expected, %2 actual")
1642 .arg(tokens.size()-1));
1646 LOG(VB_NETWORK, LOG_INFO,
LOC +
1647 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1652 strlist.pop_front();
1653 strlist.pop_front();
1663 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1664 "Event socket closed. No connection to the backend.");
1670 std::chrono::milliseconds
timeout,
1671 bool error_dialog_desired)
1676 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1677 .arg(MYTH_PROTO_VERSION,
1678 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1683 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1684 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1685 "This happens when the backend is too busy to respond,\n\t\t\t"
1686 "or has deadlocked due to bugs or hardware failure.");
1690 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1692 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1693 "(frontend=%1/%2,backend=%3/\?\?)\n")
1694 .arg(MYTH_PROTO_VERSION,
1695 QString::fromUtf8(MYTH_PROTO_TOKEN),
1700 QStringList list(strlist[1]);
1701 QCoreApplication::postEvent(
1707 if (strlist[0] ==
"ACCEPT")
1712 LOG(VB_GENERAL, LOG_INFO,
LOC +
1713 QString(
"Using protocol version %1 %2")
1714 .arg(MYTH_PROTO_VERSION,
1715 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1721 LOG(VB_GENERAL, LOG_ERR,
LOC +
1722 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1729 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1823 LOG(VB_AUDIO, LOG_DEBUG,
LOC + QString(
"audio language:%1 menu language:%2")
1837 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1864 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1877 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1897 LOG(VB_GENERAL, LOG_INFO,
1904 LOG(VB_GENERAL, LOG_ERR,
LOC +
1905 "No locale defined! We weren't able to set locale defaults.");
1927 QEventLoop eventLoop;
1928 for (
const auto& s : sigs)
1930 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1931 QString(
"Waiting for signal %1")
1936 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1947 if (!sender || !method)
1957 Qt::BlockingQueuedConnection);
1993 QThread *currentThread = QThread::currentThread();
1998 if (it.key() == sender)
2001 QThread *thread = it.key()->thread();
2003 if (thread != currentThread)
2025 Qt::BlockingQueuedConnection);
2030 if (it.key() == sender)
2033 QThread *thread = it.key()->thread();
2035 if (thread != currentThread)
2039 it.key(), it.value());
2041 it.key(), it.value(), Qt::BlockingQueuedConnection);
2076 return intvplayback;
2088 const QString &libversion,
2089 const QString &pluginversion)
2091 if (libversion == pluginversion)
2094 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2095 QString(
"Plugin %1 (%2) binary version does not "
2096 "match libraries (%3)")
2097 .arg(name, pluginversion, libversion));
2134 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2139 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2144 LOG(VB_FILE, LOG_DEBUG,
LOC +
2145 QString(
"%1").arg(
file));
2156 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2161 LOG(VB_FILE, LOG_DEBUG,
LOC +
2162 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)
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
@ GENERIC_EXIT_OK
Exited with no error.
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="")