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

📄 nvraminterface.c

📁 MTK_MMI的部分源代码,从code中大致了解到MMI的执行流程
💻 C
📖 第 1 页 / 共 5 页
字号:

    OslMfree(pBuffer);

    /* 2  Wait for write response on message queue */

    if (OslReadMsgQ(nvramQID, &queueNode, (U16*) & msgSize, OSL_INFINITE_WAIT) == OSL_SUCCESS)
    {
        writeMessage = (MMIEQNVRAMWRITERSP*) queueNode.oslDataPtr;
        if (writeMessage->result.flag == MMI_OK)
        {

            PRINT_INFORMATION((" Inside MMI_OK block"));
            *pError = NVRAM_WRITE_SUCCESS;
            status = MMI_TRUE;

        }
        else
        {

            PRINT_INFORMATION((" Inside MMI_ERROR block"));
            *pError = ST_FAILURE;
            status = MMI_FALSE;

        }

    }

    PRINT_INFORMATION((" Exiting Wriring record"));
    OslMfree(writeMessage);

    return status;

}

#else /* MMI_ON_WIN32 */ 
/* 
 * Structure of lookup table entry
 */
typedef struct
{
    U16 lid;
    U16 size;
    const U8 *default_value;
} pc_ltable_entry_struct;

/* 
 * Default Values on PC
 */
const U8 NVRAM_EF_ZERO_DEFAULT[] = {0X00};
const U8 NVRAM_EF_FF_DEFAULT[] = {0XFF};

pc_ltable_entry_struct pc_logical_data_item_table[] = 
{
    {NVRAM_EF_PHONEBOOK_SPEEDDIAL_LID, NVRAM_PHONEBOOK_SPEEDDIAL_RECORD_SIZE, NVRAM_EF_ZERO_DEFAULT},
#ifdef __MMI_MESSAGES_CHAT__    
    {NVRAM_EF_CHAT_ROOM_INFO_LID, NVRAM_CHAT_ROOM_INFO_RECORD_SIZE, NVRAM_EF_ZERO_DEFAULT},
#endif /* __MMI_MESSAGES_CHAT__ */
#ifdef __MMI_NITZ__    
        {NVRAM_EF_NITZ_NW_NAME_LID, NVRAM_NITZ_NW_NAME_SIZE, NVRAM_EF_ZERO_DEFAULT},
#endif /* __MMI_NITZ__ */
    {0, 0, NVRAM_EF_FF_DEFAULT}
};


/*****************************************************************************
 * FUNCTION
 *  ReadRecordInt
 * DESCRIPTION
 *  User level API for reading record from the file
 * PARAMETERS
 *  nFileId         [IN]        File LID
 *  nRecordId       [IN]        Record index in file
 *  pBuffer         [OUT]       Buffer in which data need to
 *  nBufferSize     [IN]        Size of record to be read
 *  pError          [OUT]       Error returned from PS
 *  filename        [?]         
 *  lineNumber      [IN]        
 *  it(?)           [IN]        Should be same as file
 *  memory(?)       [OUT]       For this.
 *  record(?)       [IN]        Size
 *  be(?)           [OUT]       Retrieved,caller will allocate
 * RETURNS
 * BOOL
 *  
 *****************************************************************************/
