#!/bin/sh

action=$1

param1=$2
param2=$3

# Function To Send Command To Director        
director () {
	command=$1
	echo -ne "$command\0" | nc -w 2 127.0.0.1 5020
}   

case "$action" in
	add)
		director "<c4soap name='AddDevice' session='0' operation='RWX' category='composer' async='False'><param name='idparent' type='number'>$param1</param><param name='c4z_name' type='string'>$param2.c4z</param></c4soap>"
		;;
	del)
		director "<c4soap name='RemoveItem' session='0' operation='RWX' category='composer' async='False'><param name='iditem' type='number'>$param1</param></c4soap>"
		;;
	set)
		director "<c4soap name='EditItemName' session='0' operation='RWX' category='composer' async='True'><param name='iditem' type='number'>$param1</param><param name='name' type='string'>$param2</param></c4soap>"
		;;
	init)
		director "<c4soap name='UpdateProjectC4i' session='0' operation='RWX' category='composer' async='False'><param name='name' type='string'>$param1.c4z</param></c4soap>"
		;;
	info)
		director "<c4soap name='GetDirectorInfo' async='False' />"
		;;
	refresh)
		director "<c4soap name='PIP' session='0' operation='RWX' category='composer' async='True' />"
		;;
	*)
		echo "c4.sh add|del|set|init|info|refresh"
		;;
esac 