implement SMS reading

This commit is contained in:
Sergey Popov 2011-12-20 17:02:34 +04:00
parent fba4ffb66e
commit 671d569f36
2 changed files with 25 additions and 5 deletions

View File

@ -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);
}

View File

@ -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);