GCOV Execution Analysis for ohpi.c

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

Exec CodeLine #
 
Source:ohpi.c
1
 
Object:.libs/ohpi.bb
2
 
/*      -*- linux-c -*-
3
 
 *
4
 
 * (C) Copright IBM Corp 2004
5
 
 *
6
 
 * This program is distributed in the hope that it will be useful,
7
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
9
 
 * file and program are licensed under a BSD style license.  See
10
 
 * the Copying file included with the OpenHPI distribution for
11
 
 * full licensing terms.
12
 
 *
13
 
 * Authors:
14
 
 *     Renier Morales < address removed >
15
 
 */
16
 
17
 
#include <oHpi.h>
18
 
#include <oh_config.h>
19
 
#include <oh_init.h>
20
 
#include <oh_plugin.h>
21
 
#include <oh_error.h>
22
 
#include <oh_lock.h>
23
 
24
 
/* Plugin operations */
25
 
26
 
/**
27
 
 * oHpiPluginLoad
28
 
 * @name: IN. String. name of plugin to load (e.g. "libdummy")
29
 
 *
30
 
 * Loads plugin into library creating a plugin object.
31
 
 *
32
 
 * Returns: SA_OK on success. Minus SA_OK on error.
33
 
 **/
34
 
SaErrorT oHpiPluginLoad(char *name)
35
46 
{
36
46 
        if (!name) {
37
1 
                dbg("Invalid parameters.");
38
1 
                return SA_ERR_HPI_INVALID_PARAMS;
39
 
        }        
40
 
        
41
45 
        if (oh_load_plugin(name))
42
2 
                return SA_ERR_HPI_ERROR;
43
 
44
43 
        return SA_OK;
45
 
}
46
 
47
 
/**
48
 
 * oHpiPluginUnload
49
 
 * @name: IN. String. name of plugin to unload (e.g. "libdummy")
50
 
 *
51
 
 * Unload plugin from library, destroying the plugin object.
52
 
 * This will return an error if there are any handlers referencing
53
 
 * the plugin (e.g. refcount > 1).
54
 
 *
55
 
 * Returns: SA_OK on success. Minus SA_OK on error.
56
 
 **/
57
 
SaErrorT oHpiPluginUnload(char *name)
58
24 
{
59
24 
        if (!name) {
60
1 
                dbg("Invalid parameters.");
61
1 
                return SA_ERR_HPI_INVALID_PARAMS;
62
 
        }        
63
 
64
23 
        if (oh_unload_plugin(name))
65
3 
                return SA_ERR_HPI_ERROR;
66
 
67
20 
        return SA_OK;
68
 
}
69
 
70
 
/**
71
 
 * oHpiPluginInfo
72
 
 * @name: IN. String. name of plugin to query (e.g. "libdummy")
73
 
 * @info: IN/OUT. Reference to information structure on the plugin.
74
 
 *
75
 
 * Fetches the information associated with the plugin and puts it
76
 
 * in @info. As of yet, @info only contains the refcount for the
77
 
 * plugin.
78
 
 *
79
 
 * Returns: SA_OK on success. Minus SA_OK on error.
80
 
 **/
81
 
SaErrorT oHpiPluginInfo(char *name, oHpiPluginInfoT *info)
82
6 
{
83
6 
        struct oh_plugin *p = NULL;
84
 
85
6 
        if (!name || !info) {
86
1 
                dbg("Invalid parameters.");
87
1 
                return SA_ERR_HPI_INVALID_PARAMS;
88
 
        }        
89
 
90
5 
        data_access_lock();
91
5 
        p = oh_lookup_plugin(name);
92
5 
        if (!p) {
93
2 
                dbg("Plugin %s not found.", name);
94
2 
        	data_access_unlock();
95
2 
                return SA_ERR_HPI_NOT_PRESENT;
96
 
        }
97
 
98
3 
        info->refcount = p->refcount;
99
3 
        data_access_unlock();
100
 
101
3 
        return SA_OK;
102
 
}
103
 
104
 
