/* 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 u_mheg5.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/11/10 $
 *  $Author: dtvbm11 $
 *  
 *  @par Description:This header file contains MHEG5 exported constants, macros, and types.
 */
/*----------------------------------------------------------------------------*/
#ifndef _U_EWS_PA_H_
#define _U_EWS_PA_H_
/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
#include "u_common.h"
#include "u_handle.h"
#include "x_dbg.h"


/*!
 * @addtogroup    groupMW_EWS_PA
 * @brief    This header file contains EWS_PA exported constants, macros, and types.
 * 
 * @see groupMW_EWS_PA
 *
 * @{
 * */


/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
-----------------------------------------------------------------------------*/
#define EWSPAR_ASYNC_RESPONSE       ((INT32)    1)    /**<Indicate the request will be responsed asynchronously        */

#define EWSPAR_OK                   ((INT32)    0)    /**<OK        */
#define EWSPAR_INV_ARG              ((INT32) -  1)    /**<Invalid arguments        */
#define EWSPAR_INV_HANDLE           ((INT32) -  2)    /**<Invalid handle        */
#define EWSPAR_OUT_OF_MEMORY        ((INT32) -  3)    /**<Out of memory        */
#define EWSPAR_OUT_OF_HANDLE        ((INT32) -  4)    /**<Out of handle        */
#define EWSPAR_INTERNAL_ERROR       ((INT32) -  5)    /**<Internal error        */
#define EWSPAR_NOT_INIT             ((INT32) -  6)    /**<Not initialized       */
#define EWSPAR_ALREADY_INIT         ((INT32) -  7)    /**<Already initialized        */
#define EWSPAR_INIT_FAIL            ((INT32) -  8)    /**<Failed to initialized        */
#define EWSPAR_INV_STATE            ((INT32) -  9)    /**<Invalid state        */
#define EWSPAR_SVC_NOT_FOUND        ((INT32) - 10)    /**<Service is not found       */
#define EWSPAR_ENG_NOT_FOUND        ((INT32) - 11)    /**<Engine is not found        */
#define EWSPAR_CONNECT_FAIL         ((INT32) - 12)    /**<Failed to connect        */
#define EWSPAR_LOAD_NIT_FAIL        ((INT32) - 13)    /**<Failed to load NIT        */
#define EWSPAR_LOAD_SDT_FAIL        ((INT32) - 14)    /**<Failed to load SDT        */
#define EWSPAR_LOAD_PAT_FAIL        ((INT32) - 15)    /**<Failed to load PAT        */
#define EWSPAR_LOAD_PMT_FAIL        ((INT32) - 16)    /**<Failed to LOAD PMT        */
#define EWSPAR_LOAD_TRDW_FAIL       ((INT32) - 17)    /**<Failed to LOAD TRDW        */
#define EWSPAR_LOAD_TCDW_FAIL       ((INT32) - 18)    /**<Failed to LOAD TCDW        */
#define EWSPAR_LOAD_TMDW_FAIL       ((INT32) - 19)    /**<Failed to LOAD TMDW        */
#define EWSPAR_OUT_OF_RESOURCES     ((INT32) - 20)    /**<Out of semaphores        */
#define EWSPAR_PARSE_PMT_FAIL       ((INT32) - 21)    /**<Failed to parse PMT        */
#define EWSPAR_PARSE_SDT_FAIL       ((INT32) - 22)    /**<Failed to parse SDT        */
#define EWSPAR_PARSE_PAT_FAIL       ((INT32) - 23)    /**<Failed to parse PAT        */
#define EWSPAR_PARSE_TRDW_FAIL      ((INT32) - 24)    /**<Failed to parse TRDW        */
#define EWSPAR_PARSE_TCDW_FAIL      ((INT32) - 25)    /**<Failed to parse TCDW        */
#define EWSPAR_PARSE_TMDW_FAIL      ((INT32) - 26)    /**<Failed to parse TMDW        */
#define EWSPAR_COMP_ALREADY_STARTED ((INT32) - 27)    /**<The EWS_PA component has already been started by a call to tmMHEG5Start()        */
#define EWSPAR_CREATE_TIMER_FAIL    ((INT32) - 28)    /**<Failed to create a timer        */
#define EWSPAR_START_TIMER_FAIL     ((INT32) - 29)    /**<Failed to start a timer        */
#define EWSPAR_MISMATCHED_RUN       ((INT32) - 30)    /**<Mismatched run        */
#define EWSPAR_SVC_UNAVAILABLE      ((INT32) - 31)    /**<Service is unavailable        */
#define EWSPAR_COMP_NOT_OPEN        ((INT32) - 32)    /**<The EWS_PA component has not been opened by a call to tmMHEG5Open()        */
#define EWSPAR_COMP_ALREADY_OPEN    ((INT32) - 33)    /**<The EWS_PA component has already been opened by a call to tmMHEG5Open()        */
#define EWSPAR_COMP_NOT_STARTED     ((INT32) - 34)    /**<The EWS_PA component has not been started by a call to tmMHEG5Start()         */
#define EWSPAR_INV_SET_INFO         ((INT32) - 35)    /**<Invalid set info*/
#define EWSPAR_INV_GET_INFO         ((INT32) - 36)    /**<Invalid get info*/


