//=========================================================================
// Summary  : */
// Filename : _vcs.h
// Author   : */
// Project  : */
// Revision : 1
// Created  : 2000/08/19
// Modified : 2000/08/19
//=========================================================================
// Description :
//=========================================================================

#include <stdlib.h>
#include "System.h"
#include "Syslog.h"
#include "VehicleConfigurationServer.h"

void printUsage( void );

int main( int argc, char **argv )
{
     if( argc < 2 ) {
	  printUsage();
	  exit(-1);
     }

     try {
	  VehicleConfigurationIF *_vconfig = new VehicleConfigurationIF( "vcs", 1 );

	  if( !strnicmp(argv[1], "relo", 4 ) ) {
	       _vconfig->reloadTables();
	  } else if ( !strnicmp( argv[1], "kill", 4 ) ) {
	       _vconfig->kill();
	  } else {
	       printf("Unknown command \'%s\'\n", argv[1] );
	       printUsage();
	  }


     } catch( SharedObjectClient::MissingServer 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, "No VCS running (or kill successful)\n");
     } 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, "Caught exception: %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, "Caught unknown exception\n");
	  fprintf(stderr, "Is vehicleConfigurationServer running?\n");
     }

     return 0;

}

void printUsage( void )
{
     printf("Usage: vcs <command>\n\n");
     printf("Where <command is one of the following:\n");
     printf("    kill          Kill a VCS currently running\n");
     printf("    reload        Tell the VCS to reload\n");
}