/**
105
 
 * oHpiPluginGetNext
106
 
 * @name: IN. String. name of plugin to search for (e.g. "libdummy")
107
 
 * @next_name: IN/OUT. Next plugin after @name will be placed here.
108
 
 * @size: IN. Size in bytes of the @next_name buffer.
109
 
 *
110
 
 * Searches for the specified plugin and returns the next plugin name
111
 
 * after that one in the list. If you pass NULL in @name, you will get
112
 
 * the name of the first plugin in @next_name. Used to iterate through
113
 
 * all loaded plugins.
114
 
 *
115
 
 * Returns: SA_OK on success. Minus SA_OK on error.
116
 
 **/
117
 
SaErrorT oHpiPluginGetNext(char *name, char *next_name, int size)
118
6 
{
119
6 
        if (!next_name) {
120
1 
                dbg("Invalid parameters.");
121
1 
                return SA_ERR_HPI_INVALID_PARAMS;
122
 
        }        
123
 
124
5 
        if (oh_lookup_next_plugin(name, next_name, size))
125
3 
                return SA_ERR_HPI_NOT_PRESENT;
126
 
127
2 
        return SA_OK;
128
 
}
129
 
130
 
131
 
/* Handler operations */
132
 
133
 
/**
134
 
 * oHpiHandlerCreate
135
 
 * @config: IN. Hash table. Holds configuration information used by handler.
136
 
 * @id: IN/OUT. The id of the newly created handler is returned here.
137
 
 *
138
 
 * Creates a new handler (instance of a plugin). Plugin handlers are what
139
 
 * respond to most API calls.
140
 
 * @config needs to have an entry for "plugin" in order to know for which
141
 
 * plugin the handler is being created.
142
 
 *
143
 
 * Returns: SA_OK on success. Minus SA_OK on error.
144
 
 **/
145
 
SaErrorT oHpiHandlerCreate(GHashTable *config,
146
 
                           oHpiHandlerIdT *id)
147
33 
{
148
33 
        oHpiHandlerIdT hid = 0;
149
 
150
33 
        if (!config || !id) {
151
1 
                dbg("Invalid parameters.");
152
1 
                return SA_ERR_HPI_INVALID_PARAMS;
153
 
        }
154
 
        
155
32 
        if (oh_initialized() != SA_OK && oh_initialize() != SA_OK) {
156
0 
                dbg("ERROR. Could not initialize the library");
157
0 
                return SA_ERR_HPI_INTERNAL_ERROR;
158
 
        }
159
 
160
32 
        if (!(hid = oh_load_handler(config))) {
161
2 
             *id = 0;
162
2 
             return SA_ERR_HPI_ERROR;
163
 
        }
164
 
165
30 
        *id = hid;
166
 
167
30 
        return SA_OK;
168
 
}
169
 
170
 
/**
171
 
 * oHpiHandlerDestroy
172
 
 * @id: IN. The id of the handler to destroy
173
 
 *
174
 
 * Destroys a handler. Calls the plugin's abi close function.
175
 
 *
176
 
 * Returns: SA_OK on success. Minus SA_OK on error.
177
 
 **/
178
 
SaErrorT oHpiHandlerDestroy(oHpiHandlerIdT id)
179
16 
{
180
16 
        if (!id)
181
1 
                return SA_ERR_HPI_INVALID_PARAMS;        
182
 
        
183
15 
        if (oh_unload_handler(id))
184
2 
                return SA_ERR_HPI_ERROR;
185
 
186
13 
        return SA_OK;
187
 
}
188
 
189
 
/**
190
 
 * oHpiHandlerInfo
191
 
 * @id: IN. The id of the handler to query
192
 
 * @info: IN/OUT. Pointer to struct for holding handler information
193
 
 *
194
 
 * Queries a handler for the information associated with it.
195
 
 *
196
 
 * Returns: SA_OK on success. Minus SA_OK on error.
197
 
 **/
198
 
