author "Janos Kovacs"
description "This init script starts the tone generator daemon"

start on started hildon-desktop
stop on stopped dbus

console output

script
	set +e
        echo "Starting tonegend"
#       /usr/sbin/waitdbus system
	/etc/osso-af-init/af-defines.sh

	imsi=`dbus-send --system --type=method_call --print-reply=True \
        	   --dest=com.nokia.phone.SIM \
		   /com/nokia/phone/SIM Phone.Sim.get_imsi`
	rc=$?                                                                           
                                                                                
	if [ $rc -ne 0 ] ; then                                                         
	    mcc=""
	    echo "Could not obtain Mobile Country Code"
	else
	    mcc=`echo $imsi | cut -b 1-3`
	    echo "Mobile Country Code = $mcc"
	fi
                                                                                
	case $mcc in                                                                    
                                                                                
	 202 | 204 | 208 | 214 | 216 | 222 | 225 | 226 | 228 | 230 | 231 | \
	 232 | 238 | 240 | 244 | 246 | 247 | 248 | 260 | 262 | 266 | 268 | \
	 270 | 290 | 293 | 294 | 295 | 297 )
	    std="cept"                                            
	    signal_option="-s $std"
	    ;;                                              
                                                                                
	 302 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 332 | 544)                     
	    std="ansi"
	    signal_option="-s $std"
	    ;;                                              
                                                                                
	 302 | 440 | 441 )
	    std="japan"                                                              
	    signal_option="-s $std"
	    ;;                                             
                                                                                
	 *)
	    std="unknown"                                                                             
	    signal_option=""
	    ;;                                                     
                                                                                
	esac 

	echo "Signalling standard = $std"

        dtmf_props="module-stream-restore.id=x-maemo-key-pressed"
        ind_props="media.role=phone,module-stream-restore.id=sink-input-by-media-role:phone"
        notif_props="media.role=phone,module-stream-restore.id=sink-input-by-media-role:phone"
        dtmf_volume=100
        ind_volume=40
        notif_volume=40

        exec /usr/bin/tonegend $signal_option -b 100 -r 20 \
             -D $dtmf_props -I $ind_props -N $notif_props \
             --volume-dtmf $dtmf_volume --volume-indicator $ind_volume \
             --volume-notif $notif_volume > /dev/null
end script

respawn
