Ticket #4115: 4115-v1.patch

File 4115-v1.patch, 8.4 KB (added by danielk, 16 years ago)

Makes network control a bit safer

  • libs/libmythtv/tv_play.h

     
    9696
    9797    // User input processing commands
    9898    void ProcessKeypress(QKeyEvent *e);
    99     void processNetworkControlCommand(QString command);
     99    void ProcessNetworkControlCommand(const QString &command);
    100100    void customEvent(QCustomEvent *e);
    101101    bool HandleTrackAction(const QString &action);
    102102
  • libs/libmythtv/tv_play.cpp

     
    5555const int TV::kInputModeTimeout=5000;
    5656
    5757#define DEBUG_CHANNEL_PREFIX 0 /**< set to 1 to channel prefixing */
    58 #define DEBUG_ACTIONS 0 /**< set to 1 to debug actions */
     58#define DEBUG_ACTIONS 1 /**< set to 1 to debug actions */
    5959#define LOC QString("TV: ")
     60#define LOC_WARN QString("TV Warning: ")
    6061#define LOC_ERR QString("TV Error: ")
    6162
    6263/*
     
    135136                    QStringList recTitles;
    136137                    QString buttonTitle;
    137138                    vector<ProgramInfo *>::iterator it = reclist->begin();
     139                    recTitles.append(tr("Exit"));
    138140                    while (it != reclist->end())
    139141                    {
    140142                        p = *it;
     
    149151                                    tr("All Tuners are Busy.\n"
    150152                                       "Select a Current Recording"),
    151153                                    recTitles, 1);
    152                     if (ret == -1)
     154                    if ((0 < ret) && (ret <= reclist->size()))
    153155                    {
    154                         quitAll = true;
     156                        p = reclist->at(ret-1);
     157                        curProgram = new ProgramInfo(*p);
    155158                    }
    156159                    else
    157160                    {
    158                         p = reclist->at(ret);
    159                         curProgram = new ProgramInfo(*p);
     161                        quitAll = true;
    160162                    }
    161163                }
    162164            }
     
    16771679void TV::RunTV(void)
    16781680{
    16791681    paused = false;
    1680     QKeyEvent *keypressed;
    1681     QString netCmd;
    16821682
    16831683    doing_ff_rew = 0;
    16841684    ff_rew_index = kInitFFRWSpeed;
     
    17671767            getRecorderPlaybackInfo = false;
    17681768        }
    17691769
    1770         if (nvp && (keyList.count() > 0))
    1771         {
     1770        bool had_key = false;
     1771        if (nvp)
     1772        {
     1773            QKeyEvent *keypressed = NULL;
     1774
    17721775            keyListLock.lock();
    1773             keypressed = keyList.first();
    1774             keyList.removeFirst();
     1776            if (keyList.count() > 0)
     1777            {
     1778                keypressed = keyList.first();
     1779                keyList.removeFirst();
     1780            }
    17751781            keyListLock.unlock();
    17761782
    1777             ProcessKeypress(keypressed);
    1778             delete keypressed;
     1783            if (keypressed)
     1784            {
     1785                had_key = true;
     1786                ProcessKeypress(keypressed);
     1787                delete keypressed;
     1788            }
    17791789        }
    17801790
    1781         netCmd = "";
    1782         ncLock.lock();
    1783         if (networkControlCommands.size())
     1791        if (nvp && !had_key && !ignoreKeys)
    17841792        {
    1785             netCmd = networkControlCommands.front();
    1786             networkControlCommands.pop_front();
     1793            QString netCmd = QString::null;
     1794            ncLock.lock();
     1795            if (networkControlCommands.size())
     1796            {
     1797                netCmd = networkControlCommands.front();
     1798                networkControlCommands.pop_front();
     1799            }
     1800            ncLock.unlock();
     1801
     1802            if (!netCmd.isEmpty())
     1803                ProcessNetworkControlCommand(netCmd);
    17871804        }
    1788         ncLock.unlock();
    17891805
    1790         if (netCmd != "")
    1791             processNetworkControlCommand(netCmd);
    1792 
    17931806        if ((recorder && recorder->GetErrorStatus()) ||
    17941807            (nvp && nvp->IsErrored()) || IsErrored())
    17951808        {
     
    31193132    }
    31203133}
    31213134
    3122 void TV::processNetworkControlCommand(QString command)
     3135void TV::ProcessNetworkControlCommand(const QString &command)
    31233136{
     3137#ifdef DEBUG_ACTIONS
     3138    VERBOSE(VB_IMPORTANT, LOC + "ProcessNetworkControlCommand(" +
     3139            QString("%1)").arg(command));
     3140#endif
     3141
    31243142    QStringList tokens = QStringList::split(" ", command);
     3143    if (tokens.size() < 2)
     3144    {
     3145        VERBOSE(VB_IMPORTANT, LOC_ERR + "Not enough tokens"
     3146                "in network control command" + "\n\t\t\t" +
     3147                QString("'%1'").arg(command));
     3148        return;
     3149    }
    31253150
     3151    if (!dialogname.isEmpty())
     3152    {
     3153        VERBOSE(VB_IMPORTANT, LOC_WARN + "Ignoring network "
     3154                "control command\n\t\t\t" +
     3155                QString("because dialog '%1'").arg(dialogname) +
     3156                "is waiting for a response");
     3157        return;
     3158    }
     3159
    31263160    if (tokens[1] != "QUERY")
    31273161        ClearOSD();
    31283162
    31293163    if (tokens.size() == 3 && tokens[1] == "CHANID")
    31303164    {
    3131         ChangeChannel(tokens[2].toUInt(), "");
     3165        queuedChanID = tokens[2].toUInt();
     3166        queuedChanNum = QString::null;
     3167        CommitQueuedInput();
    31323168    }
    31333169    else if (tokens.size() == 3 && tokens[1] == "CHANNEL")
    31343170    {
    3135         if (tokens[2] == "UP")
    3136             ChangeChannel(CHANNEL_DIRECTION_UP);
    3137         else if (tokens[2] == "DOWN")
    3138             ChangeChannel(CHANNEL_DIRECTION_DOWN);
    3139         else if (tokens[2].contains(QRegExp("^[-\\.\\d_#]+$")))
    3140             ChangeChannel(0, tokens[2]);
     3171        uint aindx = (activenvp == nvp) ? 0 : 1;
     3172        if (StateIsLiveTV(GetState()) && !pseudoLiveTVState[aindx])
     3173        {
     3174            if (tokens[2] == "UP")
     3175                ChangeChannel(CHANNEL_DIRECTION_UP);
     3176            else if (tokens[2] == "DOWN")
     3177                ChangeChannel(CHANNEL_DIRECTION_DOWN);
     3178            else if (tokens[2].contains(QRegExp("^[-\\.\\d_#]+$")))
     3179                ChangeChannel(0, tokens[2]);
     3180        }
    31413181    }
    31423182    else if (tokens.size() == 3 && tokens[1] == "SPEED")
    31433183    {
     
    32193259        }
    32203260        else if (tokens[2].contains(QRegExp("^\\d+\\/\\d+x$")))
    32213261        {
     3262            if (activerbuffer->InDVDMenuOrStillFrame())
     3263                return;
     3264
    32223265            if (paused)
    32233266                DoPause();
    32243267
     
    32603303    }
    32613304    else if (tokens.size() >= 3 && tokens[1] == "SEEK" && activenvp)
    32623305    {
     3306        if (activerbuffer->InDVDMenuOrStillFrame())
     3307            return;
     3308
    32633309        if (tokens[2] == "BEGINNING")
    32643310            DoSeek(-activenvp->GetFramesPlayed(), tr("Jump to Beginning"));
    32653311        else if (tokens[2] == "FORWARD")
     
    57185764            if ((tokens[1] != "ANSWER") && (tokens[1] != "RESPONSE"))
    57195765            {
    57205766                ncLock.lock();
    5721                 networkControlCommands.push_back(message);
     5767                networkControlCommands.push_back(QDeepCopy<QString>(message));
    57225768                ncLock.unlock();
    57235769            }
    57245770        }
  • programs/mythfrontend/networkcontrol.cpp

     
    261261    if (result != "")
    262262    {
    263263        nrLock.lock();
    264         networkControlReplies.push_back(result);
     264        networkControlReplies.push_back(QDeepCopy<QString>(result));
    265265        nrLock.unlock();
    266266
    267267        notifyDataAvailable();
     
    296296    client = s;
    297297    cs = os;
    298298
     299    ncLock.lock();
    299300    networkControlCommands.clear();
     301    ncLock.unlock();
     302
     303    nrLock.lock();
    300304    networkControlReplies.clear();
     305    nrLock.unlock();
    301306
    302307    welcomeStr = "MythFrontend Network Control\r\n";
    303308    if (closedOldConn)
     
    332337        lineIn.replace(QRegExp("[\r\n]"), "");
    333338        lineIn.replace(QRegExp("^\\s"), "");
    334339
     340        if (lineIn.isEmpty())
     341            continue;
     342
    335343        tokens = QStringList::split(" ", lineIn);
    336344
    337345        ncLock.lock();
    338         networkControlCommands.push_back(lineIn);
     346        networkControlCommands.push_back(QDeepCopy<QString>(lineIn));
    339347        ncCond.wakeOne();
    340348        ncLock.unlock();
    341349    }
     
    831839            for (unsigned int i = 3; i < tokens.size(); i++)
    832840                response += QString(" ") + tokens[i];
    833841            nrLock.lock();
    834             networkControlReplies.push_back(response);
     842            networkControlReplies.push_back(QDeepCopy<QString>(response));
    835843            nrLock.unlock();
    836844
    837845            notifyDataAvailable();