//
//  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:   
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:      
//

#if !defined(AFX_6046REMOTECOMMAND_H__24FBEE69_5773_45DB_BF52_7203281360EC__INCLUDED_)
#define AFX_6046REMOTECOMMAND_H__24FBEE69_5773_45DB_BF52_7203281360EC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning( disable : 4663 )                                           // Microsoft's STL is dirty at warning level 4, so disable warnings as necessary.
#pragma warning( disable : 4018 )
#pragma warning( disable : 4146 )
#pragma warning( push, 3 )
#include <vector>
#include <string>
#include <map>
#pragma warning( pop )
#pragma warning( default : 4146 )
#pragma warning( default : 4018 )
#pragma warning( default : 4663 )

using std::map;
using std::string;
using std::less;

class C6046RemoteCommand  
{
public:

    ///////////////
    // Definitions.

    enum ECOMMANDID                                                         // Recognised command identifiers.
    {
        commandNone                     = -1,
        commandRange,
        commandPulse,
        commandPing,
        commandTxPower,
        commandRxGain,
        commandDuration,
        commandPulseFiles,
        commandDefaultState,
        commandQueryParameters,
        commandQueryCapabilities,
        commandQuerySonarRemoteSettings,
        commandPulseWidth,
        commandRangeDepthFilters,
        commandBottomDetectFlags,
        commandMaxPingRate,
        commandAbsorptionCoef,
        commandSoundSpeed,
        commandSpreadingLoss
    };

    enum EPARAMETERTYPE                                                     // Parameter types.
    {
        paramTypeUnspecified            = -1,
        paramTypeString,
        paramTypeBool,
        paramTypeInt,
        paramTypeFloat,
        paramTypeUnsignedLong
    };

    ///////////////
    // Services.

                                        C6046RemoteCommand          (   void );
    virtual                            ~C6046RemoteCommand          (   void );
                           
	bool                                Decode                      (   const char      *pszCommand );
                           
    ECOMMANDID                          Command                     (   void )  const;
                           
    bool                                IsCommandValid              (   void )  const;

    bool                                AreParametersAvailable      (   void )  const;

    int                                 NumberOfParameters          (   void )  const;

    // Typed command parameter retrieval routines. Will retrieve only the first parameter. For multiple
    // parameters, use the interface below, viz.: ResetParamRetrivalPoint() and GetNextParameter().
                           
                                        operator const char *       (   void )  const;
                                        operator bool               (   void )  const;
                                        operator int                (   void )  const;
                                        operator float              (   void )  const;
                                        operator unsigned long      (   void )  const;

    // Multi command parameter retrieval routines.

    void                                ResetParamRetrievalPoint    (   void );

    bool                                GetNextParameter            (   void                   *pvParam,
                                                                        const EPARAMETERTYPE   &eParameterType,
                                                                        const unsigned long    &rulMaxStringLength = _MAX_PATH );

private:

    ///////////////
    // Definitions.

    class CParameter
    {
    public:

        std::string                     m_sParameter;
        EPARAMETERTYPE                  m_eParameterType;

                                        CParameter                  (   void );
        virtual                        ~CParameter                  (   void );
    };

    // Command string to identifier lookup mechamism using STL map class.

    typedef map<string, ECOMMANDID, less<string> >  CommandMap_t;
    typedef CommandMap_t::iterator                  CommandMapIterator_t;

    // Queue of parameters for the given command.

    typedef std::vector<CParameter>                 ParameterList_t;
    typedef ParameterList_t::iterator               ParameterListIterator_t;

    ///////////////
    // Attributes.

    CommandMap_t                        m_Commands;
    ECOMMANDID                          m_eCommand;
    ParameterList_t                     m_ParameterList;
    ParameterListIterator_t             m_pRetrievalPoint;

    ///////////////
    // Services.

    bool                                DecodeParameters            (   const CString               &rSCommand,
                                                                        const int                   &riParamPos,
                                                                        const ECOMMANDID            &reCommandId );

                                        C6046RemoteCommand          (   const C6046RemoteCommand    &rRhs );            // Not implemented thus private.
    C6046RemoteCommand &                operator =                  (   const C6046RemoteCommand    &rRhs );            // Not implemented thus private.

};

#endif // !defined(AFX_6046REMOTECOMMAND_H__24FBEE69_5773_45DB_BF52_7203281360EC__INCLUDED_)
