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

📄 phb_handler_search.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                return;
            }

            control_block->proc_stage = SEARCH_CONTINUE;
            control_block->data = (kal_uint8*) & control_block->temp_entry;
            control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID));

            phb_issue_IO_read(control_block);
            return;
        }
    }
}   /* end of phb_search_continue */


/*****************************************************************************
 * FUNCTION
 *  phb_search_confirm
 * DESCRIPTION
 *  This is phb_search_confirm function of PHB module.
 * PARAMETERS
 *  result              [IN]        
 *  actual_count        [IN]        
 *  src_id              [IN]        
 *  cnf_msg_id          [IN]        
 *  control_block       [?]         
 *  ilm_ptr(?)          [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
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)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    local_para_struct *local_param_ptr = NULL;
    peer_buff_struct *peer_buf_ptr = NULL;

    kal_uint16 msg_id = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SEARCH_CNF, result, actual_count, src_id, cnf_msg_id);

    /* First we release local parameter. */
    if ((result != PHB_ERRNO_BUSY) && (control_block->local_param_ptr != NULL))
    {
        free_ctrl_buffer(control_block->local_param_ptr);
    }

    if ((result == PHB_ERRNO_BUSY) || (control_block->cnf_msg_id == MSG_ID_L4CPHB_SEARCH_REQ))
    {
        l4cphb_search_cnf_struct *l4cphb_search_cnf;

        l4cphb_search_cnf = (l4cphb_search_cnf_struct*) construct_local_para(
                                                            sizeof(l4cphb_search_cnf_struct),
                                                            TD_CTRL);
        l4cphb_search_cnf->total = actual_count;
        l4cphb_search_cnf->src_id = src_id;
        l4cphb_search_cnf->result = result;

        /* Field `cause' is meaningful when I/O occured by using control blocks */
        l4cphb_search_cnf->cause = control_block->cause;

        if (result == PHB_ERRNO_BUSY)
        {

            phb_send_ilm(MOD_L4C, MSG_ID_L4CPHB_SEARCH_CNF, (local_para_struct*) l4cphb_search_cnf, NULL);
            return;
        }

        local_param_ptr = (local_para_struct*) l4cphb_search_cnf;

        msg_id = MSG_ID_L4CPHB_SEARCH_CNF;
    }

   /**
    * Under ADN mode, only when is_retrieve is true and searching into
    * physical storage device is required will call search_continue(), which
    * in consequence results in this search_confirm() is invoked.
    *
    * Since it is ADN mode, no matter the search result is,
    * the approval result is ALWAYS success!!
    */
    else if (control_block->cnf_msg_id == MSG_ID_L4CPHB_APPROVE_REQ)
    {
        l4cphb_approve_cnf_struct *l4cphb_approve_cnf;

        l4cphb_approve_cnf = (l4cphb_approve_cnf_struct*) construct_local_para(
                                                            sizeof(l4cphb_approve_cnf_struct),
                                                            TD_CTRL);
        l4cphb_approve_cnf->result = PHB_ERRNO_SUCCESS;

        /* Field `cause' is meaningful when I/O occured by using control blocks */
        l4cphb_approve_cnf->cause = control_block->cause;

        l4cphb_approve_cnf->type = control_block->type;
        l4cphb_approve_cnf->src_id = control_block->src_id;

        local_param_ptr = (local_para_struct*) l4cphb_approve_cnf;

        msg_id = MSG_ID_L4CPHB_APPROVE_CNF;
    }

    /* EXCEPTION cannot reach here */
    if (control_block->peer_buf_ptr != NULL)
    {
        if (control_block->actual_count > 0)
        {
            peer_buf_ptr = (peer_buff_struct*) control_block->peer_buf_ptr;
            control_block->peer_buf_ptr = NULL;
        }
        else
        {
            free_ctrl_buffer(control_block->peer_buf_ptr);
            peer_buf_ptr = NULL;
        }
        control_block->need_free_peer = KAL_FALSE;
    }

    phb_free_control_block(control_block);

    phb_send_ilm(MOD_L4C, msg_id, local_param_ptr, peer_buf_ptr);
}   /* end of phb_search_confirm */


