/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file c_dsmcc_db.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains DSMCC Data Broadcast specific
 *         definitions, which are exported.
 */
/*----------------------------------------------------------------------------*/

#ifndef _C_DSMCC_DB_H_
#define _C_DSMCC_DB_H_


/*---------------------------------------------------------------------------
                    include files
---------------------------------------------------------------------------*/

#include "c_handle_grp.h"
#include "c_common.h"
#include "c_tm.h"
#include "u_dsmcc_db.h"


/*---------------------------------------------------------------------------
                    functions declarations
 --------------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
/*! @brief  This API loads a DSI based on PID and TS id.
 *  @param  [in]  h_root      - Contains the handle referencing the root
 *                              object.
 *  @param  [in]  t_pid       - Contaisn the PID value.
 *  @param  [in]  ui2_ts_id   - Contains the TS id.
 *  @param  [in]  e_src_type  - Specifies the source type for loading the
 *                              requested table.
 *  @param  [in]  pv_src_info - Contains additional information describing
 *                              the source.
 *  @param  [in]  pv_nfy_tag  - Contains a notify tag value.
 *  @param  [in]  pf_nfy      - References the notify function.
 *  @param  [out] ph_dsi      - Contains a handle which references the DSI object.
 *  @param  [out] pe_cond     - Contains the condition of the DSI object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK
 *  @retval TMR_AEE_OUT_OF_RESOURCES - Not enough resources available.
 *  @retval TMR_AEE_NO_RIGHTS        - Routine failed.
 *  @retval TMR_NOT_INIT             - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG              - One or more of the arguments contain invalid data.
 *  @retval TMR_INV_HANDLE           - Invalid handle.
 *  @retval TMR_OUT_OF_HANDLES       - No handles available.
 *  @retval TMR_OUT_OF_RESOURCES     - Out of resources.
 *  @retval TMR_NO_SUPPORT           - No support.
 *  @retval TMR_INV_HANDLE_STATE     - Invalid handle state.
 *  @retval TMR_INV_OBJ_TYPE         - Invalid object type.
 *  @retval TMR_INV_LOAD_TYPE        - Invalid load operation.
 *  @retval TMR_INV_LOAD_INFO        - Invalid load operation data.
 *  @retval TMR_INV_FLAG_SETTING     - Invalid flag settings.
 *  @retval TMR_INV_SRC_TYPE         - Invalid source type.
 *  @retval TMR_INV_SRC_INFO         - Invalid source information.
 *  @retval TMR_SINGLE_SRC_REQUIRED  - Single source required.
 *  @retval TMR_SRC_PARTIAL_OVERLAP  - Sources partial overlap.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_load_dsi_by_pid_ts_id (HANDLE_T       h_root,
                                               MPEG_2_PID_T   t_pid,
                                               UINT16         ui2_ts_id,
                                               TM_SRC_TYPE_T  e_src_type,
                                               VOID*          pv_src_info,
                                               VOID*          pv_nfy_tag,
                                               x_tm_nfy_fct   pf_nfy,
                                               HANDLE_T*      ph_dsi,
                                               TM_COND_T*     pe_cond);
/*------------------------------------------------------------------*/
/*! @brief  This API loads a DSI based on PID and TS descriptor.
 *  @param  [in]  h_root      - Contains the handle referencing the root
 *                              object.
 *  @param  [in]  t_pid       - Contaisn the PID value.
 *  @param  [in]  pt_ts_descr - References the TS descriptor.
 *  @param  [in]  e_src_type  - Specifies the source type for loading the
 *                              requested table.
 *  @param  [in]  pv_src_info - Contains additional information describing
 *                              the source.
 *  @param  [in]  pv_nfy_tag  - Contains a notify tag value.
 *  @param  [in]  pf_nfy      - References the notify function.
 *  @param  [out] ph_dsi      - Contains a handle which references the DSI object.
 *  @param  [out] pe_cond     - Contains the condition of the DSI object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK
 *  @retval TMR_AEE_OUT_OF_RESOURCES - Not enough resources available.
 *  @retval TMR_AEE_NO_RIGHTS        - Routine failed.
 *  @retval TMR_NOT_INIT             - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG              - One or more of the arguments contain invalid data.
 *  @retval TMR_INV_HANDLE           - Invalid handle.
 *  @retval TMR_OUT_OF_HANDLES       - No handles available.
 *  @retval TMR_OUT_OF_RESOURCES     - Out of resources.
 *  @retval TMR_NO_SUPPORT           - No support.
 *  @retval TMR_INV_HANDLE_STATE     - Invalid handle state.
 *  @retval TMR_INV_OBJ_TYPE         - Invalid object type.
 *  @retval TMR_INV_LOAD_TYPE        - Invalid load operation.
 *  @retval TMR_INV_LOAD_INFO        - Invalid load operation data.
 *  @retval TMR_INV_FLAG_SETTING     - Invalid flag settings.
 *  @retval TMR_INV_SRC_TYPE         - Invalid source type.
 *  @retval TMR_INV_SRC_INFO         - Invalid source information.
 *  @retval TMR_SINGLE_SRC_REQUIRED  - Single source required.
 *  @retval TMR_SRC_PARTIAL_OVERLAP  - Sources partial overlap.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_load_dsi_by_pid_ts_descr (HANDLE_T       h_root,
                                                  MPEG_2_PID_T   t_pid,
                                                  TS_DESCR_T*    pt_ts_descr,
                                                  TM_SRC_TYPE_T  e_src_type,
                                                  VOID*          pv_src_info,
                                                  VOID*          pv_nfy_tag,
                                                  x_tm_nfy_fct   pf_nfy,
                                                  HANDLE_T*      ph_dsi,
                                                  TM_COND_T*     pe_cond);

/*------------------------------------------------------------------*/
/*! @brief  This API loads a module in asynchronous mode.
 *  @param  [in]  h_dii          - Contains the handle referencing the DII object.
 *  @param  [in]  ui2_module_idx - Selects the module loop.
 *  @param  [in]  ui4_offs       - The offset within the module.
 *  @param  [in]  z_buff_len     - Contains the length of the buffer in argument
 *                                 'pui1_buff'.
 *  @param  [out] pui1_buff      - Contains the loaded data.
 *  @param  [in]  pv_nfy_tag     - Contains a notify tag value.
 *  @param  [in]  pf_nfy         - References the notify function.
 *  @param  [out] ph_db_module   - Contains a handle which references the
 *                                 asynchronous module load request.
 *  @param  [out] pe_cond        - Contains the condition of the asynchronous module
 *                                 load object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK
 *  @retval TMR_AEE_OUT_OF_RESOURCES - Not enough resources available.
 *  @retval TMR_AEE_NO_RIGHTS        - Routine failed.
 *  @retval TMR_NOT_INIT             - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG              - One or more of the arguments contain invalid data.
 *  @retval TMR_INV_HANDLE           - Invalid handle.
 *  @retval TMR_OUT_OF_HANDLES       - No handles available.
 *  @retval TMR_OUT_OF_RESOURCES     - Out of resources.
 *  @retval TMR_NO_SUPPORT           - No support.
 *  @retval TMR_INV_HANDLE_STATE     - Invalid handle state.
 *  @retval TMR_INV_OBJ_TYPE         - Invalid object type.
 *  @retval TMR_INV_LOAD_TYPE        - Invalid load operation.
 *  @retval TMR_INV_LOAD_INFO        - Invalid load operation data.
 *  @retval TMR_INV_FLAG_SETTING     - Invalid flag settings.
 *  @retval TMR_INV_SRC_TYPE         - Invalid source type.
 *  @retval TMR_INV_SRC_INFO         - Invalid source information.
 *  @retval TMR_SINGLE_SRC_REQUIRED  - Single source required.
 *  @retval TMR_SRC_PARTIAL_OVERLAP  - Sources partial overlap.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_load_module_async (HANDLE_T      h_dii,
                                           UINT16        ui2_module_idx,
                                           UINT32        ui4_offs,
                                           SIZE_T        z_buff_len,
                                           UINT8*        pui1_buff,
                                           VOID*         pv_nfy_tag,
                                           x_tm_nfy_fct  pf_nfy,
                                           HANDLE_T*     ph_db_module,
                                           TM_COND_T*    pe_cond);

/*------------------------------------------------------------------*/
/*! @brief  This API returns the number of groups.
 *  @param  [in]  h_dsi           - Contains the handle referencing the DSI object.
 *  @param  [out] pui2_num_groups - Contains the number of groups.
 *  @param  [out] pe_cond         - Contains the condition of the DSI object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                 - Routine successful.
 *  @retval TMR_NOT_INIT           - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG            - One or more of the arguments contain invalid
 *                                 - data.
 *  @retval TMR_INV_HANDLE         - Invalid handle.
 *  @retval TMR_NO_SUPPORT         - No support.
 *  @retval TMR_INV_HANDLE_STATE   - Invalid handle state.
 *  @retval TMR_INV_PARSE_TYPE     - Invalid parse operation.
 *  @retval TMR_INV_PARSE_INFO     - Invalid parse operation data.
 *  @retval TMR_PARSE_FCT_FAILURE  - Parse function returned a failure.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_get_num_groups (HANDLE_T    h_dsi,
                                        UINT16*     pui2_num_groups,
                                        TM_COND_T*  pe_cond);
/*------------------------------------------------------------------*/
/*! @brief  This API returns the info of an individual group entry.
 *  @param  [in]  - h_dsi           - Contains the handle referencing the DSI object.
 *  @param  [in]  - ui2_group_idx   - Selects the group entry.
 *  @param  [in]  - e_dsmcc_db_spec - Specifies the standard to follow.
 *                                    (EN_301_192 or TS_102_006)
 *  @param  [out] - pt_group_info   - Contains the number of groups.
 *  @param  [out] - pe_cond         - Contains the condition of the DSI object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                 - Routine successful.
 *  @retval TMR_NOT_INIT           - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG            - One or more of the arguments contain invalid
 *                                 - data.
 *  @retval TMR_INV_HANDLE         - Invalid handle.
 *  @retval TMR_NO_SUPPORT         - No support.
 *  @retval TMR_INV_HANDLE_STATE   - Invalid handle state.
 *  @retval TMR_INV_PARSE_TYPE     - Invalid parse operation.
 *  @retval TMR_INV_PARSE_INFO     - Invalid parse operation data.
 *  @retval TMR_PARSE_FCT_FAILURE  - Parse function returned a failure.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_get_group_info (HANDLE_T                h_dsi,
                                        UINT16                  ui2_group_idx,
                                        DSMCC_DB_SPEC_T         e_dsmcc_db_spec,
                                        DSMCC_DB_GROUP_INFO_T*  pt_group_info,
                                        TM_COND_T*              pe_cond);

/*------------------------------------------------------------------*/
/*! @brief  This API loads a module, or part of it, based on a DII
 *          handle and an index into the DII module loop.
 *  @param  [in]  h_dii          - Contains the handle referencing the DII object.
 *  @param  [in]  ui2_module_idx - Selects the module loop.
 *  @param  [in]  ui4_offs       - The offset within the module.
 *  @param  [in]  z_buff_len     - Contains the length of the buffer in argument
 *                                 'pui1_buff'.
 *  @param  [out] pui1_buff      - Contains the loaded data.
 *  @param  [out] pz_buff_loaded - Contains the number of loaded Bytes.
 *  @param  [out] pe_cond        - Contains the DII handle condition.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                - Routine successful.
 *  @retval TMR_NOT_INIT          - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG           - One or more of the arguments contain invalid
 *                                  data.
 *  @retval TMR_INV_HANDLE        - Invalid handle.
 *  @retval TMR_NO_SUPPORT        - No support.
 *  @retval TMR_INV_HANDLE_STATE  - Invalid handle state.
 *  @retval TMR_NOT_ENOUGH_SPACE  - Not enough space.
 *  @retval TMR_INV_GET_TYPE      - Invalid et operation.
 *  @retval TMR_INV_GET_INFO      - Invalid get operation data.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_get_module_by_idx (HANDLE_T    h_dii,
                                           UINT16      ui2_module_idx,
                                           UINT32      ui4_offs,
                                           SIZE_T      z_buff_len,
                                           UINT8*      pui1_buff,
                                           SIZE_T*     pz_buff_loaded,
                                           TM_COND_T*  pe_cond);
/*------------------------------------------------------------------*/
/*! @brief  This API loads a module, or part of it, based on a DII
 *          handle and an index into the DII module loop. In addition,
 *          the client can specify a timeout value which limits the
 *          waiting time for a client.
 *  @param  [in]  h_dii          - Contains the handle referencing the DII object.
 *  @param  [in]  ui2_module_idx - Selects the module loop.
 *  @param  [in]  ui4_offs       - The offset within the module.
 *  @param  [in]  z_buff_len     - Contains the length of the buffer in argument
 *                                 'pui1_buff'.
 *  @param  [out] pui1_buff      - Contains the loaded data.
 *  @param  [out] pz_buff_loaded - Contains the number of loaded Bytes.
 *  @param  [in]  ui4_timeout    - Contains the timeout value.
 *  @param  [out] pe_cond        - Contains the DII handle condition.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                - Routine successful.
 *  @retval TMR_NOT_INIT          - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG           - One or more of the arguments contain invalid
 *                                  data.
 *  @retval TMR_INV_HANDLE        - Invalid handle.
 *  @retval TMR_NO_SUPPORT        - No support.
 *  @retval TMR_INV_HANDLE_STATE  - Invalid handle state.
 *  @retval TMR_NOT_ENOUGH_SPACE  - Not enough space.
 *  @retval TMR_INV_GET_TYPE      - Invalid et operation.
 *  @retval TMR_INV_GET_INFO      - Invalid get operation data.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_get_module_by_idx_timeout (HANDLE_T    h_dii,
                                                   UINT16      ui2_module_idx,
                                                   UINT32      ui4_offs,
                                                   SIZE_T      z_buff_len,
                                                   UINT8*      pui1_buff,
                                                   SIZE_T*     pz_buff_loaded,
                                                   UINT32      ui4_timeout,
                                                   TM_COND_T*  pe_cond);

/*------------------------------------------------------------------*/
/*! @brief  This API allows a client to parse all DSI group compatibility
 *          descriptors.
 *  @param  [in]  h_dsi           - Contains a handle referencing the DSI table.
 *  @param  [in]  ui2_group_idx   - Selecets the group entry.
 *  @param  [in]  e_dsmcc_db_spec - Specifies the standard to follow.
 *                                  (EN_301_192 or TS_102_006)
 *  @param  [in]  pv_data         - References private data which is passed to the
 *                                  parsing function.
 *  @param  [in]  z_data_len      - Contains the length of the data buffer referenced
 *                                  by argument 'pv_data'.
 *  @param  [in]  pf_parse        - References the parsing function.
 *  @param  [out] pe_cond         - Contains the condition of the table object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                 - Routine successful.
 *  @retval TMR_NOT_INIT           - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG            - One or more of the arguments contain invalid
 *                                   data.
 *  @retval TMR_INV_HANDLE         - Invalid handle.
 *  @retval TMR_NO_SUPPORT         - No support.
 *  @retval TMR_INV_HANDLE_STATE   - Invalid handle state.
 *  @retval TMR_INV_PARSE_TYPE     - Invalid parse operation.
 *  @retval TMR_INV_PARSE_INFO     - Invalid parse operation data.
 *  @retval TMR_PARSE_FCT_FAILURE  - Parse function returned a failure.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_parse_group_all_comp_descr (HANDLE_T        h_dsi,
                                                    UINT16          ui2_group_idx,
                                                    DSMCC_DB_SPEC_T e_dsmcc_db_spec,
                                                    VOID*           pv_data,
                                                    SIZE_T          z_data_len,
                                                    x_tm_parse_fct  pf_parse,
                                                    TM_COND_T*      pe_cond);
/*------------------------------------------------------------------*/
/*! @brief  This API allows a client to parse a DSI's group info.
 *  @param  [in]  h_dsi           - Contains a handle referencing the DSI table.
 *  @param  [in]  ui2_group_idx   - Selecets the group entry.
 *  @param  [in]  e_dsmcc_db_spec - Specifies the standard to follow.
 *                                  (EN_301_192 or TS_102_006)
 *  @param  [in]  pv_data         - References private data which is passed to the
 *                                  parsing function.
 *  @param  [in]  z_data_len      - Contains the length of the data buffer referenced
 *                                  by argument 'pv_data'.
 *  @param  [in]  pf_parse        - References the parsing function.
 *  @param  [out] pe_cond         - Contains the condition of the table object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                 - Routine successful.
 *  @retval TMR_NOT_INIT           - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG            - One or more of the arguments contain invalid
 *                                   data.
 *  @retval TMR_INV_HANDLE         - Invalid handle.
 *  @retval TMR_NO_SUPPORT         - No support.
 *  @retval TMR_INV_HANDLE_STATE   - Invalid handle state.
 *  @retval TMR_INV_PARSE_TYPE     - Invalid parse operation.
 *  @retval TMR_INV_PARSE_INFO     - Invalid parse operation data.
 *  @retval TMR_PARSE_FCT_FAILURE  - Parse function returned a failure.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_parse_group_info (HANDLE_T        h_dsi,
                                          UINT16          ui2_group_idx,
                                          DSMCC_DB_SPEC_T e_dsmcc_db_spec,
                                          VOID*           pv_data,
                                          SIZE_T          z_data_len,
                                          x_tm_parse_fct  pf_parse,
                                          TM_COND_T*      pe_cond);
/*------------------------------------------------------------------*/
/*! @brief  This API allows a client to parse a DSI's group private data.
 *  @param  [in]  h_dsi           - Contains a handle referencing the DSI table.
 *  @param  [in]  e_dsmcc_db_spec - Specifies the standard to follow.
 *                                  (EN_301_192 or TS_102_006)
 *  @param  [in]  pv_data         - References private data which is passed to the parsing
 *                                  function.
 *  @param  [in]  z_data_len      - Contains the length of the data buffer referenced by
 *                                  argument 'pv_data'.
 *  @param  [in]  pf_parse        - References the parsing function.
 *  @param  [out] pe_cond         - Contains the condition of the table object.
 *  @note
 *  @see
 *  @return Return the error code
 *  @retval TMR_OK                 - Routine successful.
 *  @retval TMR_NOT_INIT           - The Table Manager is not initialized.
 *  @retval TMR_INV_ARG            - One or more of the arguments contain invalid
 *                                   data.
 *  @retval TMR_INV_HANDLE         - Invalid handle.
 *  @retval TMR_NO_SUPPORT         - No support.
 *  @retval TMR_INV_HANDLE_STATE   - Invalid handle state.
 *  @retval TMR_INV_PARSE_TYPE     - Invalid parse operation.
 *  @retval TMR_INV_PARSE_INFO     - Invalid parse operation data.
 *  @retval TMR_PARSE_FCT_FAILURE  - Parse function returned a failure.
 */
/*------------------------------------------------------------------*/
extern INT32 c_dsmcc_db_parse_group_private_data (HANDLE_T        h_dsi,
                                                  DSMCC_DB_SPEC_T e_dsmcc_db_spec,
                                                  VOID*           pv_data,
                                                  SIZE_T          z_data_len,
                                                  x_tm_parse_fct  pf_parse,
                                                  TM_COND_T*      pe_cond);


#endif /* _C_DSMCC_DB_H_ */

