From 671d569f36449720862dfaf40fe005166ba7b50b Mon Sep 17 00:00:00 2001 From: Sergey Popov Date: Tue, 20 Dec 2011 17:02:34 +0400 Subject: [PATCH] implement SMS reading --- yasnd-ipc.c | 29 ++++++++++++++++++++++++----- yasnd.h | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/yasnd-ipc.c b/yasnd-ipc.c index 23e362e..9efe007 100644 --- a/yasnd-ipc.c +++ b/yasnd-ipc.c @@ -71,6 +71,22 @@ int ipc_queue_loop() char dbg_txt[150]; sprintf(dbg_txt,"Read IPC message - Type: %ld Text: %s", qbuf.mtype, qbuf.mtext); log_debug(dbg_txt,DEBUG_ALL); + if (qbuf.mtype==SMS_RECEIVE_TYPE && sms_send_enable) + { + pid_t pid = fork(); + if (pid < 0) { + log_event("Error: can not fork child :("); + exit(EXIT_FAILURE); + } + // If pid == 0, then we are in the child + if (pid == 0) { + gammu_read_sms(); + exit(EXIT_SUCCESS); + } + // wait for SMS reading thread + // STUB: need to react on status, returned by thread + waitpid(pid,NULL,0); + } if (qbuf.mtype==SMS_SEND_TYPE && sms_send_enable) { log_debug(qbuf.mtext,DEBUG_BASE); @@ -101,7 +117,10 @@ int ipc_sms_reading_loop() while(1) { sleep(30); /* wait 30 seconds */ - //gammu_read_sms(); + mymsgbuf qbuf; + qbuf.mtype=SMS_RECEIVE_TYPE; + qbuf.mtext[0]=(char)0; + send_message(qid,&qbuf); } } @@ -111,8 +130,8 @@ void ipc_init() unsigned char ipc_child_stack[16384]; ipc_clone_pid=clone(ipc_queue_loop,ipc_child_stack+8192,CLONE_VM,NULL); // start loop, that handles new incoming SMS -// unsigned char sms_child_stack[16384]; -// ipc_sms_read_clone_pid=clone(ipc_sms_reading_loop,sms_child_stack+8192,CLONE_VM,NULL); + unsigned char sms_child_stack[16384]; + ipc_sms_read_clone_pid=clone(ipc_sms_reading_loop,sms_child_stack+8192,CLONE_VM,NULL); // } @@ -120,7 +139,7 @@ void ipc_free() { kill(ipc_clone_pid,SIGTERM); waitpid(ipc_clone_pid,NULL,__WCLONE); -// kill(ipc_sms_read_clone_pid,SIGTERM); -// waitpid(ipc_sms_read_clone_pid,NULL,__WCLONE); + kill(ipc_sms_read_clone_pid,SIGTERM); + waitpid(ipc_sms_read_clone_pid,NULL,__WCLONE); remove_queue(qid); } diff --git a/yasnd.h b/yasnd.h index cf696de..e22b93f 100644 --- a/yasnd.h +++ b/yasnd.h @@ -42,6 +42,7 @@ extern void log_debug(const char *message,int verbosity); extern void* allocate_memory(int bytes); extern bool gammu_init(); extern bool gammu_send_sms(const char* message); +extern bool gammu_read_sms(); extern void ipc_init(); extern void ipc_free(); extern int send_message(int qid, mymsgbuf* qbuf);