//=========================================================================
// Summary  :
// Filename : _dumpConfig.cc
// Author   : marsh
// Project  :
// Revision : 1
// Created  : 2000/08/19
// Modified : 2000/08/19
//=========================================================================
// Description :
//=========================================================================

#include <stdio.h>
#include <stdlib.h>

#include "Syslog.h"
#include "VehicleConfigurationIF.h"

main( int argc, char **argv )
{
	VehicleConfigurationIF::DeviceInfo devInfo;

	try {
	    //  fprintf(stderr,"Before new\n");
	    VehicleConfigurationIF *_vconfig = new VehicleConfigurationIF("dumpConfig");
	    // fprintf(stderr,"After new\n");
	    short devCount = _vconfig->processCount();
	    // fprintf(stderr,"After count\n");
	    VehicleConfigurationIF::Name pname;
	    VehicleConfigurationIF::Driver sname;
	    VehicleConfigurationIF::Driver dname;
	    VehicleConfigurationIF::Name ifname;
	    VehicleConfigurationIF::Name onFault;
	    VehicleConfigurationIF::Name onFailure;
	    short ifCount;
	    int pid;
	    short s;
	    printf("%3s %20s %20s %20s %30s %5s %3s %10s %10s\n",
		   " # ", "Name", "Server Name", "Driver Name", "IF Name", "PID", "# IFs","OnFault","OnFailure" );
	    printf("%3s %20s %20s %20s %30s %5s %3s %10s %10s\n",
		   "---", "----", "--------", "-------", "-------", "---", "---","-----","-----" );
	    for ( int i=0; i<devCount; i++)
		{
			s = _vconfig->getProcessName(i,pname);
			s = _vconfig->getProcessServer(i,sname);
			s = _vconfig->getProcessDriver(i,dname);
			s = _vconfig->getIFName(i,ifname);
			ifCount = _vconfig->getInterfaceCount(i);
			pid = _vconfig->getPID( i );
			s = _vconfig->getProcessFaultAction(pname,onFault);
			s = _vconfig->getProcessFailureAction(pname,onFailure);
			printf("%3d %20s %20s %20s %30s %5d %3d %10s %10s\n",i,pname,sname,dname,ifname,pid,ifCount, onFault, onFailure);
		}
/*
		Syslog::write("dumpConfig -- Found %d processes", devCount );

		for( short i =0; i<devCount; i++ ) {
		_vconfig->deviceInfo( i, &devInfo );

		Syslog::write("%-20s%-20s%-3d%-6d%-10s%-4d",
		devInfo.name,
		devInfo.port,
		devInfo.debug,
		devInfo.pid,
		devInfo.interfaceName );

		}

		delete _vconfig;
		*/
	}
		catch(Exception e) {
		// Used to syslog::write, but since we're dealing with the vehicleConfigurationServer,
		//  it's best not to do something that's gonna try to access vcs (that's why we got an
		//  exception, after all.
		fprintf(stderr, "dumpConfig -- Caught: %s\n", e.msg );
		fprintf(stderr, "Is vehicleConfigurationServer running?\n");
	}
		catch(...) {
		// Used to syslog::write, but since we're dealing with the vehicleConfigurationServer,
		//  it's best not to do something that's gonna try to access vcs (that's why we got an
		//  exception, after all.
		fprintf(stderr, "dumpConfig -- Caught unknown error\n");
		fprintf(stderr, "Is vehicleConfigurationServer running?\n");
	}

}
