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>
43 #include "mythversion.h"
52 #define LOC QString("MythCoreContext::%1(): ").arg(__func__)
63 bool WaitForWOL(std::chrono::milliseconds
timeout = std::chrono::milliseconds::max());
127 m_guiContext(guicontext),
128 m_appBinaryVersion(
std::move(binversion)),
130 m_uiThread(QThread::currentThread())
136 #
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
137 QMutexLocker &locker,
139 QMutexLocker<QMutex> &locker,
184 GetMythDB()->GetDBManager()->CloseDatabases();
199 std::chrono::milliseconds timeout_remaining =
timeout;
202 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Wake-On-LAN in progress, waiting...");
204 std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
206 timeout_remaining -= max_wait;
222 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Out-of-memory");
228 LOG(VB_GENERAL, LOG_CRIT,
229 QString(
"Application binary version (%1) does not "
230 "match libraries (%2)")
233 QString warning = tr(
"This application is not compatible with the "
234 "installed MythTV libraries. Please recompile "
235 "after a make distclean");
236 LOG(VB_GENERAL, LOG_WARNING, warning);
242 QString lang_variables(
"");
243 QString lc_value = setlocale(LC_CTYPE,
nullptr);
244 if (lc_value.isEmpty())
248 lc_value = qEnvironmentVariable(
"LC_ALL");
249 if (lc_value.isEmpty())
250 lc_value = qEnvironmentVariable(
"LC_CTYPE");
252 if (!lc_value.contains(
"UTF-8", Qt::CaseInsensitive))
253 lang_variables.append(
"LC_ALL or LC_CTYPE");
254 lc_value = qEnvironmentVariable(
"LANG");
255 if (!lc_value.contains(
"UTF-8", Qt::CaseInsensitive))
257 if (!lang_variables.isEmpty())
258 lang_variables.append(
", and ");
259 lang_variables.append(
"LANG");
261 LOG(VB_GENERAL, LOG_INFO, QString(
"Assumed character encoding: %1")
263 if (!lang_variables.isEmpty())
265 LOG(VB_GENERAL, LOG_WARNING, QString(
"This application expects to "
266 "be running a locale that specifies a UTF-8 codeset, and many "
267 "features may behave improperly with your current language "
268 "settings. Please set the %1 variable(s) in the environment "
269 "in which this program is executed to include a UTF-8 codeset "
270 "(such as 'en_US.UTF-8').").arg(lang_variables));
299 const QString &announcement,
300 std::chrono::milliseconds
timeout,
301 bool &proto_mismatch)
303 proto_mismatch =
false;
305 #ifndef IGNORE_PROTO_VER_MISMATCH
308 proto_mismatch =
true;
315 QStringList strlist(announcement);
319 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Connecting server socket to "
320 "master backend, socket write failed");
325 strlist.empty() || (strlist[0] ==
"ERROR"))
327 if (!strlist.empty())
329 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Problem connecting "
330 "server socket to master backend");
334 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Timeout connecting "
335 "server socket to master backend");
345 bool openEventSocket)
356 bool openEventSocket)
362 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ERROR: Master backend tried to connect back "
370 if (server.isEmpty())
374 bool proto_mismatch =
false;
384 QString
type =
IsFrontend() ?
"Frontend" : (blockingClient ?
"Playback" :
"Monitor");
385 QString ann = QString(
"ANN %1 %2 %3")
388 server, port, ann, &proto_mismatch);
396 if (!openEventSocket)
415 QCoreApplication::postEvent(
426 const QString &
hostname,
int port,
const QString &announce,
427 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
441 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
443 std::chrono::seconds WOLsleepTime = 0s;
444 int WOLmaxConnTry = 0;
445 if (!WOLcmd.isEmpty())
447 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
448 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
449 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
452 bool we_attempted_wol =
false;
454 if (setup_timeout <= 0ms)
457 bool proto_mismatch =
false;
458 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
460 LOG(VB_GENERAL, LOG_INFO,
LOC +
461 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
462 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
466 std::chrono::microseconds sleepus = 0us;
470 serverSock, announce, setup_timeout, proto_mismatch))
477 if (p_proto_mismatch)
478 *p_proto_mismatch =
true;
481 serverSock =
nullptr;
485 setup_timeout += setup_timeout / 2;
487 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
489 if (!we_attempted_wol)
503 sleepus = WOLsleepTime;
507 serverSock =
nullptr;
511 QCoreApplication::postEvent(
516 usleep(sleepus.count());
519 if (we_attempted_wol)
526 if (!serverSock && !proto_mismatch)
528 LOG(VB_GENERAL, LOG_ERR,
529 "Connection to master server timed out.\n\t\t\t"
530 "Either the server is down or the master server settings"
532 "in mythtv-settings does not contain the proper IP address\n");
536 QCoreApplication::postEvent(
550 if (!eventSock->ConnectToHost(
hostname, port))
552 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
553 "socket to master backend");
554 eventSock->DecrRef();
558 QString str = QString(
"ANN Monitor %1 %2")
560 QStringList strlist(str);
561 eventSock->WriteStringList(strlist);
563 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
564 (strlist[0] ==
"ERROR"))
566 if (!strlist.empty())
568 LOG(VB_GENERAL, LOG_ERR,
LOC +
569 "Problem connecting event socket to master backend");
573 LOG(VB_GENERAL, LOG_ERR,
LOC +
574 "Timeout connecting event socket to master backend");
581 eventSock->DecrRef();
602 strlist <<
"BLOCK_SHUTDOWN";
616 strlist <<
"ALLOW_SHUTDOWN";
678 if (addr.toLower() == host.toLower())
680 QHostAddress addrfix(addr);
681 addrfix.setScopeId(QString());
682 QString addrstr = addrfix.toString();
683 if (addrfix.isNull())
687 return !addrstr.isEmpty()
688 && ((addrstr == thisip) || (addrstr == thisip6));
690 return GetSetting(
"MasterServerName") == host;
700 #if defined(Q_OS_DARWIN) || defined(__FreeBSD__) || defined(__OpenBSD__)
701 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
703 const char *command =
"%systemroot%\\system32\\tasklist.exe "
704 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
706 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
726 if (addr.toLower() == host.toLower())
729 QHostAddress addrfix(addr);
730 addrfix.setScopeId(QString());
731 QString addrstr = addrfix.toString();
733 if (addrfix.isNull())
740 return !addrstr.isEmpty() && ((addrstr == thisip));
746 bool backendOnLocalhost =
false;
748 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
753 backendOnLocalhost = strlist[0] !=
"FALSE";
755 return !backendOnLocalhost;
764 QHostAddress addr(host);
767 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
768 "IP address instead of hostname "
769 "(ID). This is invalid.").arg(host, path));
775 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
776 m_host =
"[" + addr.toString().toLower() +
"]";
778 ret.setScheme(
"myth");
779 if (!storageGroup.isEmpty())
780 ret.setUserName(storageGroup);
782 if (port > 0 && port != 6543)
784 if (!path.startsWith(
"/"))
785 path = QString(
"/") + path;
789 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
790 QString(
"GenMythURL returning %1").arg(ret.toString()));
793 return ret.toString();
816 QStringList strlist(
"QUERY_HOSTNAME");
848 int &width,
int &height,
849 double &forced_aspect,
850 double &refresh_rate,
853 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
854 refresh_rate, index);
890 const QString &newValue,
893 return d->
m_database->SaveSettingOnHost(key, newValue, host);
897 const QString &defaultval)
906 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
914 return d->
m_database->GetNumSetting(key, defaultval);
921 return d->
m_database->GetFloatSetting(key, defaultval);
926 const QString &defaultval)
930 return d->
m_database->GetSettingOnHost(key, host, defaultval);
947 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
956 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
981 (
"MasterServerName");
983 (
"BackendServerPort", masterserver, 6543);
1109 QHostAddress addr1 = addr;
1110 addr1.setScopeId(QString());
1111 QString addrstr = addr1.toString();
1129 QHostAddress addr1 = addr;
1130 addr1.setScopeId(QString());
1133 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1143 QHostAddress addr1 = addr;
1144 addr1.setScopeId(QString());
1147 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1162 const QString &host,
1193 QHostAddress addr(host);
1195 if (!host.isEmpty() && addr.isNull())
1198 QHostInfo info = QHostInfo::fromName(host);
1199 QList<QHostAddress> list = info.addresses();
1203 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1204 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1211 for (
const auto& item : qAsConst(list))
1214 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1216 if (prot == QAbstractSocket::IPv4Protocol)
1222 else if (prot == QAbstractSocket::IPv6Protocol)
1232 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1235 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1238 addr = v6.isNull() ?
1239 (v4.isNull() ? QHostAddress::LocalHostIPv6 : v4) : v6;
1243 else if (host.isEmpty())
1250 addr.setScopeId(QString());
1252 return addr.toString();
1268 QHostAddress peer = socket->peerAddress();
1285 static const QHostAddress
kLinkLocal(
"fe80::");
1292 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1293 QString(
"Repeat denied connection from ip address: %1")
1294 .arg(peer.toString()));
1306 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1307 for (
const auto & qni : qAsConst(IFs))
1309 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1312 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1313 for (
const auto & qnai : qAsConst(IPs))
1315 int pfxlen = qnai.prefixLength();
1320 if (peer.isInSubnet(qnai.ip(),pfxlen))
1328 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1329 QString(
"Denied connection from ip address: %1")
1330 .arg(peer.toString()));
1336 const QString &value)
1338 d->
m_database->OverrideSettingForSession(key, value);
1343 d->
m_database->ClearOverrideSettingForSession(key);
1370 QStringList &strlist,
bool quickTimeout,
bool block)
1375 msg =
"SendReceiveStringList(";
1376 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1377 msg += (i?
",":
"") + strlist[i];
1378 msg += (strlist.size() > 2) ?
"...)" :
")";
1379 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1382 QString query_type =
"UNKNOWN";
1384 if (!strlist.isEmpty())
1385 query_type = strlist[0];
1399 std::chrono::milliseconds
timeout = quickTimeout ?
1405 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1406 QString(
"Connection to backend server lost"));
1429 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1432 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1433 QString message = strlist[1];
1434 strlist.pop_front(); strlist.pop_front();
1450 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1451 QString(
"Reconnection to backend server failed"));
1454 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1460 if (strlist.isEmpty())
1462 else if (strlist[0] ==
"ERROR")
1464 if (strlist.size() == 2)
1466 LOG(VB_GENERAL, LOG_INFO,
LOC +
1467 QString(
"Protocol query '%1' responded with the error '%2'")
1468 .arg(query_type, strlist[1]));
1472 LOG(VB_GENERAL, LOG_INFO,
LOC +
1473 QString(
"Protocol query '%1' responded with an error, but "
1474 "no error message.") .arg(query_type));
1479 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1481 LOG(VB_GENERAL, LOG_ERR,
LOC +
1482 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1504 QStringList strlist(
"MESSAGE");
1553 const QString &
args)
1563 QStringList strlist;
1567 if (strlist.size() < 2)
1570 QString
prefix = strlist[0];
1571 QString message = strlist[1];
1572 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
1573 QStringList tokens = message.split(
" ", QString::SkipEmptyParts);
1575 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1581 else if (
prefix !=
"BACKEND_MESSAGE")
1583 LOG(VB_NETWORK, LOG_ERR,
LOC +
1584 QString(
"Received a: %1 message from the backend "
1585 "but I don't know what to do with it.")
1588 else if (message ==
"CLEAR_SETTINGS_CACHE")
1591 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1594 else if (message.startsWith(
"FILE_WRITTEN"))
1600 if (tokens.size() == NUMTOKENS)
1603 size = tokens[2].toULongLong();
1607 LOG(VB_NETWORK, LOG_ERR,
LOC +
1608 QString(
"FILE_WRITTEN event received "
1609 "with invalid number of arguments, "
1610 "%1 expected, %2 actual")
1612 .arg(tokens.size()-1));
1616 LOG(VB_NETWORK, LOG_INFO,
LOC +
1617 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1620 else if (message.startsWith(
"FILE_CLOSED"))
1625 if (tokens.size() == NUMTOKENS)
1631 LOG(VB_NETWORK, LOG_ERR,
LOC +
1632 QString(
"FILE_CLOSED event received "
1633 "with invalid number of arguments, "
1634 "%1 expected, %2 actual")
1636 .arg(tokens.size()-1));
1640 LOG(VB_NETWORK, LOG_INFO,
LOC +
1641 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1646 strlist.pop_front();
1647 strlist.pop_front();
1659 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1660 "Event socket closed. No connection to the backend.");
1666 std::chrono::milliseconds
timeout,
1667 bool error_dialog_desired)
1672 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1673 .arg(MYTH_PROTO_VERSION,
1674 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1679 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1680 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1681 "This happens when the backend is too busy to respond,\n\t\t\t"
1682 "or has deadlocked due to bugs or hardware failure.");
1686 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1688 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1689 "(frontend=%1/%2,backend=%3/\?\?)\n")
1690 .arg(MYTH_PROTO_VERSION,
1691 QString::fromUtf8(MYTH_PROTO_TOKEN),
1696 QStringList list(strlist[1]);
1697 QCoreApplication::postEvent(
1703 if (strlist[0] ==
"ACCEPT")
1708 LOG(VB_GENERAL, LOG_INFO,
LOC +
1709 QString(
"Using protocol version %1 %2")
1710 .arg(MYTH_PROTO_VERSION,
1711 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1717 LOG(VB_GENERAL, LOG_ERR,
LOC +
1718 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1725 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1799 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1826 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1839 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1859 LOG(VB_GENERAL, LOG_INFO,
1866 LOG(VB_GENERAL, LOG_ERR,
LOC +
1867 "No locale defined! We weren't able to set locale defaults.");
1889 QEventLoop eventLoop;
1890 for (
const auto& s : sigs)
1892 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1893 QString(
"Waiting for signal %1")
1898 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1909 if (!sender || !method)
1919 Qt::BlockingQueuedConnection);
1955 QThread *currentThread = QThread::currentThread();
1960 if (it.key() == sender)
1963 QThread *thread = it.key()->thread();
1965 if (thread != currentThread)
1987 Qt::BlockingQueuedConnection);
1992 if (it.key() == sender)
1995 QThread *thread = it.key()->thread();
1997 if (thread != currentThread)
2001 it.key(), it.value());
2003 it.key(), it.value(), Qt::BlockingQueuedConnection);
2038 return intvplayback;
2050 const QString &libversion,
2051 const QString &pluginversion)
2053 if (libversion == pluginversion)
2056 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2057 QString(
"Plugin %1 (%2) binary version does not "
2058 "match libraries (%3)")
2059 .arg(name, pluginversion, libversion));
2096 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2101 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2106 LOG(VB_FILE, LOG_DEBUG,
LOC +
2107 QString(
"%1").arg(
file));
2118 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2123 LOG(VB_FILE, LOG_DEBUG,
LOC +
2124 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="")