-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from tomasanchez/feature/CFG-28-pcb_handling
Feature/cfg 28 pcb handling
- Loading branch information
Showing
7 changed files
with
276 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @file cpu.h | ||
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar> | ||
* @brief | ||
* @version 0.1 | ||
* @date 04-23-2022 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "pcb.h" | ||
#include "thread_manager.h" | ||
|
||
#define MODULE_NAME "cpu" | ||
|
||
/** | ||
* @brief CPU Module. | ||
* | ||
*/ | ||
typedef struct CPU | ||
{ | ||
|
||
// TODO: Add server for Kernel - For PCB. | ||
// TODO: Add server for Kernel - For Interruptions | ||
// TODO: Add client connection to Memory. | ||
// CPU's Thread Launcher; | ||
thread_manager_t tm; | ||
// Current PCB in execution. | ||
pcb_t *pcb; | ||
} cpu_t; | ||
|
||
/** | ||
* @brief Inits a CPU module. | ||
* | ||
* @param cpu to be initialized | ||
*/ | ||
int on_init(cpu_t *cpu); | ||
|
||
/** | ||
* @brief Handles the main execution procedure. | ||
* | ||
* @param cpu to run | ||
* @return the exit status code | ||
*/ | ||
int on_run(cpu_t *cpu); | ||
|
||
/** | ||
* @brief Frees memory usage of a CPU module. | ||
* | ||
* @param cpu the module reference | ||
* @return an exit staus code | ||
*/ | ||
int on_before_exit(cpu_t *cpu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file pcb_controller.h | ||
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar> | ||
* @brief | ||
* @version 0.1 | ||
* @date 04-23-2022 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "pcb.h" | ||
#include "server.h" | ||
|
||
// ============================================================================================================ | ||
// ***** Public Functions ***** | ||
// ============================================================================================================ | ||
|
||
/** | ||
* @brief Receivesa a PCB stream. | ||
* | ||
* @param fd the file descriptor | ||
* @return a new PCB instance | ||
*/ | ||
pcb_t *receive_pcb(int fd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* @file cpu.c | ||
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar> | ||
* @brief | ||
* @version 0.1 | ||
* @date 04-23-2022 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
|
||
#include "lib.h" | ||
#include "cpu.h" | ||
#include "log.h" | ||
#include "cfg.h" | ||
#include <signal.h> | ||
|
||
// ============================================================================================================ | ||
// ***** Private Functions ***** | ||
// ============================================================================================================ | ||
|
||
cpu_t g_cpu; | ||
|
||
static void handle_sigint(int signal) | ||
{ | ||
if (signal == SIGINT) | ||
{ | ||
LOG_WARNING("SIGNINT was received."); | ||
on_before_exit(&g_cpu); | ||
exit(SIGINT); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Initializes the CPU reference. | ||
* | ||
* @param cpu the module reference | ||
* @return the return code. | ||
*/ | ||
static int | ||
on_cpu_init(cpu_t *cpu); | ||
|
||
/** | ||
* @brief Frees the CPU memory usage. | ||
* | ||
* @param cpu to be deleted | ||
* @return the exit status. | ||
*/ | ||
static int | ||
on_cpu_destroy(cpu_t *cpu); | ||
|
||
static int on_cpu_init(cpu_t *cpu) | ||
{ | ||
|
||
cpu->pcb = NULL; | ||
cpu->tm = new_thread_manager(); | ||
|
||
// TODO: Add server for Kernel - For PCB. | ||
// TODO: Add server for Kernel - For Interruptions | ||
// TODO: Add client connection to Memory. | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
static int | ||
on_cpu_destroy(cpu_t *cpu) | ||
{ | ||
pcb_destroy(cpu->pcb); | ||
thread_manager_destroy(&cpu->tm); | ||
// TODO: Add server for Kernel - For PCB. | ||
// TODO: Add server for Kernel - For Interruptions | ||
// TODO: Add client connection to Memory. | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
// ============================================================================================================ | ||
// ***** Public Functions ***** | ||
// ============================================================================================================ | ||
|
||
// ------------------------------------------------------------ | ||
// Life Cycle | ||
// ------------------------------------------------------------ | ||
|
||
int on_init(cpu_t *cpu) | ||
{ | ||
|
||
if (log_init(MODULE_NAME, true) EQ ERROR) | ||
return LOG_INITIALIZATION_ERROR; | ||
|
||
LOG_DEBUG("Logger started."); | ||
|
||
if (config_init(MODULE_NAME) EQ ERROR) | ||
{ | ||
LOG_ERROR("Could not open Configuration file."); | ||
log_close(); | ||
return CONFIGURATION_INITIALIZATION_ERROR; | ||
} | ||
|
||
LOG_DEBUG("Configurations loaded."); | ||
|
||
// Attach del evento de interrupcion forzada. | ||
signal(SIGINT, handle_sigint); | ||
|
||
on_cpu_init(cpu); | ||
LOG_DEBUG("Module started SUCCESSFULLY"); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
int on_run(cpu_t *cpu) | ||
{ | ||
LOG_TRACE("Hello World!"); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
int on_before_exit(cpu_t *cpu) | ||
{ | ||
int exit_code = EXIT_SUCCESS; | ||
|
||
LOG_WARNING("Closing Module..."); | ||
|
||
config_close(); | ||
LOG_WARNING("Configurations unloaded."); | ||
|
||
on_cpu_destroy(cpu); | ||
LOG_WARNING("CPU has been shut down."); | ||
|
||
LOG_TRACE("Program ended."); | ||
log_close(); | ||
|
||
return exit_code; | ||
} | ||
|
||
// ------------------------------------------------------------ | ||
// Event Handlers | ||
// ------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @file pcb_controller.c | ||
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar> | ||
* @brief | ||
* @version 0.1 | ||
* @date 04-23-2022 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
#include <stdlib.h> | ||
#include "pcb_controller.h" | ||
#include "log.h" | ||
|
||
// ============================================================================================================ | ||
// ***** Definitions ***** | ||
// ============================================================================================================ | ||
|
||
#define LOG_PCB(pcb) \ | ||
{ \ | ||
LOG_INFO("PCB= [id: %d, size: %lu, estimation: %d, program_counter: %d]", pcb->id, pcb->size, pcb->estimation, pcb->pc); \ | ||
} | ||
|
||
// ============================================================================================================ | ||
// ***** Public Functions ***** | ||
// ============================================================================================================ | ||
|
||
pcb_t *receive_pcb(int fd) | ||
{ | ||
ssize_t recv_bytes = -1; | ||
|
||
pcb_t *pcb = NULL; | ||
pcb = pcb_from_stream(servidor_recibir_stream(fd, &recv_bytes)); | ||
LOG_PCB(pcb); | ||
return pcb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters