00001 #ifndef MYTHCORECONTEXT_H_
00002 #define MYTHCORECONTEXT_H_
00003
00004 #include <QObject>
00005 #include <QString>
00006 #include <QHostAddress>
00007
00008 #include "mythdb.h"
00009 #include "mythbaseexp.h"
00010 #include "mythobservable.h"
00011 #include "mythsocket_cb.h"
00012 #include "mythlogging.h"
00013 #include "mythlocale.h"
00014
00015 #define MYTH_APPNAME_MYTHBACKEND "mythbackend"
00016 #define MYTH_APPNAME_MYTHJOBQUEUE "mythjobqueue"
00017 #define MYTH_APPNAME_MYTHFRONTEND "mythfrontend"
00018 #define MYTH_APPNAME_MYTHTV_SETUP "mythtv-setup"
00019 #define MYTH_APPNAME_MYTHFILLDATABASE "mythfilldatabase"
00020 #define MYTH_APPNAME_MYTHCOMMFLAG "mythcommflag"
00021 #define MYTH_APPNAME_MYTHCCEXTRACTOR "mythccextractor"
00022 #define MYTH_APPNAME_MYTHPREVIEWGEN "mythpreviewgen"
00023 #define MYTH_APPNAME_MYTHTRANSCODE "mythtranscode"
00024 #define MYTH_APPNAME_MYTHWELCOME "mythwelcome"
00025 #define MYTH_APPNAME_MYTHSHUTDOWN "mythshutdown"
00026 #define MYTH_APPNAME_MYTHLCDSERVER "mythlcdserver"
00027 #define MYTH_APPNAME_MYTHAVTEST "mythavtest"
00028 #define MYTH_APPNAME_MYTHMEDIASERVER "mythmediaserver"
00029 #define MYTH_APPNAME_MYTHMETADATALOOKUP "mythmetadatalookup"
00030 #define MYTH_APPNAME_MYTHUTIL "mythutil"
00031
00032 class MDBManager;
00033 class MythCoreContextPrivate;
00034 class MythSocket;
00035 class MythScheduler;
00036
00047 class MBASE_PUBLIC MythCoreContext : public MythObservable, public MythSocketCBs
00048 {
00049 public:
00050 MythCoreContext(const QString &binversion, QObject *eventHandler);
00051 virtual ~MythCoreContext();
00052
00053 bool Init(void);
00054
00055 void SetLocalHostname(const QString &hostname);
00056 void SetServerSocket(MythSocket *serverSock);
00057 void SetEventSocket(MythSocket *eventSock);
00058 void SetScheduler(MythScheduler *sched);
00059
00060 bool ConnectToMasterServer(bool blockingClient = true,
00061 bool openEventSocket = true);
00062
00063 MythSocket *ConnectCommandSocket(const QString &hostname, int port,
00064 const QString &announcement,
00065 bool *proto_mismatch = NULL,
00066 bool gui = true, int maxConnTry = -1,
00067 int setup_timeout = -1);
00068
00069 MythSocket *ConnectEventSocket(const QString &hostname, int port);
00070
00071 bool SetupCommandSocket(MythSocket *serverSock, const QString &announcement,
00072 uint timeout_in_ms, bool &proto_mismatch);
00073
00074 bool CheckProtoVersion(MythSocket *socket,
00075 uint timeout_ms = kMythSocketLongTimeout,
00076 bool error_dialog_desired = false);
00077
00078 QString GenMythURL(QString host = QString(), QString port = QString(),
00079 QString path = QString(), QString storageGroup = QString());
00080
00081 QString GenMythURL(QString host = QString(), int port = 0,
00082 QString path = QString(), QString storageGroup = QString());
00083
00084 QString GetMasterHostPrefix(const QString &storageGroup = QString(),
00085 const QString &path = QString());
00086 QString GetMasterHostName(void);
00087 QString GetHostName(void);
00088 QString GetFilePrefix(void);
00089
00090 bool IsConnectedToMaster(void);
00091 void SetBackend(bool backend);
00092 bool IsBackend(void) const;
00093 bool IsFrontendOnly(void);
00094
00095 bool IsMasterHost(void);
00096 bool IsMasterHost(const QString &host);
00097 bool IsMasterBackend(void);
00098 bool BackendIsRunning(void);
00099
00100 bool IsThisHost(const QString &addr);
00101 bool IsThisHost(const QString &addr, const QString &host);
00102
00103 void BlockShutdown(void);
00104 void AllowShutdown(void);
00105 bool IsBlockingClient(void) const;
00106
00107 bool SendReceiveStringList(QStringList &strlist, bool quickTimeout = false,
00108 bool block = true);
00109 void SendMessage(const QString &message);
00110 void SendEvent(const MythEvent &event);
00111 void SendSystemEvent(const QString &msg);
00112 void SendHostSystemEvent(const QString &msg, const QString &hostname,
00113 const QString &args);
00114
00115 void SetGUIObject(QObject *gui);
00116 QObject *GetGUIObject(void);
00117 bool HasGUI(void) const;
00118 bool IsUIThread(void);
00119
00120 MythDB *GetDB(void);
00121 MDBManager *GetDBManager(void);
00122 MythScheduler *GetScheduler(void);
00123
00124 bool IsDatabaseIgnored(void) const;
00125 DatabaseParams GetDatabaseParams(void)
00126 { return GetDB()->GetDatabaseParams(); }
00127
00128 void SaveSetting(const QString &key, int newValue);
00129 void SaveSetting(const QString &key, const QString &newValue);
00130 QString GetSetting(const QString &key, const QString &defaultval = "");
00131 bool SaveSettingOnHost(const QString &key, const QString &newValue,
00132 const QString &host);
00133
00134
00135 int GetNumSetting(const QString &key, int defaultval = 0);
00136 double GetFloatSetting(const QString &key, double defaultval = 0.0);
00137 void GetResolutionSetting(const QString &type, int &width, int &height,
00138 double& forced_aspect, double &refreshrate,
00139 int index=-1);
00140 void GetResolutionSetting(const QString &type, int &width, int &height,
00141 int index=-1);
00142
00143 QString GetSettingOnHost(const QString &key, const QString &host,
00144 const QString &defaultval = "");
00145 int GetNumSettingOnHost(const QString &key, const QString &host,
00146 int defaultval = 0);
00147 double GetFloatSettingOnHost(const QString &key, const QString &host,
00148 double defaultval = 0.0);
00149
00150 QString GetBackendServerIP(void);
00151 QString GetBackendServerIP(const QString &host);
00152
00153 void ClearSettingsCache(const QString &myKey = QString(""));
00154 void ActivateSettingsCache(bool activate = true);
00155 void OverrideSettingForSession(const QString &key, const QString &value);
00156 void ClearOverrideSettingForSession(const QString &key);
00157
00158 void dispatch(const MythEvent &event);
00159 void dispatchNow(const MythEvent &event);
00160
00161 void InitLocale(void);
00162 void ReInitLocale(void);
00163 MythLocale *GetLocale(void) const;
00164 const QLocale GetQLocale(void);
00165 void SaveLocaleDefaults(void);
00166 QString GetLanguage(void);
00167 QString GetLanguageAndVariant(void);
00168 void ResetLanguage(void);
00169
00170 private:
00171 MythCoreContextPrivate *d;
00172
00173 void connected(MythSocket *sock) { (void)sock; }
00174 void connectionFailed(MythSocket *sock) { (void)sock; }
00175 void connectionClosed(MythSocket *sock);
00176 void readyRead(MythSocket *sock);
00177 };
00178
00180 extern MBASE_PUBLIC MythCoreContext *gCoreContext;
00181
00183 extern MBASE_PUBLIC QMutex *avcodeclock;
00184
00185 #endif
00186
00187