⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progdown.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK *****
 * Version: RCSL 1.0/RPSL 1.0
 *
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
 *
 * The contents of this file, and the files included with this file, are
 * subject to the current version of the RealNetworks Public Source License
 * Version 1.0 (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the RealNetworks Community Source License Version 1.0
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
 * in which case the RCSL will apply. You may also obtain the license terms
 * directly from RealNetworks.  You may not use this file except in
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
 * applicable to this file, the RCSL.  Please see the applicable RPSL or
 * RCSL for the rights, obligations and limitations governing use of the
 * contents of the file.
 *
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the portions
 * it created.
 *
 * This file, and the files included with this file, is distributed and made
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 *
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */

#include "hxtypes.h"
#include "hxcom.h"
#include "ihxpckts.h"
#include "hlxclib/sys/stat.h"
#include "hxdataf.h"
#include "hxprefs.h"
#include "hxmon.h"
#include "hxcomm.h"
#include "hxcbobj.h"
#include "hxprefutil.h"
#include "pckunpck.h"
#include "baseobj.h"
#include "hxtick.h"
#include "smplmlog.h"
#include "progdown.h"

CProgressiveDownloadMonitor::CProgressiveDownloadMonitor()
{
    MLOG_PD(NULL, "CON CProgressiveDownloadMonitor 0x%08x\n", this);
    m_pContext               = NULL;
    m_pDataFile              = NULL;
    m_pResponse              = NULL;
    m_pScheduler             = NULL;
    m_pRegistry              = NULL;
    m_pStatCallback          = NULL;
    m_pProgCallback          = NULL;
    m_ulStatCallbackInterval = PROGDOWN_STAT_INTERVAL_DEFAULT;
    m_ulCurStatInterval      = PROGDOWN_STAT_INTERVAL_INITIAL;
    m_ulProgCallbackInterval = PROGDOWN_FAIL_INTERVAL_DEFAULT;
    m_ulFinishedTime         = PROGDOWN_FINISHED_TIME_DEFAULT;
    m_ulLastFileSize         = 0;
    m_ulTickAtLastFileSize   = 0;
    m_ulURLRegistryID        = 0;
    m_ulIsProgRegistryID     = 0;
    m_ulFormerProgRetryCount = 0;
    m_ulFormerProgRetryInit  = PROGDOWN_FORMER_PROG_RETRY_INIT;
    m_ulNotProgRetryCount    = 0;
    m_ulNotProgRetryInit     = PROGDOWN_NOT_PROG_RETRY_INIT;
    m_bIsProgressive         = FALSE;
    m_bMonitorEnabled        = TRUE;
    m_bHasBeenProgressive    = FALSE;
}

CProgressiveDownloadMonitor::~CProgressiveDownloadMonitor()
{
    MLOG_PD(NULL, "DES CProgressiveDownloadMonitor 0x%08x\n", this);
    Close();
}

HX_RESULT CProgressiveDownloadMonitor::Init(IUnknown* pContext, IHXDataFile* pFile,
                                            CProgressiveDownloadMonitorResponse* pResponse)
{
    MLOG_PD(NULL, "CProgressiveDownloadMonitor::Init() this=0x%08x\n", this);
    HX_RESULT retVal = HXR_FAIL;

    if (pContext && pFile && pResponse)
    {
        // Clear out any current state
        Close();
        // Save the context
        m_pContext = pContext;
        m_pContext->AddRef();
        // Save the file
        m_pDataFile = pFile;
        // XXXMEH - We will not AddRef the IHXDataFile for now, because
        // some users of the IHXFileObject do not call IHXFileObject::Close()
        // before releasing the file object. If that is the case, then 
        // the IHXDataFile never destructs. If we ever exhaustively go through
        // and verify that all users of smplfsys correctly call ::Close(),
        // then we can remove the commented-out AddRef().
//        m_pDataFile->AddRef();
        // Save the response pointer
        m_pResponse = pResponse;
        m_pResponse->AddRef();
        // Get the schedule interface
        retVal = m_pContext->QueryInterface(IID_IHXScheduler, (void**) &m_pScheduler);
        if (SUCCEEDED(retVal))
        {
            // Get the IHXRegistry interface
            m_pContext->QueryInterface(IID_IHXRegistry, (void**) &m_pRegistry);
            // Check preferences to see if alternate values
            // for stat callback interval, fail callback interval
            // and finished duration are specified
            CheckPreferenceValues(m_bMonitorEnabled,
                                  m_ulStatCallbackInterval,
                                  m_ulProgCallbackInterval,
                                  m_ulFinishedTime,
                                  m_ulFormerProgRetryInit,
                                  m_ulNotProgRetryInit);
            // Initialize the progressive state variables
            m_ulLastFileSize       = GetFileSizeNow();
            m_ulTickAtLastFileSize = HX_GET_BETTERTICKCOUNT();
            // Initialize the number of times to retry
            // if the file has not been progressive
            m_ulNotProgRetryCount = m_ulNotProgRetryInit;
            // Init the registry stats
            InitRegistryStats();
        }
    }

    return retVal;
}

HX_RESULT CProgressiveDownloadMonitor::Close()
{
    MLOG_PD(NULL, "CProgressiveDownloadMonitor::Close() this=0x%08x\n", this);
    HX_RESULT retVal = HXR_OK;

    // Clear any stat callback
    if (m_pStatCallback) m_pStatCallback->Cancel(m_pScheduler);
    HX_RELEASE(m_pStatCallback);
    // Clear any fail callback
    CancelCallback();
    HX_RELEASE(m_pProgCallback);
    // Release member variables
    HX_RELEASE(m_pContext);
        // XXXMEH - We will not AddRef the IHXDataFile for now, because
        // some users of the IHXFileObject do not call IHXFileObject::Close()
        // before releasing the file object. If that is the case, then 
        // the IHXDataFile never destructs. If we ever exhaustively go through
        // and verify that all users of smplfsys correctly call ::Close(),
        // then we can remove the commented-out HX_RELEASE()
//    HX_RELEASE(m_pDataFile);
    m_pDataFile = NULL;
    HX_RELEASE(m_pResponse);
    HX_RELEASE(m_pScheduler);
    HX_RELEASE(m_pRegistry);
    // Reset state variables to defaults
    m_ulStatCallbackInterval = PROGDOWN_STAT_INTERVAL_DEFAULT;
    m_ulCurStatInterval      = PROGDOWN_STAT_INTERVAL_INITIAL;
    m_ulProgCallbackInterval = PROGDOWN_FAIL_INTERVAL_DEFAULT;
    m_ulFinishedTime         = PROGDOWN_FINISHED_TIME_DEFAULT;
    m_ulLastFileSize         = 0;
    m_ulTickAtLastFileSize   = 0;
    m_ulURLRegistryID        = 0;
    m_ulIsProgRegistryID     = 0;
    m_ulFormerProgRetryCount = 0;
    m_ulFormerProgRetryInit  = PROGDOWN_FORMER_PROG_RETRY_INIT;
    m_ulNotProgRetryCount    = 0;
    m_ulNotProgRetryInit     = PROGDOWN_NOT_PROG_RETRY_INIT;
    m_bIsProgressive         = FALSE;
    m_bMonitorEnabled        = TRUE;
    m_bHasBeenProgressive    = FALSE;

    return retVal;
}

HX_RESULT CProgressiveDownloadMonitor::ScheduleCallback()
{
    MLOG_PD(NULL, "CProgressiveDownloadMonitor::ScheduleCallback() this=0x%08x tick=%lu\n",
            this, HX_GET_BETTERTICKCOUNT());
    HX_RESULT retVal = HXR_FAIL;

    if (m_pScheduler)
    {
        if (!m_pProgCallback)
        {
            m_pProgCallback = new CHXGenericCallback(this, CProgressiveDownloadMonitor::ProgCallback);
            if (m_pProgCallback)
            {
                m_pProgCallback->AddRef();
            }
        }
        if (m_pProgCallback)
        {
            // Clear the return value
            retVal = HXR_OK;
            // Do we already have a callback pending?
            if (!m_pProgCallback->IsCallbackPending())
            {
                // No callback pending, schedule one
                m_pProgCallback->ScheduleRelative(m_pScheduler, m_ulProgCallbackInterval);
            }
        }
    }

    return retVal;
}

BOOL CProgressiveDownloadMonitor::IsCallbackPending()
{
    BOOL bRet = FALSE;

    if (m_pProgCallback)
    {
        bRet = m_pProgCallback->IsCallbackPending();
    }

    return bRet;
}

void CProgressiveDownloadMonitor::CancelCallback()
{
    if (m_pProgCallback && m_pProgCallback->IsCallbackPending())
    {
        m_pProgCallback->Cancel(m_pScheduler);
    }
}

HX_RESULT CProgressiveDownloadMonitor::BeginSizeMonitoring()
{
    HX_RESULT retVal = HXR_FAIL;

    // Create the stat callback if it doesn't
    // already exist
    if (!m_pStatCallback)
    {
        m_pStatCallback = new CHXGenericCallback(this, CProgressiveDownloadMonitor::StatCallback);
        if (m_pStatCallback)
        {
            m_pStatCallback->AddRef();
        }
    }
    if (m_pStatCallback)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Do we already have a callback scheduled? If so,
        // then we have already begun size monitoring.
        if (!m_pStatCallback->IsCallbackPending())
        {
            // Initialize the progressive state variables
            m_ulLastFileSize       = GetFileSizeNow();
            m_ulTickAtLastFileSize = HX_GET_BETTERTICKCOUNT();
            m_ulCurStatInterval    = PROGDOWN_STAT_INTERVAL_INITIAL;
            // Kick off the callbacks, if monitoring is enabled
            ScheduleStatCallback();
        }
    }

    return retVal;
}

void CProgressiveDownloadMonitor::EndSizeMonitoring()
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -