////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: Parameter Parser V5.5.1 (2411131018)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  parametereztunegateway.h
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef PARAMETEREZTUNEGATEWAY_H
#define PARAMETEREZTUNEGATEWAY_H

#include "parametereztunecom.h"
#include "parameterutils.h"

class EzTuneGateway
{
public:
    static const UINT8 MAX_PORTS        = 8;
    static const INT32 DISCOVERY_PERIOD = 2000;
    static const INT32 PACKETS_PERIOD   = 1;
    static const CHAR* GATEWAY_BUILDID;

    struct WorkerInfo
    {
        WorkerInfo(
            EzTuneGateway* gateway,
            const ParameterEzTuneCom::SocketID& socket)
        {
            Gateway = gateway;
            Socket  = socket;
            Active  = true;
        }

        EzTuneGateway*               Gateway;
        ParameterEzTuneCom::SocketID Socket;
        bool                         Active; // Set to false when the worker exits
    };

    struct WorkerThread
    {
        WorkerThread()
        {
            Info   = nullptr;
            Thread = nullptr;
        }
        WorkerThread(WorkerInfo* info, std::thread* thread)
        {
            Info = info;
            Thread = thread;
        }
        WorkerInfo*  Info;
        std::thread* Thread;
    };

    EzTuneEvent ExitEvent;

    EzTuneGateway();
    ~EzTuneGateway();

    void Start(const UINT8 maxPorts = MAX_PORTS);
    void Stop();

    bool IsPortActive(UINT16 port);

private:
    void StartInternal();
    void StartWorker(ParameterEzTuneCom::SocketID& socket);
    static void StartWorkerThread(void* obj);
    static void GatewayWorkerThread(void* obj);
    PList<WorkerThread> m_workers;
    std::mutex   m_workerMutex; // protects the worker list
    std::thread* m_startThread;
    UINT8 m_maxPorts;
};

#endif
