//
//  Copyright © 2003, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   MMF6046.cpp
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Implements a wrapper for the 6046 MMF support based on a combination of
//              inherited template helpers (memory map and circular buffer scheme).
//
//  Notes:
//

#include "StdAfx.h"
#include "MMF6046.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// CMMF6046 class implementation.

using std::auto_ptr;

CMMF6046::CMMF6046( LPCTSTR     lpszMapName,
                    bool        bUseDiskFile )

         :CMemoryMappedFile<MEMMAP6046>(    lpszMapName,
                                            bUseDiskFile ),

          CCircularBuffer<RECORDHEADER>(    reinterpret_cast<BYTE * const>( MappedData() ),
                                            sizeof ( MEMMAP6046 ),
                                            CString( MappingName() ) + _T( "_SWMRG" ),
                                            CString( MappingName() ) + _T( "_EVENT" ) )
{
    m_bInitialized = false;

    try
    {
        m_bInitialized = (  CMemoryMappedFile<MEMMAP6046>::IsInitialized()    &&
                                CCircularBuffer<RECORDHEADER>::IsInitialized() );
    }
    catch ( ... )
    {
        m_bInitialized = false;
        TRACE( _T( "CMMF6046::CMMF6046(), Unspecified exception caught\n" ) );
    }

    ASSERT( m_bInitialized );
}

CMMF6046::~CMMF6046( void )
{
    m_bInitialized = false;
}

bool CMMF6046::IsInitialized( void ) const
{
    return m_bInitialized;
}

bool CMMF6046::InitializeMMFContents( void )
{
    return CCircularBuffer<RECORDHEADER>::InitializeHeader();
}

