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

📄 phb_handler_read.c

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

        /* error */
        else
        {
            phb_read_err_handler(NULL, control_block);
            return;
        }
    }
}   /* end of phb_read_handler */


/*****************************************************************************
 * FUNCTION
 *  phb_read_err_handler
 * DESCRIPTION
 *  This is phb_read_err_handler function of PHB module.
 *  
 *  Requirement:
 *  Error handlers should destruct control_block.
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
static void phb_read_err_handler(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 packed_peer_buff_len;
    kal_uint8 *pdu_ptr;
    l4cphb_phb_entry_array_struct *pdu_data = NULL;

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

   /**
    * Shall we try to recover/continue handling,
    * or just reject the request in processing?
    * Currently, the latter is adpoted.
    */

    pdu_ptr = get_pdu_ptr(control_block->peer_buf_ptr, &packed_peer_buff_len);

    pdu_data = (l4cphb_phb_entry_array_struct*) get_32bits_aligned_val(pdu_ptr);
    pdu_data->no_array = control_block->actual_count;
    control_block->actual_count = 0;
    phb_read_confirm(
        PHB_ERRNO_READ_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_read_err_handler function */


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

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

    if (ilm_ptr == NULL)
    {
        if ((control_block->cnf_msg_id != MSG_ID_L4CPHB_READ_REQ) &&
            (control_block->actual_count >= control_block->total))
        {
            phb_read_confirm(
                PHB_ERRNO_SUCCESS,
                control_block->actual_count,
                control_block->src_id,
                control_block->cnf_msg_id,
                control_block);
        }

        else
        {
            phb_issue_IO_read(control_block);
        }
    }
    else
    {
        phb_entry_struct *phb_entry = (phb_entry_struct*) control_block->data;

      /**
       * User specifies physical location to read;
       * therefore, the read phb_entry could be NULL.
       */
        if ((control_block->index == (kal_uint16) PHB_INVALID_VALUE) &&
            (control_block->record_index != (kal_uint16) PHB_INVALID_VALUE))
        {
         /**
          * Here, control_block->data could be NULL, if read back data is empty.
          */
         /**
          * Since alpha_id's stored in index are truncated,
          * phb_entry->alpha_id must be truncated, too, if necessary;
          * so that comparison could work properly.
          */
            if (phb_entry != NULL)
            {
                phb_entry->index = phb_se_get_index_by_record_index(
                                    control_block->type,
                                    control_block->storage,
                                    control_block->record_index);
                /* phb_se_search_by_record_index_name(control_block->type,
                   control_block->storage,
                   control_block->record_index,
                   (alpha_id_type*)&phb_entry->alpha_id); */
                /* phb_entry->index++; */

                /* Read complete, now return control back to controller */
                control_block->actual_count = 1;
            }

            (*control_block->controller) (NULL, control_block);
        }

      /**
       * User doesn't specify physical location to read,
       * therefore, the read phb_entry is always valid!!
       */
        else
        {

         /**
          * Unless someone modifies the underlying storage
          * while PHB is reading, the phb_entry just read is always valid!
          * However, prevent this WEIRD case for safety.
          */
            if (phb_entry == NULL)
            {
                phb_read_err_handler(NULL, control_block);
                return;
            }

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

            /* Read complete, now return control back to controller */
            if (++control_block->actual_count >= control_block->total)
            {
                (*control_block->controller) (NULL, control_block);
            }
            /* Still others to read */
            else
            {
                /* set storage, record_index, primary_ID, and secondary_ID */
                if (phb_se_set_control_block(
                        control_block,
                        OP_READ,
                        control_block->storage,
                        control_block->record_index) == KAL_FALSE)
                {
                    phb_read_err_handler(NULL, control_block);
                    return;
                }

                /* shift next read address */
                control_block->data = (kal_uint8*) (((phb_entry_struct*) control_block->data) + 1);
                /* 20040918, Retreive lenght again in case file id change */
                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);
            }
        }
    }
}   /* end of phb_read_continue */