SaErrorT oHpiHandlerInfo(oHpiHandlerIdT id, oHpiHandlerInfoT *info)
199
3 
{
200
3 
        struct oh_handler *h = NULL;
201
 
202
3 
        if (!id || !info)
203
1 
               return SA_ERR_HPI_INVALID_PARAMS;        
204
 
205
2 
	data_access_lock();
206
2 
        h = oh_lookup_handler(id);
207
2 
	if (!h) {
208
1 
		dbg("Handler not found.");
209
1 
		data_access_unlock();
210
1 
		return SA_ERR_HPI_NOT_PRESENT;
211
 
	}
212
 
213
1 
	strncpy(info->plugin_name, h->plugin_name, MAX_PLUGIN_NAME_LENGTH);
214
1 
	data_access_unlock();
215
 
	
216
1 
	return SA_OK;
217
 
}
218
 
219
 
/**
220
 
 * oHpiHandlerGetNext
221
 
 * @id: IN. Id of handler to search for.
222
 
 * @next_id: IN/OUT. The id of the handler next to the handler being searched for
223
 
 * will be returned here.
224
 
 *
225
 
 * Used for iterating through all loaded handlers. If you pass
226
 
 * 0 (SAHPI_FIRST_ENTRY), you will get the id of the first handler returned
227
 
 * in next_id.
228
 
 *
229
 
 * Returns: SA_OK on success. Minus SA_OK on error.
230
 
 **/
231
 
SaErrorT oHpiHandlerGetNext(oHpiHandlerIdT id, oHpiHandlerIdT *next_id)
232
8 
{
233
8 
        if (!next_id) {
234
1 
                dbg("Invalid parameters.");
235
1 
                return SA_ERR_HPI_INVALID_PARAMS;
236
 
        }        
237
 
238
7 
        if (oh_lookup_next_handler(id, next_id))
239
3 
                return SA_ERR_HPI_NOT_PRESENT;
240
 
241
4 
        return SA_OK;
242
 
}
243
 
244
 
/* Global parameters */
245
 
246
 
/**
247
 
 * oHpiGlobalParamGet
248
 
 * @param: param->type needs to be set to know what parameter to fetch.
249
 
 *
250
 
 * Gets the value of the specified global parameter.
251
 
 *
252
 
 * Returns: SA_OK on success. Minus SA_OK on error.
253
 
 **/
254
 
SaErrorT oHpiGlobalParamGet(oHpiGlobalParamT *param)
255
5 
{
256
5 
        struct oh_global_param p;
257
 
        
258
5 
        if (!param || !param->Type) {
259
2 
                dbg("Invalid parameters.");
260
2 
                return SA_ERR_HPI_INVALID_PARAMS;                
261
 
        }
262
 
        
263
3 
        p.type = param->Type;
264
 
        
265
3 
        if (oh_get_global_param(&p))
266
1 
                return SA_ERR_HPI_UNKNOWN;
267
 
                
268
2 
        memcpy(&param->u, &p.u, sizeof(oh_global_param_union));
269
 
        
270
2 
        return SA_OK;
271
 
}
272
 
273
 
/**
274
 
 * oHpiGlobalParamSet
275
 
 * @param: param->type needs to be set to know what parameter to set.
276
 
 * Also, the appropiate value in param->u needs to be filled in.
277
 
 *
278
 
 * Sets a global parameter.
279
 
 *
280
 
 * Returns: SA_OK on success. Minus SA_OK on error.
281
 
 **/
282
 
SaErrorT oHpiGlobalParamSet(oHpiGlobalParamT *param)
283
2 
{
284
2 
        struct oh_global_param p;
285
 
        
286
2 
        if (!param || !param->Type) {
287
1 
                dbg("Invalid parameters.");
288
1 
                return SA_ERR_HPI_INVALID_PARAMS;                
289
 
        }
290
 
        
291
1 
        p.type = param->Type;
292
1 
        memcpy(&p.u, &param->u, sizeof(oh_global_param_union));
293
 
                
294
1 
        if (oh_set_global_param(&p))
295
0 
                return SA_ERR_HPI_ERROR;
296
 
                
297
1 
        return SA_OK;
298
 
}
299