#!/bin/sh
#
# Changelog:
#	- Wed May 12 2010 - Guillaume Catto <guillaume.catto@alcatel-lucent.com>
#	* Script creation

#
# CONFIG VARIABLES
##################
HELPERPATH=/usr/lib/send_infra

# arg_summary is the summary on the command line except for the "-w|--wait" option
arg_summary="int:<level> boolean:<force> string:<caller> string:<log>"
arg_help="call the reboot method of Platform module with following parameters\n<level>		define the type of reboot (defined by platform, soft, hard)\n<force>		force reboot now or wait until locks are released\n<caller>	module name\n<log>		brief description."

#
# FUNCTION DEFINITION
#####################
source $HELPERPATH/.functions

############
### MAIN ###
############
: "Overwrite configuration varibles"
####################################
# sendAndWait will send a message and check the existence of the file each $sleeptime and at most for $timeout microseconds

# timeout in seconds
#timeout=5

# sleeptime in microseconds
#sleeptime=1000000

: "PROCESSING COMMAND LINE"
###########################
WAIT=0
RET=0
unset level
unset force
unset caller_str
unset log_str

[[ $# -eq 0 ]] && RET=1 && set -- -h

while [ $# -ne 0 ]; do
    case "$1" in 
        -h|--help) : "help"
            help
            exit $RET
        ;;
        -w|--wait) : "will wait"
            WAIT=1
		;;
		*)
			[[ -z $level ]] && level=$1 && shift
			[[ -z $force ]] && force=$1 && shift
			[[ -z $caller_str ]] && caller_str=$1 && shift
			[[ -z $log_str ]] && log_str=$1 && shift
		;;
	    esac
    shift
done

: "Check the arguments"
#######################
if [[ "$force" != "true" && "$force" != "false" ]]; then
	echoerror "Invalid boolean argument (expecting true/false, get $force)"
	exit 1
fi

if [[ -z $(echo $level | grep [[:digit:]]) ]]; then
	echoerror "Invalid level argument (expecting integer, get $level)"
	exit 1
fi

: "Send command"
################
dbus-send --type="method_call" --dest="com.alcatel.ICTouch.PlatformService" /Platform com.alcatel.ICTouch.ICTInterface.reboot int32:$level boolean:$force string:"$caller_str" string:"$log_str"
RET=$?

: "Post sending"
################

exit $RET
