From c062e0737663e5189695dcd227ff2a894fdc971c Mon Sep 17 00:00:00 2001 From: jmmv Date: Sun, 2 Mar 2008 11:19:30 +0000 Subject: [PATCH] Add an example on how to handle the incoming properties during module load. --- sys/modules/example/example.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sys/modules/example/example.c b/sys/modules/example/example.c index 4eed2c9243d6..923b8fdff57f 100644 --- a/sys/modules/example/example.c +++ b/sys/modules/example/example.c @@ -1,4 +1,4 @@ -/* $NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $ */ +/* $NetBSD: example.c,v 1.2 2008/03/02 11:19:30 jmmv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.2 2008/03/02 11:19:30 jmmv Exp $"); #include #include @@ -42,6 +42,26 @@ __KERNEL_RCSID(0, "$NetBSD: example.c,v 1.1 2008/01/16 12:34:57 ad Exp $"); MODULE(MODULE_CLASS_MISC, example, NULL); +static +void +handle_props(prop_dictionary_t props) +{ + prop_string_t str; + + str = prop_dictionary_get(props, "msg"); + if (str == NULL) + printf("The 'msg' property was not given.\n"); + else if (prop_object_type(str) != PROP_TYPE_STRING) + printf("The 'msg' property is not a string.\n"); + else { + const char *msg = prop_string_cstring_nocopy(str); + if (msg == NULL) + printf("Failed to process the 'msg' property.\n"); + else + printf("The 'msg' property is: %s\n", msg); + } +} + static int example_modcmd(modcmd_t cmd, void *arg) { @@ -49,6 +69,7 @@ example_modcmd(modcmd_t cmd, void *arg) switch (cmd) { case MODULE_CMD_INIT: printf("Example module loaded.\n"); + handle_props(arg); break; case MODULE_CMD_FINI: