resource.h (1354B)
1 2 #ifndef RESOURCE_H 3 #define RESOURCE_H 4 5 #include "typedefs.h" 6 7 #define STATIC_UUID 0x5A51C00000000000 8 9 enum refresh_status { 10 RESOURCE_DELETED, 11 REFRESH_NOT_NEEDED, 12 REFRESHED_ID 13 }; 14 15 struct resource_id { 16 u64 uuid; 17 u32 index; 18 u32 generation; 19 }; 20 21 struct resource_manager { 22 u8 *resources; 23 struct resource_id *ids; 24 u32 resource_count; 25 u32 generation; 26 u32 elem_size; 27 u32 slots_used; 28 u32 max_capacity; 29 u32 current_capacity; 30 31 const char *name; 32 }; 33 34 #define ideq(a, b) ((a)->uuid == (b)->uuid) 35 36 void init_id(struct resource_id *id); 37 void *get_resource(struct resource_manager *r, struct resource_id *id); 38 void *get_all_resources(struct resource_manager *, u32 *count, struct resource_id **ids); 39 void destroy_resource(struct resource_manager *, struct resource_id *id); 40 void destroy_resource_manager(struct resource_manager *); 41 void *new_resource(struct resource_manager *, struct resource_id *id); 42 void print_id(struct resource_id *, int nl); 43 void null_id(struct resource_id *id); 44 int is_resource_destroyed(struct resource_id *id); 45 46 void init_resource_manager(struct resource_manager *r, u32 elem_size, 47 u32 initial_elements, u32 max_elements, const char *name); 48 49 50 static inline int is_null_id(struct resource_id *id) 51 { 52 return id->generation == 0; 53 } 54 55 56 #endif /* RESOURCE_H */