/*
********************************************************
Copyright 2000 MBARI.
MBARI Proprietary Information. All rights reserved.
NOTE: This file is automatically generated.
DO NOT MODIFY.
********************************************************
*/

#ifndef __SmartSamplerIF_H
#define __SmartSamplerIF_H

#include "TaskInterface.h"


#define SmartSamplerIFServerName "SmartSamplerIFServer"

/*
  Interface definitions for the smartsampler server.
*/
class SmartSamplerIF : public TaskInterface {

  friend class SmartSamplerIF_SK;

  public:

  // Forward declarations of public structures
  struct PerGulperInfo;
  
  enum GulperState {
    Free = 0,
    Allocated,
    Fired
  };

  
  typedef SmartSamplerIF::PerGulperInfo GulperInfoArrayType[10];
  
  struct PerGulperInfo {
    double time;
    // Time of last change to state or allocation. 
    short dtid;
    // DecisionTool index this gulper is allocated to. 
    SmartSamplerIF::GulperState curstate;
  };
  SmartSamplerIF(const char *name, int timeout = 10);

  SmartSamplerIF(const char *name, const char *serverName, int timeout = 10);

  ~SmartSamplerIF();

  // Suspend/resume given DecisionTool.  Suspended DTs keep running
  // as normal, but do not trigger gulpers.
  void dtSuspend(short suspendNum);

  void dtResume(short resumeNum);

  // Reset state (erase memory) in given DT.  Effect depends on DT.
  void dtReset(short resetNum);

  // Get the number of instantiated DT's NOT INCLUDING 0.  Since we
  // never de-instantiate DT's, this is the index of the last DT
  // instantiated.
  void dtNum(short *numDTs);

  // For debugging: dump out info for one or all decision tools
  void dtDumpState();

  void dtDumpState(short dumpNum);

  // (re)allocated a single gulper to a single DT (overwrites previous
  // allocation).  NOTE: allocation to DT number 0 is equivalent to
  // calling the gulperFire command.
  // NOTE2: allocation to DT < 0 or greater than number instantiated
  // will deallocate the gulper.
  void gulperAllocate(short gulperNum, short dtNum);

  // return state of all gulpers
  void gulperState(SmartSamplerIF::GulperInfoArrayType gulperInfo);

  // Direct firing request.  Will still be arbitrated along with
  // other decision tools, shows up as DT number 0 in state info.
  void gulperFire(short gulperNum);

  // Simplified version of above: return the gulper number and
  // time of the last gulper fired, or (-1,-1) if none have been
  // fired.
  void gulperLastFired(double *gulperTime, short *gulperNum);

  
  protected:

  // Message codes for each method
  enum SmartSamplerIFMsgCode {
    DtSuspendMsgCode,
    DtResumeMsgCode,
    DtResetMsgCode,
    DtNumMsgCode,
    DtDumpStateMsgCode,
    DtDumpState01MsgCode,
    GulperAllocateMsgCode,
    GulperStateMsgCode,
    GulperFireMsgCode,
    GulperLastFiredMsgCode
  };

  // Define message structure for each method
  struct DtSuspendMsg : Request, Reply {
    short suspendNum;
  
  } _dtSuspendMsg;

  struct DtResumeMsg : Request, Reply {
    short resumeNum;
  
  } _dtResumeMsg;

  struct DtResetMsg : Request, Reply {
    short resetNum;
  
  } _dtResetMsg;

  struct DtNumMsg : Request, Reply {
    short numDTs;
  
  } _dtNumMsg;

  struct DtDumpStateMsg : Request, Reply {
  
  } _dtDumpStateMsg;

  struct DtDumpState01Msg : Request, Reply {
    short dumpNum;
  
  } _dtDumpState01Msg;

  struct GulperAllocateMsg : Request, Reply {
    short gulperNum;
    short dtNum;
  
  } _gulperAllocateMsg;

  struct GulperStateMsg : Request, Reply {
    SmartSamplerIF::GulperInfoArrayType gulperInfo;
  
  } _gulperStateMsg;

  struct GulperFireMsg : Request, Reply {
    short gulperNum;
  
  } _gulperFireMsg;

  struct GulperLastFiredMsg : Request, Reply {
    double gulperTime;
    short gulperNum;
  
  } _gulperLastFiredMsg;

};

#endif

