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@ 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: distclean-local:
rm -rf aclocal.m4 m4 autom4te.cache compile depcomp install-sh missing configure Makefile.in config.h* &>/dev/null 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 LT_INIT
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB(pthread, pthread_create)
PKG_CHECK_MODULES([libconfuse], [libconfuse >= 2.0]) PKG_CHECK_MODULES([libconfuse], [libconfuse >= 2.0])
# Checks for header files. # 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 = ${libconfuse_LIBS}
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
yasnd_LDADD += @GAMMU_LIBS@
sbin_PROGRAMS = yasnd sbin_PROGRAMS = yasnd
yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-sock.c yasnd_SOURCES = yasnd.c yasnd-gammu.c yasnd-ipc.c yasnd-sock.c
yasnd_CPPFLAGS = -I$(top_srcdir) yasnd_CPPFLAGS = -I$(top_srcdir) @GAMMU_CFLAGS@
distclean-local: distclean-local:
rm -f Makefile.in &>/dev/null rm -f Makefile.in &>/dev/null

View File

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

View File

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

View File

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

View File

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