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:
Sergey Popov 2011-11-29 13:47:48 +04:00
parent 9f78ad8d03
commit 3e183be533
5 changed files with 50 additions and 33 deletions

View File

@ -2,7 +2,7 @@ INCLUDES=${gammu_CFLAGS}
yasnd_LDADD = ${libconfuse_LIBS} yasnd_LDADD = ${libconfuse_LIBS}
yasnd_LDADD += ${gammu_LIBS} yasnd_LDADD += ${gammu_LIBS}
bin_PROGRAMS = yasnd bin_PROGRAMS = yasnd
yasnd_SOURCES = yasnd.c yasnd_SOURCES = yasnd.c yasnd-gammu.c
distclean-local: distclean-local:
rm -rf aclocal.m4 autom4te.cache depcomp install-sh missing configure Makefile.in config.h* &>/dev/null rm -rf aclocal.m4 autom4te.cache depcomp install-sh missing configure Makefile.in config.h* &>/dev/null

View File

@ -19,7 +19,9 @@ AC_CHECK_HEADERS([fcntl.h signal.h stdlib.h string.h syslog.h unistd.h])
AC_TYPE_PID_T AC_TYPE_PID_T
# Checks for library functions. # Checks for library functions.
AC_CHECK_FUNCS([strdup])
AC_FUNC_FORK AC_FUNC_FORK
AC_FUNC_MALLOC
AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([Makefile])
AC_OUTPUT AC_OUTPUT

14
yasnd-gammu.c Normal file
View 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
View File

@ -10,17 +10,8 @@
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <confuse.h> #include <confuse.h>
#include <gammu.h>
// Debug verbosity #include "yasnd.h"
#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;
cfg_t *cfg; // pointer to configuration structure cfg_t *cfg; // pointer to configuration structure
host_decl* hosts=NULL; // structure with hosts' definitions 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() void init()
{ {
// Initialize config parsing library // Initialize config parsing library
@ -93,17 +73,14 @@ void init()
// initialize gammu structures // initialize gammu structures
GSM_InitLocales(NULL); GSM_InitLocales(NULL);
state_machine = GSM_AllocStateMachine(); state_machine = GSM_AllocStateMachine();
// read gammu config /* Set gammu configuration */
INI_Section *gammu_cfg; GSM_Config *gammu_cfg = GSM_GetConfig(state_machine, 0);
GSM_Error error; // first, free old values and set new one
/* Find it */ free(gammu_cfg->Device);
error = GSM_FindGammuRC(&gammu_cfg, NULL); gammu_cfg->Device = strdup("/dev/ttyACM0");
check_gammu_error(error); free(gammu_cfg->Connection);
/* Read it */ gammu_cfg->Connection = strdup("at");
error = GSM_ReadConfig(gammu_cfg, GSM_GetConfig(state_machine, 0), 0); strcpy(gammu_cfg->Model, "at");
check_gammu_error(error);
/* Free allocated memory */
INI_Free(gammu_cfg);
/* We care only about first configuration */ /* We care only about first configuration */
GSM_SetConfigNum(state_machine, 1); GSM_SetConfigNum(state_machine, 1);
} }

24
yasnd.h Normal file
View 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