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

📄 psl_data_bank.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2002 Videon Central, Inc.                                 **
**  All rights reserved.                                                    **
**                                                                          **
**  The computer program contained herein contains proprietary information  **
**  which is the property of Videon Central, Inc.  The program may be used  **
**  and/or copied only with the written permission of Videon Central, Inc.  **
**  or in accordance with the terms and conditions stipulated in the        **
**  agreement/contract under which the programs have been supplied.         **
**                                                                          **
******************************************************************************
*****************************************************************************/
/**
 * @file psl_data_bank.cpp
 *
 * $Revision: 1.7 $ 
 *
 * Data Bank Module of the PSL.
 * 
 */

#include "vdvd_types.h"
#include "psl_data_bank.h"
#include "psl_interface.h"
#include "psl_external_interface.h"
#include "psl_types.h"
#include "nvs.h"
#include "dbgprint.h"

/* Debug macros */
#define DBG_PSL_DATABANK    DBG_ERROR
#define DBG_ON(x)           (DBG_PSL_DATABANK >= x)

/* Default Configuration Settings */
static const ULONG  DEF_DVD_MENU_LANGUAGE_SETTING   = 1;
static const ULONG  DEF_AUDIO_LANGUAGE_SETTING      = 1;
static const ULONG  DEF_SUBTITLE_LANGUAGE_SETTING   = 1;
static const ULONG  DEF_ASPECT_RATIO_SETTING        = VDVD_ASPECT_RATIO_16X9;
static const ULONG  DEF_VIDEO_FORMAT_SETTING        = VDVD_VIDEO_FORMAT_NTSC;
static const ULONG  DEF_SPDIF_SETTING               = VDVD_SPDIF_PCM;
static const ULONG  DEF_COUNTRY_SETTING             = 1;
static const ULONG  DEF_PARENTAL_LEVEL_SETTING      = 8;
static const ULONG  DEF_PARENTAL_PWD_SETTING        = 0Xff;

/* Handle to the nvs module */
static NVS_HANDLE   m_hNvs = NULL;

/**
 * Local functions.
 */
static void     SetDefaultConfigSettings(VDVD_USER_CONFIG &config);
static BOOLEAN  ReadChecksum(VDVD_USER_CONFIG *data);
static void     SetChecksum(VDVD_USER_CONFIG *data);

/**
 * PslDataInitialize -- Open storage device
 *
 * @param
 *      pPSL - handle to internal PSL data
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDataInitialize(PSL_HANDLE *pPSL)
{
    /* Check for valid psl handle */
    if (pPSL == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataInitialize: NULL handle!\n"));
        return (PSL_NULL_POINTER);
    }

    /* Create NVS handle for user configuration settings */
    m_hNvs = NVSOpen(0, sizeof(VDVD_USER_CONFIG) );
    if (m_hNvs == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataInitialize: Failure opening NVS!\n"));
        goto errout;
    }

    return (PSL_SUCCESS);

errout:
    
    if (m_hNvs != NULL)
    {
        NVSClose(m_hNvs);
        m_hNvs = NULL;
    }

    return (PSL_FAILURE);
}

/**
 * PslDataUninitialize -- Close storage device
 *
 * @param
 *      pPSL - handle to internal PSL data
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDataUninitialize(PSL_HANDLE *pPSL)
{
    /* Check for valid psl handle */
    if (pPSL == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataUninitialize: NULL handle!\n"));
        return (PSL_NULL_POINTER);
    }

    /* Close nvs */
    if (m_hNvs != NULL)
    {
        NVSClose(m_hNvs);
        m_hNvs = NULL;
    }

    return (PSL_SUCCESS);
}

/**
 * PslDataLoadConfigSettings -- Load configuration settings from nvs
 *
 * @param
 *      pPSL - handle to internal PSL data
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDataLoadConfigSettings(PSL_HANDLE *pPSL)
{
    /* Check for valid psl handle */
    if (pPSL == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataLoadConfigSettings: NULL handle!\n"));
        return (PSL_NULL_POINTER);
    }

    /* Load user config settings from nvs */
    if (NVSLoad(m_hNvs, (PVOID)&pPSL->user_config, sizeof(VDVD_USER_CONFIG) ) != NVS_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataLoadConfigSettings: Failure loading data from NVS!\n"));
        goto errout;
    }

    /* 
     * Check for valid size and valid checksum.  If either are invalid,
     * then restore the default configuration settings.
     */
    if ( (pPSL->user_config.size != sizeof(VDVD_USER_CONFIG) ) ||
         (FALSE == ReadChecksum(&pPSL->user_config) ) )
    {
        DBGPRINT(DBG_ON(DBG_TRACE), ("PslDataLoadConfigSettings: Restoring defaults\n"));
        
        /* Set default configuration settings in user config struct */
        SetDefaultConfigSettings(pPSL->user_config);

        /* Set the checksum field */
        SetChecksum(&pPSL->user_config);

        /* Store default configuration settings to nvs */
        if (NVSStore(m_hNvs, (PVOID)&pPSL->user_config, sizeof(VDVD_USER_CONFIG) ) != NVS_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataLoadConfigSettings: Failure storing defaults to NVS!\n"));
            goto errout;
        }
    }
    
    DBGPRINT(DBG_ON(DBG_TRACE), ("PslDataLoadConfigSettings: Config settings loaded successfully\n"));

    return (PSL_SUCCESS);
    
errout:
    
    return (PSL_FAILURE);
}

