MythTV  master
mythcorecontext.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QCoreApplication>
3 #include <QUrl>
4 #include <QDir>
5 #include <QFileInfo>
6 #include <QDebug>
7 #include <QMutex>
8 #include <QRunnable>
9 #include <QWaitCondition>
10 #include <QNetworkInterface>
11 #include <QAbstractSocket>
12 #include <QHostAddress>
13 #include <QHostInfo>
14 #include <QNetworkInterface>
15 #include <QNetworkAddressEntry>
16 #include <QLocale>
17 #include <QPair>
18 #include <QDateTime>
19 #include <QRunnable>
20 
21 // Std
22 #include <algorithm>
23 #include <cmath>
24 #include <cstdarg>
25 #include <queue>
26 #include <unistd.h> // for usleep()
27 
28 #ifdef _WIN32
29 #include <winsock2.h>
30 #else
31 #include <clocale>
32 #include <utility>
33 #endif
34 
35 // MythTV
36 #include "compat.h"
37 #include "mythconfig.h" // for CONFIG_DARWIN
38 #include "mythdownloadmanager.h"
39 #include "mythcorecontext.h"
40 #include "mythsocket.h"
41 #include "mythsystemlegacy.h"
42 #include "mthreadpool.h"
43 #include "exitcodes.h"
44 #include "mythlogging.h"
45 #include "mythversion.h"
46 #include "logging.h"
47 #include "mthread.h"
48 #include "serverpool.h"
49 #include "mythdate.h"
50 #include "mythplugin.h"
51 #include "mythmiscutil.h"
52 #include "mythpower.h"
53 
54 #define LOC QString("MythCoreContext::%1(): ").arg(__func__)
55 
56 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
57 #define qEnvironmentVariable getenv
58 #endif
59 
61 
62 class MythCoreContextPrivate : public QObject
63 {
64  public:
65  MythCoreContextPrivate(MythCoreContext *lparent, QString binversion,
66  QObject *guicontext);
67  ~MythCoreContextPrivate() override;
68 
69  bool WaitForWOL(std::chrono::milliseconds timeout = std::chrono::milliseconds::max());
70 
71  public:
73  QObject *m_guiContext;
74  QObject *m_guiObject;
76 
77  QMutex m_localHostLock;
78  QString m_localHostname;
80  QString m_masterHostname;
81  QMutex m_scopesLock;
82  QMap<QString, QString> m_scopes;
83 
84  QMutex m_sockLock;
87 
92 
93  bool m_backend;
94  bool m_frontend;
95 
96  MythDB *m_database;
97 
98  QThread *m_uiThread;
99 
101  QString m_language;
102 
104 
106 
107  QMap<QObject *, MythCoreContext::PlaybackStartCb> m_playbackClients;
111 
113 
115 
117 
118  QMap<QString, QPair<int64_t, uint64_t> > m_fileswritten;
119  QMutex m_fileslock;
120 
122 
123  QList<QHostAddress> m_approvedIps;
124  QList<QHostAddress> m_deniedIps;
125 
127 };
128 
130  QString binversion,
131  QObject *guicontext)
132  : m_parent(lparent),
133  m_guiContext(guicontext),
134  m_guiObject(nullptr),
135  m_appBinaryVersion(std::move(binversion)),
136  m_sockLock(QMutex::NonRecursive),
137  m_serverSock(nullptr),
138  m_eventSock(nullptr),
139  m_wolInProgress(false),
140  m_isWOLAllowed(true),
141  m_backend(false),
142  m_frontend(false),
143  m_database(GetMythDB()),
144  m_uiThread(QThread::currentThread()),
145  m_locale(nullptr),
146  m_scheduler(nullptr),
147  m_blockingClient(true),
148  m_inwanting(false),
149  m_intvwanting(false),
150  m_announcedProtocol(false),
151  m_pluginmanager(nullptr),
152  m_isexiting(false),
153  m_sessionManager(nullptr),
154  m_power(nullptr)
155 {
156  MThread::ThreadSetup("CoreContext");
157 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
158  srandom(MythDate::current().toSecsSinceEpoch() ^ QTime::currentTime().msec());
159 #endif
160 }
161 
162 static void delete_sock(QMutexLocker &locker, MythSocket **s)
163 {
164  if (*s)
165  {
166  MythSocket *tmp = *s;
167  *s = nullptr;
168  locker.unlock();
169  tmp->DecrRef();
170  locker.relock();
171  }
172 }
173 
175 {
176  if (m_power)
177  MythPower::AcquireRelease(this, false);
178 
180 
181  {
182  QMutexLocker locker(&m_sockLock);
183  delete_sock(locker, &m_serverSock);
184  delete_sock(locker, &m_eventSock);
185  }
186 
187  delete m_locale;
188 
189  delete m_sessionManager;
190 
192 
194 
196 
197  // This has already been run in the MythContext dtor. Do we need it here
198  // too?
199 #if 0
200  logStop(); // need to shutdown db logger before we kill db
201 #endif
202 
204 
205  GetMythDB()->GetDBManager()->CloseDatabases();
206 
207  if (m_database) {
208  DestroyMythDB();
209  m_database = nullptr;
210  }
211 
213 }
214 
218 bool MythCoreContextPrivate::WaitForWOL(std::chrono::milliseconds timeout)
219 {
220  std::chrono::milliseconds timeout_remaining = timeout;
221  while (m_wolInProgress && (timeout_remaining > 0ms))
222  {
223  LOG(VB_GENERAL, LOG_INFO, LOC + "Wake-On-LAN in progress, waiting...");
224 
225  std::chrono::milliseconds max_wait = std::min(1000ms, timeout_remaining);
226  m_wolInProgressWaitCondition.wait(&m_wolInProgressLock, max_wait.count());
227  timeout_remaining -= max_wait;
228  }
229 
230  return !m_wolInProgress;
231 }
232 
233 MythCoreContext::MythCoreContext(const QString &binversion,
234  QObject *guiContext)
235 {
236  d = new MythCoreContextPrivate(this, binversion, guiContext);
237 }
238 
240 {
241  if (!d)
242  {
243  LOG(VB_GENERAL, LOG_EMERG, LOC + "Out-of-memory");
244  return false;
245  }
246 
248  {
249  LOG(VB_GENERAL, LOG_CRIT,
250  QString("Application binary version (%1) does not "
251  "match libraries (%2)")
253 
254  QString warning = tr("This application is not compatible with the "
255  "installed MythTV libraries. Please recompile "
256  "after a make distclean");
257  LOG(VB_GENERAL, LOG_WARNING, warning);
258 
259  return false;
260  }
261 
262 #ifndef _WIN32
263  QString lang_variables("");
264  QString lc_value = setlocale(LC_CTYPE, nullptr);
265  if (lc_value.isEmpty())
266  {
267  // try fallback to environment variables for non-glibc systems
268  // LC_ALL, then LC_CTYPE
269  lc_value = qEnvironmentVariable("LC_ALL");
270  if (lc_value.isEmpty())
271  lc_value = qEnvironmentVariable("LC_CTYPE");
272  }
273  if (!lc_value.contains("UTF-8", Qt::CaseInsensitive))
274  lang_variables.append("LC_ALL or LC_CTYPE");
275  lc_value = qEnvironmentVariable("LANG");
276  if (!lc_value.contains("UTF-8", Qt::CaseInsensitive))
277  {
278  if (!lang_variables.isEmpty())
279  lang_variables.append(", and ");
280  lang_variables.append("LANG");
281  }
282  LOG(VB_GENERAL, LOG_INFO, QString("Assumed character encoding: %1")
283  .arg(lc_value));
284  if (!lang_variables.isEmpty())
285  {
286  LOG(VB_GENERAL, LOG_WARNING, QString("This application expects to "
287  "be running a locale that specifies a UTF-8 codeset, and many "
288  "features may behave improperly with your current language "
289  "settings. Please set the %1 variable(s) in the environment "
290  "in which this program is executed to include a UTF-8 codeset "
291  "(such as 'en_US.UTF-8').").arg(lang_variables));
292  }
293 #endif
294 
295  return true;
296 }
297 
299 {
300  delete d;
301  d = nullptr;
302 }
303 
304 void MythCoreContext::setTestIntSettings(QMap<QString,int> &overrides)
305 {
306  m_testOverrideInts = std::move(overrides);
307 }
308 
309 void MythCoreContext::setTestFloatSettings(QMap<QString,double> &overrides)
310 {
311  m_testOverrideFloats = std::move(overrides);
312 }
313 
314 void MythCoreContext::setTestStringSettings(QMap<QString,QString> &overrides)
315 {
316  m_testOverrideStrings = std::move(overrides);
317 }
318 
320  const QString &announcement,
321  std::chrono::milliseconds timeout,
322  bool &proto_mismatch)
323 {
324  proto_mismatch = false;
325 
326 #ifndef IGNORE_PROTO_VER_MISMATCH
327  if (!CheckProtoVersion(serverSock, timeout, true))
328  {
329  proto_mismatch = true;
330  return false;
331  }
332 #else
333  Q_UNUSED(timeout);
334 #endif
335 
336  QStringList strlist(announcement);
337 
338  if (!serverSock->WriteStringList(strlist))
339  {
340  LOG(VB_GENERAL, LOG_ERR, LOC + "Connecting server socket to "
341  "master backend, socket write failed");
342  return false;
343  }
344 
345  if (!serverSock->ReadStringList(strlist, MythSocket::kShortTimeout) ||
346  strlist.empty() || (strlist[0] == "ERROR"))
347  {
348  if (!strlist.empty())
349  {
350  LOG(VB_GENERAL, LOG_ERR, LOC + "Problem connecting "
351  "server socket to master backend");
352  }
353  else
354  {
355  LOG(VB_GENERAL, LOG_ERR, LOC + "Timeout connecting "
356  "server socket to master backend");
357  }
358  return false;
359  }
360 
361  return true;
362 }
363 
364 // Connects to master server safely (i.e. by taking m_sockLock)
366  bool openEventSocket)
367 {
368  QMutexLocker locker(&d->m_sockLock);
369  bool success = ConnectToMasterServer(blockingClient, openEventSocket);
370 
371  return success;
372 }
373 
374 // Assumes that either m_sockLock is held, or the app is still single
375 // threaded (i.e. during startup).
376 bool MythCoreContext::ConnectToMasterServer(bool blockingClient,
377  bool openEventSocket)
378 {
379  if (IsMasterBackend())
380  {
381  // Should never get here unless there is a bug in the code somewhere.
382  // If this happens, it can cause endless event loops.
383  LOG(VB_GENERAL, LOG_ERR, LOC + "ERROR: Master backend tried to connect back "
384  "to itself!");
385  return false;
386  }
387  if (IsExiting())
388  return false;
389 
390  QString server = GetMasterServerIP();
391  if (server.isEmpty())
392  return false;
393 
394  int port = GetMasterServerPort();
395  bool proto_mismatch = false;
396 
397  if (d->m_serverSock && !d->m_serverSock->IsConnected())
398  {
399  d->m_serverSock->DecrRef();
400  d->m_serverSock = nullptr;
401  }
402 
403  if (!d->m_serverSock)
404  {
405  QString type = IsFrontend() ? "Frontend" : (blockingClient ? "Playback" : "Monitor");
406  QString ann = QString("ANN %1 %2 %3")
407  .arg(type)
408  .arg(d->m_localHostname).arg(static_cast<int>(false));
410  server, port, ann, &proto_mismatch);
411  }
412 
413  if (!d->m_serverSock)
414  return false;
415 
416  d->m_blockingClient = blockingClient;
417 
418  if (!openEventSocket)
419  return true;
420 
421 
422  if (!IsBackend())
423  {
424  if (d->m_eventSock && !d->m_eventSock->IsConnected())
425  {
426  d->m_eventSock->DecrRef();
427  d->m_eventSock = nullptr;
428  }
429  if (!d->m_eventSock)
430  d->m_eventSock = ConnectEventSocket(server, port);
431 
432  if (!d->m_eventSock)
433  {
434  d->m_serverSock->DecrRef();
435  d->m_serverSock = nullptr;
436 
437  QCoreApplication::postEvent(
438  d->m_guiContext, new MythEvent("CONNECTION_FAILURE"));
439 
440  return false;
441  }
442  }
443 
444  return true;
445 }
446 
448  const QString &hostname, int port, const QString &announce,
449  bool *p_proto_mismatch, int maxConnTry, std::chrono::milliseconds setup_timeout)
450 {
451  MythSocket *serverSock = nullptr;
452 
453  {
454  QMutexLocker locker(&d->m_wolInProgressLock);
455  d->WaitForWOL();
456  }
457 
458  QString WOLcmd;
459  if (IsWOLAllowed())
460  WOLcmd = GetSetting("WOLbackendCommand", "");
461 
462  if (maxConnTry < 1)
463  maxConnTry = std::max(GetNumSetting("BackendConnectRetry", 1), 1);
464 
465  std::chrono::seconds WOLsleepTime = 0s;
466  int WOLmaxConnTry = 0;
467  if (!WOLcmd.isEmpty())
468  {
469  WOLsleepTime = GetDurSetting<std::chrono::seconds>("WOLbackendReconnectWaitTime", 0s);
470  WOLmaxConnTry = std::max(GetNumSetting("WOLbackendConnectRetry", 1), 1);
471  maxConnTry = std::max(maxConnTry, WOLmaxConnTry);
472  }
473 
474  bool we_attempted_wol = false;
475 
476  if (setup_timeout <= 0ms)
477  setup_timeout = MythSocket::kShortTimeout;
478 
479  bool proto_mismatch = false;
480  for (int cnt = 1; cnt <= maxConnTry; cnt++)
481  {
482  LOG(VB_GENERAL, LOG_INFO, LOC +
483  QString("Connecting to backend server: %1:%2 (try %3 of %4)")
484  .arg(hostname).arg(port).arg(cnt).arg(maxConnTry));
485 
486  serverSock = new MythSocket();
487 
488  std::chrono::microseconds sleepus = 0us;
489  if (serverSock->ConnectToHost(hostname, port))
490  {
491  if (SetupCommandSocket(
492  serverSock, announce, setup_timeout, proto_mismatch))
493  {
494  break;
495  }
496 
497  if (proto_mismatch)
498  {
499  if (p_proto_mismatch)
500  *p_proto_mismatch = true;
501 
502  serverSock->DecrRef();
503  serverSock = nullptr;
504  break;
505  }
506 
507  setup_timeout += setup_timeout / 2;
508  }
509  else if (!WOLcmd.isEmpty() && (cnt < maxConnTry))
510  {
511  if (!we_attempted_wol)
512  {
513  QMutexLocker locker(&d->m_wolInProgressLock);
514  if (d->m_wolInProgress)
515  {
516  d->WaitForWOL();
517  continue;
518  }
519 
520  d->m_wolInProgress = we_attempted_wol = true;
521  }
522 
525  sleepus = WOLsleepTime;
526  }
527 
528  serverSock->DecrRef();
529  serverSock = nullptr;
530 
531  if (cnt == 1)
532  {
533  QCoreApplication::postEvent(
534  d->m_guiContext, new MythEvent("CONNECTION_FAILURE"));
535  }
536 
537  if (sleepus != 0us)
538  usleep(sleepus.count());
539  }
540 
541  if (we_attempted_wol)
542  {
543  QMutexLocker locker(&d->m_wolInProgressLock);
544  d->m_wolInProgress = false;
545  d->m_wolInProgressWaitCondition.wakeAll();
546  }
547 
548  if (!serverSock && !proto_mismatch)
549  {
550  LOG(VB_GENERAL, LOG_ERR,
551  "Connection to master server timed out.\n\t\t\t"
552  "Either the server is down or the master server settings"
553  "\n\t\t\t"
554  "in mythtv-settings does not contain the proper IP address\n");
555  }
556  else
557  {
558  QCoreApplication::postEvent(
559  d->m_guiContext, new MythEvent("CONNECTION_RESTABLISHED"));
560  }
561 
562  return serverSock;
563 }
564 
566  int port)
567 {
568  auto *eventSock = new MythSocket(-1, this);
569 
570  // Assume that since we _just_ connected the command socket,
571  // this one won't need multiple retries to work...
572  if (!eventSock->ConnectToHost(hostname, port))
573  {
574  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect event "
575  "socket to master backend");
576  eventSock->DecrRef();
577  return nullptr;
578  }
579 
580  QString str = QString("ANN Monitor %1 %2")
581  .arg(d->m_localHostname).arg(static_cast<int>(true));
582  QStringList strlist(str);
583  eventSock->WriteStringList(strlist);
584  bool ok = true;
585  if (!eventSock->ReadStringList(strlist) || strlist.empty() ||
586  (strlist[0] == "ERROR"))
587  {
588  if (!strlist.empty())
589  {
590  LOG(VB_GENERAL, LOG_ERR, LOC +
591  "Problem connecting event socket to master backend");
592  }
593  else
594  {
595  LOG(VB_GENERAL, LOG_ERR, LOC +
596  "Timeout connecting event socket to master backend");
597  }
598  ok = false;
599  }
600 
601  if (!ok)
602  {
603  eventSock->DecrRef();
604  eventSock = nullptr;
605  }
606 
607  return eventSock;
608 }
609 
611 {
612  QMutexLocker locker(&d->m_sockLock);
613  return d->m_serverSock;
614 }
615 
617 {
618  QStringList strlist;
619 
620  QMutexLocker locker(&d->m_sockLock);
621  if (d->m_serverSock == nullptr)
622  return;
623 
624  strlist << "BLOCK_SHUTDOWN";
626 
627  d->m_blockingClient = true;
628 }
629 
631 {
632  QStringList strlist;
633 
634  QMutexLocker locker(&d->m_sockLock);
635  if (d->m_serverSock == nullptr)
636  return;
637 
638  strlist << "ALLOW_SHUTDOWN";
640 
641  d->m_blockingClient = false;
642 }
643 
645 {
646  return d->m_blockingClient;
647 }
648 
650 {
651  d->m_isWOLAllowed = allow;
652 }
653 
655 {
656  return d->m_isWOLAllowed;
657 }
658 
660 {
661  d->m_backend = backend;
662 }
663 
665 {
666  return d->m_backend;
667 }
668 
670 {
671  d->m_frontend = frontend;
672 }
673 
675 {
676  return d->m_frontend;
677 }
678 
680 {
681  QString host = GetHostName();
682  return IsMasterHost(host);
683 }
684 
685 bool MythCoreContext::IsMasterHost(const QString &host)
686 {
687  // Temporary code here only to facilitate the upgrade
688  // from 1346 or earlier. The way of determining master host is
689  // changing, and the new way of determning master host
690  // will not work with earlier databases.
691  // This code can be removed when updating from prior to
692  // 1347 is no longer allowed.
693  // Note that we are deprecating some settings including
694  // MasterServerIP, and can remove them at a future time.
695  if (GetNumSetting("DBSchemaVer") < 1347)
696  {
697  // Temporary copy of code from old version of
698  // IsThisHost(Qstring&,QString&)
699  QString addr(resolveSettingAddress("MasterServerIP"));
700  if (addr.toLower() == host.toLower())
701  return true;
702  QHostAddress addrfix(addr);
703  addrfix.setScopeId(QString());
704  QString addrstr = addrfix.toString();
705  if (addrfix.isNull())
706  addrstr = resolveAddress(addr);
707  QString thisip = GetBackendServerIP4(host);
708  QString thisip6 = GetBackendServerIP6(host);
709  return !addrstr.isEmpty()
710  && ((addrstr == thisip) || (addrstr == thisip6));
711  }
712  return GetSetting("MasterServerName") == host;
713 }
714 
716 {
717  return (IsBackend() && IsMasterHost());
718 }
719 
721 {
722 #if CONFIG_DARWIN || (__FreeBSD__) || defined(__OpenBSD__)
723  const char *command = "ps -axc | grep -i mythbackend | grep -v grep > /dev/null";
724 #elif defined _WIN32
725  const char *command = "%systemroot%\\system32\\tasklist.exe "
726  " | %systemroot%\\system32\\find.exe /i \"mythbackend.exe\" ";
727 #else
728  const char *command = "ps ch -C mythbackend -o pid > /dev/null";
729 #endif
730  uint res = myth_system(command, kMSDontBlockInputDevs |
733  return (res == GENERIC_EXIT_OK);
734 }
735 
736 bool MythCoreContext::IsThisBackend(const QString &addr)
737 {
738  return IsBackend() && IsThisHost(addr);
739 }
740 
741 bool MythCoreContext::IsThisHost(const QString &addr)
742 {
743  return IsThisHost(addr, GetHostName());
744 }
745 
746 bool MythCoreContext::IsThisHost(const QString &addr, const QString &host)
747 {
748  if (addr.toLower() == host.toLower())
749  return true;
750 
751  QHostAddress addrfix(addr);
752  addrfix.setScopeId(QString());
753  QString addrstr = addrfix.toString();
754 
755  if (addrfix.isNull())
756  {
757  addrstr = resolveAddress(addr);
758  }
759 
760  QString thisip = GetBackendServerIP(host);
761 
762  return !addrstr.isEmpty() && ((addrstr == thisip));
763 }
764 
766 {
767  // find out if a backend runs on this host...
768  bool backendOnLocalhost = false;
769 
770  QStringList strlist("QUERY_IS_ACTIVE_BACKEND");
771  strlist << GetHostName();
772 
773  SendReceiveStringList(strlist);
774 
775  backendOnLocalhost = strlist[0] != "FALSE";
776 
777  return !backendOnLocalhost;
778 }
779 
780 QString MythCoreContext::GenMythURL(const QString& host, int port, QString path, const QString& storageGroup)
781 {
782  QUrl ret;
783 
784  QString m_host;
785 
786  QHostAddress addr(host);
787  if (!addr.isNull())
788  {
789  LOG(VB_GENERAL, LOG_CRIT, LOC + QString("(%1/%2): Given "
790  "IP address instead of hostname "
791  "(ID). This is invalid.").arg(host).arg(path));
792  }
793 
794  m_host = host;
795 
796  // Basically if it appears to be an IPv6 IP surround the IP with [] otherwise don't bother
797  if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
798  m_host = "[" + addr.toString().toLower() + "]";
799 
800  ret.setScheme("myth");
801  if (!storageGroup.isEmpty())
802  ret.setUserName(storageGroup);
803  ret.setHost(m_host);
804  if (port > 0 && port != 6543)
805  ret.setPort(port);
806  if (!path.startsWith("/"))
807  path = QString("/") + path;
808  ret.setPath(path);
809 
810 #if 0
811  LOG(VB_GENERAL, LOG_DEBUG, LOC +
812  QString("GenMythURL returning %1").arg(ret.toString()));
813 #endif
814 
815  return ret.toString();
816 }
817 
818 QString MythCoreContext::GetMasterHostPrefix(const QString &storageGroup,
819  const QString &path)
820 {
821  return GenMythURL(GetMasterHostName(),
823  path,
824  storageGroup);
825 }
826 
828 {
829  QMutexLocker locker(&d->m_masterHostLock);
830 
831  if (d->m_masterHostname.isEmpty())
832  {
833 
834  if (IsMasterBackend())
836  else
837  {
838  QStringList strlist("QUERY_HOSTNAME");
839 
840  if (SendReceiveStringList(strlist))
841  d->m_masterHostname = strlist[0];
842  }
843  }
844 
845  return d->m_masterHostname;
846 }
847 
848 void MythCoreContext::ClearSettingsCache(const QString &myKey)
849 {
850  d->m_database->ClearSettingsCache(myKey);
851 }
852 
854 {
855  d->m_database->ActivateSettingsCache(activate);
856 }
857 
859 {
860  QMutexLocker locker(&d->m_localHostLock);
861  return d->m_localHostname;
862 }
863 
865 {
866  return GetSetting("RecordFilePrefix");
867 }
868 
870  int &width, int &height,
871  double &forced_aspect,
872  double &refresh_rate,
873  int index)
874 {
875  d->m_database->GetResolutionSetting(type, width, height, forced_aspect,
876  refresh_rate, index);
877 }
878 
879 void MythCoreContext::GetResolutionSetting(const QString &t, int &w,
880  int &h, int i)
881 {
882  d->m_database->GetResolutionSetting(t, w, h, i);
883 }
884 
886 {
887  return d->m_database->GetDBManager();
888 }
889 
897 {
898  return d->m_database->IsDatabaseIgnored();
899 }
900 
901 void MythCoreContext::SaveSetting(const QString &key, int newValue)
902 {
903  d->m_database->SaveSetting(key, newValue);
904 }
905 
906 void MythCoreContext::SaveSetting(const QString &key, const QString &newValue)
907 {
908  d->m_database->SaveSetting(key, newValue);
909 }
910 
911 bool MythCoreContext::SaveSettingOnHost(const QString &key,
912  const QString &newValue,
913  const QString &host)
914 {
915  return d->m_database->SaveSettingOnHost(key, newValue, host);
916 }
917 
918 QString MythCoreContext::GetSetting(const QString &key,
919  const QString &defaultval)
920 {
921  if (!m_testOverrideStrings.empty())
922  return m_testOverrideStrings[key];
923  return d->m_database->GetSetting(key, defaultval);
924 }
925 
926 bool MythCoreContext::GetBoolSetting(const QString &key, bool defaultval)
927 {
928  int result = GetNumSetting(key, static_cast<int>(defaultval));
929  return result > 0;
930 }
931 
932 int MythCoreContext::GetNumSetting(const QString &key, int defaultval)
933 {
934  if (!m_testOverrideInts.empty())
935  return m_testOverrideInts[key];
936  return d->m_database->GetNumSetting(key, defaultval);
937 }
938 
939 double MythCoreContext::GetFloatSetting(const QString &key, double defaultval)
940 {
941  if (!m_testOverrideFloats.empty())
942  return m_testOverrideFloats[key];
943  return d->m_database->GetFloatSetting(key, defaultval);
944 }
945 
946 QString MythCoreContext::GetSettingOnHost(const QString &key,
947  const QString &host,
948  const QString &defaultval)
949 {
950  if (!m_testOverrideStrings.empty())
951  return m_testOverrideStrings[key];
952  return d->m_database->GetSettingOnHost(key, host, defaultval);
953 }
954 
956  const QString &host,
957  bool defaultval)
958 {
959  int result = GetNumSettingOnHost(key, host, static_cast<int>(defaultval));
960  return result > 0;
961 }
962 
964  const QString &host,
965  int defaultval)
966 {
967  if (!m_testOverrideInts.empty())
968  return m_testOverrideInts[key];
969  return d->m_database->GetNumSettingOnHost(key, host, defaultval);
970 }
971 
972 double MythCoreContext::GetFloatSettingOnHost(const QString &key,
973  const QString &host,
974  double defaultval)
975 {
976  if (!m_testOverrideFloats.empty())
977  return m_testOverrideFloats[key];
978  return d->m_database->GetFloatSettingOnHost(key, host, defaultval);
979 }
980 
987 {
988  QString masterserver = gCoreContext->GetSetting("MasterServerName");
989  QString masterip = resolveSettingAddress("BackendServerAddr",masterserver);
990  // Even if empty, return it here if we were to assume that localhost
991  // should be used it just causes a lot of unnecessary error messages.
992  return masterip;
993 }
994 
1001 {
1002  QString masterserver = gCoreContext->GetSetting
1003  ("MasterServerName");
1005  ("BackendServerPort", masterserver, 6543);
1006 }
1007 
1014 {
1015  QString masterhost = GetMasterHostName();
1016 
1017  return GetBackendStatusPort(masterhost);
1018 }
1019 
1025 {
1027 }
1028 
1038 QString MythCoreContext::GetBackendServerIP(const QString &host)
1039 {
1040  return resolveSettingAddress("BackendServerAddr",host);
1041 }
1042 
1048 {
1050 }
1051 
1057 QString MythCoreContext::GetBackendServerIP4(const QString &host)
1058 {
1059  return resolveSettingAddress("BackendServerIP", host, ResolveIPv4);
1060 }
1061 
1067 {
1069 }
1070 
1076 QString MythCoreContext::GetBackendServerIP6(const QString &host)
1077 {
1078  return resolveSettingAddress("BackendServerIP6", host, ResolveIPv6);
1079 }
1080 
1085 {
1087 }
1088 
1093 {
1094  return GetNumSettingOnHost("BackendServerPort", host, 6543);
1095 }
1096 
1101 {
1103 }
1104 
1109 {
1110  return GetNumSettingOnHost("BackendStatusPort", host, 6544);
1111 }
1112 
1117 bool MythCoreContext::GetScopeForAddress(QHostAddress &addr) const
1118 {
1119  QHostAddress addr1 = addr;
1120  addr1.setScopeId(QString());
1121  QString addrstr = addr1.toString();
1122  QMutexLocker lock(&d->m_scopesLock);
1123 
1124  if (!d->m_scopes.contains(addrstr))
1125  return false;
1126 
1127  addr.setScopeId(d->m_scopes[addrstr]);
1128  return true;
1129 }
1130 
1137 void MythCoreContext::SetScopeForAddress(const QHostAddress &addr)
1138 {
1139  QHostAddress addr1 = addr;
1140  addr1.setScopeId(QString());
1141  QMutexLocker lock(&d->m_scopesLock);
1142 
1143  d->m_scopes.insert(addr1.toString(), addr.scopeId());
1144 }
1145 
1151 void MythCoreContext::SetScopeForAddress(const QHostAddress &addr, int scope)
1152 {
1153  QHostAddress addr1 = addr;
1154  addr1.setScopeId(QString());
1155  QMutexLocker lock(&d->m_scopesLock);
1156 
1157  d->m_scopes.insert(addr1.toString(), QString::number(scope));
1158 }
1159 
1171 QString MythCoreContext::resolveSettingAddress(const QString &name,
1172  const QString &host,
1173  ResolveType type, bool keepscope)
1174 {
1175  QString value;
1176 
1177  if (host.isEmpty())
1178  {
1179  value = GetSetting(name);
1180  }
1181  else
1182  {
1183  value = GetSettingOnHost(name, host);
1184  }
1185 
1186  return resolveAddress(value, type, keepscope);
1187 }
1188 
1200 QString MythCoreContext::resolveAddress(const QString &host, ResolveType type,
1201  bool keepscope)
1202 {
1203  QHostAddress addr(host);
1204 
1205  if (!host.isEmpty() && addr.isNull())
1206  {
1207  // address is likely a hostname, attempts to resolve it
1208  QHostInfo info = QHostInfo::fromName(host);
1209  QList<QHostAddress> list = info.addresses();
1210 
1211  if (list.isEmpty())
1212  {
1213  LOG(VB_GENERAL, LOG_WARNING, LOC +
1214  QString("Can't resolve hostname:'%1', using localhost").arg(host));
1215  return type == ResolveIPv4 ? "127.0.0.1" : "::1";
1216  }
1217  QHostAddress v4;
1218  QHostAddress v6;
1219 
1220  // Return the first address fitting the type critera
1221  for (const auto& item : qAsConst(list))
1222  {
1223  addr = item;
1224  QAbstractSocket::NetworkLayerProtocol prot = addr.protocol();
1225 
1226  if (prot == QAbstractSocket::IPv4Protocol)
1227  {
1228  v4 = addr;
1229  if (type == 0)
1230  break;
1231  }
1232  else if (prot == QAbstractSocket::IPv6Protocol)
1233  {
1234  v6 = addr;
1235  if (type != 0)
1236  break;
1237  }
1238  }
1239  switch (type)
1240  {
1241  case ResolveIPv4:
1242  addr = v4.isNull() ? QHostAddress::LocalHost : v4;
1243  break;
1244  case ResolveIPv6:
1245  addr = v6.isNull() ? QHostAddress::LocalHostIPv6 : v6;
1246  break;
1247  default:
1248  addr = v6.isNull() ?
1249  (v4.isNull() ? QHostAddress::LocalHostIPv6 : v4) : v6;
1250  break;
1251  }
1252  }
1253  else if (host.isEmpty())
1254  {
1255  return QString();
1256  }
1257 
1258  if (!keepscope)
1259  {
1260  addr.setScopeId(QString());
1261  }
1262  return addr.toString();
1263 }
1264 
1276 bool MythCoreContext::CheckSubnet(const QAbstractSocket *socket)
1277 {
1278  QHostAddress peer = socket->peerAddress();
1279  return CheckSubnet(peer);
1280 }
1281 
1293 bool MythCoreContext::CheckSubnet(const QHostAddress &peer)
1294 {
1295  static const QHostAddress kLinkLocal("fe80::");
1296  if (GetBoolSetting("AllowConnFromAll",false))
1297  return true;
1298  if (d->m_approvedIps.contains(peer))
1299  return true;
1300  if (d->m_deniedIps.contains(peer))
1301  {
1302  LOG(VB_GENERAL, LOG_WARNING, LOC +
1303  QString("Repeat denied connection from ip address: %1")
1304  .arg(peer.toString()));
1305  return false;
1306  }
1307 
1308  // allow all link-local
1309  if (peer.isInSubnet(kLinkLocal,10))
1310  {
1311  d->m_approvedIps.append(peer);
1312  return true;
1313  }
1314 
1315  // loop through all available interfaces
1316  QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
1317  for (const auto & qni : qAsConst(IFs))
1318  {
1319  if ((qni.flags() & QNetworkInterface::IsRunning) == 0)
1320  continue;
1321 
1322  QList<QNetworkAddressEntry> IPs = qni.addressEntries();
1323  for (const auto & qnai : qAsConst(IPs))
1324  {
1325  int pfxlen = qnai.prefixLength();
1326  // Set this to test rejection without having an extra
1327  // network.
1328  if (GetBoolSetting("DebugSubnet"))
1329  pfxlen += 4;
1330  if (peer.isInSubnet(qnai.ip(),pfxlen))
1331  {
1332  d->m_approvedIps.append(peer);
1333  return true;
1334  }
1335  }
1336  }
1337  d->m_deniedIps.append(peer);
1338  LOG(VB_GENERAL, LOG_WARNING, LOC +
1339  QString("Denied connection from ip address: %1")
1340  .arg(peer.toString()));
1341  return false;
1342 }
1343 
1344 
1346  const QString &value)
1347 {
1348  d->m_database->OverrideSettingForSession(key, value);
1349 }
1350 
1352 {
1353  d->m_database->ClearOverrideSettingForSession(key);
1354 }
1355 
1357 {
1358  return is_current_thread(d->m_uiThread);
1359 }
1360 
1380  QStringList &strlist, bool quickTimeout, bool block)
1381 {
1382  QString msg;
1383  if (HasGUI() && IsUIThread())
1384  {
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");
1390  }
1391 
1392  QString query_type = "UNKNOWN";
1393 
1394  if (!strlist.isEmpty())
1395  query_type = strlist[0];
1396 
1397  QMutexLocker locker(&d->m_sockLock);
1398  if (!d->m_serverSock)
1399  {
1400  bool blockingClient = d->m_blockingClient &&
1401  (GetNumSetting("idleTimeoutSecs",0) > 0);
1402  ConnectToMasterServer(blockingClient);
1403  }
1404 
1405  bool ok = false;
1406 
1407  if (d->m_serverSock)
1408  {
1409  QStringList sendstrlist = strlist;
1410  std::chrono::milliseconds timeout = quickTimeout ?
1412  ok = d->m_serverSock->SendReceiveStringList(strlist, 0, timeout);
1413 
1414  if (!ok)
1415  {
1416  LOG(VB_GENERAL, LOG_NOTICE, LOC +
1417  QString("Connection to backend server lost"));
1418  d->m_serverSock->DecrRef();
1419  d->m_serverSock = nullptr;
1420 
1421  if (d->m_eventSock)
1422  {
1423  d->m_eventSock->DecrRef();
1424  d->m_eventSock = nullptr;
1425  }
1426 
1427  if (block)
1428  {
1430 
1431  if (d->m_serverSock)
1432  {
1434  strlist, 0, timeout);
1435  }
1436  }
1437  }
1438 
1439  // this should not happen
1440  while (ok && strlist[0] == "BACKEND_MESSAGE")
1441  {
1442  // oops, not for us
1443  LOG(VB_GENERAL, LOG_EMERG, LOC + "SRSL you shouldn't see this!!");
1444  QString message = strlist[1];
1445  strlist.pop_front(); strlist.pop_front();
1446 
1447  MythEvent me(message, strlist);
1448  dispatch(me);
1449 
1450  ok = d->m_serverSock->ReadStringList(strlist, timeout);
1451  }
1452 
1453  if (!ok)
1454  {
1455  if (d->m_serverSock)
1456  {
1457  d->m_serverSock->DecrRef();
1458  d->m_serverSock = nullptr;
1459  }
1460 
1461  LOG(VB_GENERAL, LOG_CRIT, LOC +
1462  QString("Reconnection to backend server failed"));
1463 
1464  QCoreApplication::postEvent(d->m_guiContext,
1465  new MythEvent("PERSISTENT_CONNECTION_FAILURE"));
1466  }
1467  }
1468 
1469  if (ok)
1470  {
1471  if (strlist.isEmpty())
1472  ok = false;
1473  else if (strlist[0] == "ERROR")
1474  {
1475  if (strlist.size() == 2)
1476  {
1477  LOG(VB_GENERAL, LOG_INFO, LOC +
1478  QString("Protocol query '%1' responded with the error '%2'")
1479  .arg(query_type).arg(strlist[1]));
1480  }
1481  else
1482  {
1483  LOG(VB_GENERAL, LOG_INFO, LOC +
1484  QString("Protocol query '%1' responded with an error, but "
1485  "no error message.") .arg(query_type));
1486  }
1487 
1488  ok = false;
1489  }
1490  else if (strlist[0] == "UNKNOWN_COMMAND")
1491  {
1492  LOG(VB_GENERAL, LOG_ERR, LOC +
1493  QString("Protocol query '%1' responded with the error 'UNKNOWN_COMMAND'")
1494  .arg(query_type));
1495 
1496  ok = false;
1497  }
1498  }
1499 
1500  return ok;
1501 }
1502 
1503 class SendAsyncMessage : public QRunnable
1504 {
1505  public:
1506  SendAsyncMessage(QString msg, QStringList extra) :
1507  m_message(std::move(msg)), m_extraData(std::move(extra))
1508  {
1509  }
1510 
1511  explicit SendAsyncMessage(QString msg) : m_message(std::move(msg)) { }
1512 
1513  void run(void) override // QRunnable
1514  {
1515  QStringList strlist("MESSAGE");
1516  strlist << m_message;
1517  strlist << m_extraData;
1519  }
1520 
1521  private:
1522  QString m_message;
1523  QStringList m_extraData;
1524 };
1525 
1526 void MythCoreContext::SendMessage(const QString &message)
1527 {
1528  if (IsBackend())
1529  {
1530  dispatch(MythEvent(message));
1531  }
1532  else
1533  {
1535  new SendAsyncMessage(message), "SendMessage");
1536  }
1537 }
1538 
1540 {
1541  if (IsBackend())
1542  {
1543  dispatch(event);
1544  }
1545  else
1546  {
1548  new SendAsyncMessage(event.Message(), event.ExtraDataList()),
1549  "SendEvent");
1550  }
1551 }
1552 
1553 void MythCoreContext::SendSystemEvent(const QString &msg)
1554 {
1555  if (QCoreApplication::applicationName() == MYTH_APPNAME_MYTHTV_SETUP)
1556  return;
1557 
1558  SendMessage(QString("SYSTEM_EVENT %1 SENDER %2")
1559  .arg(msg).arg(GetHostName()));
1560 }
1561 
1563  const QString &hostname,
1564  const QString &args)
1565 {
1566  SendSystemEvent(QString("%1 HOST %2 %3").arg(msg).arg(hostname).arg(args));
1567 }
1568 
1569 
1571 {
1572  do
1573  {
1574  QStringList strlist;
1575  if (!sock->ReadStringList(strlist))
1576  continue;
1577 
1578  if (strlist.size() < 2)
1579  continue;
1580 
1581  QString prefix = strlist[0];
1582  QString message = strlist[1];
1583 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
1584  QStringList tokens = message.split(" ", QString::SkipEmptyParts);
1585 #else
1586  QStringList tokens = message.split(" ", Qt::SkipEmptyParts);
1587 #endif
1588 
1589  if (prefix == "OK")
1590  {
1591  }
1592  else if (prefix != "BACKEND_MESSAGE")
1593  {
1594  LOG(VB_NETWORK, LOG_ERR, LOC +
1595  QString("Received a: %1 message from the backend "
1596  "but I don't know what to do with it.")
1597  .arg(prefix));
1598  }
1599  else if (message == "CLEAR_SETTINGS_CACHE")
1600  {
1601  // No need to dispatch this message to ourself, so handle it
1602  LOG(VB_NETWORK, LOG_INFO, LOC + "Received remote 'Clear Cache' request");
1604  }
1605  else if (message.startsWith("FILE_WRITTEN"))
1606  {
1607  QString file;
1608  uint64_t size = 0;
1609  int NUMTOKENS = 3; // Number of tokens expected
1610 
1611  if (tokens.size() == NUMTOKENS)
1612  {
1613  file = tokens[1];
1614  size = tokens[2].toULongLong();
1615  }
1616  else
1617  {
1618  LOG(VB_NETWORK, LOG_ERR, LOC +
1619  QString("FILE_WRITTEN event received "
1620  "with invalid number of arguments, "
1621  "%1 expected, %2 actual")
1622  .arg(NUMTOKENS-1)
1623  .arg(tokens.size()-1));
1624  return;
1625  }
1626  // No need to dispatch this message to ourself, so handle it
1627  LOG(VB_NETWORK, LOG_INFO, LOC +
1628  QString("Received remote 'FILE_WRITTEN %1' request").arg(file));
1629  RegisterFileForWrite(file, size);
1630  }
1631  else if (message.startsWith("FILE_CLOSED"))
1632  {
1633  QString file;
1634  int NUMTOKENS = 2; // Number of tokens expected
1635 
1636  if (tokens.size() == NUMTOKENS)
1637  {
1638  file = tokens[1];
1639  }
1640  else
1641  {
1642  LOG(VB_NETWORK, LOG_ERR, LOC +
1643  QString("FILE_CLOSED event received "
1644  "with invalid number of arguments, "
1645  "%1 expected, %2 actual")
1646  .arg(NUMTOKENS-1)
1647  .arg(tokens.size()-1));
1648  return;
1649  }
1650  // No need to dispatch this message to ourself, so handle it
1651  LOG(VB_NETWORK, LOG_INFO, LOC +
1652  QString("Received remote 'FILE_CLOSED %1' request").arg(file));
1654  }
1655  else
1656  {
1657  strlist.pop_front();
1658  strlist.pop_front();
1659  MythEvent me(message, strlist);
1660  dispatch(me);
1661  }
1662  }
1663  while (sock->IsDataAvailable());
1664 }
1665 
1667 {
1668  (void)sock;
1669 
1670  LOG(VB_GENERAL, LOG_NOTICE, LOC +
1671  "Event socket closed. No connection to the backend.");
1672 
1673  dispatch(MythEvent("BACKEND_SOCKETS_CLOSED"));
1674 }
1675 
1677  std::chrono::milliseconds timeout,
1678  bool error_dialog_desired)
1679 {
1680  if (!socket)
1681  return false;
1682 
1683  QStringList strlist(QString("MYTH_PROTO_VERSION %1 %2")
1685  .arg(QString::fromUtf8(MYTH_PROTO_TOKEN)));
1686  socket->WriteStringList(strlist);
1687 
1688  if (!socket->ReadStringList(strlist, timeout) || strlist.empty())
1689  {
1690  LOG(VB_GENERAL, LOG_CRIT, "Protocol version check failure.\n\t\t\t"
1691  "The response to MYTH_PROTO_VERSION was empty.\n\t\t\t"
1692  "This happens when the backend is too busy to respond,\n\t\t\t"
1693  "or has deadlocked due to bugs or hardware failure.");
1694 
1695  return false;
1696  }
1697  if (strlist[0] == "REJECT" && strlist.size() >= 2)
1698  {
1699  LOG(VB_GENERAL, LOG_CRIT, LOC + QString("Protocol version or token mismatch "
1700  "(frontend=%1/%2,backend=%3/\?\?)\n")
1702  .arg(QString::fromUtf8(MYTH_PROTO_TOKEN))
1703  .arg(strlist[1]));
1704 
1705  if (error_dialog_desired && d->m_guiContext)
1706  {
1707  QStringList list(strlist[1]);
1708  QCoreApplication::postEvent(
1709  d->m_guiContext, new MythEvent("VERSION_MISMATCH", list));
1710  }
1711 
1712  return false;
1713  }
1714  if (strlist[0] == "ACCEPT")
1715  {
1716  if (!d->m_announcedProtocol)
1717  {
1718  d->m_announcedProtocol = true;
1719  LOG(VB_GENERAL, LOG_INFO, LOC +
1720  QString("Using protocol version %1 %2")
1722  .arg(QString::fromUtf8(MYTH_PROTO_TOKEN)));
1723  }
1724 
1725  return true;
1726  }
1727 
1728  LOG(VB_GENERAL, LOG_ERR, LOC +
1729  QString("Unexpected response to MYTH_PROTO_VERSION: %1")
1730  .arg(strlist[0]));
1731  return false;
1732 }
1733 
1735 {
1736  LOG(VB_NETWORK, LOG_INFO, LOC + QString("MythEvent: %1").arg(event.Message()));
1737 
1738  MythObservable::dispatch(event);
1739 }
1740 
1742 {
1743  QMutexLocker locker(&d->m_localHostLock);
1745  d->m_database->SetLocalHostname(hostname);
1746 }
1747 
1749 {
1750  d->m_guiObject = gui;
1751 }
1752 
1753 bool MythCoreContext::HasGUI(void) const
1754 {
1755  return d->m_guiObject;
1756 }
1757 
1759 {
1760  return d->m_guiObject;
1761 }
1762 
1764 {
1765  return d->m_guiContext;
1766 }
1767 
1769 {
1770  return d->m_database;
1771 }
1772 
1774 {
1775  return d->m_locale;
1776 }
1777 
1783 {
1784  return GetLanguageAndVariant().left(2);
1785 }
1786 
1795 {
1796  if (d->m_language.isEmpty())
1797  d->m_language = GetSetting("Language", "en_US").toLower();
1798 
1799  return d->m_language;
1800 }
1801 
1803 {
1804  d->m_language.clear();
1805 }
1806 
1808 {
1809  QMutexLocker locker(&d->m_sockLock);
1810  LOG(VB_GENERAL, LOG_INFO, "Restarting Backend Connections");
1811  if (d->m_serverSock)
1813  if (d->m_eventSock)
1815  dispatch(MythEvent("BACKEND_SOCKETS_CLOSED"));
1816 }
1817 
1819 {
1820  if (Create && !d->m_power)
1821  {
1823  }
1824  else if (!Create && d->m_power)
1825  {
1826  MythPower::AcquireRelease(d, false);
1827  d->m_power = nullptr;
1828  }
1829 }
1830 
1832 {
1833  if (!d->m_locale)
1834  d->m_locale = new MythLocale();
1835 
1836  QString localeCode = d->m_locale->GetLocaleCode();
1837  LOG(VB_GENERAL, LOG_NOTICE, QString("Setting QT default locale to %1")
1838  .arg(localeCode));
1839  QLocale::setDefault(d->m_locale->ToQLocale());
1840 }
1841 
1843 {
1844  if (!d->m_locale)
1845  d->m_locale = new MythLocale();
1846  else
1847  d->m_locale->ReInit();
1848 
1849  QString localeCode = d->m_locale->GetLocaleCode();
1850  LOG(VB_GENERAL, LOG_NOTICE, QString("Setting QT default locale to %1")
1851  .arg(localeCode));
1852  QLocale::setDefault(d->m_locale->ToQLocale());
1853 }
1854 
1856 {
1857  if (!d->m_locale)
1858  InitLocale();
1859 
1860  return d->m_locale->ToQLocale();
1861 }
1862 
1864 {
1865  if (!d->m_locale)
1866  InitLocale();
1867 
1868  if (!d->m_locale->GetLocaleCode().isEmpty())
1869  {
1870  LOG(VB_GENERAL, LOG_INFO,
1871  QString("Current locale %1") .arg(d->m_locale->GetLocaleCode()));
1872 
1874  return;
1875  }
1876 
1877  LOG(VB_GENERAL, LOG_ERR, LOC +
1878  "No locale defined! We weren't able to set locale defaults.");
1879 }
1880 
1882 {
1883  d->m_scheduler = sched;
1884 }
1885 
1887 {
1888  return d->m_scheduler;
1889 }
1890 
1895 void MythCoreContext::WaitUntilSignals(std::vector<CoreWaitInfo> & sigs) const
1896 {
1897  if (sigs.empty())
1898  return;
1899 
1900  QEventLoop eventLoop;
1901  for (auto s : sigs)
1902  {
1903  LOG(VB_GENERAL, LOG_DEBUG, LOC +
1904  QString("Waiting for signal %1")
1905  .arg(s.name));
1906  connect(this, s.fn, &eventLoop, &QEventLoop::quit);
1907  }
1908 
1909  eventLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
1910 }
1911 
1919 {
1920  if (!sender || !method)
1921  return;
1922 
1923  QMutexLocker lock(&d->m_playbackLock);
1924 
1925  if (!d->m_playbackClients.contains(sender))
1926  {
1927  d->m_playbackClients.insert(sender, method);
1929  sender, method,
1930  Qt::BlockingQueuedConnection);
1931  }
1932 }
1933 
1940 {
1941  QMutexLocker lock(&d->m_playbackLock);
1942 
1943  if (d->m_playbackClients.contains(sender))
1944  {
1945  PlaybackStartCb method = d->m_playbackClients.value(sender);
1946  disconnect(this, &MythCoreContext::TVPlaybackAboutToStart,
1947  sender, method);
1948  d->m_playbackClients.remove(sender);
1949  }
1950 }
1951 
1959 {
1960  QMutexLocker lock(&d->m_playbackLock);
1961  PlaybackStartCb method { nullptr };
1962  d->m_inwanting = true;
1963 
1964  // If any registered client are in the same thread, they will deadlock, so rebuild
1965  // connections for any clients in the same thread as non-blocking connection
1966  QThread *currentThread = QThread::currentThread();
1967 
1968  QMap<QObject *, PlaybackStartCb>::iterator it = d->m_playbackClients.begin();
1969  for (; it != d->m_playbackClients.end(); ++it)
1970  {
1971  if (it.key() == sender)
1972  continue; // will be done separately, no need to do it again
1973 
1974  QThread *thread = it.key()->thread();
1975 
1976  if (thread != currentThread)
1977  continue;
1978 
1979  disconnect(this, &MythCoreContext::TVPlaybackAboutToStart, it.key(), it.value());
1980  connect(this, &MythCoreContext::TVPlaybackAboutToStart, it.key(), it.value());
1981  }
1982 
1983  // disconnect sender so it won't receive the message
1984  if (d->m_playbackClients.contains(sender))
1985  {
1986  method = d->m_playbackClients.value(sender);
1987  disconnect(this, &MythCoreContext::TVPlaybackAboutToStart, sender, method);
1988  }
1989 
1990  // emit signal
1991  emit TVPlaybackAboutToStart();
1992 
1993  // reconnect sender
1994  if (method)
1995  {
1997  sender, method,
1998  Qt::BlockingQueuedConnection);
1999  }
2000  // Restore blocking connections
2001  for (; it != d->m_playbackClients.end(); ++it)
2002  {
2003  if (it.key() == sender)
2004  continue; // already done above, no need to do it again
2005 
2006  QThread *thread = it.key()->thread();
2007 
2008  if (thread != currentThread)
2009  continue;
2010 
2011  disconnect(this, &MythCoreContext::TVPlaybackAboutToStart,
2012  it.key(), it.value());
2014  it.key(), it.value(), Qt::BlockingQueuedConnection);
2015  }
2016  d->m_inwanting = false;
2017 }
2018 
2025 {
2026  // when called, it will be while the m_playbackLock is held
2027  // following a call to WantingPlayback
2028  d->m_intvwanting = b;
2029 }
2030 
2037 {
2038  bool locked = d->m_playbackLock.tryLock();
2039  bool intvplayback = d->m_intvwanting;
2040 
2041  if (!locked && d->m_inwanting)
2042  return true; // we're in the middle of WantingPlayback
2043 
2044  if (!locked)
2045  return false;
2046 
2047  d->m_playbackLock.unlock();
2048 
2049  return intvplayback;
2050 }
2051 
2053 {
2054  if (!d->m_sessionManager)
2056 
2057  return d->m_sessionManager;
2058 }
2059 
2060 bool MythCoreContext::TestPluginVersion(const QString &name,
2061  const QString &libversion,
2062  const QString &pluginversion)
2063 {
2064  if (libversion == pluginversion)
2065  return true;
2066 
2067  LOG(VB_GENERAL, LOG_EMERG, LOC +
2068  QString("Plugin %1 (%2) binary version does not "
2069  "match libraries (%3)")
2070  .arg(name).arg(pluginversion).arg(libversion));
2071  return false;
2072 }
2073 
2075 {
2076  if (d->m_pluginmanager == pmanager)
2077  return;
2078 
2079  if (d->m_pluginmanager)
2080  {
2081  delete d->m_pluginmanager;
2082  d->m_pluginmanager = nullptr;
2083  }
2084 
2085  d->m_pluginmanager = pmanager;
2086 }
2087 
2089 {
2090  return d->m_pluginmanager;
2091 }
2092 
2094 {
2095  d->m_isexiting = exiting;
2096 }
2097 
2099 {
2100  return d->m_isexiting;
2101 }
2102 
2103 void MythCoreContext::RegisterFileForWrite(const QString& file, uint64_t size)
2104 {
2105  QMutexLocker lock(&d->m_fileslock);
2106 
2107  QPair<int64_t, uint64_t> pair(QDateTime::currentMSecsSinceEpoch(), size);
2108  d->m_fileswritten.insert(file, pair);
2109 
2110  if (IsBackend())
2111  {
2112  QString message = QString("FILE_WRITTEN %1 %2").arg(file).arg(size);
2113  MythEvent me(message);
2114  dispatch(me);
2115  }
2116 
2117  LOG(VB_FILE, LOG_DEBUG, LOC +
2118  QString("%1").arg(file));
2119 }
2120 
2122 {
2123  QMutexLocker lock(&d->m_fileslock);
2124 
2125  d->m_fileswritten.remove(file);
2126 
2127  if (IsBackend())
2128  {
2129  QString message = QString("FILE_CLOSED %1").arg(file);
2130  MythEvent me(message);
2131  dispatch(me);
2132  }
2133 
2134  LOG(VB_FILE, LOG_DEBUG, LOC +
2135  QString("%1").arg(file));
2136 }
2137 
2139 {
2140  QMutexLocker lock(&d->m_fileslock);
2141 
2142  return d->m_fileswritten.contains(file);
2143 }
2144 
2145 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythCoreContext::resolveSettingAddress
QString resolveSettingAddress(const QString &name, const QString &host=QString(), ResolveType type=ResolveAny, bool keepscope=false)
Retrieve IP setting "name" for "host".
Definition: mythcorecontext.cpp:1171
MythCoreContext::SetPluginManager
void SetPluginManager(MythPluginManager *pmanager)
Definition: mythcorecontext.cpp:2074
loggingDeregisterThread
void loggingDeregisterThread(void)
Deregister the current thread's name.
Definition: logging.cpp:748
MythCoreContext::SetWOLAllowed
void SetWOLAllowed(bool allow)
Definition: mythcorecontext.cpp:649
build_compdb.args
args
Definition: build_compdb.py:11
DestroyMythDB
void DestroyMythDB(void)
Definition: mythdb.cpp:50
MythLocale::ReInit
void ReInit()
Definition: mythlocale.cpp:53
MythCoreContextPrivate::WaitForWOL
bool WaitForWOL(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
If another thread has already started WOL process, wait on them...
Definition: mythcorecontext.cpp:218
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition: mythcorecontext.cpp:1526
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:827
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
MythPower
Definition: mythpower.h:18
MythPluginManager
Definition: mythplugin.h:62
MythCoreContextPrivate::m_fileswritten
QMap< QString, QPair< int64_t, uint64_t > > m_fileswritten
Definition: mythcorecontext.cpp:118
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
MYTH_PROTO_TOKEN
#define MYTH_PROTO_TOKEN
Definition: mythversion.h:48
MythScheduler
This is an generic interface to a program scheduler.
Definition: mythscheduler.h:20
kMSDontBlockInputDevs
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:35
MythCoreContext::GetScheduler
MythScheduler * GetScheduler(void)
Definition: mythcorecontext.cpp:1886
false
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
MythCoreContext::SendReceiveStringList
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
Definition: mythcorecontext.cpp:1379
MythCoreContext::IsBlockingClient
bool IsBlockingClient(void) const
is this client blocking shutdown
Definition: mythcorecontext.cpp:644
MythCoreContext::IsFrontendOnly
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
Definition: mythcorecontext.cpp:765
MythCoreContext::AllowShutdown
void AllowShutdown(void)
Definition: mythcorecontext.cpp:630
MythCoreContextPrivate::m_masterHostLock
QMutex m_masterHostLock
Locking for m_masterHostname.
Definition: mythcorecontext.cpp:79
MythCoreContext::ResetSockets
void ResetSockets(void)
Definition: mythcorecontext.cpp:1807
MythLocale
Definition: mythlocale.h:12
MythCoreContext::GetDBManager
MDBManager * GetDBManager(void)
Definition: mythcorecontext.cpp:885
MythCoreContext::UnregisterFileForWrite
void UnregisterFileForWrite(const QString &file)
Definition: mythcorecontext.cpp:2121
MythCoreContext::ConnectToMasterServer
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:376
MythCoreContextPrivate::m_eventSock
MythSocket * m_eventSock
socket events arrive on
Definition: mythcorecontext.cpp:86
MythCoreContext::GetLocale
MythLocale * GetLocale(void) const
Definition: mythcorecontext.cpp:1773
MythCoreContext::~MythCoreContext
~MythCoreContext() override
Definition: mythcorecontext.cpp:298
mythplugin.h
MythCoreContext::InitLocale
void InitLocale(void)
Definition: mythcorecontext.cpp:1831
ShutdownMythDownloadManager
void ShutdownMythDownloadManager(void)
Deletes the running MythDownloadManager at program exit.
Definition: mythdownloadmanager.cpp:133
MythCoreContext::SetScheduler
void SetScheduler(MythScheduler *sched)
Definition: mythcorecontext.cpp:1881
MythCoreContext::GetBackendStatusPort
int GetBackendStatusPort(void)
Returns the locally defined backend status port.
Definition: mythcorecontext.cpp:1100
MythCoreContext::OverrideSettingForSession
void OverrideSettingForSession(const QString &key, const QString &value)
Definition: mythcorecontext.cpp:1345
MDBManager
DB connection pool, used by MSqlQuery. Do not use directly.
Definition: mythdbcon.h:52
MythCoreContextPrivate::m_backend
bool m_backend
Definition: mythcorecontext.cpp:93
MythLocale::ToQLocale
QLocale ToQLocale() const
Definition: mythlocale.h:30
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
MYTH_APPNAME_MYTHTV_SETUP
#define MYTH_APPNAME_MYTHTV_SETUP
Definition: mythcorecontext.h:22
MythCoreContextPrivate::m_appBinaryVersion
QString m_appBinaryVersion
Definition: mythcorecontext.cpp:75
srandom
static void srandom(unsigned int)
Definition: compat.h:148
MythCoreContext::RegisterFileForWrite
void RegisterFileForWrite(const QString &file, uint64_t size=0LL)
Definition: mythcorecontext.cpp:2103
MythCoreContext::IsDatabaseIgnored
bool IsDatabaseIgnored(void) const
/brief Returns true if database is being ignored.
Definition: mythcorecontext.cpp:896
arg
arg(title).arg(filename).arg(doDelete))
MythCoreContext::GetGUIObject
QObject * GetGUIObject(void)
Definition: mythcorecontext.cpp:1758
MythCoreContext::GetFilePrefix
QString GetFilePrefix(void)
Definition: mythcorecontext.cpp:864
MythCoreContext::IsUIThread
bool IsUIThread(void)
Definition: mythcorecontext.cpp:1356
MythCoreContext::connectionClosed
void connectionClosed(MythSocket *sock) override
Definition: mythcorecontext.cpp:1666
MythSocket::DisconnectFromHost
void DisconnectFromHost(void)
Definition: mythsocket.cpp:511
MythCoreContext::CheckProtoVersion
bool CheckProtoVersion(MythSocket *socket, std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
Definition: mythcorecontext.cpp:1676
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
is_current_thread
bool is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
Definition: mthread.cpp:40
MythCoreContextPrivate::m_blockingClient
bool m_blockingClient
Definition: mythcorecontext.cpp:105
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:45
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2060
build_compdb.file
file
Definition: build_compdb.py:55
MythCoreContextPrivate::m_intvwanting
bool m_intvwanting
Definition: mythcorecontext.cpp:110
MythObservable::dispatch
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
Definition: mythobservable.cpp:73
myth_system
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Definition: mythsystemlegacy.cpp:502
MythCoreContext::GetScopeForAddress
bool GetScopeForAddress(QHostAddress &addr) const
Return the cached scope Id for the given address.
Definition: mythcorecontext.cpp:1117
MythSocket::ConnectToHost
bool ConnectToHost(const QString &hostname, quint16 port)
connect to host
Definition: mythsocket.cpp:387
MythCoreContext::setTestStringSettings
void setTestStringSettings(QMap< QString, QString > &overrides)
Definition: mythcorecontext.cpp:314
MythCoreContext::InitPower
void InitPower(bool Create=true)
Definition: mythcorecontext.cpp:1818
MythCoreContext::SafeConnectToMasterServer
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:365
hardwareprofile.distros.mythtv_data.data_mythtv.prefix
string prefix
Definition: data_mythtv.py:40
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
MythEvent::Message
const QString & Message() const
Definition: mythevent.h:65
MythSocket::IsConnected
bool IsConnected(void) const
Definition: mythsocket.cpp:564
MythCoreContextPrivate::m_wolInProgressWaitCondition
QWaitCondition m_wolInProgressWaitCondition
Definition: mythcorecontext.cpp:89
true
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
MythCoreContextPrivate::m_database
MythDB * m_database
Definition: mythcorecontext.cpp:96
MythCoreContext::GetMasterServerStatusPort
int GetMasterServerStatusPort(void)
Returns the Master Backend status port If no master server status port has been defined in the databa...
Definition: mythcorecontext.cpp:1013
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
MythCoreContextPrivate::m_scopesLock
QMutex m_scopesLock
Locking for m_masterHostname.
Definition: mythcorecontext.cpp:81
mythversion.h
mythsystemlegacy.h
SendAsyncMessage::SendAsyncMessage
SendAsyncMessage(QString msg, QStringList extra)
Definition: mythcorecontext.cpp:1506
MythCoreContext::SendHostSystemEvent
void SendHostSystemEvent(const QString &msg, const QString &hostname, const QString &args)
Definition: mythcorecontext.cpp:1562
MythCoreContextPrivate::m_pluginmanager
MythPluginManager * m_pluginmanager
Definition: mythcorecontext.cpp:114
LOC
#define LOC
Definition: mythcorecontext.cpp:54
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
MythCoreContext::ClearOverrideSettingForSession
void ClearOverrideSettingForSession(const QString &key)
Definition: mythcorecontext.cpp:1351
MythCoreContext::IsConnectedToMaster
bool IsConnectedToMaster(void)
Definition: mythcorecontext.cpp:610
MythCoreContext::MythCoreContext
MythCoreContext(const QString &binversion, QObject *guiContext)
Definition: mythcorecontext.cpp:233
quit
@ quit
Definition: lirc_client.h:30
MThreadPool::ShutdownAllPools
static void ShutdownAllPools(void)
Definition: mthreadpool.cpp:325
MythCoreContext::UnregisterForPlayback
void UnregisterForPlayback(QObject *sender)
Definition: mythcorecontext.cpp:1939
MythCoreContext::IsRegisteredFileForWrite
bool IsRegisteredFileForWrite(const QString &file)
Definition: mythcorecontext.cpp:2138
MythCoreContext::IsMasterBackend
bool IsMasterBackend(void)
is this the actual MBE process
Definition: mythcorecontext.cpp:715
MythCoreContextPrivate::m_playbackLock
QMutex m_playbackLock
Definition: mythcorecontext.cpp:108
mythdate.h
MythCoreContextPrivate::m_localHostname
QString m_localHostname
hostname from config.xml or gethostname()
Definition: mythcorecontext.cpp:78
MythCoreContextPrivate::m_isWOLAllowed
bool m_isWOLAllowed
Definition: mythcorecontext.cpp:91
mythlogging.h
MythCoreContext::Init
bool Init(void)
Definition: mythcorecontext.cpp:239
MythCoreContext::GenMythURL
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
Definition: mythcorecontext.cpp:780
MythCoreContext::GetGUIContext
QObject * GetGUIContext(void)
Definition: mythcorecontext.cpp:1763
MythCoreContext::GetQLocale
QLocale GetQLocale(void)
Definition: mythcorecontext.cpp:1855
MythCoreContext::BackendIsRunning
static bool BackendIsRunning(void)
a backend process is running on this host
Definition: mythcorecontext.cpp:720
MythSocket::WriteStringList
bool WriteStringList(const QStringList &list)
Definition: mythsocket.cpp:314
MythCoreContext::SetAsFrontend
void SetAsFrontend(bool frontend)
Definition: mythcorecontext.cpp:669
MThreadPool::StopAllPools
static void StopAllPools(void)
Definition: mthreadpool.cpp:314
MythCoreContext::GetBackendServerPort
int GetBackendServerPort(void)
Returns the locally defined backend control port.
Definition: mythcorecontext.cpp:1084
MythCoreContext::SendSystemEvent
void SendSystemEvent(const QString &msg)
Definition: mythcorecontext.cpp:1553
MythCoreContextPrivate::m_isexiting
bool m_isexiting
Definition: mythcorecontext.cpp:116
MythCoreContext::SendEvent
void SendEvent(const MythEvent &event)
Definition: mythcorecontext.cpp:1539
MythCoreContext::GetMasterServerIP
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
Definition: mythcorecontext.cpp:986
MythCoreContext::WaitUntilSignals
void WaitUntilSignals(std::vector< CoreWaitInfo > &sigs) const
Wait until any of the provided signals have been received.
Definition: mythcorecontext.cpp:1895
MythCoreContextPrivate::m_parent
MythCoreContext * m_parent
Definition: mythcorecontext.cpp:72
hardwareprofile.i18n.t
t
Definition: i18n.py:36
MythCoreContextPrivate::m_frontend
bool m_frontend
Definition: mythcorecontext.cpp:94
compat.h
MythPower::AcquireRelease
static MythPower * AcquireRelease(void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s)
Definition: mythpower.cpp:70
MythCoreContext::GetBackendServerIP
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
Definition: mythcorecontext.cpp:1024
MythCoreContextPrivate::m_sessionManager
MythSessionManager * m_sessionManager
Definition: mythcorecontext.cpp:121
MythCoreContext::IsFrontend
bool IsFrontend(void) const
is this process a frontend process
Definition: mythcorecontext.cpp:674
MythCoreContextPrivate::m_guiObject
QObject * m_guiObject
Definition: mythcorecontext.cpp:74
MythCoreContext::GetDB
MythDB * GetDB(void)
Definition: mythcorecontext.cpp:1768
MythCoreContext::readyRead
void readyRead(MythSocket *sock) override
Definition: mythcorecontext.cpp:1570
MythWakeup
bool MythWakeup(const QString &wakeUpCommand, uint flags, std::chrono::seconds timeout)
Definition: mythmiscutil.cpp:678
MythCoreContext::GetNumSettingOnHost
int GetNumSettingOnHost(const QString &key, const QString &host, int defaultval=0)
Definition: mythcorecontext.cpp:963
MythCoreContextPrivate::m_approvedIps
QList< QHostAddress > m_approvedIps
Definition: mythcorecontext.cpp:123
MythCoreContextPrivate::m_wolInProgressLock
QMutex m_wolInProgressLock
Definition: mythcorecontext.cpp:88
MythCoreContext::GetResolutionSetting
void GetResolutionSetting(const QString &type, int &width, int &height, double &forced_aspect, double &refresh_rate, int index=-1)
Definition: mythcorecontext.cpp:869
MythCoreContext::RegisterForPlayback
void RegisterForPlayback(QObject *sender, PlaybackStartCb method)
Definition: mythcorecontext.cpp:1918
MythCoreContext::GetBackendServerIP4
QString GetBackendServerIP4(void)
Returns the IPv4 address defined for the current host see GetBackendServerIP4(host)
Definition: mythcorecontext.cpp:1047
MythCoreContext::m_testOverrideStrings
QMap< QString, QString > m_testOverrideStrings
Definition: mythcorecontext.h:321
SendAsyncMessage::m_message
QString m_message
Definition: mythcorecontext.cpp:1522
MythCoreContext::TVPlaybackAboutToStart
void TVPlaybackAboutToStart(void)
MythSocket::kShortTimeout
static constexpr std::chrono::milliseconds kShortTimeout
Definition: mythsocket.h:71
SendAsyncMessage
Definition: mythcorecontext.cpp:1503
MythCoreContext::ConnectCommandSocket
MythSocket * ConnectCommandSocket(const QString &hostname, int port, const QString &announcement, bool *proto_mismatch=nullptr, int maxConnTry=-1, std::chrono::milliseconds setup_timeout=-1ms)
Definition: mythcorecontext.cpp:447
uint
unsigned int uint
Definition: compat.h:140
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
SendAsyncMessage::m_extraData
QStringList m_extraData
Definition: mythcorecontext.cpp:1523
MythCoreContextPrivate::~MythCoreContextPrivate
~MythCoreContextPrivate() override
Definition: mythcorecontext.cpp:174
MythCoreContext::ConnectEventSocket
MythSocket * ConnectEventSocket(const QString &hostname, int port)
Definition: mythcorecontext.cpp:565
MythCoreContext::GetLanguage
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
Definition: mythcorecontext.cpp:1782
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:932
logStop
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:714
MythLocale::SaveLocaleDefaults
void SaveLocaleDefaults(bool overwrite=false)
Definition: mythlocale.cpp:172
MythCoreContext::ResolveIPv6
@ ResolveIPv6
Definition: mythcorecontext.h:211
MythCoreContext::resolveAddress
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.
Definition: mythcorecontext.cpp:1200
MythCoreContext::SetLocalHostname
void SetLocalHostname(const QString &hostname)
Definition: mythcorecontext.cpp:1741
MythCoreContextPrivate::m_locale
MythLocale * m_locale
Definition: mythcorecontext.cpp:100
SendAsyncMessage::run
void run(void) override
Definition: mythcorecontext.cpp:1513
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:926
mthreadpool.h
MythEvent::ExtraDataList
const QStringList & ExtraDataList() const
Definition: mythevent.h:67
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
MythCoreContext::GetMasterServerPort
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
Definition: mythcorecontext.cpp:1000
sched
Scheduler * sched
MYTH_PROTO_VERSION
#define MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:47
MythCoreContextPrivate::m_playbackClients
QMap< QObject *, MythCoreContext::PlaybackStartCb > m_playbackClients
Definition: mythcorecontext.cpp:107
MythCoreContext::InWantingPlayback
bool InWantingPlayback(void)
Returns true if a client has requested playback.
Definition: mythcorecontext.cpp:2036
MythCoreContext::ResolveIPv4
@ ResolveIPv4
Definition: mythcorecontext.h:211
MythCoreContext
This class contains the runtime context for MythTV.
Definition: mythcorecontext.h:62
mythmiscutil.h
MythCoreContext::setTestIntSettings
void setTestIntSettings(QMap< QString, int > &overrides)
Definition: mythcorecontext.cpp:304
mythcorecontext.h
MythCoreContext::m_testOverrideFloats
QMap< QString, double > m_testOverrideFloats
Definition: mythcorecontext.h:320
MythCoreContextPrivate::m_announcedProtocol
bool m_announcedProtocol
Definition: mythcorecontext.cpp:112
MythCoreContext::IsBackend
bool IsBackend(void) const
is this process a backend process
Definition: mythcorecontext.cpp:664
kLinkLocal
static QPair< QHostAddress, int > kLinkLocal
Definition: serverpool.cpp:25
MythCoreContextPrivate::m_masterHostname
QString m_masterHostname
master backend hostname
Definition: mythcorecontext.cpp:80
MythCoreContext::ResetLanguage
void ResetLanguage(void)
Definition: mythcorecontext.cpp:1802
MythCoreContext::GetSettingOnHost
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
Definition: mythcorecontext.cpp:946
MythCoreContextPrivate::m_scopes
QMap< QString, QString > m_scopes
Scope Id cache for Link-Local addresses.
Definition: mythcorecontext.cpp:82
kMSProcessEvents
@ kMSProcessEvents
process events while waiting
Definition: mythsystem.h:38
MythCoreContext::GetLanguageAndVariant
QString GetLanguageAndVariant(void)
Returns the user-set language and variant.
Definition: mythcorecontext.cpp:1794
std
Definition: mythchrono.h:23
MythCoreContextPrivate::m_serverSock
MythSocket * m_serverSock
socket for sending MythProto requests
Definition: mythcorecontext.cpp:85
serverpool.h
MythCoreContextPrivate::m_wolInProgress
bool m_wolInProgress
Definition: mythcorecontext.cpp:90
MythSocket::IsDataAvailable
bool IsDataAvailable(void)
Definition: mythsocket.cpp:570
MythCoreContextPrivate::m_inwanting
bool m_inwanting
Definition: mythcorecontext.cpp:109
logging.h
mthread.h
delete_sock
static void delete_sock(QMutexLocker &locker, MythSocket **s)
Definition: mythcorecontext.cpp:162
MythCoreContext::TVInWantingPlayback
void TVInWantingPlayback(bool b)
Let the TV class tell us if we was interrupted following a call to WantingPlayback().
Definition: mythcorecontext.cpp:2024
MythCoreContext::d
MythCoreContextPrivate * d
Definition: mythcorecontext.h:312
MythCoreContextPrivate::m_uiThread
QThread * m_uiThread
Definition: mythcorecontext.cpp:98
SendAsyncMessage::SendAsyncMessage
SendAsyncMessage(QString msg)
Definition: mythcorecontext.cpp:1511
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:853
MThread::Cleanup
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...
Definition: mthread.cpp:142
MythCoreContext::ResolveType
ResolveType
Definition: mythcorecontext.h:211
MythCoreContextPrivate::m_sockLock
QMutex m_sockLock
protects both m_serverSock and m_eventSock
Definition: mythcorecontext.cpp:84
MythLocale::GetLocaleCode
QString GetLocaleCode() const
Name of language in that language.
Definition: mythlocale.h:28
MythCoreContext::WantingPlayback
void WantingPlayback(QObject *sender)
All the objects that have registered using MythCoreContext::RegisterForPlayback but sender will be ca...
Definition: mythcorecontext.cpp:1958
ShutdownMythSystemLegacy
void MBASE_PUBLIC ShutdownMythSystemLegacy(void)
Definition: mythsystemunix.cpp:65
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:858
MythCoreContextPrivate::m_scheduler
MythScheduler * m_scheduler
Definition: mythcorecontext.cpp:103
MythCoreContext::ReInitLocale
void ReInitLocale(void)
Definition: mythcorecontext.cpp:1842
MThread::ThreadSetup
static void ThreadSetup(const QString &name)
This is to be called on startup in those few threads that haven't been ported to MThread.
Definition: mthread.cpp:221
MythCoreContextPrivate::m_deniedIps
QList< QHostAddress > m_deniedIps
Definition: mythcorecontext.cpp:124
MythCoreContext::IsExiting
bool IsExiting(void)
Definition: mythcorecontext.cpp:2098
MythCoreContext::GetBoolSettingOnHost
bool GetBoolSettingOnHost(const QString &key, const QString &host, bool defaultval=false)
Definition: mythcorecontext.cpp:955
MythCoreContext::ClearSettingsCache
void ClearSettingsCache(const QString &myKey=QString(""))
Definition: mythcorecontext.cpp:848
MythCoreContext::IsThisHost
bool IsThisHost(const QString &addr)
is this address mapped to this host
Definition: mythcorecontext.cpp:741
MythCoreContext::HasGUI
bool HasGUI(void) const
Definition: mythcorecontext.cpp:1753
MythCoreContext::IsMasterHost
bool IsMasterHost(void)
is this the same host as the master
Definition: mythcorecontext.cpp:679
MythCoreContextPrivate::m_localHostLock
QMutex m_localHostLock
Locking for m_localHostname.
Definition: mythcorecontext.cpp:77
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
mythpower.h
MythCoreContext::BlockShutdown
void BlockShutdown(void)
Definition: mythcorecontext.cpp:616
MythCoreContext::IsWOLAllowed
bool IsWOLAllowed() const
Definition: mythcorecontext.cpp:654
MythCoreContext::GetFloatSetting
double GetFloatSetting(const QString &key, double defaultval=0.0)
Definition: mythcorecontext.cpp:939
kMSDontDisableDrawing
@ kMSDontDisableDrawing
avoid disabling UI drawing
Definition: mythsystem.h:36
MythCoreContextPrivate::m_fileslock
QMutex m_fileslock
Definition: mythcorecontext.cpp:119
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:901
MythCoreContext::GetMasterHostPrefix
QString GetMasterHostPrefix(const QString &storageGroup=QString(), const QString &path=QString())
Definition: mythcorecontext.cpp:818
MythCoreContext::GetSessionManager
MythSessionManager * GetSessionManager(void)
Definition: mythcorecontext.cpp:2052
exitcodes.h
mythdownloadmanager.h
MythCoreContext::GetBackendServerIP6
QString GetBackendServerIP6(void)
Returns the IPv6 address defined for the current host see GetBackendServerIP6(host)
Definition: mythcorecontext.cpp:1066
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition: mthreadpool.cpp:306
MythCoreContext::GetPluginManager
MythPluginManager * GetPluginManager(void)
Definition: mythcorecontext.cpp:2088
MythCoreContext::SetScopeForAddress
void SetScopeForAddress(const QHostAddress &addr)
Record the scope Id of the given IP address.
Definition: mythcorecontext.cpp:1137
MythSocket::kLongTimeout
static constexpr std::chrono::milliseconds kLongTimeout
Definition: mythsocket.h:72
MythCoreContext::SetupCommandSocket
bool SetupCommandSocket(MythSocket *serverSock, const QString &announcement, std::chrono::milliseconds timeout, bool &proto_mismatch)
Definition: mythcorecontext.cpp:319
MythCoreContext::CheckSubnet
bool CheckSubnet(const QAbstractSocket *socket)
Check if a socket is connected to an approved peer.
Definition: mythcorecontext.cpp:1276
mythsocket.h
MythCoreContextPrivate::m_guiContext
QObject * m_guiContext
Definition: mythcorecontext.cpp:73
MythCoreContextPrivate
Definition: mythcorecontext.cpp:62
MythCoreContext::SaveLocaleDefaults
void SaveLocaleDefaults(void)
Definition: mythcorecontext.cpp:1863
MythCoreContext::dispatch
void dispatch(const MythEvent &event)
Definition: mythcorecontext.cpp:1734
MythCoreContextPrivate::m_language
QString m_language
Definition: mythcorecontext.cpp:101
MythCoreContext::SaveSettingOnHost
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
Definition: mythcorecontext.cpp:911
MythSocket::ReadStringList
bool ReadStringList(QStringList &list, std::chrono::milliseconds timeoutMS=kShortTimeout)
Definition: mythsocket.cpp:326
MythCoreContext::SetAsBackend
void SetAsBackend(bool backend)
Definition: mythcorecontext.cpp:659
MythCoreContext::m_testOverrideInts
QMap< QString, int > m_testOverrideInts
Definition: mythcorecontext.h:319
MythCoreContext::PlaybackStartCb
void(QObject::*)(void) PlaybackStartCb
Definition: mythcorecontext.h:240
MythCoreContext::IsThisBackend
bool IsThisBackend(const QString &addr)
is this address mapped to this backend host
Definition: mythcorecontext.cpp:736
MythCoreContext::setTestFloatSettings
void setTestFloatSettings(QMap< QString, double > &overrides)
Definition: mythcorecontext.cpp:309
MythCoreContext::GetFloatSettingOnHost
double GetFloatSettingOnHost(const QString &key, const QString &host, double defaultval=0.0)
Definition: mythcorecontext.cpp:972
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition: mthreadpool.cpp:341
MythCoreContext::SetExiting
void SetExiting(bool exiting=true)
Definition: mythcorecontext.cpp:2093
MythCoreContext::SetGUIObject
void SetGUIObject(QObject *gui)
Definition: mythcorecontext.cpp:1748
MythSocket::SendReceiveStringList
bool SendReceiveStringList(QStringList &list, uint min_reply_length=0, std::chrono::milliseconds timeoutMS=kLongTimeout)
Definition: mythsocket.cpp:339
MythCoreContextPrivate::m_power
MythPower * m_power
Definition: mythcorecontext.cpp:126
MythCoreContextPrivate::MythCoreContextPrivate
MythCoreContextPrivate(MythCoreContext *lparent, QString binversion, QObject *guicontext)
Definition: mythcorecontext.cpp:129
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:918
MythSessionManager
Definition: mythsession.h:98