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

📄 phb_handler_search.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
*  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:
 * ---------
 * phb_handler_search.c
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *   This is write handler of PHB module.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#include "kal_release.h"        /* Basic data type */

#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "app_buff_alloc.h"     /* Declaration of buffer management API */

#include "kal_trace.h"
#include "phb_trc.h"

#include "sim_common_enums.h"
// #include "nvram_editor_data_item.h"
#include "custom_nvram_editor_data_item.h"

#include "l4_common.h"
#include "ps2sim_struct.h"

#include "l4c2phb_enums.h"
#include "l4c2phb_struct.h"

/* Prerequisite of phb_context.h */
#include "phb_defs.h"
#include "phb_control_block.h"
#include "phb_data_desc.h"
#include "phb_data_entry_table.h"
#include "phb_pindex.h"
#include "phb_name_num_index.h"

#include "phb_context.h"
#include "phb_se.h"

#include "phb_common.h"
#include "phb_ilm.h"
#include "phb_utils.h"

#include "phb_handler_read.h"
#include "phb_handler_search.h"

#include "phb_sap.h"

#undef  _FILE_CODE_
#define _FILE_CODE_ _PHB_HANDLER_SEARCH_C_

static void phb_search_err_handler(ilm_struct *ilm_ptr, control_block_type *control_block);
static void phb_search_confirm(
                phb_errno_enum result,
                kal_uint16 actual_count,
                kal_uint8 src_id,
                msg_type cnf_msg_id,
                control_block_type *control_block);
static match_result_enum phb_compare_tel_number(l4_addr_bcd_struct *given, l4_addr_bcd_struct *candidate);


