Annotation of embedaddon/bmon/src/element_cfg.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * element_cfg.c               Element Configuration
                      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/conf.h>
                     28: #include <bmon/element.h>
                     29: #include <bmon/element_cfg.h>
                     30: #include <bmon/utils.h>
                     31: 
                     32: static LIST_HEAD(cfg_list);
                     33: 
                     34: struct element_cfg *element_cfg_alloc(const char *name)
                     35: {
                     36:        struct element_cfg *ec;
                     37: 
                     38:        if ((ec = element_cfg_lookup(name))) {
                     39:                ec->ec_refcnt++;
                     40:                return ec;
                     41:        }
                     42: 
                     43:        ec = xcalloc(1, sizeof(*ec));
                     44:        ec->ec_name = strdup(name);
                     45:        ec->ec_refcnt = 1;
                     46: 
                     47:        list_add_tail(&ec->ec_list, &cfg_list);
                     48: 
                     49:        return ec;
                     50: }
                     51: 
                     52: struct element_cfg *element_cfg_create(const char *name)
                     53: {
                     54:        struct element_cfg *cfg;
                     55: 
                     56:        if (!(cfg = element_cfg_lookup(name)))
                     57:                cfg = element_cfg_alloc(name);
                     58: 
                     59:        return cfg;
                     60: }
                     61: 
                     62: static void __element_cfg_free(struct element_cfg *ec)
                     63: {
                     64:        list_del(&ec->ec_list);
                     65:        
                     66:        xfree(ec->ec_name);
                     67:        xfree(ec->ec_description);
                     68:        xfree(ec);
                     69: }
                     70: 
                     71: void element_cfg_free(struct element_cfg *ec)
                     72: {
                     73:        if (!ec || --ec->ec_refcnt)
                     74:                return;
                     75: 
                     76:        __element_cfg_free(ec);
                     77: }
                     78: 
                     79: struct element_cfg *element_cfg_lookup(const char *name)
                     80: {
                     81:        struct element_cfg *ec;
                     82: 
                     83:        list_for_each_entry(ec, &cfg_list, ec_list)
                     84:                if (!strcmp(name, ec->ec_name))
                     85:                        return ec;
                     86:        
                     87:        return NULL;
                     88: }
                     89: 
                     90: static void __exit __element_cfg_exit(void)
                     91: {
                     92:        struct element_cfg *ec, *n;
                     93: 
                     94:        list_for_each_entry_safe(ec, n, &cfg_list, ec_list)
                     95:                __element_cfg_free(ec);
                     96: }

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