/*****************************************************************************
 * FUNCTION
 *  phb_compare_tel_number
 * DESCRIPTION
 *  This is phb_compare_tel_number function of PHB module.
 *  
 *  Algorightm:
 *  
 *  1> given => international:               +886-2-12345
 *  1-1> candidate => international:      +886-2-12345  match!!
 *  1-2> candidate => non-international:     0-2-12345  match!!
 *  
 *  2> given => non-international:              0-2-12345
 *  1-1> candidate => international:      +886-2-12345  match!!
 *  1-2> candidate => non-international:     0-2-12345  match!!
 * PARAMETERS
 *  given           [?]         
 *  candidate       [?]         
 *  ilm_ptr(?)      [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
static match_result_enum phb_compare_tel_number(l4_addr_bcd_struct *given, l4_addr_bcd_struct *candidate)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_bool result = KAL_TRUE;
    kal_uint16 given_cc_index, candidate_cc_index;
    kal_uint16 given_cc_offset, candidate_cc_offset;
    kal_bool given_flag_bcd = KAL_TRUE, candidate_flag_bcd = KAL_TRUE;
    kal_uint8 given_bcd, candidate_bcd;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /*
     * Here only compares only differentiable digits.
     * International code issues are left to caller to decide.
     * Note that the returned offset is BCD digit offset, instead of byte offset.
     */
    given_cc_offset = phb_se_get_differntiable_digits(&given->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET], &given_cc_index);
    candidate_cc_offset = phb_se_get_differntiable_digits(&candidate->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET], &candidate_cc_index);

   /** Cannot shortcut return by unequal length of differentiable digits!!
    * Because each digit must be compared until a `p' digit is found!!
    */

   /**
    * If position is even, flag must be adjusted to false for
    * get_next_bcd_digit() to retrieve second bcd
    */
    if (given_cc_offset & 1)
    {
        given_flag_bcd = KAL_FALSE;
    }
    if (candidate_cc_offset & 1)
    {
        candidate_flag_bcd = KAL_FALSE;
    }

    /* Position is BCD-digit offset, it must be adjusted byte offset */
    given_cc_offset = given_cc_offset >> 1;
    candidate_cc_offset = candidate_cc_offset >> 1;

    result = MATCH_PARTIAL;
    while ((given_cc_offset < (given->addr_length - L4_ADDR_BCD_TON_NPI_SIZE)) &&
           (candidate_cc_offset < (candidate->addr_length - L4_ADDR_BCD_TON_NPI_SIZE)))
    {
        given_cc_offset = get_next_bcd_digit(
                            &given->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET],
                            given_cc_offset,
                            &given_flag_bcd,
                            &given_bcd);
        candidate_cc_offset = get_next_bcd_digit(
                                &candidate->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET],
                                candidate_cc_offset,
                                &candidate_flag_bcd,
                                &candidate_bcd);

        /* Compare not more than number of valid digits of given phone number. */
        if (given_bcd >= DN_VALID_DIGIT_LIMIT)
        {
            break;
        }

        if (given_bcd != candidate_bcd)
        {
            result = MATCH_FAIL;
            break;
        }
    }

    if ((result == MATCH_PARTIAL) && (
                                         /* Non-internation code, and all matches */
                                         ((given_cc_index == (kal_uint16) PHB_INVALID_VALUE) &&
                                          (candidate_cc_index == (kal_uint16) PHB_INVALID_VALUE)) ||
                                         /* Internation code, and all matches */
                                         ((given_cc_index != (kal_uint16) PHB_INVALID_VALUE) &&
                                          (candidate_cc_index != (kal_uint16) PHB_INVALID_VALUE) &&
                                          (given_cc_index == candidate_cc_index))))
    {
        result = MATCH_PERFECT;
    }

    return result;
}   /* end of phb_search_confirm */


/*****************************************************************************
 * FUNCTION
 *  phb_search_fake
 * DESCRIPTION
 *  This is phb_read_fake function of PHB module.
 *  Fakes reading state to meet piggyback requirement of write, delete operation.
 *  
 *  Prerequisite:
 *  1. Candidates must be selected first.
 *  2. phb_query_method_enum must be set to control_block->piggyback
 *  3. One entry of l4cphb_phb_entry_array_struct is always allocated
 * PARAMETERS
 *  control_block       [?]         
 *  ilm_ptr             [IN]        The primitives
 *  type                [IN]        
 *  given_pattern       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_search_fake(
        control_block_type *control_block,
        ilm_struct *ilm_ptr,
        phb_type_enum type,
        l4_addr_bcd_struct *given_pattern)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    l4cphb_phb_entry_array_struct *phb_entry_array;
    l4_addr_bcd_struct *num_pattern;
    name_num_index_type *name_num_index;
    data_entry_struct *data_entry;
    peer_buff_struct *peer_buf_ptr;

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

   /**
    * First, allocate memory to temporarily store given entry,
    * since we have to verify telephone number, and put it into local paramter.
    *
    * Don't forget to release it!
    */
    num_pattern = (l4_addr_bcd_struct*) get_ctrl_buffer(sizeof(l4_addr_bcd_struct));
    kal_mem_cpy(num_pattern, (void const*)given_pattern, sizeof(l4_addr_bcd_struct));

    phb_entry_array = (l4cphb_phb_entry_array_struct*) l4cphb_alloc_peer_buf(&peer_buf_ptr, 1);
    control_block->need_free_peer = KAL_TRUE;

   /**
    * Read SOP:
    * phb_control_block_set_param(),
    * phb_control_block_set(),
    * phb_control_block_set_IO(),
    * se_control_block()
    */
    /* num_pattern is temporarily stored in local_param_ptr */
    phb_control_block_set_param(control_block, SEARCH_CONTINUE, num_pattern, peer_buf_ptr);
    phb_control_block_set(
        control_block,
        phb_search_continue,
        phb_search_handler,
        phb_search_err_handler,
        SEARCH_CONTINUE);

   /**
    * Read specific record for verification.
    */
    phb_control_block_set_IO(control_block, type, (kal_uint16) PHB_INVALID_VALUE, 1);

    /* set storage, record_index, primary_ID, and secondary_ID */
    name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
    data_entry =
        &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].position];

    phb_se_set_control_block(control_block, OP_READ, data_entry->storage, data_entry->record_index);

   /**
    * Since phb_se_set_control_block() modifies control_block->proc_stage,
    * it has to be restored.
    */
    control_block->proc_stage = SEARCH_CONTINUE;

    control_block->data = (kal_uint8*) & control_block->temp_entry;
    control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID));
}

⌨️ 快捷键说明

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