This repository has been archived on 2026-05-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LightTAM/include/users.h
T

103 lines
3.2 KiB
C

#include "main.h"
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#ifndef __USERS_H__
#define __USERS_H__
typedef struct person
{
uint16_t uuid;
char *name;
char *surname;
uint32_t department;
time_t last_time_event;
time_t total;
BYTE available;
pthread_mutex_t lock;
} person_t;
typedef struct node
{
person_t user;
struct node *next;
} node_t;
/**
* @brief Generates a unique identifier (UUID) for a new node in the linked list.
*
* This function traverses the linked list starting from the given head node
* and generates a unique 16-bit unsigned integer identifier that does not
* conflict with any existing UUIDs in the list.
*
* @param _head Pointer to the head node of the linked list.
* @return A 16-bit unsigned integer representing the generated UUID.
*/
uint16_t generateUUID(node_t *_head);
/**
* @brief Searches for a UUID associated with a user by their name and surname.
*
* This function traverses a linked list of nodes to find a user whose name
* and surname match the provided parameters. If a match is found, it returns
* a pointer to the UUID associated with that user.
*
* @param _head Pointer to the head of the linked list.
* @param _name Pointer to a string containing the user's first name.
* @param _surname Pointer to a string containing the user's surname.
* @return Pointer to the UUID of the user if found, or 0 if no match is found.
*/
uint16_t *searchUUIDByName(node_t *_head, char *_name, char *_surname);
/**
* @brief Searches for a person in a linked list by their UUID.
*
* This function traverses a linked list starting from the given head node
* and searches for a node that matches the specified UUID.
*
* @param _head Pointer to the head node of the linked list.
* @param _uuid The UUID of the person to search for.
* @return Pointer to the node containing the person with the matching UUID,
* or NULL if no such person is found.
*/
node_t *searchPersonByUUID(node_t *_head, uint16_t _uuid);
/**
* @brief Adds a new person to the linked list.
*
* This function creates a new person and appends it to the end of the linked list.
* It dynamically allocates memory for the new person and initializes their details.
* If memory allocation fails or the input parameters are invalid, the function returns an error.
*
* @param _head Pointer to the head of the linked list (node_t **).
* @param _name Pointer to a string containing the person's first name.
* @param _surname Pointer to a string containing the person's last name.
* @param _department The department number to which the person belongs.
*
* @return int Returns 1 if the person was successfully added, otherwise 0 on failure.
*
* @note Memory for the name and surname is dynamically allocated. It is the caller's
* responsibility to free the memory for the entire list to avoid memory leaks.
*
* @example
* ```c
* node_t *head = NULL;
* if (addPersonToList(&head, "John", "Doe", 101)) {
* printf("Person successfully added.\n");
* } else {
* printf("Error adding person.\n");
* }
* ```
*/
int addPersonToList(node_t **_head, char *_name, char *_surname, uint32_t _department);
int addTimeEvent(node_t *_person);
#endif