GCOV Execution Analysis for init.c

The left column is the number of times the code was executed during the unit test suites.

Exec CodeLine #
 
Source:init.c
1
 
Graph:.libs/init.gcno
2
 
Data:.libs/init.gcda
3
 
Runs:378
4
 
Programs:378
5
 
/*      -*- linux-c -*-
6
 
 *
7
 
 * (C) Copyright IBM Corp. 2004
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
12
 
 * file and program are licensed under a BSD style license.  See
13
 
 * the Copying file included with the OpenHPI distribution for
14
 
 * full licensing terms.
15
 
 *
16
 
 * Author(s):
17
 
 *      Renier Morales < address removed >
18
 
 *
19
 
 */
20
 
21
 
#include <stdlib.h>
22
 
#include <string.h>
23
 
#include <glib.h>
24
 
#include <openhpi.h>
25
 
26
 
static enum {
27
 
        UNINIT = 0,
28
 
        INIT
29
 
} oh_init_state = UNINIT;
30
 
31
 
SaErrorT oh_initialized()
32
3912 
{
33
3912 
        data_access_lock();
34
3912 
        if(oh_init_state == UNINIT) {                
35
749 
                data_access_unlock();
36
749 
                return SA_ERR_HPI_ERROR;
37
 
        } else {
38
3163 
                data_access_unlock();
39
3163 
                return SA_OK;
40
 
        }
41
 
}
42
 
43
 
/**
44
 
 * oh_initialize
45
 
 *
46
 
 * Returns:
47
 
 **/
48
 
SaErrorT oh_initialize()
49
374 
{
50
374 
        GSList *node = NULL;
51
374 
        struct oh_parsed_config config = {NULL, NULL};
52
374 
        struct oh_global_param config_param = { .type = OPENHPI_CONF };
53
374 
        int rval;
54
374 
        unsigned int u;
55
 
56
374 
        SaHpiDomainCapabilitiesT capabilities = 0x00000000;
57
374 
        SaHpiTextBufferT tag;
58
 
59
374 
        data_access_lock();
60
 
61
 
        /* Check ready state */
62
374 
        if (oh_initialized() == SA_OK) {
63
0 
                dbg("Cannot initialize twice");
64
0 
                data_access_unlock();
65
0 
                return SA_ERR_HPI_DUPLICATE;
66
 
        }
67
 
        
68
 
        /* Initialize event process queue */
69
374 
        oh_event_init();
70
 
71
 
        /* Set openhpi configuration file location */        
72
374 
        oh_get_global_param(&config_param);
73
 
74
374 
        rval = oh_load_config(config_param.u.conf, &config);
75
 
	/* Don't error out if there is no conf file */
76
374 
	if (rval < 0 && rval != -4) {
77
0 
                dbg("Can not load config");
78
0 
                data_access_unlock();
79
0 
                return SA_ERR_HPI_NOT_PRESENT;
80
 
        }
81
 
82
 
        /* Initialize uid_utils */
83
374 
        rval = oh_uid_initialize();
84
374 
        if( (rval != SA_OK) && (rval != SA_ERR_HPI_ERROR) ) {
85
0 
                dbg("uid_intialization failed");
86
0 
                data_access_unlock();
87
0 
                return(rval);
88
 
        }
89
374 
        trace("Initialized UID");
90
 
        
91
 
        /* Initialize plugins */
92
748 
        for (node = config.plugin_names; node; node = node->next) {
93
374 
                char *plugin_name = (char *)node->data;
94
374 
                if (oh_load_plugin(plugin_name) == 0) {
95
374 
                        trace("Loaded plugin %s", plugin_name);
96
 
                } else {
97
0 
                        dbg("Couldn't load plugin %s", plugin_name);
98
0 
                        g_free(plugin_name);
99
 
                }
100
 
        }
101
 
102
 
        /* Initialize handlers */        
103
748 
        for (node = config.handler_configs; node; node = node->next) {
104
374 
                GHashTable *handler_config = (GHashTable *)node->data;
105
374 
                if(oh_load_handler(handler_config) > 0) {
106
374 
                        trace("Loaded handler for plugin %s",
107
 
                              (char *)g_hash_table_lookup(handler_config, "plugin"));
108
 
                } else {
109
0 
                        dbg("Couldn't load handler for plugin %s",
110
 
                            (char *)g_hash_table_lookup(handler_config, "plugin"));
111
0 
                        g_hash_table_destroy(handler_config);
112
 
                }
113
 
        }
114
 
115
 
        /*
116
 
         * Wipes away configuration lists (plugin_names and handler_configs).
117
 
         * global_params is not touched.
118
 
         */
119
374 
        oh_clean_config();
120
 
121
 
	/* Check if there are any handler loaded */
122
374 
	oh_lookup_next_handler(0, &u);
123
374 
        if (!u) {
124
 
                /* there is no handler => this can not work */
125
0 
                dbg("No handlers loaded after initialization.");
126
0 
                dbg("Check configuration file %s", config_param.u.conf);
127
 
                /*data_access_unlock();*/
128
 
                /*return SA_ERR_HPI_NOT_PRESENT;*/
129
 
        }
130
 
131
 
        /* Initialize domain table */
132
374 
        oh_domains.table = g_hash_table_new(g_int_hash, g_int_equal);
133
374 
        trace("Initialized domain table");
134
 
135
 
        /* Create first domain */
136
374 
        tag.DataType = SAHPI_TL_TYPE_TEXT;
137
374 
        tag.Language = SAHPI_LANG_ENGLISH;
138
374 
        strcpy(tag.Data, "First Domain");
139
374 
        if (!oh_create_domain(capabilities, SAHPI_FALSE, &tag)) {
140
0 
                data_access_unlock();
141
0 
                dbg("Could not create first domain!");
142
0 
                return SA_ERR_HPI_ERROR;
143
 
        }
144
374 
        trace("Created first domain");
145
 
146
 
        /* Initialize session table */
147
374 
        oh_sessions.table = g_hash_table_new(g_int_hash, g_int_equal);
148
374 
        trace("Initialized session table");
149
 
150
374 
        oh_init_state = INIT;
151
374 
        trace("Set init state");
152
 
153
374 
        data_access_unlock();
154
 
155
374 
        return SA_OK;
156
 
}
157
 
