NAME

counterGet retrieves the current value of the counter.

SYNOPSIS

#include <game-carrier/server.h>

typedef GCT_COUNTER_VALUE (GC_CORE_API *CounterGet)(
    GCT_INT id);

typedef struct counterGet {
    /* ... Some fields ... */
    CounterGet counterGet;
    /* ... Some fields ... */
}

Parameters:

  • id GCT_INT Unique identifier of the counter.

RETURN VALUE

Returns the value of the counter upon success.

In the case of failure, returns the GC_COUNTER_INVALID_VALUE, which represents the smallest possible negative value for a 64-bit signed integer type.

DESCRIPTION

The ‘counterGet’ function is used to retrieve the current value of the counter.

The id parameter represents the unique identifier of the counter to obtain its current value.

EXAMPLE

#include <game-carrier/server.h>

#include <stdio.h>

static struct core_api api;
static GCT_INT cpu_idle_counter_id;

GC_ADAPTER_EVENT
GCT_INT adapter_initialize(
    GCT_INT adapter_id,
    struct core_api * core_api,
    GCT_CPTR load_path)
{
    api = *core_api;
    return 0;
}

GC_ADAPTER_EVENT
GCT_INT application_initialize(

    GCT_INT id,
    GCT_CSTR name,
    GCT_CSTR type_name,
    GCT_CSTR file_name)
{
    const char * counter_name = "System.CPU.Idle.Percent.Current";

    cpu_idle_counter_id = api.counterOpen(counter_name);
    if (cpu_idle_counter_id == -1)
    {
        return -1;
    }

    GCT_COUNTER_VALUE counter_value = api.counterGet(cpu_idle_counter_id);

    /* Logging current value */
    char buf[256];
    snprintf(buf, sizeof(buf), "%s: %" PRId64, counter_name, counter_value);
    api.logMessage(GCL_USER, buf);

    /* Continue application initialization */
    return 0;
}

SEE ALSO

counterCreate, counterCreateAtomic, counterGetNames