//-*-c++-*---------------------------------------------------------------------
// moDevSim.h
//
// This file contains definitions for a single-surface device simulator 
// class for use with the UDF toolkit.
//
// CLASSES:
//
// MODeviceSimulator
//-----------------------------------------------------------------------------
// $Source: /projects/HMS/nsr/udfCore/devs/moDevSim.h,v $
// $Revision: 1.2 $     $Author: hmgr $
// $State: Exp $        $Locker:  $
// $Date: 96/05/09 15:41:00 $
//-----------------------------------------------------------------------------
//      Unpublished Confidential Information of Hewlett-Packard
//      Company. Do not disclose.  Copyright (c) Hewlett-Packard
//      Company 1995. All rights reserved
// 
// The contents of this software are proprietary and confidential to
// the Hewlett- Packard Company, and are limited in distribution to
// those with a direct need to know.  Individuals having access to
// this software are responsible for maintaining the confidentiality
// of the content and for keeping the software secure when not in use.
// Transfer to any party is strictly forbidden other than as expressly
// permitted in writing by Hewlett-Packard Company.  Unauthorized
// transfer to or possession by any unauthorized party may be a
// criminal offense.
//
//                  RESTRICTED RIGHTS LEGEND
//
//      Use,  duplication,  or disclosure by the U. S. Government is
//      subject to restrictions as set forth in subparagraph (c) (1)
//      (ii) in the Rights in Technical Data and Computer Software
//      clause in DFARS 252.227-7013 or any other successor clause.
//
//                      HEWLETT-PACKARD COMPANY
//                      3000 Hanover St.
//                      Palo Alto, CA  94304 U.S.A.
//
//      Rights for non-DOD U.S. Government Departments and Agencies
//      are as set forth in FAR 52.227-19 (c) (1,2) or any other
//      successor clause.
//-----------------------------------------------------------------------------

#ifndef _MODEVSIM_H_
#define _MODEVSIM_H_

#include <rw/cstring.h>
#include "nsrLib.h"
#include "nsrASSdv.h"

#define MODevSim_Magic          "6a6f6e68"
#define MODevSim_MagicLength    8
#define MODevSim_FieldLength    10

//-----------------------------------------------------------------------------
// CLASS:  MODeviceSimulator
//
// This class simulates a single-surface disk device by using a disk file in
// a native filesystem to store the disk data.
//
// PUBLIC DATA MEMBERS:
//
// PUBLIC METHODS:
//
// USAGE NOTES:
//
//-----------------------------------------------------------------------------
// COLLABORATORS:
//
//      Derived from the SSDevice class.
//
// PRIVATE DATA MEMBERS:
//
// PRIVATE METHODS:
//
// IMPLEMENTATION NOTES:
//
//-----------------------------------------------------------------------------

class MODeviceSimulator : public NSR::SSDevice
{
    //-------------------------------------------------------------------------
    // Constructors, copy constructors, destructors
    //-------------------------------------------------------------------------

    public:
                        MODeviceSimulator(const char *filename);
                        MODeviceSimulator(const char *filename,
                                          NSR::UINT32 sectorSize,
                                          NSR::UINT32 numSectors
                                         );
    virtual             ~MODeviceSimulator(void);

    //-------------------------------------------------------------------------
    // Other public methods
    //-------------------------------------------------------------------------

    public:

    virtual NSR::UINT32 numSectors(void) const { return numSectors_; }
    virtual NSR::UINT32 sectorSize(void) const { return sectorSize_; }
    virtual NSR::INT32  read(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                             const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  read(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                             NSR::BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  write(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                             const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  write(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                             NSR::CONST_BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  writeWOE(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                                 const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  writeWOE(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                                 NSR::CONST_BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  verifyMode(NSR::INT32 newmode) { }
    virtual NSR::INT32  verifyMode(void) { return 1; }
    virtual NSR::INT32  erase(NSR::UINT32 start,NSR::UINT32 nsectors,
                              NSR::Error& err);
    virtual NSR::Error       error(void) const { return dderror_; }
    virtual NSR::Error       checkValidity(void) const;
    virtual NSR::MediaType   mediaType(void) { return NSR::media_Rewritable; }
    virtual NSR::Boolean     verifyBlank(NSR::UINT32 start,NSR::UINT32 nsectors,
                                    NSR::UINT32 *which);

    //-------------------------------------------------------------------------
    // Private methods
    //-------------------------------------------------------------------------

    protected:

    NSR::INT32          readHeader(void);
    NSR::INT32          writeHeader(NSR::UINT32 sectorSize,
                                    NSR::UINT32 numSectors);

    //-------------------------------------------------------------------------
    // Private data members
    //-------------------------------------------------------------------------

    protected:

    int                 fd_;
    NSR::UINT32         sectorSize_;
    NSR::UINT32         numSectors_;
    NSR::Error          dderror_;
    RWCString           fileName_;
};

#endif  // _MODEVSIM_H_
