[settings] Allow for arbitrarily-named settings

This provides a mechanism for using arbitrarily-named variables within
gPXE, using the existing syntax for settings.
This commit is contained in:
Michael Brown
2009-05-26 11:05:58 +01:00
parent 822b3b53f4
commit 3c06277bbb
6 changed files with 297 additions and 99 deletions

View File

@@ -269,7 +269,7 @@ struct net_device {
struct net_device_stats rx_stats;
/** Configuration settings applicable to this device */
struct simple_settings settings;
struct generic_settings settings;
/** Driver private data */
void *priv;
@@ -295,6 +295,7 @@ struct net_device {
extern struct list_head net_devices;
extern struct net_device_operations null_netdev_operations;
extern struct settings_operations netdev_settings_operations;
/**
* Initialise a network device
@@ -385,6 +386,20 @@ netdev_settings ( struct net_device *netdev ) {
return &netdev->settings.settings;
}
/**
* Initialise a per-netdevice configuration settings block
*
* @v generics Generic settings block
* @v refcnt Containing object reference counter, or NULL
* @v name Settings block name
*/
static inline __attribute__ (( always_inline )) void
netdev_settings_init ( struct net_device *netdev ) {
generic_settings_init ( &netdev->settings,
&netdev->refcnt, netdev->name );
netdev->settings.settings.op = &netdev_settings_operations;
}
/**
* Mark network device as having link up
*
@@ -440,8 +455,6 @@ extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
uint16_t net_proto, const void *ll_source );
extern struct settings_operations netdev_settings_operations;
/**
* Complete network transmission
*

View File

@@ -13,7 +13,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/tables.h>
#include <gpxe/list.h>
#include <gpxe/refcnt.h>
#include <gpxe/dhcpopts.h>
struct settings;
struct in_addr;
@@ -69,6 +68,11 @@ struct settings_operations {
*/
int ( * fetch ) ( struct settings *settings, struct setting *setting,
void *data, size_t len );
/** Clear settings block
*
* @v settings Settings block
*/
void ( * clear ) ( struct settings *settings );
};
/** A settings block */
@@ -154,23 +158,24 @@ struct settings_applicator {
#define __settings_applicator __table_entry ( SETTINGS_APPLICATORS, 01 )
/**
* A simple settings block
* A generic settings block
*
*/
struct simple_settings {
struct generic_settings {
/** Settings block */
struct settings settings;
/** DHCP options */
struct dhcp_options dhcpopts;
/** List of generic settings */
struct list_head list;
};
extern struct settings_operations simple_settings_operations;
extern int simple_settings_store ( struct settings *settings,
struct setting *setting,
const void *data, size_t len );
extern int simple_settings_fetch ( struct settings *settings,
struct setting *setting,
void *data, size_t len );
extern struct settings_operations generic_settings_operations;
extern int generic_settings_store ( struct settings *settings,
struct setting *setting,
const void *data, size_t len );
extern int generic_settings_fetch ( struct settings *settings,
struct setting *setting,
void *data, size_t len );
extern void generic_settings_clear ( struct settings *settings );
extern int register_settings ( struct settings *settings,
struct settings *parent );
@@ -201,6 +206,7 @@ extern unsigned long fetch_uintz_setting ( struct settings *settings,
struct setting *setting );
extern int fetch_uuid_setting ( struct settings *settings,
struct setting *setting, union uuid *uuid );
extern void clear_settings ( struct settings *settings );
extern int setting_cmp ( struct setting *a, struct setting *b );
extern struct settings * find_settings ( const char *name );
@@ -263,15 +269,16 @@ static inline void settings_init ( struct settings *settings,
/**
* Initialise a settings block
*
* @v simple Simple settings block
* @v generics Generic settings block
* @v refcnt Containing object reference counter, or NULL
* @v name Settings block name
*/
static inline void simple_settings_init ( struct simple_settings *simple,
struct refcnt *refcnt,
const char *name ) {
settings_init ( &simple->settings, &simple_settings_operations,
static inline void generic_settings_init ( struct generic_settings *generics,
struct refcnt *refcnt,
const char *name ) {
settings_init ( &generics->settings, &generic_settings_operations,
refcnt, name, 0 );
INIT_LIST_HEAD ( &generics->list );
}
/**