/* 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_flm.h 
 *  $File: //DTV/PROD_BR/DTV_X_IDTV1501/apollo/middleware/public/flm/u_flm.h $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains Favorite List Manager (FLM) specific
 *         definitions, which are exported.
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_FLM_H_
#define _U_FLM_H_
/*----------------------------------------------------------------------------*/
/*! @defgroup   groupMW_FLM Favorite List Manager
 *  @ingroup    groupMW
 *  @brief      The Favorites List Manager (FLM) allows the client application
 *              to create, modify, and erase one or multiple lists of favorite
 *              channels.
 *  @see        groupMW_CDB
 *  @{
 */
/*----------------------------------------------------------------------------*/

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

#include "u_common.h"
#include "u_handle.h"
#include "u_cdb.h"
#include "u_sys_name.h"

/*-------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ------------------------------------------------------------------------*/

#define FLM_NAME_LEN SYS_NAME_LEN    /**< Specifies the maximum number of characters in a favorite list name (excluding the terminating NULL character). */
#define FLM_NULL_VER_ID  1    /**< Specifies an invalid or irrelevant version ID. */
#define FLM_CH_NAME_MAX_LENGTH   64                  /**channel name len. */
#define FLM_CH_NUM_MAX_LENGTH    10                  /**channel number len. */

/* Return code status from API */
#define FLMR_OK                   ((INT32)  0)    /**< Operation succeeded. */
#define FLMR_OUT_OF_HANDLE        ((INT32) -1)    /**< Handle allocation failed. */
#define FLMR_OUT_OF_MEM           ((INT32) -2)    /**< Memory exhausted. */
#define FLMR_INV_HANDLE           ((INT32) -3)    /**< Bad handle. */
#define FLMR_INV_ARG              ((INT32) -4)    /**< Invalid argument. */
#define FLMR_REC_NOT_FOUND        ((INT32) -5)    /**< Record not found. */
#define FLMR_END_OF_ITERATION     ((INT32) -6)    /**< Iteration reached end. */
#define FLMR_CANT_CREATE_FILE     ((INT32) -7)    /**< Cannot create file. */
#define FLMR_CANT_OPEN_FILE       ((INT32) -8)    /**< Cannot open file. */
#define FLMR_MASTER_CHANGED       ((INT32) -9)    /**< Master list changed. */
#define FLMR_NO_WRITE_LOCK        ((INT32) -10)   /**< Failed initializing RW Lock. */
#define FLMR_UNKNOWN              ((INT32) -11)   /**< Unknown error. */
#define FLMR_WRITE_LOCKED         ((INT32) -12)   /**< Failed to acquire lock as DB is write locked. */
#define FLMR_MODIFIED             ((INT32) -13)   /**< Database modified since last iteration. */
#define FLMR_DEV_ERR              ((INT32) -14)   /**< File manager device error. */
#define FLMR_OS_ERR               ((INT32) -15)   /**< File manager internal error. */
#define FLMR_PERM_DENY            ((INT32) -16)   /**< File manager permission denied. */
#define FLMR_EOF                  ((INT32) -17)   /**< File manager reached end of file. */
#define FLMR_FILESYS_FULL         ((INT32) -18)   /**< File system is full. */
#define FLMR_LIMIT_EXCEED         ((INT32) -19)   /**< Reached maximum number of FLM objects. */
#define FLMR_INV_NAME             ((INT32) -20)   /**< DB name already in use. */
#define FLMR_INV_FILE             ((INT32) -21)   /**< Invalid file. */
#define FLMR_CANT_CREATE_LIST     ((INT32) -22)   /**< Cannot add name to master list. */
#define FLMR_LIST_NOT_FOUND       ((INT32) -23)   /**< List not found by given name. */
#define FLMR_INV_FILE_PATH        ((INT32) -24)   /**< Invalid file path. */
#define FLMR_FILE_NOT_FOUND       ((INT32) -25)   /**< File not found. */
#define FLMR_AEE_OUT_OF_RESOURCES ((INT32) -26)   /**< Can not allocate AEE resources. */
#define FLMR_AEE_NO_RIGHTS        ((INT32) -27)   /**< No right for the AEE resources. */
#define FLMR_FILE_READ_FAIL       ((INT32) -28)   /**< Failed to read from file. */
#define FLMR_FILE_WRITE_FAIL      ((INT32) -29)   /**< Failed to write to file. */

