/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : DeviceInterface.h                                             */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _DEVICEINTERFACE_H
#define _DEVICEINTERFACE_H

#include "ourTypes.h"
#include "SemaphoreP.h"

/*
CLASS 
DeviceInterface

DESCRIPTION
Abstract class for reading and writing to a device.

AUTHOR
Tom O'Reilly

*/
class DeviceInterface {

public:

  ///////////////////////////////////////////////////////////////////
  // Constructor
  DeviceInterface(const char *name);

  virtual ~DeviceInterface();

  ///////////////////////////////////////////////////////////////////
  // Read from device
  virtual int read(char *buf, int maxBytes, int timeout) = 0;

  ///////////////////////////////////////////////////////////////////
  // Write to device
  virtual int write(const char *buf, int nBytes) = 0;

  ///////////////////////////////////////////////////////////////////
  // Reset device
  virtual void reset() = 0;

  ///////////////////////////////////////////////////////////////////
  // Take exclusive access to the device
  void take();

  ///////////////////////////////////////////////////////////////////
  // Release exclusive access to the device
  void release();

  ///////////////////////////////////////////////////////////////////
  // Device name
  const char *name();

  Boolean simulated();

protected:

  Boolean _simulated;

private:

  const char *_name;

  // Pointer to "protection" semaphore
  Semaphore *_protectSem;

};


#endif

