5#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
6#include <QtSystemDetection>
8#include <QCoreApplication>
15#include <QWaitCondition>
16#include <QAbstractSocket>
17#include <QHostAddress>
19#include <QNetworkInterface>
20#include <QNetworkAddressEntry>
23#include <QRegularExpression>
49#include "mythversion.h"
58#define LOC QString("MythCoreContext::%1(): ").arg(__func__)
69 bool WaitForWOL(std::chrono::milliseconds
timeout = std::chrono::milliseconds::max());
135 m_guiContext(guicontext),
136 m_appBinaryVersion(std::move(binversion)),
138 m_uiThread(QThread::currentThread())
144#
if QT_VERSION < QT_VERSION_CHECK(6,0,0)
145 QMutexLocker &locker,
147 QMutexLocker<QMutex> &locker,
192 GetMythDB()->GetDBManager()->CloseDatabases();
207 std::chrono::milliseconds timeout_remaining =
timeout;
210 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Wake-On-LAN in progress, waiting...");
212 std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
214 timeout_remaining -= max_wait;
230 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"Out-of-memory");
236 LOG(VB_GENERAL, LOG_CRIT,
237 QString(
"Application binary version (%1) does not "
238 "match libraries (%2)")
241 QString warning = tr(
"This application is not compatible with the "
242 "installed MythTV libraries. Please recompile "
243 "after a make distclean");
244 LOG(VB_GENERAL, LOG_WARNING, warning);
250 static const QRegularExpression utf8
251 {
"utf-?8", QRegularExpression::CaseInsensitiveOption };
252 QString lang_variables(
"");
253 QString lc_value = setlocale(LC_CTYPE,
nullptr);
254 if (lc_value.isEmpty())
258 lc_value = qEnvironmentVariable(
"LC_ALL");
259 if (lc_value.isEmpty())
260 lc_value = qEnvironmentVariable(
"LC_CTYPE");
262 if (!lc_value.contains(utf8))
263 lang_variables.append(
"LC_ALL or LC_CTYPE");
264 lc_value = qEnvironmentVariable(
"LANG");
265 if (!lc_value.contains(utf8))
267 if (!lang_variables.isEmpty())
268 lang_variables.append(
", and ");
269 lang_variables.append(
"LANG");
271 LOG(VB_GENERAL, LOG_INFO, QString(
"Assumed character encoding: %1")
273 if (!lang_variables.isEmpty())
275 LOG(VB_GENERAL, LOG_WARNING, QString(
"This application expects to "
276 "be running a locale that specifies a UTF-8 codeset, and many "
277 "features may behave improperly with your current language "
278 "settings. Please set the %1 variable(s) in the environment "
279 "in which this program is executed to include a UTF-8 codeset "
280 "(such as 'en_US.UTF-8').").arg(lang_variables));
309 const QString &announcement,
310 [[maybe_unused]] std::chrono::milliseconds
timeout,
311 bool &proto_mismatch)
313 proto_mismatch =
false;
315#ifndef IGNORE_PROTO_VER_MISMATCH
318 proto_mismatch =
true;
323 QStringList strlist(announcement);
327 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Connecting server socket to "
328 "master backend, socket write failed");
333 strlist.empty() || (strlist[0] ==
"ERROR"))
335 if (!strlist.empty())
337 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Problem connecting "
338 "server socket to master backend");
342 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Timeout connecting "
343 "server socket to master backend");
353 bool openEventSocket)
364 bool openEventSocket)
370 LOG(VB_GENERAL, LOG_ERR,
LOC +
"ERROR: Master backend tried to connect back "
378 if (server.isEmpty())
382 bool proto_mismatch =
false;
392 QString
type {
"Monitor" };
395 else if (blockingClient)
397 QString ann = QString(
"ANN %1 %2 %3")
400 server, port, ann, &proto_mismatch);
408 if (!openEventSocket)
427 QCoreApplication::postEvent(
438 const QString &
hostname,
int port,
const QString &announce,
439 bool *p_proto_mismatch,
int maxConnTry, std::chrono::milliseconds setup_timeout)
453 maxConnTry = std::max(
GetNumSetting(
"BackendConnectRetry", 1), 1);
455 std::chrono::seconds WOLsleepTime = 0s;
456 int WOLmaxConnTry = 0;
457 if (!WOLcmd.isEmpty())
459 WOLsleepTime = GetDurSetting<std::chrono::seconds>(
"WOLbackendReconnectWaitTime", 0s);
460 WOLmaxConnTry = std::max(
GetNumSetting(
"WOLbackendConnectRetry", 1), 1);
461 maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
464 bool we_attempted_wol =
false;
466 if (setup_timeout <= 0ms)
469 bool proto_mismatch =
false;
470 for (
int cnt = 1; cnt <= maxConnTry; cnt++)
472 LOG(VB_GENERAL, LOG_INFO,
LOC +
473 QString(
"Connecting to backend server: %1:%2 (try %3 of %4)")
474 .arg(
hostname).arg(port).arg(cnt).arg(maxConnTry));
478 std::chrono::microseconds sleepus = 0us;
482 serverSock, announce, setup_timeout, proto_mismatch))
489 if (p_proto_mismatch)
490 *p_proto_mismatch =
true;
493 serverSock =
nullptr;
497 setup_timeout += setup_timeout / 2;
499 else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
501 if (!we_attempted_wol)
515 sleepus = WOLsleepTime;
519 serverSock =
nullptr;
523 QCoreApplication::postEvent(
528 std::this_thread::sleep_for(sleepus);
531 if (we_attempted_wol)
538 if (!serverSock && !proto_mismatch)
540 LOG(VB_GENERAL, LOG_ERR,
541 "Connection to master server timed out.\n\t\t\t"
542 "Either the server is down or the master server settings"
544 "in mythtv-settings does not contain the proper IP address\n");
548 QCoreApplication::postEvent(
562 if (!eventSock->ConnectToHost(
hostname, port))
564 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to connect event "
565 "socket to master backend");
566 eventSock->DecrRef();
570 QString str = QString(
"ANN Monitor %1 %2")
572 QStringList strlist(str);
573 eventSock->WriteStringList(strlist);
575 if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
576 (strlist[0] ==
"ERROR"))
578 if (!strlist.empty())
580 LOG(VB_GENERAL, LOG_ERR,
LOC +
581 "Problem connecting event socket to master backend");
585 LOG(VB_GENERAL, LOG_ERR,
LOC +
586 "Timeout connecting event socket to master backend");
593 eventSock->DecrRef();
614 strlist <<
"BLOCK_SHUTDOWN";
628 strlist <<
"ALLOW_SHUTDOWN";
690 if (addr.toLower() == host.toLower())
692 QHostAddress addrfix(addr);
693 addrfix.setScopeId(QString());
694 QString addrstr = addrfix.toString();
695 if (addrfix.isNull())
699 return !addrstr.isEmpty()
700 && ((addrstr == thisip) || (addrstr == thisip6));
702 return GetSetting(
"MasterServerName") == host;
713 const char *command =
"ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
714#elif defined(Q_OS_WINDOWS)
715 const char *command =
"%systemroot%\\system32\\tasklist.exe "
716 " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
718 const char *command =
"ps ch -C mythbackend -o pid > /dev/null";
738 if (addr.toLower() == host.toLower())
741 QHostAddress addrfix(addr);
742 addrfix.setScopeId(QString());
743 QString addrstr = addrfix.toString();
745 if (addrfix.isNull())
752 return !addrstr.isEmpty() && (addrstr == thisip);
758 bool backendOnLocalhost =
false;
760 QStringList strlist(
"QUERY_IS_ACTIVE_BACKEND");
765 backendOnLocalhost = strlist[0] !=
"FALSE";
767 return !backendOnLocalhost;
776 QHostAddress addr(host);
779 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"(%1/%2): Given "
780 "IP address instead of hostname "
781 "(ID). This is invalid.").arg(host, path));
787 if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
788 m_host =
"[" + addr.toString().toLower() +
"]";
790 ret.setScheme(
"myth");
791 if (!storageGroup.isEmpty())
792 ret.setUserName(storageGroup);
794 if (port > 0 && port != 6543)
796 if (!path.startsWith(
"/"))
797 path = QString(
"/") + path;
801 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
802 QString(
"GenMythURL returning %1").arg(ret.toString()));
805 return ret.toString();
830 QStringList strlist(
"QUERY_HOSTNAME");
862 int &width,
int &height,
863 double &forced_aspect,
864 double &refresh_rate,
867 d->
m_database->GetResolutionSetting(
type, width, height, forced_aspect,
868 refresh_rate, index);
904 const QString &newValue,
907 return d->
m_database->SaveSettingOnHost(key, newValue, host);
911 const QString &defaultval)
920 int result =
GetNumSetting(key,
static_cast<int>(defaultval));
928 return d->
m_database->GetNumSetting(key, defaultval);
935 return d->
m_database->GetFloatSetting(key, defaultval);
940 const QString &defaultval)
944 return d->
m_database->GetSettingOnHost(key, host, defaultval);
961 return d->
m_database->GetNumSettingOnHost(key, host, defaultval);
970 return d->
m_database->GetFloatSettingOnHost(key, host, defaultval);
995 (
"MasterServerName");
997 (
"BackendServerPort", masterserver, 6543);
1123 QHostAddress addr1 = addr;
1124 addr1.setScopeId(QString());
1125 QString addrstr = addr1.toString();
1143 QHostAddress addr1 = addr;
1144 addr1.setScopeId(QString());
1147 d->
m_scopes.insert(addr1.toString(), addr.scopeId());
1157 QHostAddress addr1 = addr;
1158 addr1.setScopeId(QString());
1161 d->
m_scopes.insert(addr1.toString(), QString::number(scope));
1176 const QString &host,
1207 QHostAddress addr(host);
1209 if (!host.isEmpty() && addr.isNull())
1212 QHostInfo
info = QHostInfo::fromName(host);
1213 QList<QHostAddress> list =
info.addresses();
1217 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1218 QString(
"Can't resolve hostname:'%1', using localhost").arg(host));
1225 for (
const auto& item : std::as_const(list))
1228 QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1230 if (prot == QAbstractSocket::IPv4Protocol)
1236 else if (prot == QAbstractSocket::IPv6Protocol)
1246 addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1249 addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1254 else if (!v4.isNull())
1257 addr = QHostAddress::LocalHostIPv6;
1261 else if (host.isEmpty())
1268 addr.setScopeId(QString());
1270 return addr.toString();
1286 QHostAddress peer = socket->peerAddress();
1318 static const QHostAddress
kLinkLocal(
"fe80::");
1326 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1327 QString(
"Repeat denied connection from ip address: %1")
1328 .arg(peer.toString()));
1340 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1341 for (
const auto & qni : std::as_const(IFs))
1343 if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1346 QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1347 for (
const auto & qnai : std::as_const(IPs))
1349 int pfxlen = qnai.prefixLength();
1354 if (peer.isInSubnet(qnai.ip(),pfxlen))
1363 LOG(VB_GENERAL, LOG_WARNING,
LOC +
1364 QString(
"Denied connection from ip address: %1")
1365 .arg(peer.toString()));
1371 const QString &value)
1373 d->
m_database->OverrideSettingForSession(key, value);
1378 d->
m_database->ClearOverrideSettingForSession(key);
1405 QStringList &strlist,
bool quickTimeout,
bool block)
1410 msg =
"SendReceiveStringList(";
1411 for (
uint i=0; i<(
uint)strlist.size() && i<2; i++)
1412 msg += (i?
",":
"") + strlist[i];
1413 msg += (strlist.size() > 2) ?
"...)" :
")";
1414 LOG(VB_GENERAL, LOG_DEBUG,
LOC + msg +
" called from UI thread");
1417 QString query_type =
"UNKNOWN";
1419 if (!strlist.isEmpty())
1420 query_type = strlist[0];
1434 std::chrono::milliseconds
timeout = quickTimeout ?
1440 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1441 QString(
"Connection to backend server lost"));
1464 while (ok && strlist[0] ==
"BACKEND_MESSAGE")
1467 LOG(VB_GENERAL, LOG_EMERG,
LOC +
"SRSL you shouldn't see this!!");
1468 QString message = strlist[1];
1469 strlist.pop_front(); strlist.pop_front();
1485 LOG(VB_GENERAL, LOG_CRIT,
LOC +
1486 QString(
"Reconnection to backend server failed"));
1489 new MythEvent(
"PERSISTENT_CONNECTION_FAILURE"));
1495 if (strlist.isEmpty())
1499 else if (strlist[0] ==
"ERROR")
1501 if (strlist.size() == 2)
1503 LOG(VB_GENERAL, LOG_INFO,
LOC +
1504 QString(
"Protocol query '%1' responded with the error '%2'")
1505 .arg(query_type, strlist[1]));
1509 LOG(VB_GENERAL, LOG_INFO,
LOC +
1510 QString(
"Protocol query '%1' responded with an error, but "
1511 "no error message.") .arg(query_type));
1516 else if (strlist[0] ==
"UNKNOWN_COMMAND")
1518 LOG(VB_GENERAL, LOG_ERR,
LOC +
1519 QString(
"Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1541 QStringList strlist(
"MESSAGE");
1590 const QString &
args)
1600 QStringList strlist;
1604 if (strlist.size() < 2)
1607 QString
prefix = strlist[0];
1608 QString message = strlist[1];
1609 QStringList tokens = message.split(
" ", Qt::SkipEmptyParts);
1614 else if (
prefix !=
"BACKEND_MESSAGE")
1616 LOG(VB_NETWORK, LOG_ERR,
LOC +
1617 QString(
"Received a: %1 message from the backend "
1618 "but I don't know what to do with it.")
1621 else if (message ==
"CLEAR_SETTINGS_CACHE")
1624 LOG(VB_NETWORK, LOG_INFO,
LOC +
"Received remote 'Clear Cache' request");
1627 else if (message.startsWith(
"FILE_WRITTEN"))
1633 if (tokens.size() == NUMTOKENS)
1636 size = tokens[2].toULongLong();
1640 LOG(VB_NETWORK, LOG_ERR,
LOC +
1641 QString(
"FILE_WRITTEN event received "
1642 "with invalid number of arguments, "
1643 "%1 expected, %2 actual")
1645 .arg(tokens.size()-1));
1649 LOG(VB_NETWORK, LOG_INFO,
LOC +
1650 QString(
"Received remote 'FILE_WRITTEN %1' request").arg(
file));
1653 else if (message.startsWith(
"FILE_CLOSED"))
1658 if (tokens.size() == NUMTOKENS)
1664 LOG(VB_NETWORK, LOG_ERR,
LOC +
1665 QString(
"FILE_CLOSED event received "
1666 "with invalid number of arguments, "
1667 "%1 expected, %2 actual")
1669 .arg(tokens.size()-1));
1673 LOG(VB_NETWORK, LOG_INFO,
LOC +
1674 QString(
"Received remote 'FILE_CLOSED %1' request").arg(
file));
1679 strlist.pop_front();
1680 strlist.pop_front();
1689 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
1690 "Event socket closed. No connection to the backend.");
1696 std::chrono::milliseconds
timeout,
1697 bool error_dialog_desired)
1702 QStringList strlist(QString(
"MYTH_PROTO_VERSION %1 %2")
1703 .arg(MYTH_PROTO_VERSION,
1704 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1709 LOG(VB_GENERAL, LOG_CRIT,
"Protocol version check failure.\n\t\t\t"
1710 "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1711 "This happens when the backend is too busy to respond,\n\t\t\t"
1712 "or has deadlocked due to bugs or hardware failure.");
1716 if (strlist[0] ==
"REJECT" && strlist.size() >= 2)
1718 LOG(VB_GENERAL, LOG_CRIT,
LOC + QString(
"Protocol version or token mismatch "
1719 "(frontend=%1/%2,backend=%3/\?\?)\n")
1720 .arg(MYTH_PROTO_VERSION,
1721 QString::fromUtf8(MYTH_PROTO_TOKEN),
1726 QStringList list(strlist[1]);
1727 QCoreApplication::postEvent(
1733 if (strlist[0] ==
"ACCEPT")
1738 LOG(VB_GENERAL, LOG_INFO,
LOC +
1739 QString(
"Using protocol version %1 %2")
1740 .arg(MYTH_PROTO_VERSION,
1741 QString::fromUtf8(MYTH_PROTO_TOKEN)));
1747 LOG(VB_GENERAL, LOG_ERR,
LOC +
1748 QString(
"Unexpected response to MYTH_PROTO_VERSION: %1")
1755 LOG(VB_NETWORK, LOG_INFO,
LOC + QString(
"MythEvent: %1").arg(event.
Message()));
1849 LOG(VB_AUDIO, LOG_DEBUG,
LOC + QString(
"audio language:%1 menu language:%2")
1863 LOG(VB_GENERAL, LOG_INFO,
"Restarting Backend Connections");
1890 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1903 LOG(VB_GENERAL, LOG_NOTICE, QString(
"Setting QT default locale to %1")
1923 LOG(VB_GENERAL, LOG_INFO,
1930 LOG(VB_GENERAL, LOG_ERR,
LOC +
1931 "No locale defined! We weren't able to set locale defaults.");
1953 QEventLoop eventLoop;
1954 for (
const auto& s : sigs)
1956 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
1957 QString(
"Waiting for signal %1")
1962 eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1973 if (!sender || !method)
1983 Qt::BlockingQueuedConnection);
2019 QThread *currentThread = QThread::currentThread();
2024 if (it.key() == sender)
2027 QThread *thread = it.key()->thread();
2029 if (thread != currentThread)
2051 Qt::BlockingQueuedConnection);
2057 if (it.key() == sender)
2060 QThread *thread = it.key()->thread();
2062 if (thread != currentThread)
2066 it.key(), it.value());
2068 it.key(), it.value(), Qt::BlockingQueuedConnection);
2103 return intvplayback;
2119 const QString &libversion,
2120 const QString &pluginversion)
2122 if (libversion == pluginversion)
2125 LOG(VB_GENERAL, LOG_EMERG,
LOC +
2126 QString(
"Plugin %1 (%2) binary version does not "
2127 "match libraries (%3)")
2128 .arg(name, pluginversion, libversion));
2165 QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2170 QString message = QString(
"FILE_WRITTEN %1 %2").arg(
file).arg(size);
2175 LOG(VB_FILE, LOG_DEBUG,
LOC +
2176 QString(
"%1").arg(
file));
2187 QString message = QString(
"FILE_CLOSED %1").arg(
file);
2192 LOG(VB_FILE, LOG_DEBUG,
LOC +
2193 QString(
"%1").arg(
file));
2203#include "moc_mythcorecontext.cpp"
DB connection pool, used by MSqlQuery. Do not use directly.
static void StopAllPools(void)
static MThreadPool * globalInstance(void)
void start(QRunnable *runnable, const QString &debugName, int priority=0)
static void ShutdownAllPools(void)
static void Cleanup(void)
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total...
static void ThreadSetup(const QString &name)
This is to be called on startup in those few threads that haven't been ported to MThread.
MythSocket * m_eventSock
socket events arrive on
~MythCoreContextPrivate() override
MythCoreContextPrivate(MythCoreContext *lparent, QString binversion, QObject *guicontext)
MythCoreContext * m_parent
QMutex m_sockLock
protects both m_serverSock and m_eventSock
MythSocket * m_serverSock
socket for sending MythProto requests
QMap< QObject *, MythCoreContext::PlaybackStartCb > m_playbackClients
QString m_masterHostname
master backend hostname
QString m_localHostname
hostname from config.xml or gethostname()
QWaitCondition m_wolInProgressWaitCondition
MythSessionManager * m_sessionManager
MythPluginManager * m_pluginmanager
bool WaitForWOL(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
If another thread has already started WOL process, wait on them...
QMutex m_wolInProgressLock
QMutex m_masterHostLock
Locking for m_masterHostname.
MythScheduler * m_scheduler
QMutex m_scopesLock
Locking for m_masterHostname.
QMutex m_localHostLock
Locking for m_localHostname.
QString m_appBinaryVersion
QMap< QString, QPair< int64_t, uint64_t > > m_fileswritten
QList< QHostAddress > m_deniedIps
QMap< QString, QString > m_scopes
Scope Id cache for Link-Local addresses.
QList< QHostAddress > m_approvedIps
This class contains the runtime context for MythTV.
void TVPlaybackAboutToStart(void)
bool IsFrontend(void) const
is this process a frontend process
void ResetAudioLanguage(void)
void UnregisterForPlayback(QObject *sender)
Unregister sender from being called when TVPlaybackAboutToStart signal is emitted.
bool IsConnectedToMaster(void)
void setTestIntSettings(QMap< QString, int > &overrides)
void ClearSettingsCache(const QString &myKey=QString(""))
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
QString resolveSettingAddress(const QString &name, const QString &host=QString(), ResolveType type=ResolveAny, bool keepscope=false)
Retrieve IP setting "name" for "host".
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
int GetNumSettingOnHost(const QString &key, const QString &host, int defaultval=0)
QMap< QString, QString > m_testOverrideStrings
void readyRead(MythSocket *sock) override
QMap< QString, double > m_testOverrideFloats
void ActivateSettingsCache(bool activate=true)
bool IsLocalSubnet(const QHostAddress &peer, bool log)
Check if peer is on local subnet.
void SetWOLAllowed(bool allow)
void SendHostSystemEvent(const QString &msg, const QString &hostname, const QString &args)
bool IsDatabaseIgnored(void) const
/brief Returns true if database is being ignored.
QString GetHostName(void)
void SetScopeForAddress(const QHostAddress &addr)
Record the scope Id of the given IP address.
MythCoreContextPrivate * d
static bool BackendIsRunning(void)
a backend process is running on this host
bool GetScopeForAddress(QHostAddress &addr) const
Return the cached scope Id for the given address.
void ClearOverrideSettingForSession(const QString &key)
static QHash< QString, int > s_serverPortCache
void TVInWantingPlayback(bool b)
Let the TV class tell us if we was interrupted following a call to WantingPlayback().
void connectionClosed(MythSocket *sock) override
QString GetBackendServerIP4(void)
Returns the IPv4 address defined for the current host see GetBackendServerIP4(host)
void SaveSetting(const QString &key, int newValue)
MythSocket * ConnectCommandSocket(const QString &hostname, int port, const QString &announcement, bool *proto_mismatch=nullptr, int maxConnTry=-1, std::chrono::milliseconds setup_timeout=-1ms)
void setTestFloatSettings(QMap< QString, double > &overrides)
void SetLocalHostname(const QString &hostname)
void SetExiting(bool exiting=true)
static QString resolveAddress(const QString &host, ResolveType type=ResolveAny, bool keepscope=false)
if host is an IP address, it will be returned or resolved otherwise.
void SetAsBackend(bool backend)
void RegisterForPlayback(QObject *sender, PlaybackStartCb method)
Register sender for TVPlaybackAboutToStart signal.
bool IsThisHost(const QString &addr)
is this address mapped to this host
MythScheduler * GetScheduler(void)
MythCoreContext(const QString &binversion, QObject *guiContext)
QString GetMasterHostPrefix(const QString &storageGroup=QString(), const QString &path=QString())
MythSessionManager * GetSessionManager(void)
QString GetSetting(const QString &key, const QString &defaultval="")
void SendSystemEvent(const QString &msg)
QString GetAudioLanguageAndVariant(void)
Returns the user-set audio language and variant.
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
bool IsRegisteredFileForWrite(const QString &file)
bool CheckProtoVersion(MythSocket *socket, std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
QString GetAudioLanguage(void)
Returns two character ISO-639 language descriptor for audio language.
QObject * GetGUIContext(void)
bool CheckSubnet(const QAbstractSocket *socket)
Check if a socket is connected to an approved peer.
void setTestStringSettings(QMap< QString, QString > &overrides)
MythPluginManager * GetPluginManager(void)
bool InWantingPlayback(void)
Returns true if a client has requested playback.
int GetBackendServerPort(void)
Returns the locally defined backend control port.
void OverrideSettingForSession(const QString &key, const QString &value)
void RegisterFileForWrite(const QString &file, uint64_t size=0LL)
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
QObject * GetGUIObject(void)
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
void WantingPlayback(QObject *sender)
All the objects that have registered using MythCoreContext::RegisterForPlayback but sender will be ca...
int GetBackendStatusPort(void)
Returns the locally defined backend status port.
bool IsBackend(void) const
is this process a backend process
double GetFloatSetting(const QString &key, double defaultval=0.0)
bool IsThisBackend(const QString &addr)
is this address mapped to this backend host
int GetMasterServerStatusPort(void)
Returns the Master Backend status port If no master server status port has been defined in the databa...
~MythCoreContext() override
QString GetBackendServerIP6(void)
Returns the IPv6 address defined for the current host see GetBackendServerIP6(host)
void SetScheduler(MythScheduler *sched)
QString GetFilePrefix(void)
void dispatch(const MythEvent &event)
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
void SendMessage(const QString &message)
bool SetupCommandSocket(MythSocket *serverSock, const QString &announcement, std::chrono::milliseconds timeout, bool &proto_mismatch)
bool IsMasterHost(void)
is this the same host as the master
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
void SetPluginManager(MythPluginManager *pmanager)
bool IsWOLAllowed() const
void SetGUIObject(QObject *gui)
void SaveLocaleDefaults(void)
int GetNumSetting(const QString &key, int defaultval=0)
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
void(QObject::*)(void) PlaybackStartCb
double GetFloatSettingOnHost(const QString &key, const QString &host, double defaultval=0.0)
void SetAsFrontend(bool frontend)
QString GetMasterHostName(void)
QMap< QString, int > m_testOverrideInts
bool IsMasterBackend(void)
is this the actual MBE process
MythSocket * ConnectEventSocket(const QString &hostname, int port)
static void ClearBackendServerPortCache()
void UnregisterFileForWrite(const QString &file)
bool IsBlockingClient(void) const
is this client blocking shutdown
MDBManager * GetDBManager(void)
void InitPower(bool Create=true)
bool GetBoolSettingOnHost(const QString &key, const QString &host, bool defaultval=false)
void WaitUntilSignals(std::vector< CoreWaitInfo > &sigs) const
Wait until any of the provided signals have been received.
void SendEvent(const MythEvent &event)
QString GetLanguageAndVariant(void)
Returns the user-set language and variant.
bool GetBoolSetting(const QString &key, bool defaultval=false)
MythLocale * GetLocale(void) const
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
This class is used as a container for messages.
const QString & Message() const
const QStringList & ExtraDataList() const
QLocale ToQLocale() const
QString GetLocaleCode() const
Name of language in that language.
void SaveLocaleDefaults(bool overwrite=false)
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
static MythPower * AcquireRelease(void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s)
This is an generic interface to a program scheduler.
We use digest authentication because it protects the password over unprotected networks.
static void UnlockSessions()
static void LockSessions()
Class for communcating between myth backends and frontends.
static constexpr std::chrono::milliseconds kLongTimeout
bool SendReceiveStringList(QStringList &list, uint min_reply_length=0, std::chrono::milliseconds timeoutMS=kLongTimeout)
bool ReadStringList(QStringList &list, std::chrono::milliseconds timeoutMS=kShortTimeout)
bool IsConnected(void) const
bool IsDataAvailable(void)
static constexpr std::chrono::milliseconds kShortTimeout
void DisconnectFromHost(void)
bool WriteStringList(const QStringList &list)
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
SendAsyncMessage(QString msg)
SendAsyncMessage(QString msg, QStringList extra)
@ GENERIC_EXIT_OK
Exited with no error.
void loggingDeregisterThread(void)
Deregister the current thread's name.
void logStop(void)
Entry point for stopping logging for an application.
bool is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
static constexpr const char * MYTH_APPNAME_MYTHTV_SETUP
static void delete_sock(QMutexLocker< QMutex > &locker, MythSocket **s)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void ShutdownMythDownloadManager(void)
Deletes the running MythDownloadManager at program exit.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
bool MythWakeup(const QString &wakeUpCommand, uint flags, std::chrono::seconds timeout)
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
@ kMSProcessEvents
process events while waiting
@ kMSDontDisableDrawing
avoid disabling UI drawing
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
void MBASE_PUBLIC ShutdownMythSystemLegacy(void)
None log(str msg, int level=LOGDEBUG)
static QPair< QHostAddress, int > kLinkLocal