Browse Source

comentários no código, mas não padronizado Doxygen

dev
Rodgger 2 years ago
parent
commit
b488bafc3c
  1. 84
      src/agent/agent.c
  2. 64
      src/agent/agent.h
  3. 2
      src/agent/agent_db.c

84
src/agent/agent.c

@ -1,34 +1,34 @@
/***
* _____ _ _ _____
* / ____(_) | | |_ _|
* | (___ _ _ __ ___ _ __ | | ___ ___ | | _ __
* \___ \| | '_ ` _ \| '_ \| |/ _ \/ __| | | | '_ \
* ____) | | | | | | | |_) | | __/\__ \ _| |_| |_) |
* |_____/|_|_| |_| |_| .__/|_|\___||___/ |_____| .__/
* | \/ | | | | |
* | \ / | __ _ _ __ |_|_ _ __ _ ___ _ __ |_|
* | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
* | | | | (_| | | | | (_| | (_| | __/ |
* |_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
* __/ |
* |___/
*
* .----------------. .----------------. .----------------. .----------------.
* | .--------------. || .--------------. || .--------------. || .--------------. |
* | | __ | || | ____ ____ | || | _____ | || | ________ | |
* | | / \ | || ||_ \ / _|| || | |_ _| | || | |_ ___ `. | |
* | | / /\ \ | || | | \/ | | || | | | | || | | | `. \ | |
* | | / ____ \ | || | | |\ /| | | || | | | | || | | | | | | |
* | | _/ / \ \_ | || | _| |_\/_| |_ | || | _| |_ | || | _| |___.' / | |
* | ||____| |____|| || ||_____||_____|| || | |_____| | || | |________.' | |
* | | | || | | || | | || | | |
* | '--------------' || '--------------' || '--------------' || '--------------' |
* '----------------' '----------------' '----------------' '----------------'
*
* Copyright (C) 2022 Simples IP.
* Author: dgger Bruno <rodgger.silva@simplesip.com>
* Maintainers: Rodgger Bruno <rodgger.silva@simplesip.com>
*
*/
#include <main.h>
#include <string.h>
#include <frame/frame_asterisk.h>
#include <frame/frame_asterisk.h> // camada de persistência
#include <agent/agent.h>
#include <parse_actions.h>
#include <methods_actions.h>
#include <string_functions.h>
#include <stdlib.h>
/*
* lida com os eventos agents
*
*/
int parse_event_agents( EVENT *event, s_manager *smanager ){
/*
@ -89,39 +89,41 @@ int parse_event_agents( EVENT *event, s_manager *smanager ){
status = ami_get_value( smanager->ami, event->args, "Status" );
if( !status ) { goto fail; }
{
{ //banco de dados
struct s_table_agent *table_agent = get_agents_db( Select_agents, matricula );
if (table_agent) {
if( strcmp_n( table_agent->name, name ) ||
strcmp_n( table_agent->status, status )){
/* atualizar linha de dados da tabela agent */
if(update_agents_db( Update_agents, name, status, table_agent->id ) == -1){
goto fail;
}
}
// liberar resultado mysql
free_table_agent(table_agent);
}
else {
// inseri uma linha na tabela
if(insert_agents_db( Insert_agents, name, matricula, status) == -1){
goto fail;
}
}
}
{
{ // camada de persistência
struct s_agents *agent = get_agents(matricula);
if(agent){
agent->action_update = 1;
agent->action_update = 1; // esse agente existe no asterisk
}
else{
else{ // criar um novo agente na persistência que existe no asteriks
agent = create_agents();
newstrncpy(&agent->matricula, matricula);
agent->action_update = 1;
insert_agents( agent );
}
}
return 1;
@ -130,30 +132,40 @@ fail:
return -1;
}
/*
* lida com o eventos agentscomplete.
* esse evento é recebido quando terminou a lista de eventos dos agentes, por isso o nome
* Esse evento é usado para sincronizar agentes com o asterisk
*/
int parse_event_agentscomplete(EVENT *event, s_manager *smanager){
if( strcasecmp_n( ami_get_value(smanager->ami, event->args, "Eventlist"), "Complete" ) ) {
return -1;
}
// Excluí agentes na camada de persistêcnia que não estão no asterisk
agent_update();
struct s_table_agent *table_agent = get_agents_update_db(Select_agents_update);
struct s_table_agent *root_table_agent = table_agent;
while(table_agent){
struct s_agents *agent = get_agents(table_agent->matricula);
if(agent){
if(agent->action_update == 0){
{ // Excluí agentes no banco de dados que não estão na camada de persistência
struct s_table_agent *table_agent = get_agents_all_db(Select_agents_update);
struct s_table_agent *root_table_agent = table_agent;
while(table_agent){
struct s_agents *agent = get_agents(table_agent->matricula);
if(agent){
if(agent->action_update == 0){
delete_agents_db(Delete_agents, table_agent->id);
}
agent->action_update = 0;
}
else{
delete_agents_db(Delete_agents, table_agent->id);
}
agent->action_update = 0;
}
else{
delete_agents_db(Delete_agents, table_agent->id);
table_agent = table_agent->next;
}
table_agent = table_agent->next;
}
free_table_agent(root_table_agent);

64
src/agent/agent.h

@ -1,20 +1,18 @@
/***
* _____ _ _ _____
* / ____(_) | | |_ _|
* | (___ _ _ __ ___ _ __ | | ___ ___ | | _ __
* \___ \| | '_ ` _ \| '_ \| |/ _ \/ __| | | | '_ \
* ____) | | | | | | | |_) | | __/\__ \ _| |_| |_) |
* |_____/|_|_| |_| |_| .__/|_|\___||___/ |_____| .__/
* | \/ | | | | |
* | \ / | __ _ _ __ |_|_ _ __ _ ___ _ __ |_|
* | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
* | | | | (_| | | | | (_| | (_| | __/ |
* |_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
* __/ |
* |___/
*
* .----------------. .----------------. .----------------. .----------------.
* | .--------------. || .--------------. || .--------------. || .--------------. |
* | | __ | || | ____ ____ | || | _____ | || | ________ | |
* | | / \ | || ||_ \ / _|| || | |_ _| | || | |_ ___ `. | |
* | | / /\ \ | || | | \/ | | || | | | | || | | | `. \ | |
* | | / ____ \ | || | | |\ /| | | || | | | | || | | | | | | |
* | | _/ / \ \_ | || | _| |_\/_| |_ | || | _| |_ | || | _| |___.' / | |
* | ||____| |____|| || ||_____||_____|| || | |_____| | || | |________.' | |
* | | | || | | || | | || | | |
* | '--------------' || '--------------' || '--------------' || '--------------' |
* '----------------' '----------------' '----------------' '----------------'
*
* Copyright (C) 2022 Simples IP.
* Author: dgger Bruno <rodgger.silva@simplesip.com>
* Maintainers: Rodgger Bruno <rodgger.silva@simplesip.com>
*
*/
@ -22,27 +20,57 @@
#define AGENT_H 1
#include <database/database.h>
#include <ami_c.h>
#include <ami_c.h> // biblioteca ami_c
#include <main.h>
/* struct para guardar valores da tabela agent */
struct s_table_agent {
unsigned long long int id;
unsigned long long int id; // id mariadb
char *name;
char *matricula;
char *status;
struct s_table_agent *next;
};
/* Event https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerEvent_Agents */
int parse_event_agents( EVENT *event, s_manager *smanager );
/* Event https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerEvent_AgentComplete */
int parse_event_agentscomplete(EVENT *event, s_manager *smanager);
struct s_table_agent *get_agents_update_db(stmt_t type_stmt);
/* Recebe todas as agentes */
struct s_table_agent *get_agents_all_db(stmt_t type_stmt);
/* adcionar a próxima linha do resultado sql */
int add_table_agent(struct s_table_agent **A, struct s_table_agent *next);
/* liberar ponteiro do resultado */
int free_table_agent(struct s_table_agent *A);
/* buscar um agente de acordo com a matrícula */
struct s_table_agent *get_agents_db( stmt_t type_stmt, const char *matricula );
/* atualizar um linha da tabela */
int update_agents_db( stmt_t type_stmt, const char *name, const char *status, unsigned long long int id );
/* inserir uma linha da tabela */
int insert_agents_db( stmt_t type_stmt, const char *name, const char *matricula, const char *status );
/* deletar uma linha databela agents */
int delete_agents_db(stmt_t type_stmt, unsigned long long int id);
#endif

2
src/agent/agent_db.c

@ -54,7 +54,7 @@ int free_table_agent(struct s_table_agent *A){
}
struct s_table_agent *get_agents_update_db(stmt_t type_stmt){
struct s_table_agent *get_agents_all_db(stmt_t type_stmt){
MYSQL_STMT *stmt = NULL;
SET_STMT( stmt, type_stmt, 0 );

Loading…
Cancel
Save