PROP_INGEST(3) | NetBSD Library Functions Manual | PROP_INGEST(3) |
prop_ingest_context_t
prop_ingest_context_alloc(void *private);
void
prop_ingest_context_free(prop_ingest_context_t ctx);
prop_ingest_error_t
prop_ingest_context_error(prop_ingest_context_t ctx);
prop_type_t
prop_ingest_context_type(prop_ingest_context_t ctx);
const char *
prop_ingest_context_key(prop_ingest_context_t ctx);
void *
prop_ingest_context_private(prop_ingest_context_t ctx);
bool
prop_dictionary_ingest(prop_dictionary_t dict, const prop_ingest_table_entry rules[], prop_ingest_context_t ctx);
typedef bool
(*prop_ingest_handler_t)(prop_ingest_context_t, prop_object_t);
prop_dictionary_ingest is driven by a table of rules provided by the application. Each rule consists of three items:
The table is constructed using a series of macros as follows:
static const prop_ingest_table_entry ingest_rules[] = { PROP_INGEST("file-name", PROP_TYPE_STRING, ingest_filename), PROP_INGEST("count", PROP_TYPE_NUMBER, ingest_count), PROP_INGEST_OPTIONAL("required", PROP_TYPE_BOOL, ingest_required), PROP_INGEST_OPTIONAL("extra", PROP_TYPE_UNKNOWN, ingest_extra), PROP_INGEST_END };
The PROP_INGEST macro specifies that the key is required to be present in the dictionary. The PROP_INGEST_OPTIONAL macro specifies that the presence of the key in the dictionary is optional. The PROP_INGEST_END macro marks the end of the rules table.
In each case, prop_dictionary_ingest looks up the rule's key in the dictionary. If an object is present in the dictionary at that key, its type is checked against the type specified in the rule. A type specification of PROP_TYPE_UNKNOWN allows the object to be of any type. If the object does not exist and the rule is not marked as optional, then an error is returned. Otherwise, the handler specified in the rule is invoked with the ingest context and the object (or NULL if the key does not exist in the dictionary). The handler should return false if the value of the object is invalid to indicate failure and true otherwise.
The ingest context contains several pieces of information that are useful during the ingest process. The context also provides specific error information should the ingest fail.
January 21, 2008 | NetBSD 5.99 |