typedef UINT32 EWS_PA_SET_TYPE_T;    /**< EWS_PA set type. */
typedef UINT32 EWS_PA_GET_TYPE_T;    /**< EWS_PA get type. */

#define EWS_PA_SET_TYPE_IGNORE                      ((EWS_PA_SET_TYPE_T)( 0)) /**< Ignore         */
#define EWS_PA_SET_LOCATION_CODE                    ((EWS_PA_SET_TYPE_T)( 1)) /**< type = UINT8*  */


#define EWS_PA_GET_TYPE_IGNORE                      ((EWS_PA_GET_TYPE_T)( 0)) /**< Ignore */
#define EWS_PA_GET_TYPE_SVC_INFO                    ((EWS_PA_GET_TYPE_T)( 1)) /**< type = EWS_PA_SVC_INFO_T*,             size = sizeof(DEVICE_TYPE_T)               */    
#define EWS_PA_GET_TYPE_WITH_EWS                    ((EWS_PA_GET_TYPE_T)( 2)) /**< type = BOOL*,                          size = sizeof(BOOL)                        */    
#define EWS_PA_GET_TYPE_INFO_MSG_NUM                ((EWS_PA_GET_TYPE_T)( 3)) /**< type = EWS_PA_SVC_INFO_T*,             size = sizeof(DEVICE_TYPE_T)               */  
#define EWS_PA_GET_TYPE_MORE_INFO_MSG               ((EWS_PA_GET_TYPE_T)( 4))

#define MIN(x, y)                       (((x) < (y)) ? (x) : (y))

#define EWS_PA_ASSERT(cond)                                              \
{                                                                       \
    if (!(cond))                                                        \
    {                                                                   \
        DBG_ERROR(("\n File : %s, Line : %d ", __FILE__, __LINE__));     \
        DBG_ABORT(DBG_MOD_EWS_PA);                                       \
    }                                                                   \
}   

/*------------------------------------------------------------------*/
/*! @struct EWS_PA_TMDW_INFO_T
 *  @brief EWS_PA_TMDW_INFO message structure
 *  @code
 *  typedef struct _EWS_PA_TMDW_INFO_T
 *  {
 *      UINT16       ui2_info_msg_len;
 *      CHAR*        ps_info_msg;
 *  } EWS_PA_TMDW_INFO_T;
 *  @endcode
 *  @li@c  ui2_info_msg_len                           - TMDW info message length
 *  @li@c  ps_info_msg                                - TMDW info message
 */
