/* 
 * Log Structure Layer Implementation
 * 
 * logrw.c
 *
 * logrw.c (to be implemented by the student) implements this API.
 * block.c implements a storage layer which offers the abstraction 
 * of a sequence of blocks of fixed size. Blocks are kept in memory.
 * Contains functions for creating, destroying, writing, reading and 
 * dumping blocks, among other. 
 * 
 */

#include <stdlib.h>
#include "../include/logrw.h"


/*
 * logrw_init: create a logrw instance
 * should allocate space for all registers
 * should allocate space for blocks arrays
 * - num_reg: number of registers
 * - array_dim: size of each of the two arrays of blocks
 * - bloco_dim: size of each block
 *   returns: pointer to the logrw instance
 */
logrw_struct_t* logrw_init(unsigned int num_reg, unsigned int array_dim, unsigned int bloco_dim) {
  //TO DO: IMPLEMENT THIS FUNCTION
  return NULL;
}


/*
 * logrw_free: free the logrw
 * - log - the logrw instance
 */
void logrw_free(logrw_struct_t* log)  {
  //TO DO: IMPLEMENT THIS FUNCTION
  return;
}


/*
 * logrw_num_registers: gets the number of registers
 * - log - the logrw instance
 *   returns: number of the num_reg parameter that was provided when
 *   the logrw was first initialized; -1 if error
 */
unsigned int logrw_num_registers(logrw_struct_t* log)  {
  //TO DO: IMPLEMENT THIS FUNCTION
  return -1;
}


/*
 * logrw_read: read a single register, reading the whole block with the 
 * most up-to-date content for that register
 * - log - the logrw instance
 * - register_no: the number of the register to read
 * - block: the buffer were to copy the block containing that register content [out]
 *   returns: 0 if sucessful, -1 if not
 */
int logrw_read(logrw_struct_t* log, unsigned register_no, char* block)  {
  //TO DO: IMPLEMENT THIS FUNCTION
  return -1;
}


/*
 * logrw_write: write a register into the next free array block, writing to the whole block
 * - log: the logrw instance
 * - register_no: the number of the register to write
 * - block: the buffer with the data to write
 *   returns: 0 if sucessful, -1 if not
 */
int logrw_write(logrw_struct_t* log, unsigned register_no, char* block)  {
  //TO DO: IMPLEMENT THIS FUNCTION
  return -1;
}


/*
 * block_dump: dumps general debugging information
 * such as Array with next free block, index for next free block, next block to copy
 * threads waiting on clean, and the block location for each register
 * - log - the logrw instance
 */
void logrw_dump(logrw_struct_t* log)  {
  //TO DO: IMPLEMENT THIS FUNCTION
  return;
}


/*
 * logrw_dump_register: dumps the content of a specified register
 * should indicate register index, the index and array for the register block 
 * and the contents of this register block (e.g. not necessary to print all the block,
 * it is enough just 8 first bytes of the block, for instance on hexadecimal representation)
 * - i: the number of the register to dump
 * - log - the logrw instance
 */
void logrw_dump_register(unsigned int i, logrw_struct_t* log) {
  //TO DO: IMPLEMENT THIS FUNCTION
  return;
}


/*
 * logrw_dump_all_registers: dumps the content of all registers 
 * - log - the logrw instance
 */
void logrw_dump_all_registers(logrw_struct_t* log) {
  //TO DO: IMPLEMENT THIS FUNCTION
  return;
}


/*
 * logrw_clean_func: cleaning function to copy live blocks to the other blocks array.
 * Copies live blocks from previous to new array (flip of arrays)
 * - log - the logrw instance
 */
void *logrw_clean_func(void* log) {
  //TO DO: IMPLEMENT THIS FUNCTION
  return NULL;
}
