Golioth Firmware SDK
golioth_settings.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Golioth, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #pragma once
7 
8 #include "golioth_status.h"
9 #include "golioth_client.h"
10 #include "golioth_config.h"
11 #include <stdint.h>
12 #include <stdbool.h>
13 
40 
42 typedef enum {
58 
60 typedef enum {
67 
75 typedef golioth_settings_status_t (*golioth_int_setting_cb)(int32_t new_value, void* arg);
76 typedef golioth_settings_status_t (*golioth_bool_setting_cb)(bool new_value, void* arg);
77 typedef golioth_settings_status_t (*golioth_float_setting_cb)(float new_value, void* arg);
79  *golioth_string_setting_cb)(const char* new_value, size_t new_value_len, void* arg);
80 
82 typedef struct {
83  bool is_valid;
84  const char* key; // aka name
86  union {
91  };
92  int32_t int_min_val; // applies only to integers
93  int32_t int_max_val; // applies only to integers
94  void* cb_arg;
96 
99 typedef struct {
102  size_t num_settings;
104 
120  golioth_client_t client,
121  const char* setting_name,
122  golioth_int_setting_cb callback,
123  void* callback_arg);
124 
128  golioth_client_t client,
129  const char* setting_name,
130  int32_t min_val,
131  int32_t max_val,
132  golioth_int_setting_cb callback,
133  void* callback_arg);
134 
137  golioth_client_t client,
138  const char* setting_name,
139  golioth_bool_setting_cb callback,
140  void* callback_arg);
141 
144  golioth_client_t client,
145  const char* setting_name,
146  golioth_float_setting_cb callback,
147  void* callback_arg);
148 
#define CONFIG_GOLIOTH_MAX_NUM_SETTINGS
golioth_status_t
void * golioth_client_t
Opaque handle to the Golioth client.
golioth_status_t golioth_settings_register_float(golioth_client_t client, const char *setting_name, golioth_float_setting_cb callback, void *callback_arg)
Same as golioth_settings_register_int, but for type float.
golioth_settings_status_t(* golioth_string_setting_cb)(const char *new_value, size_t new_value_len, void *arg)
golioth_settings_status_t(* golioth_float_setting_cb)(float new_value, void *arg)
golioth_status_t golioth_settings_register_bool(golioth_client_t client, const char *setting_name, golioth_bool_setting_cb callback, void *callback_arg)
Same as golioth_settings_register_int, but for type bool.
golioth_status_t golioth_settings_register_int_with_range(golioth_client_t client, const char *setting_name, int32_t min_val, int32_t max_val, golioth_int_setting_cb callback, void *callback_arg)
golioth_settings_value_type_t
Different types of setting values.
golioth_settings_status_t
Enumeration of Settings status codes.
golioth_settings_status_t(* golioth_int_setting_cb)(int32_t new_value, void *arg)
golioth_settings_status_t(* golioth_bool_setting_cb)(bool new_value, void *arg)
golioth_status_t golioth_settings_register_int(golioth_client_t client, const char *setting_name, golioth_int_setting_cb callback, void *callback_arg)
@ GOLIOTH_SETTINGS_VALUE_TYPE_STRING
@ GOLIOTH_SETTINGS_VALUE_TYPE_UNKNOWN
@ GOLIOTH_SETTINGS_VALUE_TYPE_INT
@ GOLIOTH_SETTINGS_VALUE_TYPE_BOOL
@ GOLIOTH_SETTINGS_VALUE_TYPE_FLOAT
@ GOLIOTH_SETTINGS_GENERAL_ERROR
Other general error (e.g. I/O error)
@ GOLIOTH_SETTINGS_VALUE_OUTSIDE_RANGE
The setting value is outside of allowed range.
@ GOLIOTH_SETTINGS_VALUE_STRING_TOO_LONG
The setting value string is too long, exceeds max length.
@ GOLIOTH_SETTINGS_KEY_NOT_VALID
The setting key is too long, ill-formatted.
@ GOLIOTH_SETTINGS_KEY_NOT_RECOGNIZED
The setting key is not recognized, this setting is unknown.
@ GOLIOTH_SETTINGS_SUCCESS
Setting applied successfully to the device, stored in NVS.
@ GOLIOTH_SETTINGS_VALUE_FORMAT_NOT_VALID
The setting value is improperly formatted.
Private struct for storing a single setting.
golioth_settings_value_type_t type
golioth_int_setting_cb int_cb
golioth_string_setting_cb string_cb
golioth_bool_setting_cb bool_cb
golioth_float_setting_cb float_cb