Skip to content

Commit

Permalink
CFG-27 Memory Connection Done
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaver committed Apr 27, 2022
1 parent f2b9b92 commit af10a7e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
10 changes: 10 additions & 0 deletions cpu/include/client/conexion_memoria.h
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 3 additions & 1 deletion cpu/include/module/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
43 changes: 40 additions & 3 deletions cpu/src/client/conexion_memoria.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "conexion_memoria.h"
#include "cpu.h"
#include "dispatcher.h"
#include "instruction.h"
#include "conexion.h"
#include "accion.h"
Expand All @@ -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 <Cpu> 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);
}
}
28 changes: 6 additions & 22 deletions cpu/src/module/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
*/
#include "conexion_memoria.h"
#include "cpu.h"
#include "lib.h"
#include "cpu.h"
#include "log.h"
Expand Down Expand Up @@ -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 <Cpu> 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)
{
Expand Down Expand Up @@ -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, )

Expand Down

0 comments on commit af10a7e

Please sign in to comment.