Ticket #3280: backend-functions-180707.diff

File backend-functions-180707.diff, 4.6 KB (added by devel@…, 12 years ago)

BackendIsRunning? and IsMasterBackend? functions

  • mythtv/programs/mythbackend/main.cpp

     
    573573    int port = gContext->GetNumSetting("BackendServerPort", 6543);
    574574
    575575    QString myip = gContext->GetSetting("BackendServerIP");
    576     QString masterip = gContext->GetSetting("MasterServerIP");
    577 
    578     bool ismaster = false;
    579 
    580576    if (myip.isNull() || myip.isEmpty())
    581577    {
    582578        cerr << "No setting found for this machine's BackendServerIP.\n"
     
    585581        return BACKEND_EXIT_NO_IP_ADDRESS;
    586582    }
    587583
    588     if (masterip == myip)
     584    bool ismaster = gContext->IsMasterBackend();
     585
     586
     587    if (ismaster)
    589588    {
    590589        cerr << "Starting up as the master server.\n";
    591590        gContext->LogEntry("mythbackend", LP_INFO,
    592591                           "MythBackend started as master server", "");
    593         ismaster = true;
    594592
    595593        if (nosched)
    596594            cerr << "********** The Scheduler has been DISABLED with "
  • mythtv/libs/libmyth/mythcontext.cpp

     
    10551101    return d->m_backend;
    10561102}
    10571103
     1104bool MythContext::IsMasterBackend(void)
     1105{
     1106    QString myip = gContext->GetSetting("BackendServerIP");
     1107    QString masterip = gContext->GetSetting("MasterServerIP");
     1108
     1109    bool ismaster = false;
     1110
     1111    if (masterip == myip)
     1112        ismaster = true;
     1113    return ismaster;
     1114}
     1115
     1116bool MythContext::BackendIsRunning(void)
     1117{
     1118#if defined(CONFIG_DARWIN) || (__FreeBSD__) || defined(__OpenBSD__)
     1119    char    *command = "ps -ax | grep -i mythbackend | grep -v grep > /dev/null";
     1120#else
     1121    char    *command = "ps -ae | grep mythbackend > /dev/null";
     1122#endif
     1123    bool res = myth_system(command,
     1124                MYTH_SYSTEM_DONT_BLOCK_LIRC |
     1125                MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);
     1126    return !res;
     1127}
     1128
    10581129bool MythContext::IsFrontendOnly(void)
    10591130{
    10601131    // find out if a backend runs on this host...
  • mythtv/libs/libmyth/mythcontext.h

     
    262262    void SetBackend(bool backend);
    263263    bool IsBackend(void);
    264264    bool IsFrontendOnly(void);
     265    bool IsMasterBackend(void);
     266    bool BackendIsRunning(void);
    265267
    266268    void BlockShutdown(void);
    267269    void AllowShutdown(void);
  • mythtv/programs/mythtv-setup/main.cpp

    (this hunk was shorter than expected) 
    288287        QObject::tr("Changing existing card inputs, deleting anything, "
    289288                    "or scanning for channels may not work.");
    290289
    291     bool backendIsRunning = false;
     290    bool backendIsRunning = gContext->BackendIsRunning();
    292291
    293     if (is_backend_running())
     292    if (backendIsRunning)
    294293    {
    295294        int val = MythPopupBox::show2ButtonPopup(
    296295            gContext->GetMainWindow(), QObject::tr("WARNING"),
     
    344344    // Execute UI again until there are no more problems:
    345345    }
    346346    while (haveProblems);
    347347
    348     dia = new DialogBox(mainWindow,
     348    if (gContext->IsMasterBackend())
     349    {
     350        dia = new DialogBox(mainWindow,
    349351                        QObject::tr("Please run 'mythfilldatabase' "
    350352                                    "to populate the database "
    351353                                    "with channel information."));
    352     dia->AddButton(QObject::tr("OK"));
    353     dia->exec();
    354     delete dia;
     354        dia->AddButton(QObject::tr("OK"));
     355        dia->exec();
     356        delete dia;
     357    }
    355358
    356359    if (backendIsRunning)
    357360        RemoteSendMessage("CLEAR_SETTINGS_CACHE");
    358361
    359362    return 0;
    360363}
    361 
    362 bool is_backend_running(void)
    363 {
    364 #if defined(CONFIG_DARWIN) || (__FreeBSD__) || defined(__OpenBSD__)
    365     char    *command = "ps -ax | grep -i mythbackend | grep -v grep > ";
    366 #else
    367     char    *command = "ps -ae | grep mythbackend > ";
    368 #endif
    369     QString tmp_file = "/tmp/backendrunning";
    370     myth_system(command + tmp_file,
    371                 MYTH_SYSTEM_DONT_BLOCK_LIRC |
    372                 MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);
    373 
    374     FILE *fptr = fopen(tmp_file, "r");
    375     if (!fptr)
    376         return false;
    377     char buf[1024];
    378     int read_bytes = fread(buf, 1, 1024, fptr);
    379     fclose(fptr);
    380     unlink(tmp_file);
    381 
    382     return read_bytes != 0;
    383 }