//
//  Copyright © 2001 - 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:   EdgeTechFSDW.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Main DLL header file defining the MFC class CEdgeTechFSDWApp.
//
//  Notes:      1)  If this DLL is dynamically linked against the MFC
//                  DLLs, any functions exported from this DLL which
//                  call into MFC must have the AFX_MANAGE_STATE macro
//                  added at the very beginning of the function.
//                  The macro ManageDllState_m() is defined for this purpose (see below).
//
//                  See MFC Technical Notes 33 and 58 for additional info.
//

#if !defined(AFX_EDGETECHFSDW_H__1E3A28E2_7BAE_48A5_9846_E749CBDC154E__INCLUDED_)
#define AFX_EDGETECHFSDW_H__1E3A28E2_7BAE_48A5_9846_E749CBDC154E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
#endif

#include "Resource.h"
#include "SensorList.h"

#include "SensorInterface.h"                                            // Common sensor DLL infrustructure support.

#include "..\..\..\Utils\NetUtils\WatchSentinel.h"                      // The generic threaded sentinel (watch dog) class.


class CEdgeTechFSDWApp : public CWinApp, public CSensorInterface
{
public:

    ///////////////
    // Services.

                                CEdgeTechFSDWApp                        (   void );
    virtual                    ~CEdgeTechFSDWApp                        (   void );

    static CEdgeTechFSDWApp *   This                                    (   void );


    CSensorList &               SensorList                              (   void )  const;

    void                        SonarConnectionSettings                 (   CString         &rsSonarAddress,
                                                                            unsigned long   &rulCommandPort,
                                                                            unsigned long   &rulDataPort );

    void                        SonarSettingsFromRegistry               (   void );

    bool                        SonarAutoShutdown                       (   void );

    bool                        IsSonarAvailable                        (   const CString                      &rsSonarAddress,
                                                                            const unsigned long                &rulCommandPort );

    void                        Sentinel                                (   const bool                         &rbStart );

    void                        SocketDisconnect                        (   void );

    void                        TerminationPending                      (   const bool                         &rbTerminationPending );

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CEdgeTechFSDWApp)
    public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
    //}}AFX_VIRTUAL

    //{{AFX_MSG(CEdgeTechFSDWApp)
        // NOTE - the ClassWizard will add and remove member functions here.
        //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()

private:

    ///////////////
    // Attributes.

    bool                        m_bTerminationPending;

    unsigned long               m_ulCommandPort;
    unsigned long               m_ulDataPort;
    unsigned long               m_ulAutoShutdown;

    CString                     m_sSonarAddress;

    mutable CSensorList         m_SensorList;

    CWatchSentinel             *m_pSentinel;                                                        // Threaded watchdog.


    ///////////////
    // Services.

    void                        HandleSubscribedCriticalParameterUpdate(    const int                          &riSensorIndex,
                                                                            const unsigned long                &rulTableSize,
                                                                            const CRITICALPARAMENTRY * const    psTable );

    void                        SensorCheck                             (   const int                          &riSensorIndex = -1 );

    void                        HandleSensorAlarm                       (   const int                          &riSensorIndex,
                                                                            const bool                         &rbHealthy );

    static void                 CheckSensorStatus                       (   void                               *pvParam,
                                                                            const int                          &riSensorIndex );

};

// File scope helpers.

extern CEdgeTechFSDWApp *       GetApp      (   void );

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_EDGETECHFSDW_H__1E3A28E2_7BAE_48A5_9846_E749CBDC154E__INCLUDED_)