/*****************************************************************************
 * FUNCTION
 *  phb_read_confirm
 * DESCRIPTION
 *  This is phb_read_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_read_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                                                */
    /*----------------------------------------------------------------*/
    msg_type msg_id = MSG_ID_L4CPHB_READ_CNF;   /* avoid compilation warning */
    local_para_struct *local_param_ptr = NULL;
    peer_buff_struct *peer_buf_ptr = NULL;

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

    if ((result == PHB_ERRNO_BUSY) || (control_block->cnf_msg_id == MSG_ID_L4CPHB_READ_REQ))
    {
        l4cphb_read_cnf_struct *l4cphb_read_cnf;

        l4cphb_read_cnf = (l4cphb_read_cnf_struct*) construct_local_para(sizeof(l4cphb_read_cnf_struct), TD_CTRL);
        l4cphb_read_cnf->total = actual_count;
        l4cphb_read_cnf->src_id = src_id;

        l4cphb_read_cnf->result = result;

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

        if (result == PHB_ERRNO_BUSY)
        {
            phb_send_ilm(MOD_L4C, MSG_ID_L4CPHB_READ_CNF, (local_para_struct*) l4cphb_read_cnf, NULL);
            return;
        }

        msg_id = MSG_ID_L4CPHB_READ_CNF;
        local_param_ptr = (local_para_struct*) l4cphb_read_cnf;
    }
    else if (control_block->cnf_msg_id == MSG_ID_L4CPHB_WRITE_REQ)
    {
        l4cphb_write_cnf_struct *l4cphb_write_cnf;

        kal_trace(TRACE_FUNC, FUNC_PHB_WRITE_CNF, result, control_block->actual_count, control_block->src_id);

        l4cphb_write_cnf = (l4cphb_write_cnf_struct*) construct_local_para(sizeof(l4cphb_write_cnf_struct), TD_CTRL);
        l4cphb_write_cnf->result = result;

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

        l4cphb_write_cnf->total = control_block->actual_count;
        l4cphb_write_cnf->src_id = control_block->src_id;
        l4cphb_write_cnf->old_index = control_block->candidate;

        msg_id = MSG_ID_L4CPHB_WRITE_CNF;
        local_param_ptr = (local_para_struct*) l4cphb_write_cnf;
    }
#ifdef __PHB_USIM_SUPPORT__
    else if (control_block->cnf_msg_id == MSG_ID_L4CPHB_WRITE_USIM_REQ)
    {
        l4cphb_write_usim_cnf_struct *l4cphb_write_cnf;

        kal_trace(TRACE_FUNC, FUNC_PHB_WRITE_CNF, result, control_block->actual_count, control_block->src_id);

        l4cphb_write_cnf = (l4cphb_write_usim_cnf_struct*) construct_local_para(
                                                            sizeof(l4cphb_write_usim_cnf_struct),
                                                            TD_CTRL);
        l4cphb_write_cnf->result = result;

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

        l4cphb_write_cnf->total = control_block->actual_count;
        l4cphb_write_cnf->src_id = control_block->src_id;
        l4cphb_write_cnf->old_index = control_block->candidate;

        msg_id = MSG_ID_L4CPHB_WRITE_USIM_CNF;
        local_param_ptr = (local_para_struct*) l4cphb_write_cnf;
    }
#endif /* __PHB_USIM_SUPPORT__ */ 
    else if (control_block->cnf_msg_id == MSG_ID_L4CPHB_DELETE_REQ)
    {
        l4cphb_delete_cnf_struct *l4cphb_delete_cnf;

        kal_trace(TRACE_FUNC, FUNC_PHB_DELETE_CNF, result, control_block->actual_count, control_block->src_id);

        l4cphb_delete_cnf = (l4cphb_delete_cnf_struct*) construct_local_para(
                                                            sizeof(l4cphb_delete_cnf_struct),
                                                            TD_CTRL);
        l4cphb_delete_cnf->result = result;

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

        l4cphb_delete_cnf->total = control_block->actual_count;
        l4cphb_delete_cnf->src_id = control_block->src_id;
        l4cphb_delete_cnf->old_index = control_block->candidate;

        msg_id = MSG_ID_L4CPHB_DELETE_CNF;
        local_param_ptr = (local_para_struct*) l4cphb_delete_cnf;
    }
    else if (control_block->cnf_msg_id == MSG_ID_L4CPHB_SEARCH_REQ)
    {
        l4cphb_search_cnf_struct *l4cphb_search_cnf;

        kal_trace(
            TRACE_FUNC,
            FUNC_PHB_SEARCH_CNF,
            result,
            control_block->actual_count,
            control_block->src_id,
            control_block->cnf_msg_id);

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

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

        l4cphb_search_cnf->total = control_block->actual_count;
        l4cphb_search_cnf->src_id = control_block->src_id;

        msg_id = MSG_ID_L4CPHB_SEARCH_CNF;
        local_param_ptr = (local_para_struct*) l4cphb_search_cnf;
    }

    /* Pack from control_block->peer_buf_ptr */
    if (control_block->peer_buf_ptr != NULL)
    {
        peer_buf_ptr = (peer_buff_struct*) control_block->peer_buf_ptr;
        control_block->peer_buf_ptr = NULL;
    }
    control_block->need_free_peer = KAL_FALSE;

    phb_free_control_block(control_block);

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


/*****************************************************************************
 * FUNCTION
 *  phb_read_fake
 * DESCRIPTION
 *  This is phb_read_fake function of PHB module.
 *  Fakes reading state to meet piggyback requirement of write, delete operation.
 *  This function just fakes valid read operation by setting control_block
 *  correctly.
 *  
 *  It DOES NOT send any IO primitives. It is left for caller to judege which
 *  function to call for issueing prmitives.
 *  Also keep original prmitive ID.
 *  
 *  Once this function is called, caller should completely leave program
 *  control to phb_handler_read.c; that is, read handler will take over
 *  control, hance as long as caller encounters any error, just return,
 *  since read handler will handle them in advance.
 *  

⌨️ 快捷键说明

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