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:
parent
9f78ad8d03
commit
3e183be533
@ -2,7 +2,7 @@ INCLUDES=${gammu_CFLAGS}
|
||||
yasnd_LDADD = ${libconfuse_LIBS}
|
||||
yasnd_LDADD += ${gammu_LIBS}
|
||||
bin_PROGRAMS = yasnd
|
||||
yasnd_SOURCES = yasnd.c
|
||||
yasnd_SOURCES = yasnd.c yasnd-gammu.c
|
||||
|
||||
distclean-local:
|
||||
rm -rf aclocal.m4 autom4te.cache depcomp install-sh missing configure Makefile.in config.h* &>/dev/null
|
||||
|
@ -19,7 +19,9 @@ AC_CHECK_HEADERS([fcntl.h signal.h stdlib.h string.h syslog.h unistd.h])
|
||||
AC_TYPE_PID_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_CHECK_FUNCS([strdup])
|
||||
AC_FUNC_FORK
|
||||
AC_FUNC_MALLOC
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
14
yasnd-gammu.c
Normal file
14
yasnd-gammu.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include "yasnd.h"
|
||||
|
||||
GSM_Error error; // structure to store possible gammu errors
|
||||
|
||||
bool check_gammu_error(GSM_Error err)
|
||||
{
|
||||
if (err == ERR_NONE) {
|
||||
return false;
|
||||
}
|
||||
char tmp[150];
|
||||
sprintf(tmp,"gammu failure: %s\n", GSM_ErrorString(err));
|
||||
log_event(tmp);
|
||||
return true;
|
||||
}
|
41
yasnd.c
41
yasnd.c
@ -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);
|
||||
}
|
||||
|
24
yasnd.h
Normal file
24
yasnd.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef YASND_H
|
||||
#define YASND_H
|
||||
|
||||
// Debug verbosity
|
||||
#define DEBUG_BASE 1
|
||||
#define DEBUG_ALL 2
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <gammu.h>
|
||||
|
||||
extern void log_event(const char *message);
|
||||
extern bool check_gammu_error(GSM_Error err);
|
||||
|
||||
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;
|
||||
|
||||
extern int hosts_count; // count of hosts
|
||||
extern int debug_flag;
|
||||
extern GSM_Error error; // structure to store possible gammu errors
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user