Skip to content

Commit b548036

Browse files
committed
fix(axparameter): Enforce fully-qualified parameter names for consistency
Replace all unqualified parameter names with fully-qualified names using the "root.axparameter.*" format throughout the codebase. This ensures consistent API usage and improves clarity in parameter scope handling. Described in the comment all the possible alternative formats of parameter name to be used. Closes #440
1 parent 52f1c92 commit b548036

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

axparameter/app/axparameter.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void restore_custom_value_from_backup(AXParameter* handle) {
9292
gchar* value;
9393

9494
if (!ax_parameter_get(handle, "BackupValue", &value, &error) ||
95-
!ax_parameter_add(handle, "CustomValue", value, NULL, &error))
95+
!ax_parameter_add(handle, "root." APP_NAME ".CustomValue", value, NULL, &error))
9696
panic("%s", error->message);
9797

9898
syslog(LOG_INFO,
@@ -107,9 +107,9 @@ static void back_up_and_remove_custom_value(AXParameter* handle) {
107107
GError* error = NULL;
108108
gchar* value;
109109

110-
if (!ax_parameter_get(handle, "CustomValue", &value, &error) ||
110+
if (!ax_parameter_get(handle, "root." APP_NAME ".CustomValue", &value, &error) ||
111111
!ax_parameter_set(handle, "BackupValue", value, TRUE, &error) ||
112-
!ax_parameter_remove(handle, "CustomValue", &error))
112+
!ax_parameter_remove(handle, "root." APP_NAME ".CustomValue", &error))
113113
panic("%s", error->message);
114114

115115
syslog(LOG_INFO,
@@ -128,14 +128,14 @@ static gboolean monitor_parameters(void* msg_void_ptr) {
128128

129129
syslog(LOG_INFO, "%s was changed to '%s' one second ago", msg->name, msg->value);
130130

131-
bool has_custom_value_param = has_parameter(handle, "CustomValue");
131+
bool has_custom_value_param = has_parameter(handle, "root." APP_NAME ".CustomValue");
132132

133-
if (is_parameter_yes(handle, "IsCustomized")) {
133+
if (is_parameter_yes(handle, "root." APP_NAME ".IsCustomized")) {
134134
if (!has_custom_value_param)
135135
restore_custom_value_from_backup(handle);
136136

137137
gchar* custom_value;
138-
if (!ax_parameter_get(handle, "CustomValue", &custom_value, &error))
138+
if (!ax_parameter_get(handle, "root." APP_NAME ".CustomValue", &custom_value, &error))
139139
panic("%s", error->message);
140140
syslog(LOG_INFO, "Custom value: '%s'", custom_value);
141141
g_free(custom_value);
@@ -190,12 +190,25 @@ int main(void) {
190190
syslog(LOG_INFO, "SerialNumber: '%s'", serial_number);
191191
g_free(serial_number);
192192

193-
// Act on changes to IsCustomized as soon as they happen.
194-
if (!ax_parameter_register_callback(handle, "IsCustomized", parameter_changed, handle, &error))
193+
// It is possible to subscribe for several formats of the parameter name:
194+
// - "IsCustomized"
195+
// - "root.axparameter.IsCustomized"
196+
197+
// Act on changes to root.axparameter.IsCustomized as soon as they happen.
198+
if (!ax_parameter_register_callback(handle,
199+
"root." APP_NAME ".IsCustomized",
200+
parameter_changed,
201+
handle,
202+
&error))
195203
panic("%s", error->message);
196204

197-
// Register the same callback for CustomValue, even though that parameter does not exist yet!
198-
if (!ax_parameter_register_callback(handle, "CustomValue", parameter_changed, handle, &error))
205+
// Register the same callback for root.axparameter.CustomValue, even though that parameter does
206+
// not exist yet!
207+
if (!ax_parameter_register_callback(handle,
208+
"root." APP_NAME ".CustomValue",
209+
parameter_changed,
210+
handle,
211+
&error))
199212
panic("%s", error->message);
200213

201214
// Start listening to callbacks by launching a GLib main loop.

0 commit comments

Comments
 (0)