1*14e25719Spgoyette /* $NetBSD: properties.c,v 1.1 2015/05/13 07:07:36 pgoyette Exp $ */
2*14e25719Spgoyette
3*14e25719Spgoyette /*-
4*14e25719Spgoyette * Copyright (c) 2008 The NetBSD Foundation, Inc.
5*14e25719Spgoyette * All rights reserved.
6*14e25719Spgoyette *
7*14e25719Spgoyette * Redistribution and use in source and binary forms, with or without
8*14e25719Spgoyette * modification, are permitted provided that the following conditions
9*14e25719Spgoyette * are met:
10*14e25719Spgoyette * 1. Redistributions of source code must retain the above copyright
11*14e25719Spgoyette * notice, this list of conditions and the following disclaimer.
12*14e25719Spgoyette * 2. Redistributions in binary form must reproduce the above copyright
13*14e25719Spgoyette * notice, this list of conditions and the following disclaimer in the
14*14e25719Spgoyette * documentation and/or other materials provided with the distribution.
15*14e25719Spgoyette *
16*14e25719Spgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*14e25719Spgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*14e25719Spgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*14e25719Spgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*14e25719Spgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*14e25719Spgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*14e25719Spgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*14e25719Spgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*14e25719Spgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*14e25719Spgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*14e25719Spgoyette * POSSIBILITY OF SUCH DAMAGE.
27*14e25719Spgoyette */
28*14e25719Spgoyette
29*14e25719Spgoyette #include <sys/cdefs.h>
30*14e25719Spgoyette __KERNEL_RCSID(0, "$NetBSD: properties.c,v 1.1 2015/05/13 07:07:36 pgoyette Exp $");
31*14e25719Spgoyette
32*14e25719Spgoyette #include <sys/param.h>
33*14e25719Spgoyette #include <sys/kernel.h>
34*14e25719Spgoyette #include <sys/module.h>
35*14e25719Spgoyette
36*14e25719Spgoyette MODULE(MODULE_CLASS_MISC, properties, NULL);
37*14e25719Spgoyette
38*14e25719Spgoyette static void
handle_props(prop_dictionary_t props)39*14e25719Spgoyette handle_props(prop_dictionary_t props)
40*14e25719Spgoyette {
41*14e25719Spgoyette const char *msg;
42*14e25719Spgoyette prop_string_t str;
43*14e25719Spgoyette
44*14e25719Spgoyette if (props != NULL) {
45*14e25719Spgoyette str = prop_dictionary_get(props, "msg");
46*14e25719Spgoyette } else {
47*14e25719Spgoyette printf("No property dictionary was provided.\n");
48*14e25719Spgoyette str = NULL;
49*14e25719Spgoyette }
50*14e25719Spgoyette if (str == NULL)
51*14e25719Spgoyette printf("The 'msg' property was not given.\n");
52*14e25719Spgoyette else if (prop_object_type(str) != PROP_TYPE_STRING)
53*14e25719Spgoyette printf("The 'msg' property is not a string.\n");
54*14e25719Spgoyette else {
55*14e25719Spgoyette msg = prop_string_cstring_nocopy(str);
56*14e25719Spgoyette if (msg == NULL)
57*14e25719Spgoyette printf("Failed to process the 'msg' property.\n");
58*14e25719Spgoyette else
59*14e25719Spgoyette printf("The 'msg' property is: %s\n", msg);
60*14e25719Spgoyette }
61*14e25719Spgoyette }
62*14e25719Spgoyette
63*14e25719Spgoyette static int
properties_modcmd(modcmd_t cmd,void * arg)64*14e25719Spgoyette properties_modcmd(modcmd_t cmd, void *arg)
65*14e25719Spgoyette {
66*14e25719Spgoyette switch (cmd) {
67*14e25719Spgoyette case MODULE_CMD_INIT:
68*14e25719Spgoyette handle_props(arg);
69*14e25719Spgoyette return 0;
70*14e25719Spgoyette case MODULE_CMD_FINI:
71*14e25719Spgoyette return 0;
72*14e25719Spgoyette default:
73*14e25719Spgoyette return ENOTTY;
74*14e25719Spgoyette }
75*14e25719Spgoyette }
76