#ifndef _SMARTSAMPLERINPUT_H
#define _SMARTSAMPLERINPUT_H


/****************************************************************************
 *
 * Message queue for SmartSampler input from server to driver.  Current
 * commands are:
 *
 * Suspend => Suspend the indexed DecisionTool.  This means that
 *            updates to DT state are still triggered, but requests to
 *            fire will be ignored.
 * Resume => Remove suspension of indexed DT.
 * Reset => DT-specific command to reset state.  Handled internally within the
 *          DecisionTool code.

 * DumpDTState => Write to syslog the top level state of the indexed
 *                DT (if index -1 given, write them all).  This
 *                includes DT number, suspended or not, time of last
 *                firing along with maxwait time associated with this
 *                DT, and list of allocated gulpers (even if they have been fired).
 * Allocate => takes a (short) gulper num as target and (short) DT index as arg.
 * Fire => takes a (short) gulper number as target
 *
 ****************************************************************************/

#include "MessageQueue.h"
#include "ssdbg.hh"

// This allows us to suspend/resume/reset up to ten DT's AND allocate
// all ten gulpers in one callback period.
#define MAX_INPUT_SIZE 20

#define SmartSamplerInputName "SmartSamplerInput"

class SmartSamplerInput : public MessageQueue {
  public:
  SmartSamplerInput( MessageQueue::Access access = NoAccess )
    : MessageQueue( SmartSamplerInputName, sizeof( Command ),
		    MAX_INPUT_SIZE, access, False ){ssdbg(DBG_LOAD)("Initializing SmartSamplerInput");};

  ~SmartSamplerInput(){ssdbg(DBG_CLEAN)("destroying SmartSamplerInput");};

  enum SmartSamplerCmds {
    cmdNone = 0,
    cmdSuspend,
    cmdResume,
    cmdReset,
    cmdDumpDTState,
    cmdAllocate,
    cmdFire
  };

  struct Command 
  {
    SmartSamplerCmds _cmd;
    short _target, _arg;
    
    Command() {
      _cmd = SmartSamplerInput::cmdNone;
      _target = -1;
      _arg = -1;
    };
    Command( SmartSamplerCmds cmd )
    {
      _cmd = cmd;
      _target = -1;
      _arg = -1;
    }
    Command( SmartSamplerCmds cmd, short target )
    {
      _cmd = cmd;
      _target = target;
      _arg = -1;
    }
    Command( SmartSamplerCmds cmd, short target, short arg )
    {
      _cmd = cmd;
      _target = target;
      _arg = arg;
    }
  };
    
  int read( Command *cmd ){return MessageQueue::read((void *)cmd);};
  int write( Command *cmd ){return MessageQueue::write((void *)cmd);};
};

#endif
