/*
 * SPDX-FileCopyrightText: 2014 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#ifndef TANGO_SERVER_DEVINTRTHREAD_H
#define TANGO_SERVER_DEVINTRTHREAD_H

#include <tango/server/DevIntr.h>

namespace Tango
{

//=================================================================================================================
//
//            The DevIntrThCmd structure
//
// description :
//        This structure is used to shared data between the Device interface change thread and the main thread.
//
//================================================================================================================

enum DevIntrCmdCode
{
    DEV_INTR_SLEEP = 0,
    DEV_INTR_EXIT
};

struct _ShDevIntrTh
{
    bool cmd_pending;        // The new command flag
    DevIntrCmdCode cmd_code; // The command code
    bool th_running;         // Thread running flag
    Tango::DevIntr iface;    // Device interface
};
typedef struct _ShDevIntrTh ShDevIntrTh;

enum DevIntrCmdType
{
    DEV_INTR_TIME_OUT = 0,
    DEV_INTR_COMMAND
};

//=================================================================================================================
//
//            The DevIntrThread class
//
// description :
//        Class to store all the necessary information for the device interface change event thread.
//        It's run() method is the thread code
//        This is a detached thread
//
//=================================================================================================================

class TangoMonitor;

// NOLINTNEXTLINE(cppcoreguidelines-virtual-class-destructor)
class DevIntrThread : public omni_thread
{
  public:
    DevIntrThread(ShDevIntrTh &, TangoMonitor &, DeviceImpl *);

    void run(void *) override;

    void execute_cmd();
    DevIntrCmdType get_command(DevLong);
    void push_event();

  protected:
    ShDevIntrTh &shared_data;
    TangoMonitor &p_mon;
    DeviceImpl *dev;

    ShDevIntrTh local_cmd;

  private:
    ~DevIntrThread() override = default;
};

} // namespace Tango

#endif /* _DINTRTHREAD_ */
