168 lines
5.0 KiB
C
168 lines
5.0 KiB
C
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* Copyright (c) Camden Dixie O'Brien
|
|
*/
|
|
|
|
#ifndef SETTINGS_H
|
|
#define SETTINGS_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define SETTINGS_MAX_VALUE_SIZE 32U
|
|
|
|
/**
|
|
* Callback type for settings updates
|
|
*/
|
|
typedef void (*SettingsCallback)(const char *value);
|
|
|
|
/**
|
|
* Initialize the settings module.
|
|
*
|
|
* If there are saved settings, they will be loaded. Otherwise,
|
|
* the default settings will be loaded and saved.
|
|
*/
|
|
void settings_init(void);
|
|
|
|
/**
|
|
* Set the device's hostname.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void settings_set_hostname(const char *hostname);
|
|
|
|
/**
|
|
* Write the device's hostname into the given buffer.
|
|
*
|
|
* The length of the hostname is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t settings_get_hostname(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for hostname updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever
|
|
* the hostname is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void settings_add_hostname_callback(SettingsCallback callback);
|
|
|
|
/**
|
|
* Set the SSID of the WiFi network.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void settings_set_ssid(const char *ssid);
|
|
|
|
/**
|
|
* Write the SSID of the WiFi network into the given buffer.
|
|
*
|
|
* The length of the SSID is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t settings_get_ssid(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for SSID updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever
|
|
* the SSID is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void settings_add_ssid_callback(SettingsCallback callback);
|
|
|
|
/**
|
|
* Set the PSK for the WiFi network.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void settings_set_psk(const char *psk);
|
|
|
|
/**
|
|
* Write the PSK for the WiFi network into the given buffer.
|
|
*
|
|
* The length of the psk is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t settings_get_psk(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for PSK updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever the
|
|
* PSK is updated, with the new value as its argument. The lifetime of
|
|
* the passed argument will be static, but the value may be modified
|
|
* once the callback returns.
|
|
*/
|
|
void settings_add_psk_callback(SettingsCallback callback);
|
|
|
|
/**
|
|
* Set the timezone.
|
|
*
|
|
* The argument should be a null-terminated string, containing a
|
|
* timezone spec in the format expected by tzset(). If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void settings_set_timezone(const char *psk);
|
|
|
|
/**
|
|
* Write the timezone into the given buffer.
|
|
*
|
|
* The length of the timezone is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t settings_get_timezone(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for timezone updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever the
|
|
* timezone is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void settings_add_timezone_callback(SettingsCallback callback);
|
|
|
|
/**
|
|
* Set the SNTP server URL.
|
|
*
|
|
* The argument should be a null-terminated string, containing a valid
|
|
* domain name for an SNTP server. If the maximum length is exceeded,
|
|
* the value will still be used, but will be truncated.
|
|
*/
|
|
void settings_set_sntp_server(const char *sntp_server);
|
|
|
|
/**
|
|
* Write the SNTP server URL into the given buffer.
|
|
*
|
|
* The length of the SNTP server domain is returned. If the value's
|
|
* size exceeds the size of the buffer, nothing will be written to the
|
|
* buffer but the length is still returned.
|
|
*/
|
|
size_t settings_get_sntp_server(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for SNTP server URL updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever the
|
|
* SNTP server is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void settings_add_sntp_server_callback(SettingsCallback callback);
|
|
|
|
#endif
|