Skip to content

Commit

Permalink
fix: always pass "floats" as doubles
Browse files Browse the repository at this point in the history
Consistent usage of doubled and consistent with the roverlib-go API
ielaajezdev committed Dec 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 332bcc8 commit 99626f2
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions include/roverlib/configuration.h
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ typedef struct {

Service_configuration new_service_configuration(Service service);

void set_number_value(Service_configuration *config, char *key, double value);
void set_float_value(Service_configuration *config, char *key, double value);

void set_string_value(Service_configuration *config, char *key, char *value);

@@ -39,8 +39,8 @@ void set_string_value(Service_configuration *config, char *key, char *value);
// Gets the float value of the configuration option with the given name, returns NULL if the option does not exist or does not exist for this type
// Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly
// If you want to read the configuration values with concurrency-safety, use the _safe methods
float* get_float_value(Service_configuration *config, char *key);
float* get_float_value_safe(Service_configuration *config, char *key);
double* get_float_value(Service_configuration *config, char *key);
double* get_float_value_safe(Service_configuration *config, char *key);

// Gets the string value of the configuration option with the given name, returns NULL if the option does not exist or does not exist for this type
// Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly
8 changes: 4 additions & 4 deletions src/configuration.c
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ Service_configuration new_service_configuration(Service service) {
return config;
}

void set_number_value(Service_configuration *config, char *key, double value) {
void set_float_value(Service_configuration *config, char *key, double value) {
pthread_rwlock_wrlock(config->rwlock);

// Check if this key is tunable
@@ -63,12 +63,12 @@ void set_string_value(Service_configuration *config, char *key, char *value) {
// Gets the float value of the configuration option with the given name, returns NULL if the option does not exist or does not exist for this type
// Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly
// If you want to read the configuration values with concurrency-safety, use the _safe methods
float* get_float_value(Service_configuration *config, char *key) {
double* get_float_value(Service_configuration *config, char *key) {
return hashtable_lookup(config->float_values, key);
}
float* get_float_value_safe(Service_configuration *config, char *key) {
double* get_float_value_safe(Service_configuration *config, char *key) {
pthread_rwlock_rdlock(config->rwlock);
float *value = hashtable_lookup(config->float_values, key);
double *value = hashtable_lookup(config->float_values, key);
pthread_rwlock_unlock(config->rwlock);
return value;
}
2 changes: 1 addition & 1 deletion src/run.c
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ void *configuration_thread(void *arg) {
ProtobufMsgs__TuningState__Parameter *param = tuning_state->dynamicparameters[i];

if (param->parameter_case == PROTOBUF_MSGS__TUNING_STATE__PARAMETER__PARAMETER_NUMBER) {
set_number_value(args->config, param->number->key, param->number->value);
set_float_value(args->config, param->number->key, param->number->value);
} else if (param->parameter_case == PROTOBUF_MSGS__TUNING_STATE__PARAMETER__PARAMETER_STRING) {
set_string_value(args->config, param->string->key, param->string->value);
}

0 comments on commit 99626f2

Please sign in to comment.