Skip to content

Commit

Permalink
Merge pull request #17 from tomasanchez/CFG-21-console-connection
Browse files Browse the repository at this point in the history
Cfg 21 console connection
  • Loading branch information
tomasanchez authored Apr 23, 2022
2 parents 9079e1c + 42c3e60 commit c26980f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
6 changes: 0 additions & 6 deletions console/test/cliente.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,3 @@ CTEST2(client_send, no_se_envia_null)
int result = on_send_instruction((void *)&data->conexion, NULL);
ASSERT_EQUAL(ERROR, result);
}

CTEST2(client_send, no_se_envia_sin_conexion)
{
int result = on_send_instruction((void *)&data->conexion, strdup(LINE_STR));
ASSERT_EQUAL(ERROR, result);
}
6 changes: 6 additions & 0 deletions kernel/inc/server/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include "accion.h"
#include "instruction.h"

#include "thread_manager.h"

void *dispatch_imprimir_mensaje(void *args);

void *dispatch_handle_instruction(void *args);

void *dispatch_handle_action(void *args);
24 changes: 24 additions & 0 deletions kernel/src/server/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <commons/collections/list.h>

#include "dispatcher.h"
#include "accion.h"
#include "instruction.h"
#include "thread_manager.h"
#include "server.h"
#include "smartlist.h"
Expand Down Expand Up @@ -64,6 +66,28 @@ void *dispatch_imprimir_mensaje(void *args)
return NULL;
}

void *dispatch_handle_instruction(void *args)
{
instruction_t *instruction = ((instruction_t *)args);

THREAD_SAFE(LOG_INFO("Received Instruction: %d %d %d", instruction->icode, instruction->param0, instruction->param1));

instruction_destroy(instruction);

return NULL;
}

void *dispatch_handle_action(void *args)
{
accion_t *accion = ((accion_t *)args);

THREAD_SAFE(LOG_INFO("Received Action: %d %d", accion->actioncode, accion->param););

accion_destroy(accion);

return NULL;
}

// ------------------------------------------------------------
// Getters
// ------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions kernel/src/server/routines.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "kernel.h"
#include "server.h"
#include "dispatcher.h"
#include "instruction.h"
#include "conexion.h"
#include "accion.h"
#include "log.h"
#include "cfg.h"

Expand Down Expand Up @@ -29,6 +32,16 @@ recibir_mensaje(int cliente)
return servidor_recibir_mensaje(cliente, &size);
}

static instruction_t *recibir_instruction(int cliente)
{
ssize_t size = ERROR;
void *stream = servidor_recibir_stream(cliente, &size);
instruction_t *instruction = instruction_from_stream(stream);
free(stream);

return instruction;
}

// ============================================================================================================
// ***** Funciones Publicas *****
// ============================================================================================================
Expand Down Expand Up @@ -74,6 +87,14 @@ void *routine(void *fd)
dispatch_imprimir_mensaje((void *)recibir_mensaje(sender_fd));
break;

case SYS:
dispatch_handle_action((void *)accion_recibir(sender_fd));
break;

case CMD:
dispatch_handle_instruction((void *)recibir_instruction(sender_fd));
break;

default:
LOG_ERROR("Client<%d>: Unrecognized operation code (%d)", sender_fd, opcode);
break;
Expand Down

0 comments on commit c26980f

Please sign in to comment.