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

📄 phb_handler_search.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                    if (i == name_index->used_count)
                    {
                        /* NOT found any match */
                        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;
                    }
                    count++;
                    start = i;
                    for (i = start + 1; 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))
                        {
                            count++;
                        }
                    /* total "count" matches starting from "start" */

                    control_block->index = start + 1;
                    control_block->record_index = (kal_uint16) PHB_INVALID_VALUE;
                    if (count > 15)
                    {
                        count = 15;
                    }
                    control_block->total = count;
                    /* 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;
                }
            #endif /* __PHB_SORT_ENABLE__ */ 

                /* For PHB_BYNAME, more than 1 candidate exists, sigh, verification is necessary */

            /**
             * Even only exactly one candidate is found for searching BYNUMBER,
             * verification is still needed.
             */

            /**
             * Only search of PHB_BYNUMBER can reach here.
             *
             * Candidates of searching telephone number are selected.
             * Now verify them. So lousy..
             */

            /**
             * Initialize hit and same_count of control_block, also
             * increment index to candidate, since it begins from 1.
             */
                control_block->match_result = MATCH_FAIL;

                phb_search_fake(
                    control_block,
                    ilm_ptr,
                    l4cphb_search_req->type,
                    &l4cphb_search_req->pattern_value.tel_number);

                phb_search_continue(NULL, control_block);
            }
            /* error */
            else
            {
                phb_search_err_handler(NULL, control_block);
                return;
            }
        }
        /* error, either STATE_NOT_READY or incorrect type requested for searching */
        else
        {
            kal_trace(TRACE_ERROR, ERROR_PHB_STATE);

            if (phb_ptr->state != PHB_STATE_READY)
            {
                control_block->actual_count = 0;
                phb_search_confirm(
                    PHB_ERRNO_NOT_READY,
                    control_block->actual_count,
                    control_block->src_id,
                    control_block->cnf_msg_id,
                    control_block);
            }
            else
            {
                phb_search_err_handler(NULL, control_block);
            }
            return;
        }

    }
    else
    {
        /* Verification over. */
        if (control_block->proc_stage == SEARCH_CONTINUE)
        {
         /**
          * Only search of PHB_BYNUMBER can reach here.
          * And no piggyback is provided, so confirmation can be sent back now.
          * Hence, if found, actual_count is 1 and will be transfered to `total' field of
          * confirmation primitive; otherwise it is 0.
          */

            /* No candidate matches! */
            if (control_block->actual_count == 0)
            {
                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);
            }
            else
            {
                name_num_index_type *name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
                data_entry_struct *data_entry;
                l4cphb_phb_entry_array_struct *phb_entry_array;

                kal_uint8 *pdu_ptr;
                kal_uint16 pdu_length;

                data_entry =
                    &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].
                                                            position];
            /**
             * To reduce code size, another possible function which
             * searches index to name_index by index to num_index
             * is not implemented .
             */
                pdu_ptr = get_pdu_ptr(control_block->peer_buf_ptr, &pdu_length);
                phb_entry_array = ((l4cphb_phb_entry_array_struct*) get_32bits_aligned_val(pdu_ptr));
                phb_entry_array->array[0].index = phb_se_search_by_record_index_name(
                                                    control_block->type,
                                                    data_entry->storage,
                                                    data_entry->record_index,
                                                    &data_entry->alpha_id);
                phb_entry_array->array[0].index++;
                control_block->actual_count = 1;
                phb_search_confirm(
                    PHB_ERRNO_SUCCESS,
                    control_block->actual_count,
                    control_block->src_id,
                    control_block->cnf_msg_id,
                    control_block);
            }
        }
        /* error */
        else
        {
            phb_search_err_handler(NULL, control_block);
            return;
        }
    }
}   /* end of phb_search_handler */


/*****************************************************************************
 * FUNCTION
 *  phb_search_err_handler
 * DESCRIPTION
 *  This is phb_search_err_handler function of PHB module.
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
static void phb_search_err_handler(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

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

   /**
    * Shall we try to recover/continue handling,
    * or just reject the request in processing?
    * Currently, the latter is adpoted.
    */
    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);

    /*
     * if (ilm_ptr != NULL)
     * (*phb_ptr->control_block.controller)(ilm_ptr);
     */
}   /* end of phb_search_err_handler function */


/*****************************************************************************
 * FUNCTION
 *  phb_search_continue
 * DESCRIPTION
 *  This is phb_search_continue function of PHB module.
 *  
 *  Note:
 *  Only searching PHB_PHBONEBOOK and PHB_BYNUMBER can reach this function.
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_search_continue(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

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

    /* It's time to write prepared dat */
    if (ilm_ptr == NULL)
    {
        phb_issue_IO_read(control_block);
    }

    /* Read confirmed. Now verify the entry! */
    else
    {
        /* Only PHB_BYNUMBER can reach here */

        /* Query pattern is stored in local_param_ptr */
        l4_addr_bcd_struct *given = (l4_addr_bcd_struct*) control_block->local_param_ptr;

        /* The just read back candidate is stored in control_block->data */
        phb_entry_struct *candidate_entry = (phb_entry_struct*) control_block->data;
        l4_addr_bcd_struct *candidate = &candidate_entry->tel_number;

        match_result_enum result = phb_compare_tel_number(given, candidate);

      /**
       * First we have to verify the candidate. The most possible candidate is
       * copied into the first element of l4cphb_phb_entry_array_struct stored
       * in control_block->peer_buf_ptr.
       */
      /**
       * Verification passed: perfect matched: CC/NDC/SN are all matched.
       * Finally we found it!
       */
        if ((result == MATCH_PERFECT) ||
         /**
          * Verification passed: partial matched: only NDC/SN are matched
          * Other candidate still have chances to match.
          * *Sigh*, Retain this candidate and go on verification.
          */
            (result == MATCH_PARTIAL))
        {
            kal_uint8 *pdu_ptr;
            kal_uint16 pdu_length;

            ++control_block->actual_count;

            pdu_ptr = get_pdu_ptr(control_block->peer_buf_ptr, &pdu_length);
            kal_mem_cpy(
                (phb_entry_struct*) & ((l4cphb_phb_entry_array_struct*) get_32bits_aligned_val(pdu_ptr))-> array[0],
                (void const*)candidate_entry,
                sizeof(phb_entry_struct));

            if (result == MATCH_PERFECT)
            {
                (*control_block->controller) (NULL, control_block);
                return;
            }
        }

        /* *Sigh*, Continue verification. */

        /* Verification complete, finally control can be returned back to controller */
        /* if (control_block->actual_count > control_block->candidate_count) */
        if (!phb_se_is_next_also_candidate(
                (name_num_index_type*) control_block->candidate_name_num_index,
                control_block->candidate,
                KAL_FALSE))
        {
            (*control_block->controller) (NULL, control_block);
        }

      /**
       * Still others to verify.
       * Since index, total is in ensured to be in range, tested in handler(), it is uncessary
       * to test it here.
       */
        else
        {
            name_num_index_type *name_num_index;
            data_entry_struct *data_entry;

            /* Set index field of next entry to read */
            control_block->index = ++control_block->candidate;

         /**
          * Read specific record for verification.
          */
            phb_control_block_set_IO(control_block, 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];

            if (phb_se_set_control_block(
                    control_block,
                    OP_READ,
                    data_entry->storage,
                    data_entry->record_index) == KAL_FALSE)
            {
                phb_search_err_handler(NULL, control_block);

⌨️ 快捷键说明

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