EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
handle_manager

Overview

A utility to manage handing out integer handles to resources.

#include "etcpal/handle_manager.h"

This struct and the accompanying functions are a utility to manage handing out integer handles to resources. It first assigns monotonically-increasing positive values starting at 0 to handles; after wraparound, it uses the value_in_use function to find holes where new handle values can be assigned.

Data Structures

struct  IntHandleManager
 State for managing generic integer handle values. More...
 

Typedefs

typedef bool(* HandleValueInUseFunction) (int handle_val, void *context)
 A pointer to a function that tests if a given handle value is currently assigned to a resource.
 
typedef struct IntHandleManager IntHandleManager
 State for managing generic integer handle values.
 

Functions

void init_int_handle_manager (IntHandleManager *manager, int max_value, HandleValueInUseFunction value_in_use_func, void *context)
 Initialize an IntHandleManager instance. More...
 
int get_next_int_handle (IntHandleManager *manager)
 Once the int handle manager is initialized, this is used to get the next handle value. More...
 

Function Documentation

◆ get_next_int_handle()

int get_next_int_handle ( IntHandleManager manager)

Once the int handle manager is initialized, this is used to get the next handle value.

This function provides the next handle value that is not currently assigned to a resource.

Parameters
[in,out]managerThe handle manager to get the new handle from.
Returns
The new handle, or -1 if all handles are used.

◆ init_int_handle_manager()

void init_int_handle_manager ( IntHandleManager manager,
int  max_value,
HandleValueInUseFunction  value_in_use_func,
void *  context 
)

Initialize an IntHandleManager instance.

Once an IntHandleManager has been instantiated, it should be passed to this function to initialize its state.

Parameters
[in,out]managerThe handle manager instance to initialize.
[in]max_valueDetermines a custom wrap-around point. It will be ignored if it's negative. Otherwise it represents the highest allowed handle value.
[in]value_in_use_funcThe function that tests if a given handle value is currently assigned to a resource.
[in,out]contextAn optional pointer that will be passed to the value-in-use function. This can be NULL.