Move gammu-related functions into separate file. Change "check_gammu_error" function to return error state. Some configure.ac dependecies added

This commit is contained in:
2011-11-29 13:47:48 +04:00
parent 9f78ad8d03
commit 3e183be533
5 changed files with 50 additions and 33 deletions

41
yasnd.c
View File

@ -10,17 +10,8 @@
#include <signal.h>
#include <string.h>
#include <confuse.h>
#include <gammu.h>
// Debug verbosity
#define DEBUG_BASE 1
#define DEBUG_ALL 2
typedef struct {
char* hostname; // address of host
pid_t helper_pid; // pid of helper('pinger') child process
int fail_count; // how many times in a row host was unreachable
} host_decl;
#include "yasnd.h"
cfg_t *cfg; // pointer to configuration structure
host_decl* hosts=NULL; // structure with hosts' definitions
@ -49,17 +40,6 @@ void* allocate_memory(int bytes)
}
}
void check_gammu_error(GSM_Error err)
{
if (err == ERR_NONE) {
return;
}
char tmp[150];
sprintf(tmp,"gammu failure: %s\n", GSM_ErrorString(err));
log_event(tmp);
exit(EXIT_FAILURE);
}
void init()
{
// Initialize config parsing library
@ -93,17 +73,14 @@ void init()
// initialize gammu structures
GSM_InitLocales(NULL);
state_machine = GSM_AllocStateMachine();
// read gammu config
INI_Section *gammu_cfg;
GSM_Error error;
/* Find it */
error = GSM_FindGammuRC(&gammu_cfg, NULL);
check_gammu_error(error);
/* Read it */
error = GSM_ReadConfig(gammu_cfg, GSM_GetConfig(state_machine, 0), 0);
check_gammu_error(error);
/* Free allocated memory */
INI_Free(gammu_cfg);
/* Set gammu configuration */
GSM_Config *gammu_cfg = GSM_GetConfig(state_machine, 0);
// first, free old values and set new one
free(gammu_cfg->Device);
gammu_cfg->Device = strdup("/dev/ttyACM0");
free(gammu_cfg->Connection);
gammu_cfg->Connection = strdup("at");
strcpy(gammu_cfg->Model, "at");
/* We care only about first configuration */
GSM_SetConfigNum(state_machine, 1);
}