/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_CLIENT_EVENTQUEUE_H
#define TANGO_CLIENT_EVENTQUEUE_H

#include <tango/client/AttrConfEventData.h>
#include <tango/client/AttrConfEventDataList.h>
#include <tango/client/CallBack.h>
#include <tango/client/DataReadyEventData.h>
#include <tango/client/DataReadyEventDataList.h>
#include <tango/client/DevIntrChangeEventData.h>
#include <tango/client/DevIntrChangeEventDataList.h>
#include <tango/client/EventData.h>
#include <tango/client/EventDataList.h>
#include <tango/client/PipeEventData.h>
#include <tango/client/PipeEventDataList.h>

namespace Tango
{

/********************************************************************************
 *                                                                                 *
 *                         EventQueue class                                        *
 *                                                                                 *
 *******************************************************************************/
class EventQueue
{
  public:
    EventQueue();
    EventQueue(long max_size);
    ~EventQueue();

    void insert_event(EventData *new_event);
    void insert_event(AttrConfEventData *new_event);
    void insert_event(DataReadyEventData *new_event);
    void insert_event(DevIntrChangeEventData *new_event);
    void insert_event(PipeEventData *new_event);

    int size();
    TimeVal get_last_event_date();

    bool is_empty()
    {
        return size() == 0;
    }

    void get_events(EventDataList &event_list);
    void get_events(AttrConfEventDataList &event_list);
    void get_events(DataReadyEventDataList &event_list);
    void get_events(DevIntrChangeEventDataList &event_list);
    void get_events(PipeEventDataList &event_list);
    void get_events(CallBack *cb);

  private:
    template <typename T, typename U>
    void insert_event_helper(T elem, U &vec);
    template <typename T, typename U>
    void get_events_helper(T &output, U &vec);
    void inc_indexes();

    std::vector<EventData *> event_buffer;
    std::vector<AttrConfEventData *> conf_event_buffer;
    std::vector<DataReadyEventData *> ready_event_buffer;
    std::vector<DevIntrChangeEventData *> dev_inter_event_buffer;
    std::vector<PipeEventData *> pipe_event_buffer;

    long max_elt;
    long insert_elt;
    long nb_elt;

    omni_mutex modification_mutex;
};

} // namespace Tango

#endif // TANGO_CLIENT_EVENTQUEUE_H