/* FLM notification reason bit masks */
#define FLM_REASON_UNK          ((UINT32) 0)             /**< Reason unknown */
#define FLM_RECORD_ADD          (MAKE_BIT_MASK_32(1))    /**< Reason for adding records */
#define FLM_RECORD_DEL          (MAKE_BIT_MASK_32(2))    /**< Reason for deleting records */
#define FLM_RECORD_MOD          (MAKE_BIT_MASK_32(3))    /**< Reason for modifying records */

/* Notification condition */
/*------------------------------------------------------------------*/
/*! @brief  Enumeration for notification conditions.
 *  @code
 *  typedef  enum
 *  {
 *      FLM_NO_COND,
 *      FLM_UPDATING,      
 *      FLM_UPDATED,       
 *      FLM_CLOSED         
 *  } FLM_COND_T;
 *  @endcode
 *  @li@c  FLM_NO_COND                   - Unknown condition.
 *  @li@c  FLM_UPDATING                  - When flm_lock is called.
 *  @li@c  FLM_UPDATED                   - When flm_unlock is called.
 *  @li@c  FLM_CLOSED                    - When flm_delete is called.
 */
/*------------------------------------------------------------------*/
typedef  enum
{
    FLM_NO_COND,
    FLM_UPDATING,      /* When _lock is called. */
    FLM_UPDATED,       /* When _unlock is called. */
    FLM_CLOSED         /* When _delete is called. */
} FLM_COND_T;

/*------------------------------------------------------------------*/
/*! @brief  This function is called by the favorite list manager to notify of
 *          changes in the state of the favorite list.
 *  @param  [in]  h_fav_handle      - User name associated with this list.
 *  @param  [in]  e_cond            - Specifies the notification condition.
 *  @param  [in]  ui4_reason        - Specifies the notification reason.
 *  @param  [in]  pv_tag            - Contains the tag passed when the favorite
 *                                    list was created or opened.
 *  @param  [in]  ui4_data          - Contains some additional data.
 *  @return None
 */
/*------------------------------------------------------------------*/
typedef  VOID (*pf_flm_nfy_func)
(
    HANDLE_T            h_fav_handle,
    FLM_COND_T          e_cond,
    UINT32              ui4_reason,
    VOID*               pv_tag,
    UINT32              ui4_data
);

/*------------------------------------------------------------------*/
/*! @brief  Structure for FLM list object.
 *  @code
 *  typedef struct {
 *      HANDLE_T        h_db;      
 *      HANDLE_T        h_self;    
 *      pf_flm_nfy_func pf_flm_notify;
 *      CHAR            as_name[FLM_NAME_LEN+1];
 *  } FLM_LIST_T;
 *  @endcode
 *  @li@c  h_db                          - Handle to client database object.
 *  @li@c  h_self                        - Handle to self.
 *  @li@c  pf_flm_notify                 - Registered notification function.
 *  @li@c  as_name                       - List name.
 */
/*------------------------------------------------------------------*/
typedef struct {
    HANDLE_T        h_db;      /* handle to client database object */
    HANDLE_T        h_self;    /* handle to self */
    pf_flm_nfy_func pf_flm_notify;
    CHAR            as_name[FLM_NAME_LEN+1];
} FLM_LIST_T;

/*------------------------------------------------------------------*/
/*! @brief  Structure for FLM records.
 *  @code
 *  typedef  struct {
 *      UINT16 ui2_svc_id;
 *      UINT16 ui2_svc_rec_id;
 *  } FLM_REC_T;
 *  @endcode
 *  @li@c  ui2_svc_id                    - SVL ID of the favorite channel.
 *  @li@c  ui2_svc_rec_id                - SVL record ID of the favorite
 *                                         channel.
 */
/*------------------------------------------------------------------*/
typedef  struct {
    UINT16 ui2_svc_id;
    UINT16 ui2_svc_rec_id;
    CHAR   ps_user_defined_ch_num[FLM_CH_NUM_MAX_LENGTH+1];
    CHAR   ps_user_defined_ch_name[FLM_CH_NAME_MAX_LENGTH+1];
} FLM_REC_T;

/*----------------------------------------------------------------------------*/
/*! @} */
/*----------------------------------------------------------------------------*/
#endif
