annotate src/recpt1ctl.c @ 176:2ae60285f383

Change DLNA display name.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Mon, 05 Nov 2012 23:11:32 +0900
parents 061ef2cd98f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 #include <sys/types.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2 #include <sys/ipc.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 #include <sys/msg.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 #include <stdio.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 #include <stdlib.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 #include <string.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 #include <ctype.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 #include <getopt.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 #include "version.h"
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
12 #include "pt1_common.h"
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 void
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 show_usage(char *cmd)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17 fprintf(stderr, "Usage: \n%s --pid pid [--channel channel] [--extend time_to_extend] [--time recording_time]\n", cmd);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 void
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22 show_options(void)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 fprintf(stderr, "Options:\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25 fprintf(stderr, "--pid: Process id of recpt1 to control\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 fprintf(stderr, "--channel: Tune to specified channel\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 fprintf(stderr, "--extend: Extend recording time\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
28 fprintf(stderr, "--time: Set total recording time\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29 fprintf(stderr, "--help: Show this help\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 fprintf(stderr, "--version: Show version\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 fprintf(stderr, "--list: Show channel list\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
34 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35 parse_time(char *rectimestr, int *recsec)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37 /* indefinite */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
38 if(!strcmp("-", rectimestr)) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39 *recsec = -1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
40 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 /* colon */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 else if(strchr(rectimestr, ':')) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 int n1, n2, n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45 *recsec = n1 * 3600 + n2 * 60 + n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 *recsec = n1 * 3600 + n2 * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 /* HMS */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51 char *tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52 char *p1, *p2;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
53
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 tmpstr = strdup(rectimestr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55 p1 = tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59 /* hour */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 *recsec += atoi(p1) * 3600;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
65 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
66 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
68 /* minute */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
69 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
70 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
71 *recsec += atoi(p1) * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
72 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
73 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
77 /* second */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78 *recsec += atoi(p1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 free(tmpstr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
81 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83 return 0; /* success */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
84 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
85
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
86 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87 main(int argc, char **argv)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89 int msqid;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90 int msgflg = IPC_CREAT | 0666;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 key_t key = 0;
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
92 int recsec = 0, extsec=0;
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
93 char *channel = NULL;
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
94 pt1_message_buf sbuf;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95 size_t buf_length;
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
96 char *sid_list = NULL;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 int result;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99 int option_index;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 struct option long_options[] = {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 { "pid", 1, NULL, 'p'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 { "channel", 1, NULL, 'c'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 { "extend", 1, NULL, 'e'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 { "time", 1, NULL, 't'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 { "help", 0, NULL, 'h'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 { "version", 0, NULL, 'v'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 { "list", 0, NULL, 'l'},
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
108 { "sid", 1, NULL, 'i'},
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
109 { "SID", 1, NULL, 'i'},
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 {0, 0, NULL, 0} /* terminate */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 };
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
113 while((result = getopt_long(argc, argv, "p:c:e:t:hvli",
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 long_options, &option_index)) != -1) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 switch(result) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 case 'h':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 show_usage(argv[0]);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 show_options();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 show_channels();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 case 'v':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 fprintf(stderr, "%s %s\n", argv[0], version);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 fprintf(stderr, "control command for recpt1.\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 case 'l':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 show_channels();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 /* following options require argument */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 case 'p':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 key = (key_t)atoi(optarg);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 fprintf(stderr, "Pid = %d\n", key);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 case 'c':
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
141 channel = optarg;
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
142 fprintf(stderr, "Channel = %s\n", channel);
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 case 'e':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 parse_time(optarg, &extsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 fprintf(stderr, "Extend %d sec\n", extsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 case 't':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 parse_time(optarg, &recsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 fprintf(stderr, "Total recording time = %d sec\n", recsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 break;
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
152 case 'i':
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
153 sid_list = optarg;
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
154 break;
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 if(!key) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 fprintf(stderr, "Arguments are necessary!\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 if ((msqid = msgget(key, msgflg )) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 perror("msgget");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 sbuf.mtype = 1;
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
170 sprintf(sbuf.mtext, "ch=%s t=%d e=%d i=%s", channel, recsec, extsec, sid_list);
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 buf_length = strlen(sbuf.mtext) + 1 ;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 perror("msgsnd");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 }