// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY

#pragma once

#include <stdint.h>

#include "ntcore_c.h"

#ifdef __cplusplus
extern "C" {
#endif

{% for t in types %}
/**
 * Timestamped {{ t.TypeName }}.
 * @ingroup ntcore_c_api
 */
struct NT_Timestamped{{ t.TypeName }} {
  /**
   * Time in local time base.
   */
  int64_t time;

  /**
   * Time in server time base.  May be 0 or 1 for locally set values.
   */
  int64_t serverTime;

  /**
   * Value.
   */
{%- if t.c.ValueInline %}
  {{ t.c.ValueInline }} value;
{%- else %}
  {{ t.c.ValueType }} value;
{%- endif %}
{%- if t.c.IsArray %}
  /**
   * Value length.
   */
  size_t len;
{% endif %}
};

/**
 * @defgroup ntcore_{{ t.TypeName }}_cfunc {{ t.TypeName }} Functions
 * @ingroup ntcore_c_api
 * @{
 */

/**
 * Publish a new value.
 *
 * @param pubentry publisher or entry handle
 * @param time timestamp; 0 indicates current NT time should be used
 * @param value value to publish
{%- if t.c.IsArray %}
 * @param len length of value
{% endif %}
 */
NT_Bool NT_Set{{ t.TypeName }}(NT_Handle pubentry, int64_t time, {{ t.c.ParamType }} value{% if t.c.IsArray %}, size_t len{% endif %});

/**
 * Publish a default value.
 * On reconnect, a default value will never be used in preference to a
 * published value.
 *
 * @param pubentry publisher or entry handle
 * @param defaultValue default value
{%- if t.c.IsArray %}
 * @param defaultValueLen length of default value
{% endif %}
 */
NT_Bool NT_SetDefault{{ t.TypeName }}(NT_Handle pubentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %});

/**
 * Get the last published value.
 * If no value has been published, returns the passed defaultValue.
 *
 * @param subentry subscriber or entry handle
 * @param defaultValue default value to return if no value has been published
{%- if t.c.ValueInline %}
 * @param value returned value (output)
{% endif %}
{%- if t.c.IsArray %}
 * @param defaultValueLen length of default value
 * @param len length of returned value (output)
{% endif %}
{%- if not t.c.ValueInline %}
 * @return value
{%- endif %}
 */
{%- if t.c.ValueInline %}
void NT_Get{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue, {{ t.c.ValueType }} value);
{%- else %}
{{ t.c.ValueType }} NT_Get{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen, size_t* len{% endif %});
{%- endif %}

/**
 * Get the last published value along with its timestamp.
 * If no value has been published, returns the passed defaultValue and a
 * timestamp of 0.
 *
 * @param subentry subscriber or entry handle
 * @param defaultValue default value to return if no value has been published
{%- if t.c.IsArray %}
 * @param defaultValueLen length of default value
{% endif %}
 * @param value timestamped value (output)
 */
void NT_GetAtomic{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %}, struct NT_Timestamped{{ t.TypeName }}* value);

/**
 * Disposes a timestamped value (as returned by NT_GetAtomic{{ t.TypeName }}).
 *
 * @param value timestamped value
 */
void NT_DisposeTimestamped{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* value);

/**
 * Get an array of all value changes since the last call to ReadQueue.
 * Also provides a timestamp for each value.
 *
 * @note The "poll storage" subscribe option can be used to set the queue
 *     depth.
 *
 * @param subentry subscriber or entry handle
 * @param len length of returned array (output)
 * @return Array of timestamped values; NULL if no new changes have
 *     been published since the previous call.
 */
struct NT_Timestamped{{ t.TypeName }}* NT_ReadQueue{{ t.TypeName }}(NT_Handle subentry, size_t* len);

/**
 * Frees a timestamped array of values (as returned by NT_ReadQueue{{ t.TypeName }}).
 *
 * @param arr array
 * @param len length of array
 */
void NT_FreeQueue{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* arr, size_t len);

{%- if not t.c.IsArray and not t.c.ValueInline %}
/**
 * Get an array of all value changes since the last call to ReadQueue.
 *
 * @note The "poll storage" subscribe option can be used to set the queue
 *     depth.
 *
 * @param subentry subscriber or entry handle
 * @param len length of returned array (output)
 * @return Array of values; NULL if no new changes have
 *     been published since the previous call.
 */
{{ t.c.ValueType }}* NT_ReadQueueValues{{ t.TypeName }}(NT_Handle subentry, size_t* len);
{%- endif %}

/** @} */
{% endfor %}

#ifdef __cplusplus
}  // extern "C"
#endif

