comparison src/checksignal.c @ 164:7d8a5bb874ad

EXPERIMENTAL: Change phisical channel by mq_recv(). KNOWN ISSUE: Cannnot split BS-TBS(BS1_1). enable compile recpt1ctl. SID can specified by recpt1ctl.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Mon, 01 Oct 2012 21:52:05 +0900
parents 4e39ce051c57
children 061ef2cd98f0
comparison
equal deleted inserted replaced
163:57eae2aec60d 164:7d8a5bb874ad
34 #include "pt1_dev.h" 34 #include "pt1_dev.h"
35 #include "tssplitter_lite.h" 35 #include "tssplitter_lite.h"
36 36
37 #define MAX_RETRY (2) 37 #define MAX_RETRY (2)
38 38
39 /* type definitions */
40 typedef int boolean;
41
42 /* globals */ 39 /* globals */
43 boolean f_exit = FALSE; 40 boolean f_exit = FALSE;
44 boolean use_bell = FALSE; 41 boolean use_bell = FALSE;
45 42
46 /* prototypes */ 43 /* prototypes */
47 int tune(char *channel, thread_data *tdata, char *device); 44 int tune(char *channel, thread_data *tdata, char *device);
48 int close_tuner(thread_data *tdata); 45 int close_tuner(thread_data *tdata);
49 46
50 void 47 void
51 cleanup(thread_data *tdata) 48 cleanup(void)
52 { 49 {
53 f_exit = TRUE; 50 f_exit = TRUE;
54 } 51 }
55 52
56 /* will be signal handler thread */ 53 /* will be signal handler thread */
57 void * 54 void *
58 process_signals(void *data) 55 process_signals(void *p)
59 { 56 {
60 sigset_t waitset; 57 sigset_t waitset;
61 int sig; 58 int sig;
62 thread_data *tdata = (thread_data *)data;
63 59
64 sigemptyset(&waitset); 60 sigemptyset(&waitset);
65 sigaddset(&waitset, SIGINT); 61 sigaddset(&waitset, SIGINT);
66 sigaddset(&waitset, SIGTERM); 62 sigaddset(&waitset, SIGTERM);
67 sigaddset(&waitset, SIGUSR1); 63 sigaddset(&waitset, SIGUSR1);
69 sigwait(&waitset, &sig); 65 sigwait(&waitset, &sig);
70 66
71 switch(sig) { 67 switch(sig) {
72 case SIGINT: 68 case SIGINT:
73 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); 69 fprintf(stderr, "\nSIGINT received. cleaning up...\n");
74 cleanup(tdata); 70 cleanup();
75 break; 71 break;
76 case SIGTERM: 72 case SIGTERM:
77 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); 73 fprintf(stderr, "\nSIGTERM received. cleaning up...\n");
78 cleanup(tdata); 74 cleanup();
79 break; 75 break;
80 case SIGUSR1: /* normal exit*/ 76 case SIGUSR1: /* normal exit*/
81 cleanup(tdata); 77 cleanup();
82 break; 78 break;
83 } 79 }
84 80
85 return NULL; /* dummy */ 81 return NULL; /* dummy */
86 } 82 }
87 83
88 void 84 void
89 init_signal_handlers(pthread_t *signal_thread, thread_data *tdata) 85 init_signal_handlers(pthread_t *signal_thread)
90 { 86 {
91 sigset_t blockset; 87 sigset_t blockset;
92 88
93 sigemptyset(&blockset); 89 sigemptyset(&blockset);
94 sigaddset(&blockset, SIGINT); 90 sigaddset(&blockset, SIGINT);
96 sigaddset(&blockset, SIGUSR1); 92 sigaddset(&blockset, SIGUSR1);
97 93
98 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL)) 94 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
99 fprintf(stderr, "pthread_sigmask() failed.\n"); 95 fprintf(stderr, "pthread_sigmask() failed.\n");
100 96
101 pthread_create(signal_thread, NULL, process_signals, tdata); 97 pthread_create(signal_thread, NULL, process_signals, NULL);
102 } 98 }
103 99
104 /* lookup frequency conversion table*/ 100 /* lookup frequency conversion table*/
105 ISDB_T_FREQ_CONV_TABLE * 101 ISDB_T_FREQ_CONV_TABLE *
106 searchrecoff(char *channel) 102 searchrecoff(char *channel)
307 } 303 }
308 fprintf(stderr, "No signal. Still trying: %s\n", device); 304 fprintf(stderr, "No signal. Still trying: %s\n", device);
309 } 305 }
310 306
311 fprintf(stderr, "device = %s\n", device); 307 fprintf(stderr, "device = %s\n", device);
312 tdata->ch = atoi(channel); 308 strncpy(tdata->ch, channel, sizeof(tdata->ch));
313 } 309 }
314 else { 310 else {
315 /* case 2: loop around available devices */ 311 /* case 2: loop around available devices */
316 if(tdata->table->type == CHTYPE_SATELLITE) { 312 if(tdata->table->type == CHTYPE_SATELLITE) {
317 tuner = bsdev; 313 tuner = bsdev;
360 if(tdata->tfd < 0) { 356 if(tdata->tfd < 0) {
361 fprintf(stderr, "Cannot tune to the specified channel\n"); 357 fprintf(stderr, "Cannot tune to the specified channel\n");
362 return 1; 358 return 1;
363 } 359 }
364 else { 360 else {
365 tdata->ch = atoi(channel); 361 strncpy(tdata->ch, channel, sizeof(tdata->ch));
366 } 362 }
367 } 363 }
368 364
369 return 0; /* success */ 365 return 0; /* success */
370 } 366 }
462 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); 458 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
463 return 1; 459 return 1;
464 } 460 }
465 461
466 /* spawn signal handler thread */ 462 /* spawn signal handler thread */
467 init_signal_handlers(&signal_thread, &tdata); 463 init_signal_handlers(&signal_thread);
468 464
469 /* tune */ 465 /* tune */
470 if(tune(argv[optind], &tdata, device) != 0) 466 if(tune(argv[optind], &tdata, device) != 0)
471 return 1; 467 return 1;
472 468