S32 ReadRecordInt(
        U16 nFileId,
        U16 nRecordId,
        void *pBuffer,
        U16 nBufferSize,
        S16 *pError,
        S8 *filename,
        S32 lineNumber)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 fileNameA[sizeof(NVRM_FILES_PATH) + 7];  /* 7 : xxx_xxx */
    S8 fileNameU[(sizeof(NVRM_FILES_PATH) + 7) * 2];
    U32 iBytesRead;
    FS_HANDLE handle;
    S32 retValue = -1;
    U32 temp = 0;
    static U8 is_nvram_init = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!is_nvram_init)
    {
        S8 pathNameA[sizeof(NVRM_FILES_PATH)];
        S8 pathNameU[(sizeof(NVRM_FILES_PATH)) * 2];

        sprintf(pathNameA, "..\\..\\WIN32FS\\DRIVE_C\\NVRAM\\");

        AnsiiToUnicodeString(pathNameU, pathNameA);

        retValue = FS_CreateDir((PU16) pathNameU);

        if (retValue < FS_NO_ERROR && retValue != FS_FILE_EXISTS)
        {
            *pError = NVRAM_READ_FAIL;
            return retValue;
        }

        sprintf(pathNameA, "%s", NVRM_FILES_PATH);

        AnsiiToUnicodeString(pathNameU, pathNameA);

        retValue = FS_CreateDir((PU16) pathNameU);

        if (retValue < FS_NO_ERROR && retValue != FS_FILE_EXISTS)
        {
            *pError = NVRAM_READ_FAIL;
            return retValue;
        }

        is_nvram_init = 1;
    }

    sprintf(fileNameA, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);

    AnsiiToUnicodeString(fileNameU, fileNameA);

    handle = FS_Open((PU16) fileNameU, FS_READ_ONLY);
    PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"ReadRecordInt open org file: %d",handle));

    if (handle == FS_FILE_NOT_FOUND)
    {
        U32 len = 1;
        U16 i;
        pc_ltable_entry_struct *ldi;

        for (i = 0; i < (sizeof(pc_logical_data_item_table) / sizeof(pc_ltable_entry_struct)); i++)
        {
            ldi = &pc_logical_data_item_table[i];
            if (ldi->lid == nFileId)
            {
                break;
            }
        }

        /* Assign Default */
        if (ldi->default_value == NVRAM_EF_ZERO_DEFAULT)
        {
            memset(pBuffer, 0x00, nBufferSize);
        }
        else if (ldi->lid == 0 ||   /* not found */
                 ldi->default_value == NVRAM_EF_FF_DEFAULT)
        {
            memset(pBuffer, 0xFF, nBufferSize);
        }
        else
        {
            memcpy(pBuffer, &ldi->default_value, ldi->size);
        }

        handle = FS_Open((PU16) fileNameU, FS_CREATE_ALWAYS);
        PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"ReadRecordInt create new file: %d",handle));

        if (handle < FS_NO_ERROR)
        {
            *pError = NVRAM_READ_FAIL;
        }
        else
        {
            retValue = FS_Write(handle, pBuffer, nBufferSize, &iBytesRead);
            FS_Close(handle);
        }

        if (retValue >= FS_NO_ERROR)
        {
            *pError = NVRAM_READ_SUCCESS;
        }
        else
        {
            *pError = NVRAM_READ_FAIL;
        }

    }
    else
    {
        retValue = FS_Read(handle, pBuffer, nBufferSize, &iBytesRead);
        if (retValue >= FS_NO_ERROR)
        {
            retValue = iBytesRead;
            *pError = NVRAM_READ_SUCCESS;
        }
        else
        {
            *pError = NVRAM_READ_FAIL;
        }

        FS_Close(handle);

    }

    return retValue;

}


/*****************************************************************************
 * FUNCTION
 *  WriteRecordInt
 * DESCRIPTION
 *  User level API for writing record in the file
 *  
 *  The nBufferSize shall be even
 * PARAMETERS
 *  nFileId         [IN]        File LID
 *  nRecordId       [IN]        Record index in file
 *  pBuffer         [IN]        Buffer in which data need to
 *  nBufferSize     [IN]        Size of record to be write
 *  pError          [OUT]       Error returned from PS
 *  filename        [?]         
 *  lineNumber      [IN]        
 *  it(?)           [IN]        Should be same as file
 *  memory(?)       [IN]        For this.
 *  record(?)       [IN]        Size
 *  be(?)           [IN]        Retrieved,caller will allocate
 * RETURNS
 * BOOL
 *  
 *****************************************************************************/
