1 /**
2 * @file lv_cache_entry.h
3 *
4  */
5 
6 #ifndef LV_CACHE_ENTRY_H
7 #define LV_CACHE_ENTRY_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_types.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 
22 /**********************
23  *      TYPEDEFS
24  **********************/
25 
26 /**********************
27  * GLOBAL PROTOTYPES
28  **********************/
29 
30 /**
31  * Get the size of a cache entry.
32  * @param node_size     The size of the node in the cache.
33  * @return              The size of the cache entry.
34  */
35 uint32_t lv_cache_entry_get_size(const uint32_t node_size);
36 
37 /**
38  * Get the reference count of a cache entry.
39  * @param entry        The cache entry to get the reference count of.
40  * @return             The reference count of the cache entry.
41  */
42 int32_t  lv_cache_entry_get_ref(lv_cache_entry_t * entry);
43 
44 /**
45  * Get the node size of a cache entry. Which is the same size with lv_cache_entry_get_size()'s node_size parameter.
46  * @param entry        The cache entry to get the node size of.
47  * @return             The node size of the cache entry.
48  */
49 uint32_t lv_cache_entry_get_node_size(lv_cache_entry_t * entry);
50 
51 /**
52  * Check if a cache entry is invalid.
53  * @param entry        The cache entry to check.
54  * @return             True: the cache entry is invalid. False: the cache entry is valid.
55  */
56 bool     lv_cache_entry_is_invalid(lv_cache_entry_t * entry);
57 
58 /**
59  * Get the data of a cache entry.
60  * @param entry        The cache entry to get the data of.
61  * @return             The pointer to the data of the cache entry.
62  */
63 void  *  lv_cache_entry_get_data(lv_cache_entry_t * entry);
64 
65 /**
66  * Get the cache instance of a cache entry.
67  * @param entry        The cache entry to get the cache instance of.
68  * @return             The pointer to the cache instance of the cache entry.
69  */
70 const lv_cache_t * lv_cache_entry_get_cache(const lv_cache_entry_t * entry);
71 
72 /**
73  * Get the cache entry of a data. The data should be allocated by the cache instance.
74  * @param data         The data to get the cache entry of.
75  * @param node_size    The size of the node in the cache.
76  * @return             The pointer to the cache entry of the data.
77  */
78 lv_cache_entry_t * lv_cache_entry_get_entry(void * data, const uint32_t node_size);
79 
80 /**
81  * Allocate a cache entry.
82  * @param node_size    The size of the node in the cache.
83  * @param cache        The cache instance to allocate the cache entry from.
84  * @return             The pointer to the allocated cache entry.
85  */
86 lv_cache_entry_t * lv_cache_entry_alloc(const uint32_t node_size, const lv_cache_t * cache);
87 
88 /**
89  * Initialize a cache entry.
90  * @param entry        The cache entry to initialize.
91  * @param cache        The cache instance to allocate the cache entry from.
92  * @param node_size    The size of the node in the cache.
93  */
94 void lv_cache_entry_init(lv_cache_entry_t * entry, const lv_cache_t * cache, const uint32_t node_size);
95 
96 /**
97  * Deallocate a cache entry. And the data of the cache entry will be freed.
98  * @param entry        The cache entry to deallocate.
99  */
100 void lv_cache_entry_delete(lv_cache_entry_t * entry);
101 /*************************
102  *    GLOBAL VARIABLES
103  *************************/
104 
105 /**********************
106  *      MACROS
107  **********************/
108 
109 #ifdef __cplusplus
110 } /*extern "C"*/
111 #endif
112 
113 #endif /*LV_CACHE_ENTRY_H*/
114