158
 
#if 0
159
 
/**
160
 
 * oh_finalize
161
 
 *
162
 
 * Returns:
163
 
 **/
164
 
SaErrorT oh_finalize()
165
 
{
166
 
        OH_STATE_READY_CHECK;
167
 
168
 
        /* free mutex */
169
 
        /* TODO: this wasn't here in branch, need to resolve history */
170
 
        data_access_lock();
171
 
172
 
        /* TODO: realy should have a oh_uid_finalize() that */
173
 
        /* frees memory,                                    */
174
 
        if(oh_uid_map_to_file())
175
 
                dbg("error writing uid entity path mapping to file");
176
 
177
 
        /* check for open sessions */
178
 
        if ( global_session_list ) {
179
 
                dbg("cannot saHpiFinalize because of open sessions" );
180
 
                data_access_unlock();
181
 
                return SA_ERR_HPI_BUSY;
182
 
        }
183
 
184
 
        /* close all plugins */
185
 
        while(global_handler_list) {
186
 
                struct oh_handler *handler = (struct oh_handler *)global_handler_list->data;
187
 
                /* unload_handler will remove handler from global_handler_list */
188
 
                unload_handler(handler);
189
 
        }
190
 
191
 
        /* unload plugins */
192
 
        while(global_plugin_list) {
193
 
                struct oh_plugin_config *plugin = (struct oh_plugin_config *)global_plugin_list->data;
194
 
                unload_plugin(plugin);
195
 
        }
196
 
197
 
        /* free global rpt */
198
 
        if (default_rpt) {
199
 
                oh_flush_rpt(default_rpt);
200
 
                g_free(default_rpt);
201
 
                default_rpt = 0;
202
 
        }
203
 
204
 
        /* free global_handler_configs and uninit_plugin */
205
 
        oh_unload_config();
206
 
        oh_exit_ltdl(); /* Free ltdl structures after unloading plugins */
207
 
208
 
        /* free domain list */
209
 
        oh_cleanup_domain();
210
 
211
 
        oh_hpi_state = OH_STAT_UNINIT;
212
 
213
 
        /* free mutex */
214
 
        data_access_unlock();
215
 
216
 
        return SA_OK;
217
 
}
218
 
#endif
219