S32 WriteRecordInt(
        U16 nFileId,
        U16 nRecordId,
        void *pBuffer,
        U16 nBufferSize,
        S16 *pError,
        S8 *filename,
        S32 lineNumber)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 fileNameA[sizeof(NVRM_FILES_PATH) + 7];  /* 7 : xxx_xxx */
    S8 fileNameU[(sizeof(NVRM_FILES_PATH) + 7) * 2];
    U32 iBytes;
    FS_HANDLE handle;
    S32 retValue = -1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sprintf(fileNameA, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);

    AnsiiToUnicodeString(fileNameU, fileNameA);

    handle = FS_Open((PU16) fileNameU, FS_CREATE_ALWAYS);
    PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"WriteRecordInt open file: %d",handle));

    if (handle < FS_NO_ERROR)
    {
        *pError = NVRAM_WRITE_FAIL;
    }
    else
    {
        retValue = FS_Write(handle, pBuffer, nBufferSize, &iBytes);
        if (retValue >= FS_NO_ERROR)
        {
            retValue = iBytes;
            *pError = NVRAM_WRITE_SUCCESS;
        }
        else
        {
            *pError = NVRAM_WRITE_FAIL;
        }

        FS_Close(handle);

    }
    return retValue;

}


/*****************************************************************************
 * FUNCTION
 *  DeleteRecord
 * DESCRIPTION
 *  User level API for Deleting record from the file
 * PARAMETERS
 *  nFileId         [IN]        File LID
 *  nRecordId       [IN]        Record index in file
 *  pError          [OUT]       Error returned from PS
 * RETURNS
 * BOOL
 *  
 *****************************************************************************/
pBOOL DeleteRecord(U16 nFileId, U16 nRecordId, S16 *pError)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 fileName[100];
    S32 retValue = -1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sprintf(fileName, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);

    /* Remove file */
    retValue = remove(fileName);
    if (retValue == 0)
    {
        return MMI_TRUE;
    }
    else
    {
        return MMI_FALSE;
    }
}

#endif /* MMI_ON_WIN32 */ 


/*****************************************************************************
 * FUNCTION
 *  ReadValueInt
 * DESCRIPTION
 *  User level API for 1 byte , 2 byte and 8 byte
 *  
 *  The nBufferSize shall be even
 * PARAMETERS
 *  nDataItemId     [IN]        Data Item ID
 *  pBuffer         [IN]        Buffer in which data need to
 *  nDataType       [IN]        
 *  pError          [OUT]       Error returned from PS
 *  fileName        [?]         
 *  lineNumber      [IN]        
 *  memory(?)       [IN]        For this.
 *  be(?)           [IN]        Retrieved,caller will allocate
 * RETURNS
 * BOOL
 *  
 *****************************************************************************/
S32 ReadValueInt(U8 nDataItemId, void *pBuffer, U8 nDataType, S16 *pError, S8 *fileName, S32 lineNumber)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    S32 status = -1;
    S16 error = -1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_HDLR, nDataItemId, nDataType));

    switch (nDataType)
    {

        case DS_BYTE:
        {
            /* second time reading, it alwasy return one request item */
            if (byteDataReadFlag)
            {
                MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO_HDLR, nDataType));
                /* Data is cached no need to read from NVRAM */
                memcpy(pBuffer, &byte_data[nDataItemId * nDataType], nDataType);
                status = DS_BYTE;
                error = NVRAM_READ_SUCCESS;
            }
            /* process first time reading all data and return first request item data */
            else
            {
                /* Read data from the NVRAM file */
                /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files, first time to read all out */
                U8 tempBuffer[NVRAM_CACHE_SIZE];

                status = ReadRecordInt(
                            NVRAM_EF_CACHE_BYTE_LID,
                            1,
                            tempBuffer,
                            sizeof(tempBuffer),

⌨️ 快捷键说明

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