//
//  Copyright © 2004, 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:   RESON7KSonar.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Defines the CRESON7kSonarApp class.
//
//  Notes:      
//

#if !defined(AFX_RESON7KSONAR_H__C6794ABB_4202_4673_949F_5E7D310F1E45__INCLUDED_)
#define AFX_RESON7KSONAR_H__C6794ABB_4202_4673_949F_5E7D310F1E45__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"                                                   // Main resource symbols.

#include "SensorInterface.h"                                            // Common sensor DLL infrustructure support.
#include "7kSubsystem.h"                                                // 7k sonar specialized sensors.


#include "..\..\Include\SurveyEventTypes.h"                             // Event log types (alarms, warnings & annotations etc).

#include "..\..\..\Utils\NetUtils\SensorList.h"                         // Linked list of sensor objects.
#include "..\..\..\Utils\NetUtils\WatchSentinel.h"                      // Generic threaded sentinel (watch dog) object.

namespace NRESON7kSonarApp                                              // Begin namespace NRESON7kSonarApp
{
    class CRESON7kSonarApp : public CWinApp, public CSensorInterface
    {
    public:

        ///////////////
        // Services.

                                            CRESON7kSonarApp                        (   void );
        virtual                            ~CRESON7kSonarApp                        (   void );

        static
        CRESON7kSonarApp                 *  This                                    (   void );

        CSensorList<C7kSubsystem>        &  SensorList                              (   void )  const;

        bool                                AutoShutdown                            (   void )  const;

        bool                                ConfigureCriticalParameters             (   const int                          &riSensorIndex );

        bool                                IsMessageRoutingEnabled                 (   void )  const;
        bool                                IsParameterRoutingEnabled               (   void )  const;

        void                                Sentinel                                (   const bool  &rbStart );

        static void                         CheckSensorStatus                       (   void                               *pvParam,
                                                                                        const int                          &riSensorIndex );

        static bool                         Check7kCenterIsRunning                  (   void );


        ///////////////
        // Attributes.

        CCritical                           m_SensorListGuard;                                                  // Critical section to protect sensor list and internal state.

        // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CRESON7kSonarApp)
	    public:
        virtual BOOL InitInstance();
	    virtual int ExitInstance();
	    //}}AFX_VIRTUAL

        //{{AFX_MSG(CRESON7kSonarApp)
            // 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_bRemote;

        unsigned long                       m_bMessageRouting;
        unsigned long                       m_bParameterRouting;
        unsigned long                       m_ulAutoShutdown;
        unsigned long                       m_ulPort;

        CString                             m_szAddress;

        mutable CSensorList<C7kSubsystem>   m_SensorList;

        CWatchSentinel                     *m_pSentinel;                                                        // Threaded watchdog.

        ///////////////
        // Services.

        void                                SensorCheck                             (   const int                          &riSensorIndex );

        void                                SettingsFromRegistry                    (   void );

        void                                HandleSubscribedCriticalParameterUpdate (   const int                          &riSensorIndex,
                                                                                        const unsigned long                &rulTableSize,
                                                                                        const CRITICALPARAMENTRY * const    psTable );

    };

    ///////////////////////////////////////////////////////////////////////////////
    // File scope helpers.

    extern CRESON7kSonarApp *   GetApp              (   void );

    extern bool                 LogEvent            (   const int   &riEventType,
                                                        char        *pszFormat, ... );

    extern bool                 ReportAlarm         (   const bool  &rbSet,
                                                        const int   &riAlarmId,
                                                        char        *pszFormat, ... );

}                                                                       // End namespace NRESON7kSonarApp.

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RESON7KSONAR_H__C6794ABB_4202_4673_949F_5E7D310F1E45__INCLUDED_)
