//
//  Copyright © 2002, 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:   SensorInterface.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Base class defining common components in defining a 6046 sensor module interface.
//
//  Notes:      
//

#if !defined(AFX_SENSORINTERFACE_H__8EAE372B_BD4C_4410_8825_2CFA85E0C954__INCLUDED_)
#define AFX_SENSORINTERFACE_H__8EAE372B_BD4C_4410_8825_2CFA85E0C954__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "..\..\..\Utils\NetUtils\Critical.h"                                       // Critical section object.
#include "..\..\..\Utils\NetUtils\CriticalParameterTable.h"                         // Critical parameter table definition.

class CSensorInterface
{
public:

    ///////////////
    // Services.

                                    CSensorInterface                    (   void );
    virtual                        ~CSensorInterface                    (   void );

    static CSensorInterface *       This                                (   void );

    void                            Version                             (   const   double                             &rdVersion );
    double                          Version                             (   void )  const;

    void                            EventLog                            (   void                                       *pvfnLog );

    void                            CriticalParameterTable              (   void                                       *pvCriticalParameterTable );

    int                             AddSensorRef                        (   void );
    int                             ReleaseSensorRef                    (   void );
    int                             SensorRefCount                      (   void )  const;

    bool                            SubscribeToCriticalParameters       (   const int                                  &riSensorIndex,
                                                                            CCriticalParameterTable::ParameterList_t   &rParameters );

    bool                            UnsubscribeFromCriticalParameters   (   const int                                  &riSensorIndex );


    static
    bool                            UpdateCriticalParameters            (   const unsigned long                        &rulParametersToUpdate,
                                                                            const CRITICALPARAMENTRY                   *psParameterEntry,
                                                                            const unsigned long                        &rulTimeStamp );

    static
    bool                            LogEvent                            (   int                                         iEventType,
                                                                            int                                         iAction,
                                                                            int                                         iId,
                                                                            char                                       *pszFormat, ... );
protected:

    ///////////////
    // Attributes.

    static CSensorInterface        *m_pthis;

    bool                            m_bRetrievedSonarSettings;
    mutable CCritical               m_Critical;

    ///////////////
    // Services.

    virtual void                    HandleSubscribedCriticalParameterUpdate(    const int                          &riSensorIndex,
                                                                                const unsigned long                &rulTableSize,
                                                                                const CRITICALPARAMENTRY * const    psTable );

private:

    ///////////////
    // Definitions.

    typedef int                     ( _cdecl * PFN_LOGEVENT )           (   int                                 iEventType,
                                                                            int                                 iAction,
                                                                            int                                 iId,
                                                                            char                               *pszFormat, ... );

    ///////////////
    // Attributes.

    int                             m_iSensorRefCount;
    double                          m_dVersion;

    CCriticalParameterTable        *m_pCriticalParameters;
    PFN_LOGEVENT                    m_pfnLogEvent;

    static
    void                            SubscribedCriticalParameterUpdate   (   void                               *pvParam,
                                                                            int                                 iSensorIndex,
                                                                            unsigned long                       ulTableSize,
                                                                            CRITICALPARAMENTRY                 *psTable );

};

#endif // !defined(AFX_SENSORINTERFACE_H__8EAE372B_BD4C_4410_8825_2CFA85E0C954__INCLUDED_)
