NAME

counterOpen - retrieves the unique identifier for an existing counter.

SYNOPSIS

#include <game-carrier/server.h>

typedef GCT_INT (GC_CORE_API *CounterOpen)(
    GCT_CSTR name);

typedef struct counterOpen {
    /* ... Some fields ... */
    CounterOpen counterOpen;
    /* ... Some fields ... */
}

Parameters:

  • name GCT_INT The name of the counter to retrieve its unique identifier.

RETURN VALUE

Returns the unique identifier of the counter upon success.

Returns ‘-1’ on failure, for instance, when the requested counter does not exist.

DESCRIPTION

The counterOpen function retrieves the identifier for an existing counter. An application can request counters at any time after they have been created.

The name parameter identifies the name of the counter to retrieve. The retrieved value is the unique identifier of the counter.

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, counterAdd, counterSet