Ticket #3280: backend_functions.diff

File backend_functions.diff, 4.7 KB (added by devel@…, 13 years ago)

BackendIsRunning? and IsMasterBackend? functions

Line 
1Index: mythtv/programs/mythtv-setup/main.cpp
2===================================================================
3--- mythtv/programs/mythtv-setup/main.cpp    (revision 13185)
4+++ mythtv/programs/mythtv-setup/main.cpp    (working copy)
5@@ -36,7 +36,6 @@
6 #include "checksetup.h"
7 
8 using namespace std;
9-bool is_backend_running(void);
10 
11 void SetupMenuCallback(void* data, QString& selection) {
12     (void)data;
13@@ -291,9 +290,9 @@
14         QObject::tr("Changing existing card inputs, deleting anything, "
15                     "or scanning for channels may not work.");
16 
17-    bool backendIsRunning = false;
18+    bool backendIsRunning = gContext->BackendIsRunning();
19 
20-    if (is_backend_running())
21+    if (backendIsRunning)
22     {
23         int val = MythPopupBox::show2ButtonPopup(
24             gContext->GetMainWindow(), QObject::tr("WARNING"),
25@@ -344,40 +343,20 @@
26     }
27     while (haveProblems);
28 
29-    dia = new DialogBox(mainWindow,
30+    if (gContext->IsMasterBackend())
31+    {
32+        dia = new DialogBox(mainWindow,
33                         QObject::tr("Please run 'mythfilldatabase' "
34                                     "to populate the database "
35                                     "with channel information."));
36-    dia->AddButton(QObject::tr("OK"));
37-    dia->exec();
38-    delete dia;
39+        dia->AddButton(QObject::tr("OK"));
40+        dia->exec();
41+        delete dia;
42+    }
43 
44     if (backendIsRunning)
45         RemoteSendMessage("CLEAR_SETTINGS_CACHE");
46 
47     return 0;
48 }
49-
50-bool is_backend_running(void)
51-{
52-#if defined(CONFIG_DARWIN) || (__FreeBSD__) || defined(__OpenBSD__)
53-    char    *command = "ps -ax | grep -i mythbackend | grep -v grep > ";
54-#else
55-    char    *command = "ps -ae | grep mythbackend > ";
56-#endif
57-    QString tmp_file = "/tmp/backendrunning";
58-    myth_system(command + tmp_file,
59-                MYTH_SYSTEM_DONT_BLOCK_LIRC |
60-                MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);
61-
62-    FILE *fptr = fopen(tmp_file, "r");
63-    if (!fptr)
64-        return false;
65-    char buf[1024];
66-    int read_bytes = fread(buf, 1, 1024, fptr);
67-    fclose(fptr);
68-    unlink(tmp_file);
69-
70-    return read_bytes != 0;
71-}
72Index: mythtv/libs/libmyth/mythcontext.h
73===================================================================
74--- mythtv/libs/libmyth/mythcontext.h   (revision 13185)
75+++ mythtv/libs/libmyth/mythcontext.h   (working copy)
76@@ -261,6 +261,8 @@
77     void SetBackend(bool backend);
78     bool IsBackend(void);
79     bool IsFrontendOnly(void);
80+    bool IsMasterBackend(void);
81+    bool BackendIsRunning(void);
82 
83     void BlockShutdown(void);
84     void AllowShutdown(void);
85
86Index: mythtv/libs/libmyth/mythcontext.cpp
87===================================================================
88--- mythtv/libs/libmyth/mythcontext.cpp (revision 13185)
89+++ mythtv/libs/libmyth/mythcontext.cpp (working copy)
90@@ -1057,6 +1085,31 @@
91     return d->m_backend;
92 }
93 
94+bool MythContext::IsMasterBackend(void)
95+{
96+    QString myip = gContext->GetSetting("BackendServerIP");
97+    QString masterip = gContext->GetSetting("MasterServerIP");
98+
99+    bool ismaster = false;
100+
101+    if (masterip == myip)
102+        ismaster = true;
103+    return ismaster;
104+}
105+
106+bool MythContext::BackendIsRunning(void)
107+{
108+#if defined(CONFIG_DARWIN) || (__FreeBSD__) || defined(__OpenBSD__)
109+    char    *command = "ps -ax | grep -i mythbackend | grep -v grep > /dev/null";
110+#else
111+    char    *command = "ps -ae | grep mythbackend > /dev/null";
112+#endif
113+    bool res = myth_system(command,
114+                MYTH_SYSTEM_DONT_BLOCK_LIRC |
115+                MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);
116+    return !res;
117+}
118+
119 bool MythContext::IsFrontendOnly(void)
120 {
121     // find out if a backend runs on this host...
122Index: mythtv/programs/mythbackend/main.cpp
123===================================================================
124--- mythtv/programs/mythbackend/main.cpp        (revision 13185)
125+++ mythtv/programs/mythbackend/main.cpp        (working copy)
126@@ -570,10 +570,6 @@
127     int port = gContext->GetNumSetting("BackendServerPort", 6543);
128 
129     QString myip = gContext->GetSetting("BackendServerIP");
130-    QString masterip = gContext->GetSetting("MasterServerIP");
131-
132-    bool ismaster = false;
133-
134     if (myip.isNull() || myip.isEmpty())
135     {
136         cerr << "No setting found for this machine's BackendServerIP.\n"
137@@ -582,12 +578,14 @@
138         return BACKEND_EXIT_NO_IP_ADDRESS;
139     }
140 
141-    if (masterip == myip)
142+    bool ismaster = gContext->IsMasterBackend();
143+
144+
145+    if (ismaster)
146     {
147         cerr << "Starting up as the master server.\n";
148         gContext->LogEntry("mythbackend", LP_INFO,
149                            "MythBackend started as master server", "");
150-        ismaster = true;
151 
152         if (nosched)
153             cerr << "********** The Scheduler has been DISABLED with "