/** Settings block operations */
struct settings_operations {
- /** Set value of setting
+ /** Store value of setting
*
* @v settings Settings block
* @v tag Setting tag number
* @v len Length of setting data
* @ret rc Return status code
*/
- int ( * set ) ( struct settings *settings, unsigned int tag,
- const void *data, size_t len );
- /** Get value of setting
+ int ( * store ) ( struct settings *settings, unsigned int tag,
+ const void *data, size_t len );
+ /** Fetch value of setting
*
* @v settings Settings block
* @v tag Setting tag number
* The actual length of the setting will be returned even if
* the buffer was too small.
*/
- int ( * get ) ( struct settings *settings, unsigned int tag,
- void *data, size_t len );
+ int ( * fetch ) ( struct settings *settings, unsigned int tag,
+ void *data, size_t len );
};
/** A settings block */
/** Reference counter */
struct refcnt *refcnt;
/** Name */
- char name[16];
- /** List of all settings */
- struct list_head list;
+ const char *name;
+ /** Parent settings block */
+ struct settings *parent;
+ /** Sibling settings blocks */
+ struct list_head siblings;
+ /** Child settings blocks */
+ struct list_head children;
/** Settings block operations */
struct settings_operations *op;
};
* @v value Formatted setting data
* @ret rc Return status code
*/
- int ( * setf ) ( struct settings *settings, unsigned int tag,
- const char *value );
- /** Get and format value of setting
+ int ( * storef ) ( struct settings *settings, unsigned int tag,
+ const char *value );
+ /** Fetch and format value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v tag Setting tag number
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
- int ( * getf ) ( struct settings *settings, unsigned int tag,
- char *buf, size_t len );
+ int ( * fetchf ) ( struct settings *settings, unsigned int tag,
+ char *buf, size_t len );
};
/** Declare a configuration setting type */
struct named_setting {
/** Name
*
- * This is the human-readable name for the setting. Where
- * possible, it should match the name used in dhcpd.conf (see
- * dhcp-options(5)).
+ * This is the human-readable name for the setting.
*/
const char *name;
/** Description */
/** Declare a configuration setting */
#define __named_setting __table ( struct named_setting, named_settings, 01 )
-extern struct settings interactive_settings;
-
-extern int get_setting ( struct settings *settings, unsigned int tag,
- void *data, size_t len );
-extern int get_setting_len ( struct settings *settings, unsigned int tag );
-extern int get_string_setting ( struct settings *settings, unsigned int tag,
- char *data, size_t len );
-extern int get_ipv4_setting ( struct settings *settings, unsigned int tag,
- struct in_addr *inp );
-extern int get_int_setting ( struct settings *settings, unsigned int tag,
- long *value );
-extern int get_uint_setting ( struct settings *settings, unsigned int tag,
- unsigned long *value );
+/**
+ * A settings applicator
+ *
+ */
+struct settings_applicator {
+ /** Apply updated settings
+ *
+ * @ret rc Return status code
+ */
+ int ( * apply ) ( void );
+};
+
+/** Declare a settings applicator */
+#define __settings_applicator \
+ __table ( struct settings_applicator, settings_applicators, 01 )
+
+extern int simple_settings_store ( struct settings *settings, unsigned int tag,
+ const void *data, size_t len );
+extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
+ void *data, size_t len );
+extern struct settings_operations simple_settings_operations;
+
+extern int register_settings ( struct settings *settings,
+ struct settings *parent );
+extern void unregister_settings ( struct settings *settings );
+extern int store_setting ( struct settings *settings, unsigned int tag,
+ const void *data, size_t len );
+extern int fetch_setting ( struct settings *settings, unsigned int tag,
+ void *data, size_t len );
+extern int fetch_setting_len ( struct settings *settings, unsigned int tag );
+extern int fetch_string_setting ( struct settings *settings, unsigned int tag,
+ char *data, size_t len );
+extern int fetch_ipv4_setting ( struct settings *settings, unsigned int tag,
+ struct in_addr *inp );
+extern int fetch_int_setting ( struct settings *settings, unsigned int tag,
+ long *value );
+extern int fetch_uint_setting ( struct settings *settings, unsigned int tag,
+ unsigned long *value );
+extern long fetch_intz_setting ( struct settings *settings, unsigned int tag );
+extern unsigned long fetch_uintz_setting ( struct settings *settings,
+ unsigned int tag );
extern struct settings * find_settings ( const char *name );
-extern int set_typed_setting ( struct settings *settings,
- unsigned int tag, struct setting_type *type,
- const char *value );
-extern int set_named_setting ( const char *name, const char *value );
-extern int get_named_setting ( const char *name, char *buf, size_t len );
+extern int store_typed_setting ( struct settings *settings,
+ unsigned int tag, struct setting_type *type,
+ const char *value );
+extern int store_named_setting ( const char *name, const char *value );
+extern int fetch_named_setting ( const char *name, char *buf, size_t len );
+
+extern struct setting_type setting_type_ __setting_type;
+extern struct setting_type setting_type_string __setting_type;
+extern struct setting_type setting_type_ipv4 __setting_type;
+extern struct setting_type setting_type_int8 __setting_type;
+extern struct setting_type setting_type_int16 __setting_type;
+extern struct setting_type setting_type_int32 __setting_type;
+extern struct setting_type setting_type_uint8 __setting_type;
+extern struct setting_type setting_type_uint16 __setting_type;
+extern struct setting_type setting_type_uint32 __setting_type;
+extern struct setting_type setting_type_hex __setting_type;
/**
- * Set value of setting
+ * Initialise a settings block
*
* @v settings Settings block
- * @v tag Setting tag number
- * @v data Setting data, or NULL to clear setting
- * @v len Length of setting data
- * @ret rc Return status code
+ * @v op Settings block operations
+ * @v refcnt Containing object reference counter, or NULL
+ * @v name Settings block name
*/
-static inline int set_setting ( struct settings *settings, unsigned int tag,
- const void *data, size_t len ) {
- return settings->op->set ( settings, tag, data, len );
+static inline void settings_init ( struct settings *settings,
+ struct settings_operations *op,
+ struct refcnt *refcnt,
+ const char *name ) {
+ INIT_LIST_HEAD ( &settings->siblings );
+ INIT_LIST_HEAD ( &settings->children );
+ settings->op = op;
+ settings->refcnt = refcnt;
+ settings->name = name;
}
/**
*/
static inline int delete_setting ( struct settings *settings,
unsigned int tag ) {
- return set_setting ( settings, tag, NULL, 0 );
+ return store_setting ( settings, tag, NULL, 0 );
}
/**
- * Get and format value of setting
+ * Fetch and format value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v tag Setting tag number
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static inline int get_typed_setting ( struct settings *settings,
- unsigned int tag,
- struct setting_type *type,
- char *buf, size_t len ) {
- return type->getf ( settings, tag, buf, len );
+static inline int fetch_typed_setting ( struct settings *settings,
+ unsigned int tag,
+ struct setting_type *type,
+ char *buf, size_t len ) {
+ return type->fetchf ( settings, tag, buf, len );
}
/**
* @ret rc Return status code
*/
static inline int delete_named_setting ( const char *name ) {
- return set_named_setting ( name, NULL );
+ return store_named_setting ( name, NULL );
}
#endif /* _GPXE_SETTINGS_H */