/*------------------------------------------------------------------*/
typedef struct _EWS_PA_TMDW_INFO_T
{
    UINT16                          ui2_info_msg_len;
    CHAR*                           ps_info_msg; 
    
}EWS_PA_TMDW_INFO_T;

/*------------------------------------------------------------------*/
/*! @struct EWS_PA_SVC_INFO_T
 *  @brief EWS_PA_SVC_INFO message structure
 *  @code
 *typedef struct _EWS_PA_SVC_INFO_T
 *{
 *    UINT16                          ui2_disaster_code;
 *    UINT8                           ui1_package_id;
 *    UINT8                           ui1_location_type_code;
 *    
 *    UINT8                           aui1_location_code[3];
 *    
 *    UINT8                           ui1_authority;
 *    #if 0
 *    UINT8                           ui1_disaster_code_len;
 *    UINT8                           ui1_disaster_date_len;
 *    UINT8                           ui1_disaster_position_len;
 *    UINT8                           ui1_disaster_characterstic_len;
 *    UINT8                           ui1_location_code_len;
 *    #endif
 *
 *    UINT8                           ui2_info_msg_num;
 *
 *    CHAR*                           ps_location_code;
 *    CHAR*                           ps_disaster_code;
 *    CHAR*                           ps_disaster_position;    
 *    CHAR*                           ps_disaster_date;    
 *    CHAR*                           ps_disaster_characterstic; 
 *
 *    _EWS_PA_TMDW_INFO_T*            pt_info_msg;
 *    
 *  @endcode
 *  @li@c  ui2_disaster_code           - 
 *  @li@c  ui1_package_id              -  
 *  @li@c  ui1_location_type_code      -  
 *  @li@c  aui1_location_code[3]       -  
 *  @li@c  ui1_authority               -  
 *  @li@c  ui2_info_msg_num            -  
 *  @li@c  ps_location_code            -  
 *  @li@c  ps_disaster_code            -  
 *  @li@c  ps_disaster_position        -  
 *  @li@c  ps_disaster_characterstic   -  
 *  @li@c  pt_info_msg                 -    
 */
/*------------------------------------------------------------------*/

typedef struct _EWS_PA_SVC_INFO_T
{
    UINT16                          ui2_disaster_code;
    UINT8                           ui1_package_id;
    UINT8                           ui1_location_type_code;
    
    UINT8                           aui1_location_code[3];
    
    UINT8                           ui1_authority;
    UINT8                           ui1_trdw_version;
    UINT8                           ui1_tcdw_version;
    UINT8                           ui1_tmdw_version;

    UINT8                           ui1_location_code_len;
    UINT8                           ui1_disaster_code_len;
    UINT8                           ui1_disaster_date_len;
    UINT8                           ui1_disaster_position_len;
    UINT8                           ui1_disaster_characterstic_len;   

    UINT16                          ui2_info_msg_num;

    CHAR*                           ps_location_code;
    CHAR*                           ps_disaster_code;
    CHAR*                           ps_disaster_position;    
    CHAR*                           ps_disaster_date;    
    CHAR*                           ps_disaster_characterstic; 

    EWS_PA_TMDW_INFO_T*             pt_info_msg;
    
}EWS_PA_SVC_INFO_T;

/*------------------------------------------------------------------*/
/*! @struct EWS_PA_MSG_T
 *  @brief EWS_PA message structure
 *  @code
 *  typedef struct _EWS_PA_MSG_T
 *  {
 *      UINT32        ui4_inst_id;
 *      UINT16        ui2_msg_type;
 *      VOID*         pv_nfy_tag;
 *  } EWS_PA_MSG_T;
 *  @endcode
 *  @li@c  ui4_inst_id                                   - Instance ID
 *  @li@c  ui2_msg_type                               - Message type
 *  @li@c  pv_nfy_tag                                  - Tag
 */
/*------------------------------------------------------------------*/
typedef struct _EWS_PA_MSG_T
{
    UINT16         ui2_msg_type;
    HANDLE_T       h_tuner;
    HANDLE_T       h_obj;
    UINT16         ui2_seq_num;
    VOID*          pv_nfy_tag;    
} EWS_PA_MSG_T;

