#!/bin/sh
# Copyright (C) 2009 Ubicom, Inc.

if [ $# -ne 1 ] ; then
echo "Usage: dc_cstate_get <xml_doc_name>"
echo "   <xml_doc_name>: Name (and path) of XML document to dump."
exit 1
fi

XML_DOC=$1

STATE_MAJOR_NUMBER=$(cat /sys/devices/system/ubicom_default_classifier/ubicom_default_classifier0/default_classifier_dev_major)

#
# Mount the special file that allows us to read the state of the classifier
#
mknod /dev/ubicom_default_classifier c $STATE_MAJOR_NUMBER 0

#
# Prep the XML doc
#
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" > $XML_DOC
echo "<?xml-stylesheet type=\"text/xsl\" href=\"dc_cstate_style.xsl\"?>" >> $XML_DOC
echo "<dynamic_classifier_state>"  >> $XML_DOC

#
# Dump all cstat files to the XML doc
#
cat /dev/ubicom_default_classifier >> $XML_DOC

#
# End the XML doc
#
echo "</dynamic_classifier_state>" >> $XML_DOC

#
# No longer need the special file
#
rm /dev/ubicom_default_classifier
