/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : ArmTheGulper.cc						    */
/* Author   : rsm, hjt                                                      */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 21/03/2007                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include "MissionTimeAttribute.h"
#include "BooleanAttribute.h"
#include "ArmTheGulper.h"
#include "Syslog.h"

ArmTheGulper::ArmTheGulper()
   : Behavior(ArmTheGulperBehaviorName, Sequential)
{
   Attribute::Input *input;

   char nameStr[64];
   for( int i=0; i< NGULPERS; i++ )
   {
      sprintf( nameStr, "gulper%d", i );
      attributes.add(new BooleanAttribute(nameStr,
					  nameStr,
					  &_gulpersToArm[i], 0));
   }
   try 
   {
      _adaptiveIF = new AdaptiveSamplerIF(AdaptiveSamplerIFServerName);
   } 
   catch(...)
   {
      Syslog::write("ArmTheGulper:: -- Failed to initialize connection "
		    "to AdaptiveSamplerIF, exiting\n");
      throw;
   }
}


ArmTheGulper::~ArmTheGulper()
{
   delete _adaptiveIF ;
}

Boolean ArmTheGulper::validInput()
{
  return True;
}

Boolean ArmTheGulper::shouldBehaviorStart( )
{
     return bothSequence();
}

void ArmTheGulper::execute()
{
  // fpy : check for valid pointer first 
  if( NULL!=_adaptiveIF ) {
    //
    // Nothing fancy here.  Just do it.
    //
    _adaptiveIF->armGulper( _gulpersToArm );
    for( int i=0; i<NGULPERS; i++ ) 
      {
	if( _gulpersToArm[i] ) Syslog::write("Gulper %d is now armed.\n", i);
      }
  } else 
    Syslog::write("Armgulper:: -- not connected to AdaptiveSamplerIF\n");
  setState(Finished);
  return;
}






