BarcodeDownload.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:12k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * BarcodeDownload.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Barcode download/upload source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include <IniFiles.hpp>
- #include <stdio.h>
- #pragma hdrstop
- #include "form_BarcodeDownload.h"
- #include "BarcodeDownload.h"
- #include "man_active.h"
- #include "man_fdm.h"
- // NVRAM
- #ifndef _NVRAM_VER_H_
- #include "nvram_ver.h"
- #endif
- //---------------------------------------------------------------------------
- static CBARCODE* barcode_ptr;
- static bool g_bIsRunning;
- //===========================================================================
- static void CNF_ReadFromNVRAM( void )
- {
- barcode_ptr->CNF_ReadFromNVRAM( );
- }
- //--------------------------------------------------------------------------
- static void CNF_WriteToNVRAM( void )
- {
- barcode_ptr->CNF_WriteToNVRAM( );
- }
- //--------------------------------------------------------------------------
- static void REQ_TimeOut( void )
- { barcode_ptr->REQ_TimeOut();
- }
- //--------------------------------------------------------------------------
- static void REQ_Finish( void )
- { barcode_ptr->REQ_Finish();
- }
- //===========================================================================
- CBARCODE::CBARCODE( void )
- {
- g_bIsRunning = false;
- ConfirmCallback = 0;
- m_iBarcodeBufSize = 0;
- m_pcBarcodeBuf = 0;
- }
- //---------------------------------------------------------------------------
- CBARCODE::~CBARCODE( )
- {
- g_bIsRunning = false;
- ConfirmCallback = 0;
- if(m_pcBarcodeBuf)
- {
- delete [] m_pcBarcodeBuf;
- m_pcBarcodeBuf = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void CBARCODE::REQ_Finish(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- Confirm(METAAPP_SUCCESS);
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CBARCODE::REQ_Stop( void )
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_Cancel_r(m_META_HANDLE_Obj.Get_MainHandle(), m_sBARCODE_ID);
- Confirm(METAAPP_STOP);
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CBARCODE::REQ_TimeOut(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_Cancel_r(m_META_HANDLE_Obj.Get_MainHandle(), m_sBARCODE_ID);
- Confirm(METAAPP_TIMEOUT);
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CBARCODE::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if(!g_bIsRunning) return;
- if(ConfirmCallback==0) return;
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction( ConfirmCallback );
- }
- //===========================================================================
- void CBARCODE::REQ_Read_From_NVRAM( void )
- {
- barcode_ptr = this;
- g_bIsRunning = true;
- if (NULL == m_pcBarcodeBuf)
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_BARCODE_NUM_LID",
- &m_iBarcodeBufSize );
- if (MetaResult != META_SUCCESS)
- {
- Confirm( METAAPP_FAIL ); return; }
- m_pcBarcodeBuf = new char[m_iBarcodeBufSize];
- }
- NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
- NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_BARCODE_NUM_LID",
- 1, // only 1 record
- m_iBarcodeBufSize,
- m_pcBarcodeBuf );
-
- }
- //-------------------------------------
- void CBARCODE::CNF_ReadFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- if (!Decompose_Barcode())
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- ActiveMan->SetActiveFunction(::REQ_Finish);
- }
- break;
- default:
- {
- Confirm(state);
- }
- break;
- }
- }
- //===========================================================================
- void CBARCODE::REQ_Write_To_NVRAM( void )
- {
- barcode_ptr = this;
- g_bIsRunning = true;
- unsigned short lid_ver;
- META_RESULT MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_BARCODE_NUM_LID", &lid_ver);
- if (lid_ver > NVRAM_EF_BARCODE_NUM_LID_VERNO)
- {
- Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
- return;
- }
- if (NULL == m_pcBarcodeBuf)
- {
- MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_BARCODE_NUM_LID",
- &m_iBarcodeBufSize );
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_pcBarcodeBuf = new char[m_iBarcodeBufSize];
- }
- if (!Compose_Barcode())
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
- NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_BARCODE_NUM_LID",
- 1,
- m_iBarcodeBufSize,
- m_pcBarcodeBuf);
- }
- //-------------------------------------
- void CBARCODE::CNF_WriteToNVRAM( void )
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //--------------------------------------------------------------------------
- bool CBARCODE::Compose_Barcode( void )
- {
- int i;
- char str[MAX_BARCODE_LEN+1];
- for( i=0; i<MAX_BARCODE_LEN; i++ )
- {
- sprintf( str, "nvram_ef_barcode_num[%d]", i );
- META_RESULT MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_BARCODE_NUM_LID",
- str,
- m_pcBarcodeBuf,
- m_iBarcodeBufSize,
- &m_sBarcode.c_Barcode[i],
- sizeof(m_sBarcode.c_Barcode[i]) );
- if(MetaResult!=META_SUCCESS) return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool CBARCODE::Decompose_Barcode( void )
- {
- int i;
- char str[MAX_BARCODE_LEN+1];
- for( i=0; i<MAX_BARCODE_LEN; i++ )
- {
- sprintf( str, "nvram_ef_barcode_num[%d]", i );
- META_RESULT MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_BARCODE_NUM_LID",
- str,
- m_pcBarcodeBuf,
- m_iBarcodeBufSize,
- &m_sBarcode.c_Barcode[i],
- sizeof(m_sBarcode.c_Barcode[i]) );
- if(MetaResult!=META_SUCCESS) return false;
- }
- m_sBarcode.c_Barcode[MAX_BARCODE_LEN]=' ';
- return true;
- }
- //===========================================================================
- bool CBARCODE::BarcodeSectionExist( char *filename )
- {
- TIniFile *ini_file;
- ini_file = new TIniFile( filename );
- if( ini_file == NULL ) return false;
- if( ini_file->SectionExists( "Barcode" ) )
- {
- return true;
- }
- return false;
- }
- //--------------------------------------------------------------------------
- bool CBARCODE::REQ_Read_From_File( char *filename )
- {
- TIniFile *ini_file;
- AnsiString as_Barcode;
- ini_file = new TIniFile( filename );
- if( ini_file == NULL ) return false;
- as_Barcode = ini_file->ReadString( "Barcode",
- "Barcode",
- "0" );
- strcpy(m_sBarcode.c_Barcode, as_Barcode.c_str());
- delete ini_file;
- return true;
- }
- //--------------------------------------------------------------------------
- bool CBARCODE::REQ_Write_To_File( char *filename )
- {
- TIniFile *ini_file;
- ini_file = new TIniFile( filename );
- if( ini_file == NULL ) return false;
- if(ini_file != NULL)
- {
- ini_file->WriteString( "Barcode",
- "Barcode",
- m_sBarcode.c_Barcode );
- delete ini_file;
- }
- return true;
- }
- //===========================================================================
- //////////////////////////// Global information ///////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CBARCODE::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- S_BARCODE CBARCODE::Get_Barcode(void)
- {
- return m_sBarcode;
- }
- //--------------------------------------------------------------------------
- void CBARCODE::Set_Barcode(S_BARCODE &barcode)
- {
- m_sBarcode = barcode;
- }