/*------------------------------------------------------------------*/
/*! @enum EWS_PA_NFY_COND_T
 *  @brief EWS_PA notify condition
 *  @code
 *  typedef enum _EWS_PA_NFY_COND_T
 *  {
 *      MHEG5_NFY_COND_TABLE_LOADED,
 *      MHEG5_NFY_COND_TABLE_FAILED,    
 *      MHEG5_NFY_COND_DATA_BROADCASD_ID_DESC_RETURNS,
 *      MHEG5_NFY_COND_DATA_BROADCASD_ID_DESC_GONE,
 *      MHEG5_NFY_COND_NB_ACTION_INITIATE_AUTOBOOT,
 *      MHEG5_NFY_COND_CAROUSEL_ID_CHANGED,
 *      MHEG5_NFY_COND_SERVICE_GONE,
 *      MHEG5_NFY_COND_SERVICE_RETURNS,
 *      MHEG5_NFY_COND_SERVICE_CHANGED
 *  } MHEG5_NFY_COND_T;
 *  @endcode
 *  @li@c  MHEG5_NFY_COND_TABLE_LOADED                       - SI table loaded well
 *  @li@c  MHEG5_NFY_COND_TABLE_FAILED                        - SI table loaded failed
 *  @li@c  MHEG5_NFY_COND_DATA_BROADCASD_ID_DESC_RETURNS     - Broadcast ID descriptor returns
 *  @li@c  MHEG5_NFY_COND_DATA_BROADCASD_ID_DESC_GONE        - Broadcast ID descriptor gone
 *  @li@c  MHEG5_NFY_COND_NB_ACTION_INITIATE_AUTOBOOT        - initiate autoboot
 *  @li@c  MHEG5_NFY_COND_CAROUSEL_ID_CHANGED                - Carousel ID chanaged
 *  @li@c  MHEG5_NFY_COND_SERVICE_GONE                       - Service gone
 *  @li@c  MHEG5_NFY_COND_SERVICE_RETURNS                    - Service returns
 *  @li@c  MHEG5_NFY_COND_SERVICE_CHANGED                    - Service changed
 */
/*------------------------------------------------------------------*/
typedef enum _EWS_PA_NFY_COND_T
{
    EWS_PA_NFY_COND_TABLE_ERROR,
    EWS_PA_NFY_COND_SERVICE_GONE,
    EWS_PA_NFY_COND_SERVICE_FOUND,
    EWS_PA_NFY_COND_SERVICE_CHANGED
} EWS_PA_NFY_COND_T;

/*------------------------------------------------------------------*/
/*! @brief Callback to notify the SI loading status
 *  @param [in] e_cond - EWS_PA notify condition
 *  @param [in] pv_tag - User's tag
 *  @param [out] None.
 */
/*------------------------------------------------------------------*/
typedef INT32 (*x_ews_pa_eng_load_si_nfy)(
    EWS_PA_NFY_COND_T    e_cond,
    VOID*                pv_tag);


/*------------------------------------------------------------------*/
/*! @struct EWS_PA_FUNC_TBL_T
 *  @brief  EWS_PA Instance function table
 *  @code
 *  typedef struct _EWS_PA_FUNC_TBL_T
 *  {
 *      x_ews_pa_eng_load_si_nfy                 pf_load_si_nfy;
 *  } EWS_PA_FUNC_TBL_T;
 *  @endcode
 *  @li@c  pf_load_si_nfy                       - EWS_PA COMP function: Load SI NFY
 *------------------------------------------------------------------*/
typedef struct _EWS_PA_FUNC_TBL_T
{
    x_ews_pa_eng_load_si_nfy                     pf_load_si_nfy;
} EWS_PA_FUNC_TBL_T;



/*! @}  */

#endif /* _U_EWS_PA_H_ */


