rewrite core to use libev event loop
[dvblast.git] / dvblast_mmi.sh
blob7b4f5d15351292a26e03fa78c270f7ab3bfc89ff
1 #!/bin/sh
2 ###############################################################################
3 # dvblast_mmi.sh
4 ###############################################################################
5 # Copyright (C) 1998-2008 VideoLAN
7 # Authors: Christophe Massiot <massiot@via.ecp.fr>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 ###############################################################################
24 BASE_DIR=`dirname $_`
28 # Check args
31 if test x"$1" != x"-r" -o -z "$2"; then
32 echo "Usage: $0 -r <remote socket> [<slot 0-n>]" >&2
33 exit 1
36 SOCKET=$2
37 SLOT=$3
39 if which dvblastctl >/dev/null; then
40 DVBLASTCTL="dvblastctl -r $SOCKET"
41 elif test -x "$PWD/dvblastctl"; then
42 DVBLASTCTL="$PWD/dvblastctl -r $SOCKET"
43 elif test -x "$BASE_DIR/dvblastctl"; then
44 DVBLASTCTL="$BASE_DIR/dvblastctl -r $SOCKET"
45 else
46 echo "Couldn't find dvblastctl"
47 exit 1
52 # Check adapter status
55 $DVBLASTCTL mmi_status >/dev/null
56 NUM_SLOTS=$?
58 if test $NUM_SLOTS -eq 255; then
59 echo "Unable to set up a connection" >&2
60 exit 2
62 if test $NUM_SLOTS -eq 0; then
63 echo "Adapter has no available CAM module" >&2
64 exit 3
66 if test -z $SLOT; then
67 echo "Defaulting to slot #0"
68 SLOT=0
70 if test "$SLOT" -ge $NUM_SLOTS; then
71 echo "Slot out of range, pick in the range 0-`expr $NUM_SLOTS - 1`" >&2
72 exit 3
77 # Check CAM status
80 $DVBLASTCTL mmi_slot_status $SLOT >/dev/null
81 STATUS=$?
83 if test $STATUS -ne 0; then
84 echo "Slot is not ready, retry later" >&2
85 exit 3
88 $DVBLASTCTL mmi_get $SLOT >/dev/null
89 STATUS=$?
91 if test $STATUS -eq 255; then
92 echo "Opening MMI session..."
93 $DVBLASTCTL mmi_open $SLOT
94 STATUS=$?
95 if test $STATUS -eq 255; then
96 echo "Communication error" >&2
97 exit 2
98 elif test $STATUS -ne 0; then
99 echo "Couldn't open MMI session" >&2
100 exit 4
102 sleep 3
107 # Da loop
110 while :; do
111 $DVBLASTCTL mmi_get $SLOT
112 STATUS=$?
114 case $STATUS in
115 255)
116 echo "Connection closed" >&2
117 exit 2
119 254)
120 echo -n "Your choice (empty for extra choices) ? "
122 253)
123 echo "CAUTION: the password won't be bulleted, be alone"
124 echo -n "Your choice (empty for extra choices) ? "
126 252)
127 sleep 1
128 continue
131 echo -n "Your choice: (B)ack, (C)lose or (R)etry ? "
134 echo -n "Your choice: [0-$STATUS], (C)lose or (R)etry ? "
136 esac
138 read -r ANSWER
140 case $STATUS in
141 254|253)
142 if test -z "$ANSWER"; then
143 echo -n "(B)ack, (C)lose or (R)etry ? "
144 read -r ANSWER
146 case "$ANSWER" in
147 B|b|Back|back|BACK)
148 if ! $DVBLASTCTL mmi_send_text $SLOT; then
149 echo "mmi_send_text failed, apparently" >&2
150 else
151 sleep 1
154 C|c|Close|close|CLOSE)
155 $DVBLASTCTL mmi_close $SLOT
156 exit 0
158 R|r|Retry|retry|RETRY)
162 echo "Invalid string, retry..."
164 esac
166 else
167 if ! $DVBLASTCTL mmi_send_text $SLOT "$ANSWER"; then
168 echo "mmi_send_text failed, apparently" >&2
169 else
170 sleep 1
176 case "$ANSWER" in
177 B|b|Back|back|BACK)
178 if ! $DVBLASTCTL mmi_send_choice $SLOT 0; then
179 echo "mmi_send_choice failed, apparently" >&2
180 else
181 sleep 1
184 C|c|Close|close|CLOSE)
185 $DVBLASTCTL mmi_close $SLOT
186 exit 0
188 R|r|Retry|retry|RETRY)
192 echo "$ANSWER" | grep -q "^[[:digit:]]\+\$"
193 if test $? -ne 0; then
194 echo "Invalid string, retry..."
195 else
196 if ! $DVBLASTCTL mmi_send_choice $SLOT "$ANSWER"; then
197 echo "mmi_send_choice failed, apparently" >&2
198 else
199 sleep 1
203 esac
205 esac
207 echo
208 done