/*
 * Copyright 2014-2025 Real Logic Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AERON_SYSTEM_COUNTERS_H
#define AERON_SYSTEM_COUNTERS_H

#include "aeron_counters.h"
#include "concurrent/aeron_counters_manager.h"

typedef enum aeron_system_counter_enum_stct
{
    AERON_SYSTEM_COUNTER_BYTES_SENT = AERON_SYSTEM_COUNTER_ID_BYTES_SENT,
    AERON_SYSTEM_COUNTER_BYTES_RECEIVED = AERON_SYSTEM_COUNTER_ID_BYTES_RECEIVED,
    AERON_SYSTEM_COUNTER_RECEIVER_PROXY_FAILS = AERON_SYSTEM_COUNTER_ID_RECEIVER_PROXY_FAILS,
    AERON_SYSTEM_COUNTER_SENDER_PROXY_FAILS = AERON_SYSTEM_COUNTER_ID_SENDER_PROXY_FAILS,
    AERON_SYSTEM_COUNTER_CONDUCTOR_PROXY_FAILS = AERON_SYSTEM_COUNTER_ID_CONDUCTOR_PROXY_FAILS,
    AERON_SYSTEM_COUNTER_NAK_MESSAGES_SENT = AERON_SYSTEM_COUNTER_ID_NAK_MESSAGES_SENT,
    AERON_SYSTEM_COUNTER_NAK_MESSAGES_RECEIVED = AERON_SYSTEM_COUNTER_ID_NAK_MESSAGES_RECEIVED,
    AERON_SYSTEM_COUNTER_STATUS_MESSAGES_SENT = AERON_SYSTEM_COUNTER_ID_STATUS_MESSAGES_SENT,
    AERON_SYSTEM_COUNTER_STATUS_MESSAGES_RECEIVED = AERON_SYSTEM_COUNTER_ID_STATUS_MESSAGES_RECEIVED,
    AERON_SYSTEM_COUNTER_HEARTBEATS_SENT = AERON_SYSTEM_COUNTER_ID_HEARTBEATS_SENT,
    AERON_SYSTEM_COUNTER_HEARTBEATS_RECEIVED = AERON_SYSTEM_COUNTER_ID_HEARTBEATS_RECEIVED,
    AERON_SYSTEM_COUNTER_RETRANSMITS_SENT = AERON_SYSTEM_COUNTER_ID_RETRANSMITS_SENT,
    AERON_SYSTEM_COUNTER_FLOW_CONTROL_UNDER_RUNS = AERON_SYSTEM_COUNTER_ID_FLOW_CONTROL_UNDER_RUNS,
    AERON_SYSTEM_COUNTER_FLOW_CONTROL_OVER_RUNS = AERON_SYSTEM_COUNTER_ID_FLOW_CONTROL_OVER_RUNS,
    AERON_SYSTEM_COUNTER_INVALID_PACKETS = AERON_SYSTEM_COUNTER_ID_INVALID_PACKETS,
    AERON_SYSTEM_COUNTER_ERRORS = AERON_SYSTEM_COUNTER_ID_ERRORS,
    AERON_SYSTEM_COUNTER_SHORT_SENDS = AERON_SYSTEM_COUNTER_ID_SHORT_SENDS,
    AERON_SYSTEM_COUNTER_FREE_FAILS = AERON_SYSTEM_COUNTER_ID_FREE_FAILS,
    AERON_SYSTEM_COUNTER_SENDER_FLOW_CONTROL_LIMITS = AERON_SYSTEM_COUNTER_ID_SENDER_FLOW_CONTROL_LIMITS,
    AERON_SYSTEM_COUNTER_UNBLOCKED_PUBLICATIONS = AERON_SYSTEM_COUNTER_ID_UNBLOCKED_PUBLICATIONS,
    AERON_SYSTEM_COUNTER_UNBLOCKED_COMMANDS = AERON_SYSTEM_COUNTER_ID_UNBLOCKED_COMMANDS,
    AERON_SYSTEM_COUNTER_POSSIBLE_TTL_ASYMMETRY = AERON_SYSTEM_COUNTER_ID_POSSIBLE_TTL_ASYMMETRY,
    AERON_SYSTEM_COUNTER_CONTROLLABLE_IDLE_STRATEGY = AERON_SYSTEM_COUNTER_ID_CONTROLLABLE_IDLE_STRATEGY,
    AERON_SYSTEM_COUNTER_LOSS_GAP_FILLS = AERON_SYSTEM_COUNTER_ID_LOSS_GAP_FILLS,
    AERON_SYSTEM_COUNTER_CLIENT_TIMEOUTS = AERON_SYSTEM_COUNTER_ID_CLIENT_TIMEOUTS,
    AERON_SYSTEM_COUNTER_RESOLUTION_CHANGES = AERON_SYSTEM_COUNTER_ID_RESOLUTION_CHANGES,
    AERON_SYSTEM_COUNTER_CONDUCTOR_MAX_CYCLE_TIME = AERON_SYSTEM_COUNTER_ID_CONDUCTOR_MAX_CYCLE_TIME,
    AERON_SYSTEM_COUNTER_CONDUCTOR_CYCLE_TIME_THRESHOLD_EXCEEDED = AERON_SYSTEM_COUNTER_ID_CONDUCTOR_CYCLE_TIME_THRESHOLD_EXCEEDED,
    AERON_SYSTEM_COUNTER_SENDER_MAX_CYCLE_TIME = AERON_SYSTEM_COUNTER_ID_SENDER_MAX_CYCLE_TIME,
    AERON_SYSTEM_COUNTER_SENDER_CYCLE_TIME_THRESHOLD_EXCEEDED = AERON_SYSTEM_COUNTER_ID_SENDER_CYCLE_TIME_THRESHOLD_EXCEEDED,
    AERON_SYSTEM_COUNTER_RECEIVER_MAX_CYCLE_TIME = AERON_SYSTEM_COUNTER_ID_RECEIVER_MAX_CYCLE_TIME,
    AERON_SYSTEM_COUNTER_RECEIVER_CYCLE_TIME_THRESHOLD_EXCEEDED = AERON_SYSTEM_COUNTER_ID_RECEIVER_CYCLE_TIME_THRESHOLD_EXCEEDED,
    AERON_SYSTEM_COUNTER_NAME_RESOLVER_MAX_TIME = AERON_SYSTEM_COUNTER_ID_NAME_RESOLVER_MAX_TIME,
    AERON_SYSTEM_COUNTER_NAME_RESOLVER_TIME_THRESHOLD_EXCEEDED = AERON_SYSTEM_COUNTER_ID_NAME_RESOLVER_TIME_THRESHOLD_EXCEEDED,
    AERON_SYSTEM_COUNTER_AERON_VERSION = AERON_SYSTEM_COUNTER_ID_AERON_VERSION,
    AERON_SYSTEM_COUNTER_BYTES_CURRENTLY_MAPPED = AERON_SYSTEM_COUNTER_ID_BYTES_CURRENTLY_MAPPED,
    AERON_SYSTEM_COUNTER_RETRANSMITTED_BYTES = AERON_SYSTEM_COUNTER_ID_RETRANSMITTED_BYTES,
    AERON_SYSTEM_COUNTER_RETRANSMIT_OVERFLOW = AERON_SYSTEM_COUNTER_ID_RETRANSMIT_OVERFLOW,
    AERON_SYSTEM_COUNTER_ERROR_FRAMES_RECEIVED = AERON_SYSTEM_COUNTER_ID_ERROR_FRAMES_RECEIVED,
    AERON_SYSTEM_COUNTER_ERROR_FRAMES_SENT = AERON_SYSTEM_COUNTER_ID_ERROR_FRAMES_SENT,
    AERON_SYSTEM_COUNTER_PUBLICATIONS_REVOKED = AERON_SYSTEM_COUNTER_ID_PUBLICATIONS_REVOKED,
    AERON_SYSTEM_COUNTER_PUBLICATION_IMAGES_REVOKED = AERON_SYSTEM_COUNTER_ID_PUBLICATION_IMAGES_REVOKED,
    AERON_SYSTEM_COUNTER_IMAGES_REJECTED = AERON_SYSTEM_COUNTER_ID_IMAGES_REJECTED,
    AERON_SYSTEM_COUNTER_CONTROL_PROTOCOL_VERSION = AERON_SYSTEM_COUNTER_ID_CONTROL_PROTOCOL_VERSION,

    // Add all new counters before this one (used for a static assertion).
    AERON_SYSTEM_COUNTER_DUMMY_LAST,
}
aeron_system_counter_enum_t;

typedef struct aeron_system_counter_stct
{
    const char *label;
    int32_t id;
}
aeron_system_counter_t;

typedef struct aeron_system_counters_stct
{
    aeron_counters_manager_t *manager;
}
aeron_system_counters_t;

int aeron_system_counters_init(aeron_system_counters_t *counters, aeron_counters_manager_t *manager);

void aeron_system_counters_close(aeron_system_counters_t *counters);

inline int64_t *aeron_system_counter_addr(aeron_system_counters_t *counters, aeron_system_counter_enum_t type)
{
    return aeron_counters_manager_addr(counters->manager, (int32_t)type);
}

#endif //AERON_SYSTEM_COUNTERS_H
