Annotation of embedaddon/bmon/src/input.c, revision 1.1.1.2
1.1 misho 1: /*
2: * input.c Input API
3: *
1.1.1.2 ! misho 4: * Copyright (c) 2001-2013 Thomas Graf <tgraf@suug.ch>
! 5: * Copyright (c) 2013 Red Hat, Inc.
1.1 misho 6: *
7: * Permission is hereby granted, free of charge, to any person obtaining a
8: * copy of this software and associated documentation files (the "Software"),
9: * to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11: * and/or sell copies of the Software, and to permit persons to whom the
12: * Software is furnished to do so, subject to the following conditions:
13: *
14: * The above copyright notice and this permission notice shall be included
15: * in all copies or substantial portions of the Software.
16: *
17: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23: * DEALINGS IN THE SOFTWARE.
24: */
25:
26: #include <bmon/bmon.h>
27: #include <bmon/input.h>
1.1.1.2 ! misho 28: #include <bmon/module.h>
1.1 misho 29: #include <bmon/utils.h>
30:
1.1.1.2 ! misho 31: static struct bmon_subsys input_subsys;
1.1 misho 32:
1.1.1.2 ! misho 33: void input_register(struct bmon_module *m)
1.1 misho 34: {
1.1.1.2 ! misho 35: module_register(&input_subsys, m);
1.1 misho 36: }
37:
1.1.1.2 ! misho 38: static void activate_default(void)
1.1 misho 39: {
1.1.1.2 ! misho 40: /*
! 41: * Try to activate a default input module if the user did not make
! 42: * a selection
! 43: */
! 44: if (!input_subsys.s_nmod) {
! 45: struct bmon_module *m;
1.1 misho 46:
1.1.1.2 ! misho 47: #ifdef SYS_LINUX
! 48: if (!input_set("netlink"))
! 49: return;
1.1 misho 50:
1.1.1.2 ! misho 51: if (!input_set("proc"))
! 52: return;
! 53: #endif
1.1 misho 54:
1.1.1.2 ! misho 55: #ifdef SYS_BSD
! 56: if (!input_set("sysctl"))
! 57: return;
1.1 misho 58: #endif
59:
1.1.1.2 ! misho 60: /* Fall back to anything that could act as default */
! 61: list_for_each_entry(m, &input_subsys.s_mod_list, m_list) {
! 62: if (m->m_flags & BMON_MODULE_DEFAULT)
! 63: if (!input_set(m->m_name))
! 64: return;
1.1 misho 65: }
66:
1.1.1.2 ! misho 67: quit("No input module found\n");
1.1 misho 68: }
69: }
70:
1.1.1.2 ! misho 71: void input_read(void)
1.1 misho 72: {
1.1.1.2 ! misho 73: module_foreach_run_enabled(&input_subsys);
1.1 misho 74: }
75:
1.1.1.2 ! misho 76: int input_set(const char *name)
1.1 misho 77: {
1.1.1.2 ! misho 78: return module_set(&input_subsys, name);
1.1 misho 79: }
80:
1.1.1.2 ! misho 81: static struct bmon_subsys input_subsys = {
! 82: .s_name = "input",
! 83: .s_activate_default = &activate_default,
! 84: .s_mod_list = LIST_SELF(input_subsys.s_mod_list),
! 85: };
1.1 misho 86:
1.1.1.2 ! misho 87: static void __init __input_init(void)
1.1 misho 88: {
1.1.1.2 ! misho 89: module_register_subsys(&input_subsys);
1.1 misho 90: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>