Files
progettoso/lib/log/taglialegna.h

79 lines
1.6 KiB
C
Raw Permalink Normal View History

2022-03-21 01:51:45 +01:00
#pragma once
#ifndef _TAGLIALEGNA
#define _TAGLIALEGNA
#include <stdio.h>
#include <pthread.h>
#include "fileQueue.h"
2022-03-21 01:51:45 +01:00
typedef struct taglia_s {
FILE *file;
size_t max_files;
long max_size;
size_t cache_misses;
pthread_mutex_t m; /* per sincronizzare le scritture al file */
2022-03-21 01:51:45 +01:00
} taglia_t;
/**
* @brief Creates new instance
*
* @param file path to file to write into
* @param n number of optional parameters, in order:
* int max_files, int max_size, int cache_misses
* @return created istance, NULL if error
*/
2022-03-21 01:51:45 +01:00
taglia_t *taglia_init(char *file, int n, ...);
/**
* @brief Deallocates instance
*
* @param taglia instance to deallocate
*/
2022-03-21 01:51:45 +01:00
void taglia_del(taglia_t *taglia);
/**
* @brief Writes buffer to the log
*
* @param taglia
* @param buf NULL terminated string to write
* @return number of char written, -1 if error occurred
*/
2022-03-21 01:51:45 +01:00
size_t taglia_write(taglia_t *taglia, char *buf);
/**
* @brief Writes buffer to the log with timestamp
*
* @param taglia
* @param buf NULL terminated string to write
* @return number of char written, -1 if error occurred
*/
2022-03-21 01:51:45 +01:00
size_t taglia_log(taglia_t *taglia, char *buf);
/**
* @brief Updates statistics
*
* @param taglia
* @param queue structure that holds the files
* @param miss number of cache misses to add
* @return 1 if success, -1 if error occurred
*/
2022-03-21 01:51:45 +01:00
int taglia_update(taglia_t *taglia, queueT *queue, int miss);
/**
* @brief Writes stats to the stream and to the log
*
* @param taglia
* @param stream
* @return 0 if success, -1 if error occurred
*/
2022-03-21 01:51:45 +01:00
int taglia_stats(taglia_t *taglia, FILE *stream);
#endif /* _TAGLIALEGNA */