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. * Copyright (C) 2022 Simples IP.
* Author: dgger Bruno <rodgger.silva@simplesip.com> * Maintainers: Rodgger Bruno <rodgger.silva@simplesip.com>
* *
*/ */
#include <main.h> #include <main.h>
#include <string.h> #include <string.h>
#include <frame/frame_asterisk.h> #include <frame/frame_asterisk.h> // camada de persistência
#include <agent/agent.h> #include <agent/agent.h>
#include <parse_actions.h>
#include <methods_actions.h>
#include <string_functions.h> #include <string_functions.h>
#include <stdlib.h> #include <stdlib.h>
/*
* lida com os eventos agents
*
*/
int parse_event_agents( EVENT *event, s_manager *smanager ){ 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" ); status = ami_get_value( smanager->ami, event->args, "Status" );
if( !status ) { goto fail; } if( !status ) { goto fail; }
{ { //banco de dados
struct s_table_agent *table_agent = get_agents_db( Select_agents, matricula ); struct s_table_agent *table_agent = get_agents_db( Select_agents, matricula );
if (table_agent) { if (table_agent) {
if( strcmp_n( table_agent->name, name ) || if( strcmp_n( table_agent->name, name ) ||
strcmp_n( table_agent->status, status )){ 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){ if(update_agents_db( Update_agents, name, status, table_agent->id ) == -1){
goto fail; goto fail;
} }
} }
// liberar resultado mysql
free_table_agent(table_agent); free_table_agent(table_agent);
} }
else { else {
// inseri uma linha na tabela
if(insert_agents_db( Insert_agents, name, matricula, status) == -1){ if(insert_agents_db( Insert_agents, name, matricula, status) == -1){
goto fail; goto fail;
} }
} }
} }
{ { // camada de persistência
struct s_agents *agent = get_agents(matricula); struct s_agents *agent = get_agents(matricula);
if(agent){ 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(); agent = create_agents();
newstrncpy(&agent->matricula, matricula); newstrncpy(&agent->matricula, matricula);
agent->action_update = 1; agent->action_update = 1;
insert_agents( agent ); insert_agents( agent );
} }
} }
return 1; return 1;
@ -130,30 +132,40 @@ fail:
return -1; 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){ int parse_event_agentscomplete(EVENT *event, s_manager *smanager){
if( strcasecmp_n( ami_get_value(smanager->ami, event->args, "Eventlist"), "Complete" ) ) { if( strcasecmp_n( ami_get_value(smanager->ami, event->args, "Eventlist"), "Complete" ) ) {
return -1; return -1;
} }
// Excluí agentes na camada de persistêcnia que não estão no asterisk
agent_update(); agent_update();
struct s_table_agent *table_agent = get_agents_update_db(Select_agents_update); { // Excluí agentes no banco de dados que não estão na camada de persistência
struct s_table_agent *root_table_agent = table_agent; struct s_table_agent *table_agent = get_agents_all_db(Select_agents_update);
while(table_agent){ struct s_table_agent *root_table_agent = table_agent;
struct s_agents *agent = get_agents(table_agent->matricula); while(table_agent){
if(agent){ struct s_agents *agent = get_agents(table_agent->matricula);
if(agent->action_update == 0){ 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); delete_agents_db(Delete_agents, table_agent->id);
} }
agent->action_update = 0; table_agent = table_agent->next;
}
else{
delete_agents_db(Delete_agents, table_agent->id);
} }
table_agent = table_agent->next;
} }
free_table_agent(root_table_agent); free_table_agent(root_table_agent);

64
src/agent/agent.h

@ -1,20 +1,18 @@
/*** /***
* _____ _ _ _____ * .----------------. .----------------. .----------------. .----------------.
* / ____(_) | | |_ _| * | .--------------. || .--------------. || .--------------. || .--------------. |
* | (___ _ _ __ ___ _ __ | | ___ ___ | | _ __ * | | __ | || | ____ ____ | || | _____ | || | ________ | |
* \___ \| | '_ ` _ \| '_ \| |/ _ \/ __| | | | '_ \ * | | / \ | || ||_ \ / _|| || | |_ _| | || | |_ ___ `. | |
* ____) | | | | | | | |_) | | __/\__ \ _| |_| |_) | * | | / /\ \ | || | | \/ | | || | | | | || | | | `. \ | |
* |_____/|_|_| |_| |_| .__/|_|\___||___/ |_____| .__/ * | | / ____ \ | || | | |\ /| | | || | | | | || | | | | | | |
* | \/ | | | | | * | | _/ / \ \_ | || | _| |_\/_| |_ | || | _| |_ | || | _| |___.' / | |
* | \ / | __ _ _ __ |_|_ _ __ _ ___ _ __ |_| * | ||____| |____|| || ||_____||_____|| || | |_____| | || | |________.' | |
* | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__| * | | | || | | || | | || | | |
* | | | | (_| | | | | (_| | (_| | __/ | * | '--------------' || '--------------' || '--------------' || '--------------' |
* |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| * '----------------' '----------------' '----------------' '----------------'
* __/ | *
* |___/
*
* Copyright (C) 2022 Simples IP. * 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 #define AGENT_H 1
#include <database/database.h> #include <database/database.h>
#include <ami_c.h> #include <ami_c.h> // biblioteca ami_c
#include <main.h> #include <main.h>
/* struct para guardar valores da tabela agent */
struct s_table_agent { struct s_table_agent {
unsigned long long int id; unsigned long long int id; // id mariadb
char *name; char *name;
char *matricula; char *matricula;
char *status; char *status;
struct s_table_agent *next; 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 ); 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); 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); 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); 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 ); 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 ); 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 ); 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); int delete_agents_db(stmt_t type_stmt, unsigned long long int id);
#endif #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; MYSQL_STMT *stmt = NULL;
SET_STMT( stmt, type_stmt, 0 ); SET_STMT( stmt, type_stmt, 0 );

Loading…
Cancel
Save