Ticket #155: mythtv.diff

File mythtv.diff, 5.3 KB (added by mythtv@…, 15 years ago)

Patch file

  • libs/libmyth/mythcontext.h

     
    187187    void SetBackend(bool backend);
    188188    bool IsBackend(void);
    189189
     190    void BlockShutdown(void);
     191    void AllowShutdown(void);
     192   
    190193    QString GetInstallPrefix(void);
    191194    QString GetShareDir(void);
    192195    QString GetLibraryDir(void);
  • libs/libmyth/mythcontext.cpp

     
    813813    return d->serverSock;
    814814}
    815815
     816void MythContext::BlockShutdown(void)
     817{
     818    QStringList strlist;
     819
     820    if (d->serverSock == NULL)
     821        return;
     822   
     823    strlist << "BLOCK_SHUTDOWN";
     824    WriteStringList(d->serverSock, strlist);
     825    ReadStringList(d->serverSock, strlist);
     826
     827    // wait for the event socket to finish connecting if necessary
     828    while (d->eventSock->state() == QSocket::HostLookup ||     
     829           d->eventSock->state() == QSocket::Connecting)
     830    {
     831        qApp->processEvents();
     832    }       
     833   
     834    if (d->eventSock->state() != QSocket::Connected)
     835        return;
     836
     837    strlist.clear();
     838    strlist << "BLOCK_SHUTDOWN";
     839    WriteStringList(d->eventSock, strlist);
     840    ReadStringList(d->eventSock, strlist);
     841}
     842
     843void MythContext::AllowShutdown(void)
     844{
     845    QStringList strlist;
     846   
     847    if (d->serverSock == NULL)
     848        return;       
     849   
     850    strlist << "ALLOW_SHUTDOWN";
     851    WriteStringList(d->serverSock, strlist);
     852    ReadStringList(d->serverSock, strlist);
     853   
     854    // wait for the eventSocket to finish connecting if necessary
     855    while (d->eventSock->state() == QSocket::HostLookup ||     
     856           d->eventSock->state() == QSocket::Connecting)
     857    {
     858        qApp->processEvents();
     859    }       
     860   
     861    if (d->eventSock->state() != QSocket::Connected)
     862        return;
     863
     864    strlist.clear();
     865    strlist << "ALLOW_SHUTDOWN";
     866    WriteStringList(d->eventSock, strlist);
     867    ReadStringList(d->eventSock, strlist);
     868}
     869
    816870void MythContext::SetBackend(bool backend)
    817871{
    818872    d->m_backend = backend;
     
    21392193                         .arg(d->m_localhostname).arg(true);
    21402194    QStringList strlist = str;
    21412195    WriteStringList(d->eventSock, strlist);
    2142 //    ReadStringList(d->eventSock, strlist);
     2196    ReadStringList(d->eventSock, strlist);
    21432197}
    21442198
    21452199void MythContext::EventSocketClosed(void)
  • programs/mythbackend/playbacksock.h

     
    2828    bool isLocal(void) { return local; }
    2929    bool wantsEvents(void) { return events; }
    3030
     31    bool getBlockShutdown(void) { return blockshutdown; }
     32    void setBlockShutdown(bool value) { blockshutdown = value; }
     33
    3134    // all backend<->backend stuff below here
    3235    bool isSlaveBackend(void) { return backend; }
    3336    void setAsSlaveBackend(void) { backend = true; }
     
    6366
    6467    bool local;
    6568    bool events;
    66 
     69    bool blockshutdown;
    6770    bool backend;
    6871
    6972    QMutex sockLock;
  • programs/mythbackend/mainserver.cpp

     
    494494        else
    495495            HandleSetSetting(tokens, pbs);
    496496    }
     497    else if (command == "ALLOW_SHUTDOWN")
     498    {
     499        if (tokens.size() != 1)
     500            VERBOSE(VB_ALL, "Bad ALLOW_SHUTDOWN");
     501        else
     502            HandleBlockShutdown(false, pbs);
     503    }
     504    else if (command == "BLOCK_SHUTDOWN")
     505    {
     506        if (tokens.size() != 1)
     507            VERBOSE(VB_ALL, "Bad BLOCK_SHUTDOWN");
     508        else
     509            HandleBlockShutdown(true, pbs);
     510    }
    497511    else if (command == "SHUTDOWN_NOW")
    498512    {
    499513        if (tokens.size() != 1)
     
    33013315    SendResponse(socket, retlist);   
    33023316}
    33033317
     3318void MainServer::HandleBlockShutdown(bool blockShutdown, PlaybackSock *pbs)
     3319{           
     3320    pbs->setBlockShutdown(blockShutdown);
     3321   
     3322    QSocket *socket = pbs->getSocket();
     3323    QStringList retlist = "OK";
     3324    SendResponse(socket, retlist);   
     3325}
     3326
    33043327void MainServer::deferredDeleteSlot(void)
    33053328{
    33063329    QMutexLocker lock(&deferredDeleteLock);
     
    36433666        for (; !foundClient && (it != playbackList.end()); ++it)
    36443667        {
    36453668            // we simply ignore slaveBackends!
    3646             if (!(*it)->isSlaveBackend())
     3669            // and clients that don't want to block shutdown
     3670            if (!(*it)->isSlaveBackend() && (*it)->getBlockShutdown())
    36473671                foundClient = true;
    36483672        }
    36493673    }
  • programs/mythbackend/mainserver.h

     
    126126    void HandleQueryLoad(PlaybackSock *pbs);
    127127    void HandleQueryUptime(PlaybackSock *pbs);
    128128    void HandleQueryMemStats(PlaybackSock *pbs);
    129 
     129    void HandleBlockShutdown(bool blockShutdown, PlaybackSock *pbs);
     130   
    130131    void SendResponse(QSocket *pbs, QStringList &commands);
    131132
    132133    void getGuideDataThrough(QDateTime &GuideDataThrough);