Skip to content

Commit

Permalink
refactor: console sends a list of instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed Jun 1, 2022
1 parent 8c09a41 commit 058ea4f
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions console/src/module/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lib.h"
#include "context.h"
#include "instruction.h"
#include "instruction_lambdas.h"
#include "conexion.h"
#include "accion.h"
#include "smartlist.h"
Expand Down Expand Up @@ -61,6 +62,14 @@ static int on_connect(void);
*/
static unsigned int parse(char *instructions_file);

/**
* @brief Sends a package with a lsit of instructions.
*
* @param conexion the connection to send the instructions
* @param instructions the list
* @return ssize_t
*/
ssize_t on_send_instructions(void *conexion, t_list *instructions);
// ============================================================================================================
// ***** Funciones Privadas - Definiciones *****
// ============================================================================================================
Expand Down Expand Up @@ -197,16 +206,22 @@ int on_run(char *instructions_file_name, uint32_t process_size)
}

LOG_WARNING("Streaming Instructions (%d)", list_size(input_file_commands));
while (input_file_commands->elements_count > 0)

if (!list_is_empty(input_file_commands))
{
if (on_send_instruction(
&this.conexion,
list_remove(input_file_commands, 0)) > 0)
{
LOG_DEBUG("Instruction %d sent.", list_size(input_file_commands));
}
on_send_instructions(&this.conexion, input_file_commands);
}

// while (input_file_commands->elements_count > 0)
// {
// if (on_send_instruction(
// &this.conexion,
// list_remove(input_file_commands, 0)) > 0)
// {
// LOG_DEBUG("Instruction %d sent.", list_size(input_file_commands));
// }
// }

this.status = not RUNNING;
}
}
Expand Down Expand Up @@ -256,3 +271,12 @@ ssize_t on_send_instruction(void *conexion, instruction_t *inst)

return (ssize_t)ERROR;
}

ssize_t on_send_instructions(void *conexion, t_list *instructions)
{
void *stream = instructions_fold(instructions);
size_t size = list_size(instructions) * sizeof(instruction_t) + sizeof(uint32_t);
ssize_t ret = conexion_enviar_stream(*(conexion_t *)conexion, CMD, stream, size);
free(stream);
return ret;
}

0 comments on commit 058ea4f

Please sign in to comment.