Split out GAMMU-related code from library into daemon.

Add proper optional support for GAMMU via build-time options.
This commit fixes #4, but some additional checks maybe needed.
This commit is contained in:
Sergey Popov 2013-09-02 22:54:14 +04:00
parent badad6874c
commit a1c83a3df2
8 changed files with 23 additions and 8 deletions

View File

@ -1,6 +1,6 @@
SUBDIRS = lib @DAEMON@
include_HEADERS = yasnd.h yasnd-gammu.h yasnd-log.h yasnd-lpt.h
include_HEADERS = yasnd.h yasnd-log.h yasnd-lpt.h
distclean-local:
rm -rf aclocal.m4 m4 autom4te.cache compile depcomp install-sh missing configure Makefile.in config.h* &>/dev/null

View File

@ -15,6 +15,7 @@ AM_PROG_CC_C_O
LT_INIT
# Checks for libraries.
AC_CHECK_LIB(pthread, pthread_create)
PKG_CHECK_MODULES([libconfuse], [libconfuse >= 2.0])
# Checks for header files.

View File

@ -1,10 +1,11 @@
include_HEADERS = $(top_srcdir)/yasnd.h yasnd-sock.h
include_HEADERS = $(top_srcdir)/yasnd.h yasnd-gammu.h yasnd-sock.h
yasnd_LDADD = ${libconfuse_LIBS}
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
yasnd_LDADD += @GAMMU_LIBS@
sbin_PROGRAMS = yasnd
yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-sock.c
yasnd_CPPFLAGS = -I$(top_srcdir)
yasnd_SOURCES = yasnd.c yasnd-gammu.c yasnd-ipc.c yasnd-sock.c
yasnd_CPPFLAGS = -I$(top_srcdir) @GAMMU_CFLAGS@
distclean-local:
rm -f Makefile.in &>/dev/null

View File

@ -1,10 +1,15 @@
#include <gammu.h>
#include "config.h"
#include "yasnd.h"
#include "yasnd-log.h"
#ifdef HAVE_LIBGAMMU
#include <gammu.h>
#endif
char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0"
char* phone_model=NULL; // gammu phone model, for example: "at"
char* phone_connection=NULL; // gammu phone connection type, for example: "at"
#ifdef HAVE_LIBGAMMU
GSM_Error error; // structure to store possible gammu errors
GSM_StateMachine *state_machine=NULL; // structure to interact with mobile phones
volatile gboolean gammu_shutdown=FALSE; // variable that indicates gammu shutdown
@ -180,3 +185,4 @@ bool gammu_send_sms(const char* message)
}
return true;
}
#endif

View File

@ -1,3 +1,4 @@
#include "config.h"
#include <sys/ipc.h>
#include <sys/msg.h>
#include <pthread.h>
@ -70,6 +71,7 @@ void* ipc_queue_loop(void* param)
char dbg_txt[150];
sprintf(dbg_txt,"Read IPC message - Type: %ld Text: %s", qbuf.mtype, qbuf.mtext);
log_debug(dbg_txt,DEBUG_ALL);
#ifdef HAVE_LIBGAMMU
if (qbuf.mtype==SMS_RECEIVE_TYPE && sms_enable)
{
pid_t pid = fork();
@ -103,6 +105,7 @@ void* ipc_queue_loop(void* param)
// STUB: need to react on status, returned by thread
waitpid(pid,NULL,0);
}
#endif
}
}

View File

@ -1,3 +1,4 @@
#include "config.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
@ -152,9 +153,11 @@ void init()
hosts[i].alert_sent=false;
hosts[i].reaction_obtained=false;
}
#ifdef HAVE_LIBGAMMU
// initialize gammu structures
if (sms_enable)
gammu_init();
#endif
// initialize LPT control circuit
lpt_init();
// initialize server socket
@ -281,8 +284,10 @@ void signal_handler(int signum)
ipc_free();
// free config structure
cfg_free(cfg);
#ifdef HAVE_LIBGAMMU
// free gammu structure
gammu_free();
#endif
// free hosts structures memory
if (hosts!=NULL)
free(hosts);

View File

@ -1,7 +1,6 @@
lib_LTLIBRARIES = libyasnd.la
libyasnd_la_SOURCES = libyasnd.c yasnd-gammu.c yasnd-log.c yasnd-lpt.c
libyasnd_la_CPPFLAGS = -I$(top_srcdir) @GAMMU_CFLAGS@
libyasnd_la_LIBADD = @GAMMU_LIBS@
libyasnd_la_SOURCES = libyasnd.c yasnd-log.c yasnd-lpt.c
libyasnd_la_CPPFLAGS = -I$(top_srcdir)
distclean-local:
rm -f Makefile.in &>/dev/null