mirror of
				https://github.com/nyanmisaka/mpp.git
				synced 2025-10-31 12:36:44 +08:00 
			
		
		
		
	 dee9bced95
			
		
	
	dee9bced95
	
	
	
		
			
			Platform: General
Spec: all
Error case:
Constructors may be added after 65535(mpp_singleton_init)
ex: mpp_platform added after 65535 when mpp_soc is
    refactored to c
Signed-off-by: Hongjin Li <vic.hong@rock-chips.com>
Signed-off-by: xiaoxu.chen <xiaoxu.chen@rock-chips.com>
Change-Id: If736904beb0cd64a3e4ae3b20fd72e1198646ac7
		
	
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: Apache-2.0 OR MIT */
 | |
| /*
 | |
|  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
 | |
|  */
 | |
| 
 | |
| #ifndef __MPP_SINGLETON_H__
 | |
| #define __MPP_SINGLETON_H__
 | |
| 
 | |
| #include "rk_type.h"
 | |
| 
 | |
| typedef enum MppSingletonId_e {
 | |
|     MPP_SGLN_BASE           = 0,
 | |
|     /* osal base module */
 | |
|     MPP_SGLN_OS_LOG         = MPP_SGLN_BASE,
 | |
|     MPP_SGLN_OS_MEM,
 | |
|     MPP_SGLN_OS_ALLOCATOR,
 | |
|     MPP_SGLN_MEM_POOL,
 | |
|     /* hardware platform */
 | |
|     MPP_SGLN_SOC,
 | |
|     MPP_SGLN_PLATFORM,
 | |
|     /* software platform */
 | |
|     MPP_SGLN_RUNTIME,
 | |
|     /* base module */
 | |
|     MPP_SGLN_BUFFER,
 | |
|     MPP_SGLN_META,
 | |
|     MPP_SGLN_FRAME,
 | |
|     MPP_SGLN_PACKET,
 | |
|     /* system module */
 | |
|     MPP_SGLN_KOBJ,
 | |
|     MPP_SGLN_ENC_CFG,
 | |
|     MPP_SGLN_DEC_CFG,
 | |
|     MPP_SGLN_DEC_RC_API,
 | |
| 
 | |
|     /* max count for start init process */
 | |
|     MPP_SGLN_MAX_CNT,
 | |
| } MppSingletonId;
 | |
| 
 | |
| typedef struct MppSingletonInfo_t {
 | |
|     MppSingletonId  id;
 | |
|     const char      *name;
 | |
|     void            (*init)(void);
 | |
|     void            (*deinit)(void);
 | |
| } MppSingletonInfo;
 | |
| 
 | |
| #define SNGL_TO_STR(x)  #x
 | |
| #define SNGL_TO_FUNC(x) __mpp_singleton_add_##x
 | |
| /* warning: constructor priorities from 0 to 100 are reserved for the implementation */
 | |
| #define SNGL_BASE_ID    101
 | |
| #define MPP_SINGLETON(id, name, init, deinit) \
 | |
|     /* increase id from base id to avoid compiler warning */ \
 | |
|     __attribute__((constructor(SNGL_BASE_ID + id))) \
 | |
|     static void SNGL_TO_FUNC(name)(void) { \
 | |
|         MppSingletonInfo info = { \
 | |
|             id, \
 | |
|             SNGL_TO_STR(name), \
 | |
|             init, \
 | |
|             deinit, \
 | |
|         }; \
 | |
|         mpp_singleton_add(&info, __FUNCTION__); \
 | |
|     }
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| rk_s32 mpp_singleton_add(MppSingletonInfo *info, const char *caller);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* __MPP_SINGLETON_H__ */
 |