diff --git a/cpu/include/client/conexion_memoria.h b/cpu/include/client/conexion_memoria.h index e69de29..9c67246 100644 --- a/cpu/include/client/conexion_memoria.h +++ b/cpu/include/client/conexion_memoria.h @@ -0,0 +1,10 @@ +#pragma once + +/** + * @brief Se llama a la rutina para el hilo-cliente que conecta con memoria + * + * @param fd + * @return void* + */ + +void *routine_conexion_memoria(void *fd); diff --git a/cpu/include/module/cpu.h b/cpu/include/module/cpu.h index adf2c04..2cf516d 100644 --- a/cpu/include/module/cpu.h +++ b/cpu/include/module/cpu.h @@ -24,14 +24,16 @@ typedef struct CPU { - // TODO: Add server for Kernel - For PCB. + // TODO: Add server for Kernel - For PCB (Dispatch) // TODO: Add server for Kernel - For Interruptions // TODO: Add client connection to Memory. // La conexion del cliente conexion_t conexion; + // CPU's Thread Launcher; thread_manager_t tm; + // Current PCB in execution. pcb_t *pcb; diff --git a/cpu/src/client/conexion_memoria.c b/cpu/src/client/conexion_memoria.c index 62c48f7..26a9ba5 100644 --- a/cpu/src/client/conexion_memoria.c +++ b/cpu/src/client/conexion_memoria.c @@ -1,6 +1,5 @@ #include "conexion_memoria.h" #include "cpu.h" -#include "dispatcher.h" #include "instruction.h" #include "conexion.h" #include "accion.h" @@ -13,9 +12,47 @@ extern cpu_t g_cpu; +// ============================================================================================================ +// ***** Private Functions ***** +// ============================================================================================================ + +static int conexion_init(cpu_t* cpu) +{ + char *port = puerto_kernel(); + char *ip = ip_kernel(); + + LOG_DEBUG("Connecting at %s:%s", ip, port); + //cpu->conexion = conexion_cliente_create(ip, port); + + // Test connection with Kernel + cpu->conexion = conexion_cliente_create("127.0.0.1", "8000"); + + if (on_connect(&cpu->conexion, false) EQ SUCCESS) + { + //LOG_DEBUG("Connected as CLIENT at %s:%s", ip, port); + // Test connection with Kernel + LOG_DEBUG("Connected as CLIENT at %s:%s", "127.0.0.1", "8000"); + } + + return SUCCESS; +} + + +// ============================================================================================================ +// ***** Public Functions ***** +// ============================================================================================================ -void *routine_conexion_memoria(void *fd) +void *routine_conexion_memoria(void *data) { - //conexion_init(cpu); + cpu_t *cpu = data; + + conexion_init(cpu); + + conexion_enviar_mensaje(cpu->conexion, "Mando un msj"); + + for(;;){ + LOG_WARNING("Hola Thread 2"); + sleep(TIEMPO_ESPERA); + } } diff --git a/cpu/src/module/cpu.c b/cpu/src/module/cpu.c index ffe5af6..9984da8 100644 --- a/cpu/src/module/cpu.c +++ b/cpu/src/module/cpu.c @@ -9,6 +9,7 @@ * */ #include "conexion_memoria.h" +#include "cpu.h" #include "lib.h" #include "cpu.h" #include "log.h" @@ -77,26 +78,6 @@ on_cpu_destroy(cpu_t *cpu) return EXIT_SUCCESS; } -static int conexion_init(cpu_t* cpu) -{ - char *port = puerto_kernel(); - char *ip = ip_kernel(); - - LOG_DEBUG("Connecting at %s:%s", ip, port); - cpu->conexion = conexion_cliente_create(ip, port); - - // Test connection with Kernel - //cpu->conexion = conexion_cliente_create("127.0.0.1", "8000"); - - if (on_connect(&cpu->conexion, false) EQ SUCCESS) - { - LOG_DEBUG("Connected as CLIENT at %s:%s", ip, port); - // Test connection with Kernel - //LOG_DEBUG("Connected as CLIENT at %s:%s", "127.0.0.1", "8000"); - } - - return SUCCESS; -} int on_connect(void *conexion, bool offline_mode) { @@ -164,9 +145,12 @@ int on_run(cpu_t *cpu) // TODO: create thread for memory-conection (CLIENT) thread_manager_launch(&cpu->tm, routine_conexion_memoria, cpu); + for(;;){ + LOG_ERROR("Hola Thread 1"); + sleep(TIEMPO_ESPERA); + } - - conexion_init(cpu); + //conexion_init(cpu); //thread_manager_launch(&cpu->tm, )