Mercurial > pt1
annotate recpt1/recpt1ctl.c @ 142:1e7718cc2556
use utf-8 instead of euc-jp
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 30 Apr 2014 11:26:24 +0900 |
parents | c9b1d21c5035 |
children |
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> |
140
c9b1d21c5035
separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
78
diff
changeset
|
10 #include "recpt1core.h" |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
11 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
12 #define MSGSZ 255 |
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 main(int argc, char **argv) |
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 int msqid; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
38 int msgflg = IPC_CREAT | 0666; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
39 key_t key = 0; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
40 int channel=0, recsec = 0, extsec=0; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
41 message_buf sbuf; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
42 size_t buf_length; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
43 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
44 int result; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
45 int option_index; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
46 struct option long_options[] = { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
47 { "pid", 1, NULL, 'p'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
48 { "channel", 1, NULL, 'c'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
49 { "extend", 1, NULL, 'e'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
50 { "time", 1, NULL, 't'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
51 { "help", 0, NULL, 'h'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
52 { "version", 0, NULL, 'v'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
53 { "list", 0, NULL, 'l'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
54 {0, 0, NULL, 0} /* terminate */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
55 }; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
56 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
57 while((result = getopt_long(argc, argv, "p:c:e:t:hvl", |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
58 long_options, &option_index)) != -1) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
59 switch(result) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
60 case 'h': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
61 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
62 show_usage(argv[0]); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
63 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
64 show_options(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
65 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
66 show_channels(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
67 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
68 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
69 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
70 case 'v': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
71 fprintf(stderr, "%s %s\n", argv[0], version); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
72 fprintf(stderr, "control command for recpt1.\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
73 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
74 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
75 case 'l': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
76 show_channels(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
77 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
78 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
79 /* following options require argument */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
80 case 'p': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
81 key = (key_t)atoi(optarg); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
82 fprintf(stderr, "Pid = %d\n", key); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
83 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
84 case 'c': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
85 channel = atoi(optarg); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
86 fprintf(stderr, "Channel = %d\n", channel); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
87 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
88 case 'e': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
89 parse_time(optarg, &extsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
90 fprintf(stderr, "Extend %d sec\n", extsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
91 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
92 case 't': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
93 parse_time(optarg, &recsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
94 fprintf(stderr, "Total recording time = %d sec\n", recsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
95 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
96 } |
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 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
99 if(!key) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
100 fprintf(stderr, "Arguments are necessary!\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
101 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
|
102 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
103 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
104 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
105 if ((msqid = msgget(key, msgflg )) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
106 perror("msgget"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
107 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
108 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
109 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
110 sbuf.mtype = 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
111 sprintf(sbuf.mtext, "ch=%d t=%d e=%d", channel, recsec, extsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
112 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
113 buf_length = strlen(sbuf.mtext) + 1 ; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
114 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
115 if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
116 perror("msgsnd"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
117 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
118 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
119 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
120 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
121 } |