File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bmon / src / input.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jul 30 07:55:27 2014 UTC (9 years, 10 months ago) by misho
Branches: bmon, MAIN
CVS tags: v4_0p0, v3_3, HEAD
bmon 3.3

    1: /*
    2:  * input.c            Input API
    3:  *
    4:  * Copyright (c) 2001-2013 Thomas Graf <tgraf@suug.ch>
    5:  * Copyright (c) 2013 Red Hat, Inc.
    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>
   28: #include <bmon/module.h>
   29: #include <bmon/utils.h>
   30: 
   31: static struct bmon_subsys input_subsys;
   32: 
   33: void input_register(struct bmon_module *m)
   34: {
   35: 	module_register(&input_subsys, m);
   36: }
   37: 
   38: static void activate_default(void)
   39: {
   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;
   46: 
   47: #ifdef SYS_LINUX
   48: 		if (!input_set("netlink"))
   49: 			return;
   50: 
   51: 		if (!input_set("proc"))
   52: 			return;
   53: #endif
   54: 
   55: #ifdef SYS_BSD
   56: 		if (!input_set("sysctl"))
   57: 			return;
   58: #endif
   59: 
   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;
   65: 		}
   66: 
   67: 		quit("No input module found\n");
   68: 	}
   69: }
   70: 
   71: void input_read(void)
   72: {
   73: 	module_foreach_run_enabled(&input_subsys);
   74: }
   75: 
   76: int input_set(const char *name)
   77: {
   78: 	return module_set(&input_subsys, name);
   79: }
   80: 
   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: };
   86: 
   87: static void __init __input_init(void)
   88: {
   89: 	module_register_subsys(&input_subsys);
   90: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>