/*****************************************************************************
 * FUNCTION
 *  phb_search_handler
 * DESCRIPTION
 *  This is phb_search_handler function of PHB module.
 *  Handles write request from L4C.
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_search_handler(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SEARCH);

    if (ilm_ptr != NULL)
    {
        l4cphb_search_req_struct *l4cphb_search_req;

        l4cphb_search_req = (l4cphb_search_req_struct*) ilm_ptr->local_para_ptr;

        /* Cannot allocate, means that PHB is still operating. Reject request! */
        control_block = phb_alloc_control_block();
        if (control_block == NULL)
        {
            phb_search_confirm(PHB_ERRNO_BUSY, 0, l4cphb_search_req->src_id, MSG_ID_INVALID_TYPE, control_block);
            return;
        }

        control_block->src_id = l4cphb_search_req->src_id;

        /* Retain msg_id */
        control_block->cnf_msg_id = ilm_ptr->msg_id;

        if ((phb_ptr->state == PHB_STATE_READY) &&
            ((l4cphb_search_req->type == PHB_PHONEBOOK) ||
             (l4cphb_search_req->type == PHB_FDN) ||
             (l4cphb_search_req->type == PHB_BDN)) && ((l4cphb_search_req->pattern_tag == PHB_BYNAME) ||
    #ifdef __PHB_SORT_ENABLE__
                                                       (l4cphb_search_req->pattern_tag == PHB_BYNAME_EXACT) ||
    #endif 
                                                       (l4cphb_search_req->pattern_tag == PHB_BYNUMBER)))
        {
            if (control_block->proc_stage == SEARCH_NONE)
            {
                kal_bool is_more_candidates;
                l4_name_struct *alpha_id;

            #ifdef __PHB_SORT_ENABLE__
                l4_addr_bcd_struct *tel_number;
            #endif 

            /**
             * Here we borrow total_piggyback to store pattern_tag.
             * When used!?
             */
                /* control_block->total_piggyback = l4cphb_search_req->pattern_tag; */
                control_block->total_piggyback = l4cphb_search_req->total;

                /* Search by name, valid for both of PHB_PHONEBOOK, PHB_FDN and PHB_BDN */
                if ((l4cphb_search_req->pattern_tag == PHB_BYNAME) ||
                    (l4cphb_search_req->pattern_tag == PHB_BYNAME_EXACT))
                {
                    alpha_id = &l4cphb_search_req->pattern_value.alpha_id;
                    control_block->candidate_name_num_index = phb_se_search_by_name(
                                                                l4cphb_search_req->type,
                                                                (alpha_id_type*) alpha_id,
                                                                &control_block->candidate,
                                                                &is_more_candidates);

               /**
                * For SEARCH_BYNAME, no candidate is impossible.
                * Because a nearest one is always found,
                * therefore candidate_count is at least 1.
                */
                }

            #ifdef __PHB_SORT_ENABLE__
                /* Search by telephone number, only valid for PHB_PHONEBOOK */
                else if ((l4cphb_search_req->pattern_tag == PHB_BYNUMBER) && (l4cphb_search_req->type == PHB_PHONEBOOK))
                {
                    tel_number = &l4cphb_search_req->pattern_value.tel_number;
                    control_block->candidate_name_num_index = phb_se_search_by_tel_num(
                                                                l4cphb_search_req->type,
                                                                tel_number,
                                                                &control_block->candidate,
                                                                &is_more_candidates);

                }
            #endif /* __PHB_SORT_ENABLE__ */ 
                /* Illegal comination of parameters. */
                else
                {
                    phb_search_err_handler(NULL, control_block);
                    return;
                }

                /* Search telephone number in phonebook: nvram_ef_phb_lid and ADN */

                /* No candidate, great!! */
                if ((control_block->candidate == (kal_uint16) PHB_INVALID_VALUE) ||
                    (control_block->candidate_name_num_index == NULL))
                {
                    control_block->actual_count = 0;
                    phb_search_confirm(
                        PHB_ERRNO_SUCCESS,
                        control_block->actual_count,
                        control_block->src_id,
                        control_block->cnf_msg_id,
                        control_block);
                    return;
                }

                /* Exactly only one candidate is found! Great!! */
            /**
             * Q: The query pattern may exceeds ALPHA_ID_DEPTH,
             *   why NOT exact match alpha_id, then retrieves the following
             *   entries begun from the index to that one?
             *
             * A: Though exact matching is possible, retrieves from that index is
             *   non-sense, because the sorted array is not precise, that means
             *   the following entries begun from that index could be erroneous.
             */
                if (l4cphb_search_req->pattern_tag == PHB_BYNAME)
                {
                    kal_uint16 index;

               /**
                * Search BYNAME, if alpha_id.name_length <= PHB_ALPHA_ID_DEPTH,
                * then there must be exactly one nearest hit!
                *
                * Note: hit must start from 1.
                */
                    index = control_block->candidate;

                    if (l4cphb_search_req->total < 1)
                    {
                        l4cphb_search_req->total = 1;
                    }

                    phb_control_block_set_IO(control_block, l4cphb_search_req->type, ++index, l4cphb_search_req->total);

                    if (phb_se_is_in_range(control_block->type, index, &control_block->total) == KAL_FALSE)
                    {
                        control_block->actual_count = 0;
                        phb_search_confirm(
                            PHB_ERRNO_FAIL,
                            control_block->actual_count,
                            control_block->src_id,
                            control_block->cnf_msg_id,
                            control_block);
                        return;
                    }

                    /* Piggyback is ALWAYS required. */

               /**
                * Now we have to transform the state to a *FAKE* read state.
                * The fakes status ALWAYS read from index, instead of specific record.
                */

                    /* If any critial error occured. read_err_handler will handle it. */
                    if (phb_read_fake(control_block, NULL) == KAL_FALSE)
                    {
                        return;
                    }

                    /* Finally, faking complete....Now continue reading */
                    phb_read_continue(NULL, control_block);
                    return;
                }
            #ifdef __PHB_SORT_ENABLE__
                else if (l4cphb_search_req->pattern_tag == PHB_BYNAME_EXACT)
                {
                    kal_uint16 i, start, count = 0;
                    pindex_type *name_index;
                    data_entry_table_type *desc_table;

                    if (l4cphb_search_req->type == PHB_PHONEBOOK)
                    {
                        control_block->type = l4cphb_search_req->type;
                        name_index = (pindex_type*) & phb_ptr->indices.phb_index.name_index;
                        desc_table = (data_entry_table_type*) & phb_ptr->indices.phb_index.data_entry_table;
                    }
                    else
                    {
                        control_block->actual_count = 0;
                        phb_search_confirm(
                            PHB_ERRNO_FAIL,
                            control_block->actual_count,
                            control_block->src_id,
                            control_block->cnf_msg_id,
                            control_block);
                        return;
                    }

                    for (i = control_block->candidate; i < name_index->used_count; i++)
                        if (phb_is_prefix(
                                (alpha_id_type*) & l4cphb_search_req->pattern_value.alpha_id,
                                (alpha_id_type*) & desc_table->table[name_index->table[i].position]. alpha_id))
                        {
                            break;
                        }

⌨️ 快捷键说明

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