session#
Simple session manager.
The purpose of this session manager is to maintain global states. This library supports multiple sessions, but may also be used when you only want to maintain a single global state. In this case, use session_get_default() instead of session_create().
Creating, freeing and accessing sessions
-
Session *session_create(const char *session_id)#
Create a new session with given
session_id
.- Returns:
Pointer to the session or NULL on error.
Accessing and setting default session
Useful these functions to maintain a single global state.
Setting and accessing global states
Useful these functions to maintain a single global state.
-
int session_add_state(Session *s, const char *name, void *ptr, void (*free_fun)(void *ptr))#
Add new global state.
- Parameters:
s – Pointer to session
name – A new unique name associated with the state
ptr – Pointer to state data
free_fun – Pointer to function that free state data
- Returns:
Non-zero on error.
-
int session_remove_state(Session *s, const char *name)#
Remove global state with given name.
name
must refer to an existing state.- Returns:
Non-zero on error.
-
void *session_get_state(Session *s, const char *name)#
Retrieve global state corresponding to
name
- Returns:
Pointer to global state or NULL if no state with this name exists.
-
void session_dump(void)#
Dump a listing of all sessions to stdout. For debugging
Typedefs
-
typedef struct _Session Session#
Opaque session type.