Home | History | Annotate | Download | only in core

Lines Matching refs:SETTINGS

34 #include <gpxe/settings.h>
38 * Configuration settings
44 * Generic settings blocks
54 /** List of generic settings */
88 * @v generics Generic settings block
107 * @v settings Settings block
113 int generic_settings_store ( struct settings *settings,
117 container_of ( settings, struct generic_settings, settings );
159 * @v settings Settings block
165 int generic_settings_fetch ( struct settings *settings,
169 container_of ( settings, struct generic_settings, settings );
185 * Clear generic settings block
187 * @v settings Settings block
189 void generic_settings_clear ( struct settings *settings ) {
191 container_of ( settings, struct generic_settings, settings );
202 /** Generic settings operations */
211 * Registered settings blocks
216 /** Root generic settings block */
218 .settings = {
222 LIST_HEAD_INIT ( generic_settings_root.settings.siblings ),
224 LIST_HEAD_INIT ( generic_settings_root.settings.children ),
230 /** Root settings block */
231 #define settings_root generic_settings_root.settings
234 * Find child named settings block
236 * @v parent Parent settings block
238 * @ret settings Settings block, or NULL
240 static struct settings * find_child_settings ( struct settings *parent,
242 struct settings *settings;
249 list_for_each_entry ( settings, &parent->children, siblings ) {
250 if ( strcmp ( settings->name, name ) == 0 )
251 return settings;
258 * Find or create child named settings block
260 * @v parent Parent settings block
262 * @ret settings Settings block, or NULL
264 static struct settings * autovivify_child_settings ( struct settings *parent,
270 struct settings *settings;
272 /* Return existing settings, if existent */
273 if ( ( settings = find_child_settings ( parent, name ) ) != NULL )
274 return settings;
276 /* Create new generic settings block */
279 DBGC ( parent, "Settings %p could not create child %s\n",
285 settings = &new_child->generic.settings;
286 register_settings ( settings, parent );
287 return settings;
291 * Return settings block name (for debug only)
293 * @v settings Settings block
294 * @ret name Settings block name
296 static const char * settings_name ( struct settings *settings ) {
301 for ( count = 0 ; settings ; settings = settings->parent ) {
303 snprintf ( buf, sizeof ( buf ), "%s%c%s", settings->name,
310 * Parse settings block name
313 * @v get_child Function to find or create child settings block
314 * @ret settings Settings block, or NULL
316 static struct settings *
318 struct settings * ( * get_child ) ( struct settings *,
320 struct settings *settings = &settings_root;
338 /* Special case "netX" root settings block */
341 settings = get_child ( settings, netdev->name );
343 settings = get_child ( settings, subname );
345 if ( ! settings )
349 return settings;
353 * Find named settings block
356 * @ret settings Settings block, or NULL
358 struct settings * find_settings ( const char *name ) {
364 * Apply all settings
372 /* Call all settings applicators */
375 DBG ( "Could not apply settings using applicator "
385 * Reprioritise settings
387 * @v settings Settings block
389 * Reorders the settings block amongst its siblings according to its
392 static void reprioritise_settings ( struct settings *settings ) {
393 struct settings *parent = settings->parent;
395 struct settings *tmp;
403 priority = fetch_intz_setting ( settings, &priority_setting );
406 list_del ( &settings->siblings );
414 list_add_tail ( &settings->siblings, &tmp->siblings );
421 * Register settings block
423 * @v settings Settings block
424 * @v parent Parent settings block, or NULL
427 int register_settings ( struct settings *settings, struct settings *parent ) {
428 struct settings *old_settings;
430 /* NULL parent => add to settings root */
431 assert ( settings != NULL );
435 /* Remove any existing settings with the same name */
436 if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
439 /* Add to list of settings */
440 ref_get ( settings->refcnt );
442 settings->parent = parent;
443 list_add_tail ( &settings->siblings, &parent->children );
444 DBGC ( settings, "Settings %p (\"%s\") registered\n",
445 settings, settings_name ( settings ) );
447 /* Fix up settings priority */
448 reprioritise_settings ( settings );
450 /* Apply potentially-updated settings */
457 * Unregister settings block
459 * @v settings Settings block
461 void unregister_settings ( struct settings *settings ) {
463 DBGC ( settings, "Settings %p (\"%s\") unregistered\n",
464 settings, settings_name ( settings ) );
466 /* Remove from list of settings */
467 ref_put ( settings->refcnt );
468 ref_put ( settings->parent->refcnt );
469 settings->parent = NULL;
470 list_del ( &settings->siblings );
472 /* Apply potentially-updated settings */
478 * Core settings routines
486 * @v settings Settings block, or NULL
492 int store_setting ( struct settings *settings, struct setting *setting,
496 /* NULL settings implies storing into the global settings root */
497 if ( ! settings )
498 settings = &settings_root;
501 if ( ! settings->op->store )
505 if ( ( rc = settings->op->store ( settings, setting,
509 /* Reprioritise settings if necessary */
511 reprioritise_settings ( settings );
513 /* If these settings are registered, apply potentially-updated
514 * settings
516 for ( ; settings ; settings = settings->parent ) {
517 if ( settings == &settings_root ) {
530 * @v settings Settings block, or NULL to search all blocks
539 int fetch_setting ( struct settings *settings, struct setting *setting,
541 struct settings *child;
547 /* NULL settings implies starting at the global settings root */
548 if ( ! settings )
549 settings = &settings_root;
552 if ( ! settings->op->fetch )
556 if ( ( ret = settings->op->fetch ( settings, setting,
561 list_for_each_entry ( child, &settings->children, siblings ) {
573 * @v settings Settings block, or NULL to search all blocks
580 int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
581 return fetch_setting ( settings, setting, NULL, 0 );
587 * @v settings Settings block, or NULL to search all blocks
597 int fetch_string_setting ( struct settings *settings, struct setting *setting,
600 return fetch_setting ( settings, setting, data,
607 * @v settings Settings block, or NULL to search all blocks
617 int fetch_string_setting_copy ( struct settings *settings,
623 len = fetch_setting_len ( settings, setting );
631 check_len = fetch_string_setting ( settings, setting, *data,
640 * @v settings Settings block, or NULL to search all blocks
645 int fetch_ipv4_setting ( struct settings *settings, struct setting *setting,
649 len = fetch_setting ( settings, setting, inp, sizeof ( *inp ) );
660 * @v settings Settings block, or NULL to search all blocks
665 int fetch_int_setting ( struct settings *settings, struct setting *setting,
678 len = fetch_setting ( settings, setting, &buf, sizeof ( buf ) );
696 * @v settings Settings block, or NULL to search all blocks
701 int fetch_uint_setting ( struct settings *settings, struct setting *setting,
710 len = fetch_int_setting ( settings, setting, &svalue );
724 * @v settings Settings block, or NULL to search all blocks
728 long fetch_intz_setting ( struct settings *settings, struct setting *setting ){
731 fetch_int_setting ( settings, setting, &value );
738 * @v settings Settings block, or NULL to search all blocks
742 unsigned long fetch_uintz_setting ( struct settings *settings,
746 fetch_uint_setting ( settings, setting, &value );
753 * @v settings Settings block, or NULL to search all blocks
758 int fetch_uuid_setting ( struct settings *settings, struct setting *setting,
762 len = fetch_setting ( settings, setting, uuid, sizeof ( *uuid ) );
771 * Clear settings block
773 * @v settings Settings block
775 void clear_settings ( struct settings *settings ) {
776 if ( settings->op->clear )
777 settings->op->clear ( settings );
781 * Compare two settings
785 * @ret 0 Settings are the same
786 * @ret non-zero Settings are not the same
790 /* If the settings have tags, compare them */
794 /* Otherwise, if the settings have names, compare them */
812 * @v settings Settings block
814 * @v type Settings type
818 int storef_setting ( struct settings *settings, struct setting *setting,
826 return delete_setting ( settings, setting );
828 return setting->type->storef ( settings, setting, value );
840 for_each_table_entry ( setting, SETTINGS ) {
887 * @v get_child Function to find or create child settings block
888 * @v settings Settings block to fill in
902 struct settings * ( * get_child ) ( struct settings *,
904 struct settings **settings, struct setting *setting,
912 *settings = &settings_root;
929 /* Identify settings block, if specified */
931 *settings = parse_settings_name ( settings_name, get_child );
932 if ( *settings == NULL ) {
933 DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
945 setting->tag |= (*settings)->tag_magic;
972 struct settings *settings;
978 &settings, &setting, tmp_name )) != 0)
980 return storef_setting ( settings, &setting, value );
992 struct settings *settings;
998 &settings, &setting, tmp_name )) != 0)
1000 return fetchf_setting ( settings, &setting, buf, len );
1013 * @v settings Settings block
1018 static int storef_string ( struct settings *settings, struct setting *setting,
1020 return store_setting ( settings, setting, value, strlen ( value ) );
1026 * @v settings Settings block, or NULL to search all blocks
1032 static int fetchf_string ( struct settings *settings, struct setting *setting,
1034 return fetch_string_setting ( settings, setting, buf, len );
1047 * @v settings Settings block
1052 static int storef_uristring ( struct settings *settings,
1059 return store_setting ( settings, setting, buf, len );
1065 * @v settings Settings block, or NULL to search all blocks
1071 static int fetchf_uristring ( struct settings *settings,
1079 raw_len = fetch_setting ( settings, setting, NULL, 0 );
1086 fetch_string_setting ( settings, setting, raw_buf,
1102 * @v settings Settings block
1107 static int storef_ipv4 ( struct settings *settings, struct setting *setting,
1113 return store_setting ( settings, setting, &ipv4, sizeof ( ipv4 ) );
1119 * @v settings Settings block, or NULL to search all blocks
1125 static int fetchf_ipv4 ( struct settings *settings, struct setting *setting,
1130 if ( ( raw_len = fetch_ipv4_setting ( settings, setting, &ipv4 ) ) < 0)
1145 * @v settings Settings block
1151 static int storef_int ( struct settings *settings, struct setting *setting,
1162 return store_setting ( settings, setting,
1169 * @v settings Settings block
1175 static int storef_int8 ( struct settings *settings, struct setting *setting,
1177 return storef_int ( settings, setting, value, 1 );
1183 * @v settings Settings block
1189 static int storef_int16 ( struct settings *settings, struct setting *setting,
1191 return storef_int ( settings, setting, value, 2 );
1197 * @v settings Settings block
1203 static int storef_int32 ( struct settings *settings, struct setting *setting,
1205 return storef_int ( settings, setting, value, 4 );
1211 * @v settings Settings block, or NULL to search all blocks
1217 static int fetchf_int ( struct settings *settings, struct setting *setting,
1222 if ( ( rc = fetch_int_setting ( settings, setting, &value ) ) < 0 )
1230 * @v settings Settings block, or NULL to search all blocks
1236 static int fetchf_uint ( struct settings *settings, struct setting *setting,
1241 if ( ( rc = fetch_uint_setting ( settings, setting, &value ) ) < 0 )
1291 * @v settings Settings block
1296 static int storef_hex ( struct settings *settings, struct setting *setting,
1306 return store_setting ( settings, setting, bytes, len );
1319 * @v settings Settings block, or NULL to search all blocks
1325 static int fetchf_hex ( struct settings *settings, struct setting *setting,
1332 raw_len = fetch_setting_len ( settings, setting );
1339 check_len = fetch_setting ( settings, setting, raw,
1366 * @v settings Settings block
1371 static int storef_uuid ( struct settings *settings __unused,
1380 * @v settings Settings block, or NULL to search all blocks
1386 static int fetchf_uuid ( struct settings *settings, struct setting *setting,
1391 if ( ( raw_len = fetch_uuid_setting ( settings, setting, &uuid ) ) < 0)
1405 * Settings
1453 .description = "Priority of these settings",