1: /*
2: * output.c Output 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/output.h>
28: #include <bmon/module.h>
29: #include <bmon/conf.h>
30: #include <bmon/group.h>
31: #include <bmon/utils.h>
32:
33: static struct bmon_subsys output_subsys;
34:
35: void output_register(struct bmon_module *m)
36: {
37: module_register(&output_subsys, m);
38: }
39:
40: static void activate_default(void)
41: {
42: /*
43: * Try to activate a default output module if the user did not make
44: * a selection
45: */
46: if (!output_subsys.s_nmod) {
47: struct bmon_module *m;
48:
49: if (!output_set("curses"))
50: return;
51:
52: if (!output_set("ascii"))
53: return;
54:
55: /* Fall back to anything that could act as default */
56: list_for_each_entry(m, &output_subsys.s_mod_list, m_list) {
57: if (m->m_flags & BMON_MODULE_DEFAULT)
58: if (!output_set(m->m_name))
59: return;
60: }
61:
62: quit("No output module found\n");
63: }
64: }
65:
66: void output_pre(void)
67: {
68: module_foreach_run_enabled_pre(&output_subsys);
69: }
70:
71: void output_draw(void)
72: {
73: module_foreach_run_enabled(&output_subsys);
74: }
75:
76: void output_post(void)
77: {
78: module_foreach_run_enabled_post(&output_subsys);
79: }
80:
81: int output_set(const char *name)
82: {
83: return module_set(&output_subsys, name);
84: }
85:
86: static struct bmon_subsys output_subsys = {
87: .s_name = "output",
88: .s_activate_default = &activate_default,
89: .s_mod_list = LIST_SELF(output_subsys.s_mod_list),
90: };
91:
92: static void __init __output_init(void)
93: {
94: return module_register_subsys(&output_subsys);
95: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>