/* 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_mdb.h 
 *  $RCSfile: c_mdb.h,v$
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This file contains File Manager exported API's.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_MTP_MNGR_MDB Multimedia Transfer Protocol Database Builder
 *  @ingroup groupMW_MTP_MNGR
 *  @brief Provides a unified interface for MDB
 *  %This module provides query functionality, properties collection function for applications 
 *   and provide application a flexible way to configure directory appearance in File manager.
 *   - including these sub modules:
 *  @see groupMW_MTP_MNGR
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
 
#ifndef _C_MDB_H_
#define _C_MDB_H_

/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
#include "u_common.h"
#include "u_mtp.h"
#include "u_mdb.h"
#include "u_dm.h"

/*-----------------------------------------------------------------------------
                    external functions declarations
 ----------------------------------------------------------------------------*/    
 
/*******************
  Virtual Tree Define related API
 *******************/ 
/*------------------------------------------------------------------*/
/*! @brief          start to define the virtual tree structure
 *  @param [in]     ppv_tree                Point to the virtual tree.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_ARG            Invalid argument.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_start_define_tree(VOID** ppv_tree);

/*------------------------------------------------------------------*/
/*! @brief          configure the category for the virtual tree structure
 *  @param [in]        pv_tree                 Point to the virtual tree.
 *  @param [in]        ui1_category_idx        category index number.
 *  @param [in]        ui4_max_item            the max item number for this category.
 *  @param [in]        ui4_format_num          the format number for this category.
 *  @param [in]        aui2_formats            point to the format array for this category.
 *  @param [out]        -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_ARG            Invalid argument.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_config_category(VOID*               pv_tree,
                                   UINT8               ui1_category_idx,
                                   UINT32              ui4_max_item,
                                   UINT32              ui4_format_num,
                                   UINT16*             aui2_formats);

/*------------------------------------------------------------------*/
/*! @brief          add tree node function.
 *  @param [in]        pv_tree                 Point to the virtual tree.
 *  @param [in]        pt_node                 point to the layout node structure.
 *  @param [in]        t_parent                the parent node handle.
 *  @param [out]        pt_new_node             point to the new node handle.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_ARG            Invalid argument.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_add_layout_node(VOID*               pv_tree,
                                   MDB_LAYOUT_NODE_T*  pt_node, 
                                   MDB_NODE_HND_T      t_parent,
                                   MDB_NODE_HND_T*     pt_new_node);
                                   
/*------------------------------------------------------------------*/
/*! @brief          finish the virtual tree structure define.
 *  @param [in]     pv_tree                 Point to the virtual tree.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_ARG            Invalid argument.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_finish_define_tree(VOID*    pv_tree);

/*------------------------------------------------------------------*/
/*! @brief               free the virtual tree structure
 *  @param [in]       pv_tree                 Point to the virtual tree.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_ARG            Invalid argument.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_virtual_tree_free(VOID*    pv_tree);

/*******************
  MTP database builder related API
 *******************/  
/*------------------------------------------------------------------*/
/*! @brief      This API create resources of MDB environment.
 *  @param [in]     pt_cfg                  contains configuration of MTP device
 *  @param [out]    ph_mdb                  Handle to the MDB
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_ALREADY_EXIST      Run out of handles
 *  @retval        MDBR_OUT_OF_MEMORY      Run out of memory
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_open(
/*
#if !(CONFIG_SECTION_BUILD_LINUX_PROG)
                    DM_DEV_STAT_T*      pt_cfg,
#else
                    LIBMTP_mtpdevice_t* pt_cfg,
#endif*/
                    VOID*               pt_cfg,
                        HANDLE_T*       ph_mdb);

/*------------------------------------------------------------------*/
/*! @brief      register the asynchronous callback function for MDB module.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [in]     pf_async                point to asynchronous callback function.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_register_async(HANDLE_T              h_mdb,
                                  x_mdb_async_fct       pf_async);

/*------------------------------------------------------------------*/
/*! @brief      deregister the asynchronous callback function for MDB module.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [in]        pf_async                point to asynchronous callback function.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_deregister_async(HANDLE_T            h_mdb,
                                    x_mdb_async_fct     pf_async);

/*------------------------------------------------------------------*/
/*! @brief      configuration the MDB database information.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [in]        pt_cfg                  point to the configure structure.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_config(HANDLE_T          h_mdb,
                          MDB_CONFIG_T*     pt_cfg);

/*------------------------------------------------------------------*/
/*! @brief      close the MDB module, and destroy the internal structure.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_close(HANDLE_T h_mdb);

/*------------------------------------------------------------------*/
/*! @brief      get the MDB module status.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    pe_status               point to the MDB module status.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_status(HANDLE_T         h_mdb,
                          MDB_STATUS_T*    pe_status);

/*------------------------------------------------------------------*/
/*! @brief      start to the MDB database creating process.
 *  @param [in]    h_mdb                   Handle of MDB module.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_start(HANDLE_T     h_mdb);

/*------------------------------------------------------------------*/
/*! @brief      MDB database creating process pause.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_pause(HANDLE_T     h_mdb);

/*------------------------------------------------------------------*/
/*! @brief      MDB database creating process resume from pause.
 *  @param [in]         h_mdb                   Handle of MDB module.
 *  @param [out]    -
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_resume(HANDLE_T    h_mdb);

/*------------------------------------------------------------------*/
/*! @brief      get MDB database creating process percentage.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    pui1_percentage         point to the percentage.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_percentage(HANDLE_T    h_mdb,
                              UINT8*      pui1_percentage);

/*------------------------------------------------------------------*/
/*! @brief      get obj detail info of MTP device.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [in]        t_obj                   object handle in MTP device.
 *  @param [out]    pt_info                 point to the detail object info structure.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_obj_detail_info(HANDLE_T                 h_mdb,
                                   MDB_OBJ_HND_T            t_obj, 
                                   MDB_ITEM_DETAIL_INFO_T*  pt_info);


/*------------------------------------------------------------------*/
/*! @brief      get device info of MTP device.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    ppt_mdb_device_info     point to the device info structure.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_device_info(HANDLE_T             h_mdb,
                               MTP_DEVICE_INFO_T**  ppt_mdb_device_info);

/*------------------------------------------------------------------*/
/*! @brief      get storage id of MTP device.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [out]    pui4_storage_num        point to storage number.
 *  @param [out]        ppui4_storage_ids       point to the array of storage ids.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_storage_ids(HANDLE_T     h_mdb,
                               UINT32*      pui4_storage_num,
                               UINT32**     ppui4_storage_ids);

/*------------------------------------------------------------------*/
/*! @brief      get storage info of MTP device.
 *  @param [in]     h_mdb                   Handle of MDB module.
 *  @param [in]        ui4_storage_id          storage id.
 *  @param [out]    ppt_mdb_storage_info    point to the MTP storage info structure.
 *  @note
 *  @see
 *  @return      the error code
 *  @retval      MDBR_OK                 Success.
 *  @retval        MDBR_INV_HANDLE         Run out of handles
 *  @retval        MDBR_NOT_SUPPORT        MDB status is not ready.
 */
/*------------------------------------------------------------------*/
extern INT32 c_mdb_storage_info(HANDLE_T                h_mdb,
                                UINT32                  ui4_storage_id,
                                MTP_STORAGE_INFO_T**    ppt_mdb_storage_info);

#endif /* _C_MDB_H_ */

/*----------------------------------------------------------------------------*/
/*! @} */                                      /* end of groupMW_MTP_MNGR_MDB */
/*----------------------------------------------------------------------------*/

