Ticket #12960: idlescreen.patch

File idlescreen.patch, 8.5 KB (added by mythtv@…, 4 years ago)

Patch to implement controlled disable of WOL when idlesceen has focus.

  • mythtv/libs/libmythbase/mythcorecontext.cpp

    a b  
    323323
    324324// Connects to master server safely (i.e. by taking m_sockLock)
    325325bool MythCoreContext::SafeConnectToMasterServer(bool blockingClient,
    326                                                 bool openEventSocket)
     326                                                bool openEventSocket,
     327                                                bool disableWOL)
    327328{
    328329    QMutexLocker locker(&d->m_sockLock);
    329     bool success = ConnectToMasterServer(blockingClient, openEventSocket);
     330    bool success = ConnectToMasterServer(blockingClient, openEventSocket, disableWOL);
    330331
    331332    return success;
    332333}
     
    334335// Assumes that either m_sockLock is held, or the app is still single
    335336// threaded (i.e. during startup).
    336337bool MythCoreContext::ConnectToMasterServer(bool blockingClient,
    337                                             bool openEventSocket)
     338                                            bool openEventSocket,
     339                                            bool disableWOL)
    338340{
    339341    if (IsMasterBackend())
    340342    {
     
    362364            .arg(type)
    363365            .arg(d->m_localHostname).arg(false);
    364366        d->m_serverSock = ConnectCommandSocket(
    365             server, port, ann, &proto_mismatch);
     367            server, port, ann, &proto_mismatch,true,-1,-1,disableWOL);
    366368    }
    367369
    368370    if (!d->m_serverSock)
     
    401403
    402404MythSocket *MythCoreContext::ConnectCommandSocket(
    403405    const QString &hostname, int port, const QString &announce,
    404     bool *p_proto_mismatch, bool gui, int maxConnTry, int setup_timeout)
     406    bool *p_proto_mismatch, bool gui, int maxConnTry, int setup_timeout,
     407    bool disableWOL)
    405408{
    406409    MythSocket *serverSock = NULL;
    407410
     
    410413        d->WaitForWOL();
    411414    }
    412415
    413     QString WOLcmd = GetSetting("WOLbackendCommand", "");
     416    QString WOLcmd = disableWOL?"":GetSetting("WOLbackendCommand", "");
    414417
    415418    if (maxConnTry < 1)
    416419        maxConnTry = max(GetNumSetting("BackendConnectRetry", 1), 1);
  • mythtv/libs/libmythbase/mythcorecontext.h

    a b  
    6464    void SetScheduler(MythScheduler *sched);
    6565
    6666    bool SafeConnectToMasterServer(bool blockingClient = true,
    67                                    bool openEventSocket = true);
     67                                   bool openEventSocket = true,
     68                                   bool disableWOL = false);
    6869    bool ConnectToMasterServer(bool blockingClient = true,
    69                                bool openEventSocket = true);
     70                               bool openEventSocket = true,
     71                               bool disableWOL = false);
    7072
    7173    MythSocket *ConnectCommandSocket(const QString &hostname, int  port,
    7274                                     const QString &announcement,
    7375                                     bool *proto_mismatch = NULL,
    7476                                     bool gui = true, int maxConnTry = -1,
    75                                      int setup_timeout = -1);
     77                                     int setup_timeout = -1,
     78                                     bool disableWOL = false);
    7679
    7780    MythSocket *ConnectEventSocket(const QString &hostname, int port);
    7881
  • mythtv/programs/mythfrontend/backendconnectionmanager.cpp

    a b  
    2222
    2323class Reconnect : public QRunnable
    2424{
     25  private:
     26    bool m_disableWOL;
     27
    2528  public:
    26     Reconnect()
     29    Reconnect(bool disableWOL = false)
    2730    {
    2831        setAutoDelete(false);
     32        m_disableWOL = disableWOL;
    2933    }
    3034
    3135    virtual void run(void)
    3236    {
    33         if (!gCoreContext->SafeConnectToMasterServer(gCoreContext->IsBlockingClient()))
     37        if (!gCoreContext->SafeConnectToMasterServer(gCoreContext->IsBlockingClient(),true,m_disableWOL))
    3438            gCoreContext->dispatch(MythEvent(QString("RECONNECT_FAILURE")));
    3539        else
    3640            gCoreContext->dispatch(MythEvent(QString("RECONNECT_SUCCESS")));
     
    6973        MythEvent *me = (MythEvent *)event;
    7074        QString message = me->Message();
    7175
     76        if (message == "IDLE_SCREEN_LOADED")
     77        {
     78            m_frontend_idle = true;
     79            LOG(VB_SOCKET, LOG_INFO, "IDLE_SCREEN_LOADED");
     80        }
     81
     82        if (message == "IDLE_SCREEN_DESTROYED")
     83        {
     84            m_frontend_idle = false;
     85            LOG(VB_SOCKET, LOG_INFO, "IDLE_SCREEN_DESTROYED");
     86        }
     87
     88        if (message == "SHUTDOWN_NOW")
     89        {
     90            // m_shutdown_now is restored to false when a successful connection is made.
     91            m_shutdown_now = true;
     92            LOG(VB_SOCKET, LOG_INFO, "SHUTDOWN_NOW");
     93        }
    7294        if (message == "BACKEND_SOCKETS_CLOSED")
    7395        {
    7496            LOG(VB_SOCKET, LOG_INFO, "Got BACKEND_SOCKETS_CLOSED message");
     
    100122            }
    101123            reconnect = m_reconnect_again;
    102124            m_reconnect_again = message == "RECONNECT_FAILURE";
     125            if (message == "RECONNECT_SUCCESS" && m_shutdown_now)
     126            {
     127                    // Backend has restarted after a shutdown
     128                LOG(VB_SOCKET, LOG_INFO, "RECONNECT_SUCCESS after SHUTDOWN_NOW");
     129                m_shutdown_now = false;
     130            }
    103131        }
    104132    }
    105133
     
    118146
    119147void BackendConnectionManager::ReconnectToBackend(void)
    120148{
    121     LOG(VB_SOCKET, LOG_INFO, "Reconnecting");
    122     m_reconnecting = new Reconnect();
     149    bool disableWOL = (m_frontend_idle && m_shutdown_now);
     150    if (disableWOL)
     151       LOG(VB_SOCKET, LOG_INFO, "Reconnecting with WOL disabled");
     152    else
     153       LOG(VB_SOCKET, LOG_INFO, "Reconnecting");
     154    m_reconnecting = new Reconnect(disableWOL);
    123155    MThreadPool::globalInstance()->start(m_reconnecting, "Reconnect");
    124156}
  • mythtv/programs/mythfrontend/backendconnectionmanager.h

    a b  
    2121    Reconnect *m_reconnecting;
    2222    QTimer    *m_reconnect_timer;
    2323    bool       m_reconnect_again;
     24    bool       m_frontend_idle;
     25    bool       m_shutdown_now;
    2426};
  • mythtv/programs/mythfrontend/idlescreen.cpp

    a b  
    2626              m_conflictWarning(NULL),
    2727              m_secondsToShutdown(-1),
    2828              m_pendingSchedUpdate(false),
    29               m_hasConflicts(false)
     29              m_hasConflicts(false),
     30              m_disableWOL(false)
    3031{
    3132    gCoreContext->addListener(this);
    3233    GetMythMainWindow()->EnterStandby();
     
    3435    connect(m_updateScreenTimer, SIGNAL(timeout()),
    3536            this, SLOT(UpdateScreen()));
    3637    m_updateScreenTimer->start(UPDATE_INTERVAL);
     38    gCoreContext->dispatch(MythEvent(QString("IDLE_SCREEN_LOADED")));
     39    gContext->SetDisableEventPopup(true);
    3740}
    3841
    3942IdleScreen::~IdleScreen()
    4043{
     44    gContext->SetDisableEventPopup(false);
     45    gCoreContext->dispatch(MythEvent(QString("IDLE_SCREEN_DESTROYED")));
    4146    GetMythMainWindow()->ExitStandby();
    4247    gCoreContext->removeListener(this);
    4348
     
    95100        bRes = true;
    96101    else
    97102    {
    98         if (gCoreContext->SafeConnectToMasterServer(false))
     103        if (gCoreContext->SafeConnectToMasterServer(false,true,m_disableWOL))
    99104            bRes = true;
    100105    }
    101106
     
    255260    {
    256261        MythEvent *me = static_cast<MythEvent *>(event);
    257262
     263        if (me->Message().startsWith("RECONNECT_SUCCESS"))
     264            m_disableWOL = false;
     265
    258266        if (me->Message().startsWith("RECONNECT_"))
    259267        {
    260268            m_secondsToShutdown = -1;
     
    268276        }
    269277        else if (me->Message().startsWith("SHUTDOWN_NOW"))
    270278        {
     279            m_disableWOL = true;
    271280            if (gCoreContext->IsFrontendOnly())
    272281            {
    273282                // does the user want to shutdown this frontend only machine
  • mythtv/programs/mythfrontend/idlescreen.h

    a b  
    5050    bool            m_pendingSchedUpdate;
    5151    ProgramList     m_scheduledList;
    5252    bool            m_hasConflicts;
     53    bool            m_disableWOL;
    5354};
    5455
    5556#endif