Ticket #9867: 0047-freemheg-Add-timeout-error-to-wait-for-file.patch

File 0047-freemheg-Add-timeout-error-to-wait-for-file.patch, 4.3 KB (added by Lawrence Rust <lvr@…>, 9 years ago)
  • mythtv/libs/libmythfreemheg/Engine.cpp

    From 0cc02800fc2b676da3b7c0e5fc224605a923f616 Mon Sep 17 00:00:00 2001
    From: Lawrence Rust <lvr@softsystem.co.uk>
    Date: Fri, 24 Jun 2011 19:59:40 +0200
    Subject: [PATCH 47/47] freemheg: Add timeout error to wait for file
    
    This fix adds timeouts and EngineEvents to all waits for carousel data.
    This prevents the MHEG interface hanging in the event of missing files.
    
    Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
    ---
     mythtv/libs/libmythfreemheg/Engine.cpp |   22 ++++++++++++++++++++--
     mythtv/libs/libmythfreemheg/Engine.h   |    2 ++
     mythtv/libs/libmythtv/mhi.cpp          |    3 +++
     3 files changed, 25 insertions(+), 2 deletions(-)
    
    diff --git a/mythtv/libs/libmythfreemheg/Engine.cpp b/mythtv/libs/libmythfreemheg/Engine.cpp
    index 1284d2d..dc3e201 100644
    a b bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn) 
    193193    QByteArray text;
    194194    // Check that the file exists before we commit to the transition.
    195195    // This may block if we cannot be sure whether the object is present.
    196     if (! m_Context->GetCarouselData(csPath, text)) return false;
     196    if (! m_Context->GetCarouselData(csPath, text))
     197    {
     198        if (CurrentApp())
     199            EventTriggered(CurrentApp(), EventEngineEvent, 2); // GroupIDRefError
     200        return false;
     201    }
    197202
    198203    // Clear the action queue of anything pending.
    199204    m_ActionStack.clear();
    void MHEngine::TransitionToScene(const MHObjectRef &target) 
    281286    QString csPath = GetPathName(target.m_GroupId);
    282287    QByteArray text;
    283288    // Check that the file exists before we commit to the transition.
    284     if (! m_Context->GetCarouselData(csPath, text)) return;
     289    if (! m_Context->GetCarouselData(csPath, text))
     290    {
     291        EventTriggered(CurrentApp(), EventEngineEvent, 2); // GroupIDRefError
     292        return;
     293    }
    285294
    286295    // Parse and run the file.
    287296    MHGroup *pProgram = ParseProgram(text);
    void MHEngine::RequestExternalContent(MHIngredient *pRequester) 
    683692        MHExternContent *pContent = new MHExternContent;
    684693        pContent->m_FileName = csPath;
    685694        pContent->m_pRequester = pRequester;
     695        pContent->m_time.start();
    686696        m_ExternContentTable.append(pContent);
    687697    }
    688698}
    void MHEngine::CheckContentRequests() 
    730740            delete pContent;
    731741            it = m_ExternContentTable.erase(it);
    732742        }
     743        else if (pContent->m_time.elapsed() > 60000) // TODO Get this from carousel
     744        {
     745            MHLOG(MHLogWarning, QString("CheckContentRequests %1 timed out")
     746                .arg(pContent->m_FileName));
     747            delete pContent;
     748            it = m_ExternContentTable.erase(it);
     749            EventTriggered(CurrentApp(), EventEngineEvent, 3); // ContentRefError
     750        }
    733751        else
    734752            ++it;
    735753    }
  • mythtv/libs/libmythfreemheg/Engine.h

    diff --git a/mythtv/libs/libmythfreemheg/Engine.h b/mythtv/libs/libmythfreemheg/Engine.h
    index 4612aa8..34cf4c7 100644
    a b  
    3636#include <QList>
    3737#include <QStack>
    3838#include <QQueue>
     39#include <QTime>
    3940
    4041class MHDLADisplay;
    4142
    class MHExternContent { 
    6263public:
    6364    QString m_FileName;
    6465    MHIngredient *m_pRequester;
     66    QTime m_time;
    6567};
    6668
    6769class MHInteractible;
  • mythtv/libs/libmythtv/mhi.cpp

    diff --git a/mythtv/libs/libmythtv/mhi.cpp b/mythtv/libs/libmythtv/mhi.cpp
    index 82c6608..7705a3d 100644
    a b bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result) 
    381381    // same thread this is safe.  Otherwise we need to make a deep copy of
    382382    // the result.
    383383
     384    QTime t; t.start();
    384385    while (!m_stop)
    385386    {
    386387        int res = m_dsmcc->GetDSMCCObject(path, result);
    bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result) 
    388389            return true; // Found it
    389390        else if (res < 0)
    390391            return false; // Not there.
     392        else if (t.elapsed() > 60000) // TODO get this from carousel info
     393            return false; // Not there.
    391394        // Otherwise we block.
    392395        // Process DSMCC packets then block for a second or until we receive
    393396        // some more packets.  We should eventually find out if this item is