Changeset 5275:811818eb5b81 in roaraudio for libroar/roardl.c
- Timestamp:
- 11/19/11 22:54:26 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/roardl.c
r5270 r5275 40 40 #endif 41 41 42 struct roar_dl_lhandle { 43 struct roar_dl_librarypara * para; 44 struct roar_dl_libraryinst * lib; 45 #if defined(ROAR_HAVE_LIBDL) 46 void * handle; 47 #endif 48 }; 49 50 51 struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, 52 const char * appname, const char * abiversion) { 53 struct roar_dl_librarypara * ret = roar_mm_malloc(sizeof(struct roar_dl_librarypara)); 54 ssize_t argc; 55 int err; 56 57 if ( ret == NULL ) 58 return NULL; 59 60 memset(ret, 0, sizeof(struct roar_dl_librarypara)); 61 62 ret->version = ROAR_DL_LIBPARA_VERSION; 63 ret->len = sizeof(struct roar_dl_librarypara); 64 ret->refc = 1; 65 ret->argc = 0; 66 ret->argv = NULL; 67 ret->args_store = NULL; 68 ret->binargv = binargv; 69 ret->appname = appname; 70 ret->abiversion = abiversion; 71 72 if ( args != NULL ) { 73 ret->args_store = roar_mm_strdup(args); 74 if ( ret->args_store == NULL ) { 75 err = roar_error; 76 roar_mm_free(ret); 77 roar_error = err; 78 return NULL; 79 } 80 81 argc = roar_keyval_split(&(ret->argv), ret->args_store, NULL, NULL, 0); 82 if ( argc == -1 ) { 83 err = roar_error; 84 roar_mm_free(ret->args_store); 85 roar_mm_free(ret); 86 roar_error = err; 87 return NULL; 88 } 89 90 ret->argc = argc; 91 } 92 93 return ret; 94 } 95 96 int roar_dl_para_ref (struct roar_dl_librarypara * para) { 97 if ( para == NULL ) { 98 roar_err_set(ROAR_ERROR_FAULT); 99 return -1; 100 } 101 102 para->refc++; 103 104 return 0; 105 } 106 107 int roar_dl_para_unref (struct roar_dl_librarypara * para) { 108 if ( para == NULL ) { 109 roar_err_set(ROAR_ERROR_FAULT); 110 return -1; 111 } 112 113 para->refc--; 114 115 if ( para->refc == 0 ) { 116 if ( para->args_store != NULL ) { 117 roar_mm_free(para->args_store); 118 roar_mm_free(para->argv); 119 } 120 roar_mm_free(para); 121 } 122 123 return 0; 124 } 125 int roar_dl_para_check_version (struct roar_dl_librarypara * para, 126 const char * appname, const char * abiversion) { 127 if ( para == NULL ) { 128 roar_err_set(ROAR_ERROR_FAULT); 129 return -1; 130 } 131 132 // check if both appnames are NULL or non-NULL. 133 if ( (para->appname == NULL && appname != NULL) || (para->appname != NULL && appname == NULL) ) { 134 roar_err_set(ROAR_ERROR_BADVERSION); 135 return -1; 136 } 137 138 // check if the appname matches if given. 139 if ( para->appname != NULL && !!strcmp(para->appname, appname) ) { 140 roar_err_set(ROAR_ERROR_BADVERSION); 141 return -1; 142 } 143 144 // check if both ABI versions are NULL or non-NULL. 145 if ( (para->abiversion == NULL && abiversion != NULL) || (para->abiversion != NULL && abiversion == NULL) ) { 146 roar_err_set(ROAR_ERROR_BADVERSION); 147 return -1; 148 } 149 150 // check if the ABI versions matches if given. 151 if ( para->abiversion != NULL && !!strcmp(para->abiversion, abiversion) ) { 152 roar_err_set(ROAR_ERROR_BADVERSION); 153 return -1; 154 } 155 156 return 0; 157 } 158 159 42 160 #if defined(ROAR_HAVE_LIBDL) 43 161 static void * _roardl2ldl (struct roar_dl_lhandle * lhandle) { … … 52 170 #endif 53 171 54 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, int ra_init) { 172 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, 173 int ra_init, struct roar_dl_librarypara * para) { 55 174 struct roar_dl_lhandle * ret = NULL; 175 int err; 56 176 57 177 // early errors just return. 58 178 59 if ( flags != ROAR_DL_FLAG_DEFAUTS ) 60 return NULL; 179 if ( flags != ROAR_DL_FLAG_DEFAUTS ) { 180 roar_err_set(ROAR_ERROR_NOTSUP); 181 return NULL; 182 } 61 183 62 184 if ( (ret = roar_mm_malloc(sizeof(struct roar_dl_lhandle))) == NULL ) … … 80 202 #else 81 203 roar_mm_free(ret); 204 roar_err_set(ROAR_ERROR_NOSYS); 82 205 return NULL; 83 206 #endif 84 207 85 if ( ret == NULL ) 86 return NULL; 208 ret->para = para; 87 209 88 210 if ( ra_init ) { 89 roar_dl_ra_init(ret, NULL); 90 } 211 if ( roar_dl_ra_init(ret, NULL, para) == -1 ) { 212 err = roar_error; 213 ROAR_WARN("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not init RA lib: %s", filename, flags, ra_init, para, roar_error2str(err)); 214 #if defined(ROAR_HAVE_LIBDL) 215 dlclose(ret->handle); 216 #endif 217 roar_mm_free(ret); 218 roar_error = err; 219 return NULL; 220 } 221 } 222 223 if ( para != NULL ) 224 roar_dl_para_ref(para); 91 225 92 226 return ret; … … 96 230 int ret = -1; 97 231 98 if ( lhandle == ROAR_DL_HANDLE_DEFAULT )99 r eturn -1;100 if ( lhandle == ROAR_DL_HANDLE_NEXT )101 return -1;232 if ( lhandle == ROAR_DL_HANDLE_DEFAULT || lhandle == ROAR_DL_HANDLE_NEXT ) { 233 roar_err_set(ROAR_ERROR_BADFH); 234 return -1; 235 } 102 236 103 237 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) … … 110 244 #endif 111 245 246 if ( lhandle->para != NULL ) 247 roar_dl_para_unref(lhandle->para); 248 112 249 roar_mm_free(lhandle); 113 250 … … 129 266 } 130 267 131 int roar_dl_ra_init(struct roar_dl_lhandle * lhandle, const char * prefix) { 268 int roar_dl_ra_init(struct roar_dl_lhandle * lhandle, 269 const char * prefix, 270 struct roar_dl_librarypara * para) { 132 271 #define _SUFFIX "_roaraudio_library_init" 133 272 char name[80] = _SUFFIX; 134 273 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 135 274 struct roar_dl_libraryinst * lib; 136 struct roar_dl_librarypara * para = NULL;137 275 int i; 138 276 … … 141 279 return -1; 142 280 } else { 143 para = lhandle->para; 281 if ( para == NULL ) 282 para = lhandle->para; 144 283 } 145 284 … … 181 320 } 182 321 183 c har *roar_dl_errstr(struct roar_dl_lhandle * lhandle) {322 const char * roar_dl_errstr(struct roar_dl_lhandle * lhandle) { 184 323 #if defined(ROAR_HAVE_LIBDL) 185 324 (void)lhandle; … … 190 329 } 191 330 331 struct roar_dl_librarypara * roar_dl_getpara(struct roar_dl_lhandle * lhandle) { 332 if ( (void*)lhandle < (void*)128 ) { 333 roar_err_set(ROAR_ERROR_NOTSUP); 334 return NULL; 335 } 336 337 if ( lhandle->para == NULL ) { 338 roar_err_set(ROAR_ERROR_NOENT); 339 return NULL; 340 } 341 342 if ( roar_dl_para_ref(lhandle->para) == -1 ) 343 return NULL; 344 345 return lhandle->para; 346 } 347 348 const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle) { 349 if ( (void*)lhandle < (void*)128 ) { 350 roar_err_set(ROAR_ERROR_NOTSUP); 351 return NULL; 352 } 353 354 if ( lhandle->lib == NULL ) { 355 roar_err_set(ROAR_ERROR_BADLIB); 356 return NULL; 357 } 358 359 if ( lhandle->lib->libname == NULL ) { 360 roar_err_set(ROAR_ERROR_NOENT); 361 return NULL; 362 } 363 364 if ( lhandle->lib->libname->version != ROAR_DL_LIBNAME_VERSION ) { 365 roar_err_set(ROAR_ERROR_BADVERSION); 366 return NULL; 367 } 368 369 if ( lhandle->lib->libname->len != sizeof(struct roar_dl_libraryname) ) { 370 roar_err_set(ROAR_ERROR_HOLE); 371 return NULL; 372 } 373 374 return lhandle->lib->libname; 375 } 376 192 377 //ll
Note: See TracChangeset
for help on using the changeset viewer.