#!/bin/sh

# PROVIDE: uhidd
# REQUIRE: DAEMON cleanvar
# KEYWORD: nojail shutdown

# Usage:
#	uhidd start ugenX.Y	# start uhidd on device 'ugenX.Y'
#	uhidd stop ugenX.Y	# stop uhidd on device 'ugenX.Y'
#	uhidd start		# start uhidd on all ugen device.
#	uhidd stop		# stop all uhidd instances.

. /etc/rc.subr

name=uhidd
rcvar=uhidd_enable

load_rc_config $name

: ${uhidd_enable:=NO}

command=%%PREFIX%%/sbin/${name}
start_cmd=uhidd_start
required_modules=vkbd
pidprefix=/var/run/uhidd
pidfile=${2+$pidprefix.`basename $2`.pid}

uhidd_start()
{
	local dev pf

	if [ -n "$1" ]; then
		${command} ${uhidd_flags} $1
	else
		for dev in /dev/ugen*; do
			pf="${pidprefix}.`basename ${dev}`.pid"
			if [ ! -f ${pf} ]; then
				${command} ${uhidd_flags} ${dev}
			fi
		done
	fi
}

run_rc_command $*
