Changeset 5488:cd3f4f76a154 in roaraudio
- Timestamp:
- 05/04/12 13:12:31 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r5484 r5488 12 12 * Some small, general improvements to roarclients. 13 13 * Changed roard plugin ABI version to 1.0beta1. 14 * Corrected usage of -Wextra (pr 0).15 * Updated build options for RAT (pr 0).16 * Work around bugs in win32 while using stdvios (pr 0).17 * Added support to load plugins on win32 (pr 0).14 * Corrected usage of -Wextra (pr1). 15 * Updated build options for RAT (pr1). 16 * Work around bugs in win32 while using stdvios (pr1). 17 * Added support to load plugins on win32 (pr1). 18 18 * Added support for quotes strings to kv split and 19 roardl para argument splitting (pr0). 20 * Added support for an application mode in roarpluginrunner (pr0). 19 roardl para argument splitting (pr1). 20 * Added support for an application mode in roarpluginrunner (pr1). 21 * Improved plugincontainer (pr1). 21 22 22 23 v. 1.0beta0 - Fri Mar 16 2012 19:39 CET -
include/libroar/plugincontainer.h
r5487 r5488 41 41 struct roar_plugincontainer; 42 42 43 struct roar_plugincontainer_callbacks { 44 /* prefree() is called before the container is freed. 45 */ 46 int (*prefree)(struct roar_plugincontainer * cont, void ** userdata); 47 48 /* freeuserdata() is called when the userdata needs to be freed. 49 * This is the case then the container is freed. 50 * It is not called when the current userdata is NULL. 51 * If not set or userdata is still non-NULL after this call the userdata 52 * is freed using roar_mm_free(). 53 */ 54 int (*freeuserdata)(struct roar_plugincontainer * cont, void ** userdata); 55 56 /* freecontext() is called when the context needs to be freed. 57 * It is not called when the current context is NULL. 58 * If not set or context is still non-NULL after this call the context 59 * is freed using roar_mm_free(). 60 */ 61 int (*freecontext)(struct roar_plugincontainer * cont, void ** context); 62 63 /* preload() and postload() are called before and after a plugin is loaded. 64 */ 65 int (*preload) (struct roar_plugincontainer * cont, void ** context, 66 const char * name, int flags, struct roar_dl_librarypara * para); 67 int (*postload)(struct roar_plugincontainer * cont, void ** context, struct roar_dl_lhandle * lhandle, 68 const char * name, int flags, struct roar_dl_librarypara * para); 69 70 /* preunload() and postunload() are called before and after a plugin is unloaded. 71 * Those functions are also called if the plugin was loaded but ra_init was not yet done or failed. 72 */ 73 int (*preunload) (struct roar_plugincontainer * cont, void ** context, struct roar_dl_lhandle * lhandle); 74 int (*postunload)(struct roar_plugincontainer * cont, void ** context); 75 76 /* prera_init() and postra_init() are called before and after a plugin is ra_init-ed. 77 * This is also true if the plugin is ra_init-ed while being loaded. 78 * Note the limits of roar_plugincontainer_ra_init() if this is used 79 * with roar_plugincontainer_ra_init(). 80 * postra_init() is also called in case the ra_init failed. 81 */ 82 int (*prera_init) (struct roar_plugincontainer * cont, void ** context, struct roar_dl_lhandle * lhandle, 83 struct roar_dl_librarypara * para); 84 int (*postra_init)(struct roar_plugincontainer * cont, void ** context, struct roar_dl_lhandle * lhandle, 85 struct roar_dl_librarypara * para); 86 }; 87 88 struct roar_plugincontainer_plugininfo { 89 /* The name of the plugin. 90 */ 91 const char * libname; 92 /* The roardl's library handle. 93 */ 94 struct roar_dl_lhandle * handle; 95 /* The number of librarys/plugins depending on this plugin. 96 */ 97 size_t rdepends; 98 /* A pointer to the current user context. 99 */ 100 void ** context; 101 }; 102 43 103 /* Create a new plugin container. 44 104 * Takes a default parameter set. … … 58 118 int roar_plugincontainer_unref(struct roar_plugincontainer * cont); 59 119 60 /* Get a lhandle by name of the loaded plugin 120 /* Set callbacks. 121 */ 122 int roar_plugincontainer_set_callbacks(struct roar_plugincontainer * cont, 123 const struct roar_plugincontainer_callbacks * callbacks); 124 125 /* Set container's userdata. 126 */ 127 int roar_plugincontainer_set_userdata(struct roar_plugincontainer * cont, void * userdata); 128 129 /* Get container's userdata. 130 */ 131 void * roar_plugincontainer_get_userdata(struct roar_plugincontainer * cont); 132 133 /* Get a lhandle by name of the loaded plugin. 61 134 */ 62 135 struct roar_dl_lhandle * roar_plugincontainer_get_lhandle_by_name (struct roar_plugincontainer * cont, 63 136 const char * name); 137 138 /* Get infos about current state of plugin. 139 */ 140 struct roar_plugincontainer_plugininfo roar_plugincontainer_get_info_by_name (struct roar_plugincontainer * cont, 141 const char * name); 64 142 65 143 // plugin loading and unloading: -
libroar/plugincontainer.c
r5487 r5488 40 40 struct roar_plugincontainer { 41 41 size_t refc; 42 const struct roar_plugincontainer_callbacks * callbacks; 43 void * userdata; 42 44 struct roar_dl_librarypara * default_para; 43 45 struct roar_dl_lhandle * handle[MAX_PLUGINS]; 44 46 size_t deprefc[MAX_PLUGINS]; 47 void * context[MAX_PLUGINS]; 45 48 size_t numhandles; 46 49 }; 50 51 static inline void _unload(struct roar_plugincontainer * cont, size_t index) { 52 int err = roar_error; 53 54 if ( cont->callbacks != NULL && cont->callbacks->preunload != NULL ) 55 cont->callbacks->preunload(cont, &(cont->context[index]), cont->handle[index]); 56 57 roar_err_set(err); 58 roar_dl_unref(cont->handle[index]); 59 err = roar_error; 60 cont->handle[index] = NULL; 61 cont->numhandles--; 62 63 if ( cont->callbacks != NULL && cont->callbacks->postunload != NULL ) 64 cont->callbacks->postunload(cont, &(cont->context[index])); 65 66 if ( cont->context[index] != NULL ) 67 if ( cont->callbacks != NULL && cont->callbacks->freecontext != NULL ) 68 cont->callbacks->freecontext(cont, &(cont->context[index])); 69 70 if ( cont->context[index] != NULL ) { 71 roar_mm_free(cont->context[index]); 72 cont->context[index] = NULL; 73 } 74 75 roar_err_set(err); 76 } 47 77 48 78 static int _loader(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp) { … … 209 239 } 210 240 241 if ( cont->callbacks != NULL && cont->callbacks->prefree != NULL ) 242 cont->callbacks->prefree(cont, &(cont->userdata)); 243 211 244 while (cont->numhandles) { 212 245 for (i = 0; i < MAX_PLUGINS; i++) { … … 218 251 continue; 219 252 220 roar_dl_close(cont->handle[i]); 221 cont->handle[i] = NULL; 222 cont->numhandles--; 223 } 224 } 253 _unload(cont, i); 254 } 255 } 256 257 // try to free user data... 258 if ( cont->userdata != NULL ) { 259 if ( cont->callbacks != NULL && cont->callbacks->freeuserdata != NULL ) { 260 cont->callbacks->freeuserdata(cont, &(cont->userdata)); 261 } 262 } 263 264 // if still not freed by caller, free it using memmgr. 265 if ( cont->userdata != NULL ) 266 roar_mm_free(cont->userdata); 225 267 226 268 if ( cont->default_para != NULL ) … … 233 275 } 234 276 235 struct roar_dl_lhandle * roar_plugincontainer_get_lhandle_by_name (struct roar_plugincontainer * cont, 236 const char * name) { 277 int roar_plugincontainer_set_callbacks(struct roar_plugincontainer * cont, 278 const struct roar_plugincontainer_callbacks * callbacks) { 279 if ( cont == NULL ) { 280 roar_err_set(ROAR_ERROR_FAULT); 281 return -1; 282 } 283 284 cont->callbacks = callbacks; 285 286 return 0; 287 } 288 289 int roar_plugincontainer_set_userdata(struct roar_plugincontainer * cont, void * userdata) { 290 if ( cont == NULL ) { 291 roar_err_set(ROAR_ERROR_FAULT); 292 return -1; 293 } 294 295 cont->userdata = userdata; 296 297 return 0; 298 } 299 300 void * roar_plugincontainer_get_userdata(struct roar_plugincontainer * cont) { 301 if ( cont == NULL ) { 302 roar_err_set(ROAR_ERROR_FAULT); 303 return NULL; 304 } 305 306 if ( cont->userdata == NULL ) { 307 roar_err_set(ROAR_ERROR_NOENT); 308 return NULL; 309 } 310 311 return cont->userdata; 312 } 313 314 struct roar_plugincontainer_plugininfo roar_plugincontainer_get_info_by_name (struct roar_plugincontainer * cont, 315 const char * name) { 316 struct roar_plugincontainer_plugininfo ret; 237 317 const struct roar_dl_libraryname * libname; 238 318 size_t i; 239 319 320 memset(&ret, 0, sizeof(ret)); 321 240 322 if ( cont == NULL || name == NULL ) { 241 323 roar_err_set(ROAR_ERROR_FAULT); 242 return NULL;324 return ret; 243 325 } 244 326 … … 252 334 if ( !strcmp(libname->name, name) ) { 253 335 if ( roar_dl_ref(cont->handle[i]) == -1 ) 254 return NULL; 255 256 return cont->handle[i]; 336 return ret; 337 338 ret.libname = libname->name; 339 ret.handle = cont->handle[i]; 340 ret.rdepends = cont->deprefc[i]; 341 ret.context = &(cont->context[i]); 342 return ret; 257 343 } 258 344 } 259 345 260 346 roar_err_set(ROAR_ERROR_NOENT); 261 return NULL; 347 return ret; 348 } 349 350 struct roar_dl_lhandle * roar_plugincontainer_get_lhandle_by_name (struct roar_plugincontainer * cont, 351 const char * name) { 352 struct roar_plugincontainer_plugininfo info = roar_plugincontainer_get_info_by_name(cont, name); 353 354 if ( info.libname == NULL ) 355 return NULL; 356 357 return info.handle; 262 358 } 263 359 … … 316 412 } 317 413 318 cont->handle[idx] = roar_dl_open(name, flags, ra_init, para); 414 cont->context[idx] = NULL; // clear context. 415 cont->deprefc[idx] = 0; 416 417 if ( cont->callbacks != NULL && cont->callbacks->preload != NULL ) 418 cont->callbacks->preload(cont, &(cont->context[idx]), name, flags, para); 419 420 cont->handle[idx] = roar_dl_open(name, flags, 0, para); 319 421 if ( cont->handle[idx] == NULL ) { 320 422 err = roar_error; … … 324 426 } 325 427 326 cont->deprefc[idx] = 0;327 428 cont->numhandles++; 429 430 if ( cont->callbacks != NULL && cont->callbacks->postload != NULL ) 431 cont->callbacks->postload(cont, &(cont->context[idx]), cont->handle[idx], name, flags, para); 432 433 if ( ra_init ) { 434 if ( cont->callbacks != NULL && cont->callbacks->prera_init != NULL ) 435 cont->callbacks->prera_init(cont, &(cont->context[idx]), cont->handle[idx], para); 436 if ( roar_dl_ra_init(cont->handle[idx], NULL, para) == -1 ) { 437 err = roar_error; 438 439 if ( cont->callbacks != NULL && cont->callbacks->postra_init != NULL ) 440 cont->callbacks->postra_init(cont, &(cont->context[idx]), cont->handle[idx], para); 441 442 _unload(cont, idx); 443 444 roar_dl_para_unref(para); 445 cont->handle[idx] = NULL; 446 roar_error = err; 447 return NULL; 448 } 449 450 if ( cont->callbacks != NULL && cont->callbacks->postra_init != NULL ) 451 cont->callbacks->postra_init(cont, &(cont->context[idx]), cont->handle[idx], para); 452 } 328 453 329 454 roar_dl_para_unref(para); … … 369 494 return -1; 370 495 } 371 roar_dl_close(cont->handle[i]); 372 cont->handle[i] = NULL; 373 cont->numhandles--; 496 _unload(cont, i); 374 497 return 0; 375 498 } … … 391 514 if ( cont->handle[i] == NULL ) 392 515 continue; 516 517 if ( cont->callbacks != NULL && cont->callbacks->prera_init != NULL ) 518 cont->callbacks->prera_init(cont, &(cont->context[i]), cont->handle[i], cont->default_para); 519 393 520 roar_dl_ra_init(cont->handle[i], NULL, cont->default_para); 521 522 if ( cont->callbacks != NULL && cont->callbacks->postra_init != NULL ) 523 cont->callbacks->postra_init(cont, &(cont->context[i]), cont->handle[i], cont->default_para); 394 524 } 395 525
Note: See TracChangeset
for help on using the changeset viewer.