/**
 * PslDataStoreConfigSettings -- Store configuration settings to nvs
 *
 * @param
 *      pPSL - handle to internal PSL data
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDataStoreConfigSettings(PSL_HANDLE *pPSL)
{
    /* Check for valid psl handle */
    if (pPSL == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataStoreConfigSettings: NULL handle!\n"));
        return (PSL_NULL_POINTER);
    }

    /* Check for valid nvs handle */
    if (m_hNvs == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataStoreConfigSettings: NVS handle not created!\n"));
        return (PSL_FAILURE);
    }
    
    /* Set the checksum field */
    SetChecksum(&pPSL->user_config);

    /* Store default configuration settings to nvs */
    if (NVSStore(m_hNvs, (PVOID)&pPSL->user_config, sizeof(VDVD_USER_CONFIG) ) != NVS_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataStoreConfigSettings: Failure storing config settings to NVS!\n"));
        return (PSL_FAILURE);
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("PslDataStoreConfigSettings: Config settings stored successfully\n"));

    return (PSL_SUCCESS);
}

/**
 * PslDataRestoreDefaultSettings -- Restore default configuration settings
 *
 * @param
 *      pPSL - handle to internal PSL data
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDataRestoreDefaultSettings(PSL_HANDLE *pPSL)
{
    /* Check for valid psl handle */
    if (pPSL == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataRestoreDefaultSettings: NULL handle!\n"));
        return (PSL_NULL_POINTER);
    }

    /* Check for valid nvs handle */
    if (m_hNvs == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataRestoreDefaultSettings: NVS handle not created!\n"));
        return (PSL_FAILURE);
    }
        
    /* Set default configuration settings in user config struct */
    SetDefaultConfigSettings(pPSL->user_config);
    
    /* Set the checksum field */
    SetChecksum(&pPSL->user_config);

    /* Store default configuration settings to nvs */
    if (NVSStore(m_hNvs, (PVOID)&pPSL->user_config, sizeof(VDVD_USER_CONFIG) ) != NVS_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataRestoreDefaultSettings: Failure storing defaults to NVS!\n"));
        return (PSL_FAILURE);
    }

    return (PSL_SUCCESS);
}

/**
 * PslDataSetMenuLanguage -- set the default menu language configuration setting
 *
 * @param
 *      pPSL        - handle to internal PSL data
 *      ulLangCode  - language code
 *
 * @retval
 *    none.
 */
void  PslDataSetMenuLanguage(PSL_HANDLE *pPSL, ULONG ulLangCode)
{
    if (pPSL != NULL)
    {
        pPSL->user_config.dvd_menu_language = (UCHAR)(ulLangCode);

        /* update navigator with new configuration setting */
        PslExternalUpdateLanguageMenu(pPSL);
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataSetMenuLanguage: NULL handle!\n"));
    }
}

/**
 * PslDataSetSubtitleLanguage -- set the default subtitle language configuration setting
 *
 * @param
 *      pPSL        - handle to internal PSL data
 *      ulLangCode  - language code
 *
 * @retval
 *    none.
 */
void  PslDataSetSubtitleLanguage(PSL_HANDLE *pPSL, ULONG ulLangCode)
{
    if (pPSL != NULL)
    {
        pPSL->user_config.subtitle_language = (UCHAR)(ulLangCode);

        /* update navigator with new configuration setting */
        PslExternalUpdateLanguageSubtitle(pPSL);
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataSetSubtitleLanguage: NULL handle!\n"));
    }
}

/**
 * PslDataSetAudioLanguage -- set the default audio language configuration setting
 *
 * @param
 *      pPSL        - handle to internal PSL data
 *      ulLangCode  - language code
 *
 * @retval
 *    none.
 */
void  PslDataSetAudioLanguage(PSL_HANDLE *pPSL, ULONG ulLangCode)
{
    if (pPSL != NULL)
    {
        pPSL->user_config.audio_language = (UCHAR)(ulLangCode);

        /* update navigator with new configuration setting */
        PslExternalUpdateLanguageAudio(pPSL);
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataSetAudioLanguage: NULL handle!\n"));
    }
}

/**
 * PslDataSetParentalLevel -- set the parental level configuration setting
 *
 * @param
 *      pPSL        - handle to internal PSL data
 *      ulParLevel  - parental level 
 *
 * @retval
 *    none.
 */
void  PslDataSetParentalLevel(PSL_HANDLE *pPSL, ULONG ulParLevel)
{
    if (pPSL != NULL)
    {
        pPSL->user_config.parental = (UCHAR)(ulParLevel);

        /* update navigator with new configuration setting */
        PslExternalUpdateParentalLevel(pPSL);
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataSetParentalLevel: NULL handle!\n"));
    }
}

/**
 * PslDataSetParentalPassword -- set the parental password configuration setting
 *
 * @param
 *      pPSL            - handle to internal PSL data
 *      ulParPassword   - parental password
 *
 * @retval
 *    none.
 */
void  PslDataSetParentalPassword(PSL_HANDLE *pPSL, ULONG ulParPassword)
{
    if (pPSL != NULL)
    {
        pPSL->user_config.parental_password[0] = (UCHAR)((ulParPassword & 0xff000000) >> 24);
        pPSL->user_config.parental_password[1] = (UCHAR)((ulParPassword & 0x00ff0000) >> 16);
        pPSL->user_config.parental_password[2] = (UCHAR)((ulParPassword & 0x0000ff00) >> 8);
        pPSL->user_config.parental_password[3] = (UCHAR)(ulParPassword & 0x000000ff);
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslDataSetParentalPassword: NULL handle!\n"));
    }
}

/**
 * PslDataSetCountryStandard -- set the country standard configuration setting
 *
 * @param
 *      pPSL         - handle to internal PSL data
 *      ulStandard   - country standard
 *
 * @retval
 *    none.
 */
void  PslDataSetCountryStandard(PSL_HANDLE *pPSL, ULONG ulStandard)
{

⌨️ 快捷键说明

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