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