Skip to content

Commit

Permalink
feat(lib): add module shared functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed Apr 29, 2022
1 parent 2c22d8b commit 610fdb5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/inc/modules/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file module.h
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar>
* @brief
* @version 0.1
* @date 04-29-2022
*
* @copyright Copyright (c) 2022
*
*/

#pragma once

#include "conexion.h"

/**
* @brief Forces a module connection
*
* @param connection to connect
* @param offline_mode wether the module is working offline or not.
* @return exit status code
*/
int on_module_connect(void *connection, bool offline_mode);
36 changes: 36 additions & 0 deletions lib/src/modules/module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file module.c
* @author Tomás Sánchez <tosanchez@frba.utn.edu.ar>
* @brief
* @version 0.1
* @date 04-29-2022
*
* @copyright Copyright (c) 2022
*
*/

#include "module.h"
#include "log.h"
#include "lib.h"

int on_module_connect(void *connection, bool offline_mode)
{
if (offline_mode)
{
LOG_WARNING("Module working in offline mode.");
return ERROR;
}

while (!conexion_esta_conectada(*(conexion_t *)connection))
{
LOG_TRACE("Connecting...");

if (conexion_conectar((conexion_t *)connection) EQ ERROR)
{
LOG_ERROR("Could not connect.");
sleep(TIEMPO_ESPERA);
}
}

return SUCCESS;
}

0 comments on commit 610fdb5

Please sign in to comment.