//  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:   7kTriggerController.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Defines the logical trigger controller class exported from 
//              the RESON7kSonar interface DLL.
//
//  Notes:      
//

#if !defined(AFX_7KTRIGGERCONTROLLER_H__F89C4DCD_4EB8_4C41_8FE7_0F2E7F103FC9__INCLUDED_)
#define AFX_7KTRIGGERCONTROLLER_H__F89C4DCD_4EB8_4C41_8FE7_0F2E7F103FC9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "7kPort.h"
#include "7kTrigger.h"
#include "7kTriggerSequence.h"

class EXPORT_DLL C7kTriggerController                                                                                       // Logical trigger controller class.
{
public:

    ////////////////
    // Services.

    // Construction, destruction and initialization.

                            C7kTriggerController    (   void );
    virtual                ~C7kTriggerController    (   void );

    bool                    IsInitialized           (   void )  const;

    // Connection to the sonar and general state control/interogation.

    bool                    Reset                   (   const bool                 &rbClear         = false );

    bool                    Connect                 (   const bool                 &rbLocal         = true,                 // Local (true), or remote (false ).
                                                        LPCTSTR                     lpszAddress     = _T( "127.0.0.1" ),    // Address of sonar, if remote.
                                                        const unsigned long        &rulPortIn       = 7000UL,               // Input to 7k sonar, if remote.
                                                        const unsigned long        &rulPortOut      = 7001UL,               // Output from sonar, if remote.
                                                        const unsigned long        &rulType         = 0 );                  // 0 - UDP, 1 - TCP.
    bool                    Disconnect              (   void );
    bool                    IsConnected             (   void )      const;

    bool                    Enable                  (   void );
    bool                    Disable                 (   void );
    bool                    IsEnabled               (   void )      const;

    // Error state retrieval following an invalid return code.

    int                     ErrorCode               (   void )      const;
    LPCTSTR                 ErrorMsg                (   void )      const;

    // Port configuration.

    bool                    AddPort                 (   C7kPort                    &rPort );
    bool                    RemovePort              (   const unsigned long        &rulPortIndex );
    C7kPort *               Port                    (   const unsigned long        &rulPortIndex );

    // Trigger configuration.

    bool                    AddTrigger              (   C7kTrigger                 &rTrigger );
    bool                    RemoveTrigger           (   const unsigned long        &rulTrigger );
    C7kTrigger *            Trigger                 (   const unsigned long        &rulTrigger );

    // Sequence configuration.

    bool                    AddSequence             (   C7kTriggerSequence         &rSequence );
    bool                    RemoveSequence          (   const unsigned long        &rulSequence );

    // Enacting the configuration.

    bool                    Configure               (   void );

private:

    ////////////////
    // Attributes.

    bool                    m_bInitialized;
    bool                    m_bConnected;
    bool                    m_bEnabled;

    int                     m_iLastError;
    CString                 m_LastErrorMsg;

    void                   *m_pvTriggerTable;

    ////////////////
    // Services.

    void                    SetError                (   const int                  &riErrorCode,
                                                        LPCTSTR                     lpszErrorMsg    = NULL );

    void                    ResetError              (   void );

    // Standard services that are not implemented.

                            C7kTriggerController    (   const C7kTriggerController &rRhs );         // Not implemented thus private.
    C7kTriggerController &  operator =              (   const C7kTriggerController &rRhs );         // Not implemented thus private.
};

#endif // !defined(AFX_7KTRIGGERCONTROLLER_H__F89C4DCD_4EB8_4C41_8FE7_0F2E7F103FC9__INCLUDED_)
