
#include "u_common.h"
#include "x_os.h"
#include "x_dbg.h"
#include "u_handle.h"
#include "u_handle_grp.h"
#include "u_sys_name.h"

#include "u_opera_hbbtv.h"
#include "u_opera_hbbtv_util.h"

#ifndef __OPERA_HBBTV_UTIL_H__
#define __OPERA_HBBTV_UTIL_H__

#define OPHT_RES_UTIL           (HT_GROUP_OP_HBBTV + (HANDLE_TYPE_T) 8)

/*
      if return TRUE means can reclain the res by resmngr else  not
                           or resume when res is available
*/
typedef struct _OPERA_HBBTV_RES
{
   OPERA_HBBTV_RES_TYPE           t_res_type;
   BOOL                           b_registered;

   HANDLE_T                       h_res_binary;
   BOOL                           b_sync_wait;;

   OPERA_HBBTV_LOCK_TYPE          t_lock_type;
   UINT32                         ui4_count;

   OPERA_HBBTV_LOCK_OWNER         t_cur_owner;
   opera_hbbtv_res_client_cb_fct  pf_cur_client_cb_fct;
   VOID*                          pv_cur_tag;
   HANDLE_T                       h_cur_handle;


   opera_hbbtv_res_client_cb_fct  pf_pre_client_cb_fct;
   VOID*                          pv_pre_tag;
   OPERA_HBBTV_LOCK_OWNER         t_pre_owner;
   UINT32                         ui4_prev_count;
   HANDLE_T                       h_pre_handle;

} OPERA_HBBTV_RES;



INT32 opera_hbbtv_res_init();
INT32 opera_hbbtv_res_register(OPERA_HBBTV_RES_TYPE t_res_type, OPERA_HBBTV_LOCK_TYPE t_lock_type);
INT32 opera_hbbtv_res_unregister(OPERA_HBBTV_RES_TYPE t_res_type);
INT32 x_opera_hbbtv_res_reset(OPERA_HBBTV_LOCK_OWNER t_owner, OPERA_HBBTV_RES_TYPE t_res_type, OPERA_HBBTV_LOCK_TYPE t_lock_type, UINT32 ui4_count);
INT32 x_opera_hbbtv_res_get(OPERA_HBBTV_LOCK_OWNER t_owner, OPERA_HBBTV_RES_TYPE t_res_type,  SEMA_OPTION_T t_option, opera_hbbtv_res_client_cb_fct pf_client_cb_fct, VOID* pv_tag);
INT32 x_opera_hbbtv_res_put(OPERA_HBBTV_LOCK_OWNER t_owner, OPERA_HBBTV_RES_TYPE t_res_type);
INT32 opera_hbbtv_res_get(OPERA_HBBTV_LOCK_OWNER           t_owner,
                              OPERA_HBBTV_RES_TYPE             t_res_type,
                              SEMA_OPTION_T                    t_option,
                              opera_hbbtv_res_client_cb_fct    pf_client_cb_fct,
                              VOID*                            pv_tag,
                              HANDLE_T*                        ph_handle);


#endif  // __OPERA_HBBTV_UTIL_H__

