Changeset 5436:a29ea4926470 in roaraudio
- Timestamp:
- 03/20/12 16:28:25 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/plugincontainer.h
r5433 r5436 41 41 struct roar_plugincontainer; 42 42 43 #if 0 43 /* Create a new plugin container. 44 * Takes a default parameter set. 45 */ 44 46 struct roar_plugincontainer * roar_plugincontainer_new(struct roar_dl_librarypara * default_para); 45 #endif46 47 47 48 /* Create a new plugin container. -
libroar/plugincontainer.c
r5432 r5436 46 46 }; 47 47 48 static int _loader(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp) { 49 roar_err_set(ROAR_ERROR_NOSYS); 50 return -1; 51 } 52 53 static inline void _copy_str(char ** dst, const char * src) { 54 for (; *src; src++, (*dst)++) **dst = *src; 55 *((*dst)++) = 0; 56 } 57 58 static void * _copy_kv(struct roar_keyval ** copy, struct roar_keyval * src, size_t len) { 59 size_t buflen, i; 60 void * ret; 61 char * p; 62 struct roar_keyval * c; 63 64 buflen = len * (sizeof(struct roar_keyval) + 2 /* terminating \0s */); 65 66 for (i = 0; i < len; i++) { 67 if ( src[i].key != NULL ) 68 buflen += roar_mm_strlen(src[i].key); 69 if ( src[i].value != NULL ) 70 buflen += roar_mm_strlen(src[i].value); 71 } 72 73 ret = roar_mm_malloc(buflen); 74 if ( ret == NULL ) 75 return NULL; 76 77 memset(ret, 0, buflen); 78 79 c = ret; 80 p = ret + len*sizeof(struct roar_keyval); 81 82 for (i = 0; i < len; i++) { 83 if ( src[i].key == NULL ) { 84 c[i].key = NULL; 85 } else { 86 c[i].key = p; 87 _copy_str(&p, src[i].key); 88 } 89 90 if ( src[i].value == NULL ) { 91 c[i].value = NULL; 92 } else { 93 c[i].value = p; 94 _copy_str(&p, src[i].value); 95 } 96 } 97 98 *copy = c; 99 return ret; 100 } 101 102 static struct roar_dl_librarypara * _copy_para(struct roar_dl_librarypara * para, struct roar_plugincontainer * cont) { 103 struct roar_dl_librarypara * ret = NULL; 104 int err; 105 106 if ( para == NULL || cont == NULL ) { 107 roar_err_set(ROAR_ERROR_FAULT); 108 return NULL; 109 } 110 111 ret = roar_dl_para_new(NULL, para->binargv, para->appname, para->abiversion); 112 113 if ( para->argc && para->argv != NULL ) { 114 ret->argc = para->argc; 115 ret->args_store = _copy_kv(&(ret->argv), para->argv, para->argc); 116 if ( ret->args_store == NULL ) { 117 err = roar_error; 118 roar_dl_para_unref(ret); 119 roar_error = err; 120 return NULL; 121 } 122 } 123 124 ret->notifycore = para->notifycore; 125 ret->container = cont; 126 ret->loader = _loader; 127 ret->loader_userdata = NULL; 128 129 return ret; 130 } 131 48 132 static struct roar_plugincontainer * _new_init(void) { 49 133 struct roar_plugincontainer * ret = roar_mm_malloc(sizeof(struct roar_plugincontainer)); … … 58 142 } 59 143 60 st atic struct roar_plugincontainer * roar_plugincontainer_new(struct roar_dl_librarypara * default_para) {144 struct roar_plugincontainer * roar_plugincontainer_new(struct roar_dl_librarypara * default_para) { 61 145 struct roar_plugincontainer * ret = _new_init(); 62 146 int err; … … 66 150 67 151 if ( default_para != NULL ) { 68 if ( roar_dl_para_ref(default_para) == -1 ) { 152 ret->default_para = _copy_para(default_para, ret); 153 if ( ret->default_para == NULL ) { 69 154 err = roar_error; 70 155 roar_plugincontainer_unref(ret); … … 72 157 return NULL; 73 158 } 74 ret->default_para = default_para;75 159 } 76 160 … … 158 242 ssize_t idx = -1; 159 243 size_t i; 244 int err; 160 245 161 246 if ( cont == NULL || name == NULL ) { … … 164 249 } 165 250 166 if ( para == NULL ) 251 if ( para == NULL ) { 167 252 para = cont->default_para; 168 // we do not need to _ref(para) here. This will be done by the roardl open function. 253 roar_dl_para_ref(para); 254 } else { 255 para = _copy_para(para, cont); 256 } 169 257 170 258 … … 172 260 if ( cont->numhandles == MAX_PLUGINS ) { 173 261 // return early if we are full. 262 roar_dl_para_unref(para); 174 263 roar_err_set(ROAR_ERROR_NOSPC); 175 264 return NULL; … … 183 272 184 273 if ( idx == -1 ) { 274 roar_dl_para_unref(para); 185 275 roar_err_set(ROAR_ERROR_NOSPC); 186 276 return NULL; … … 188 278 189 279 cont->handle[idx] = roar_dl_open(name, flags, ra_init, para); 190 if ( cont->handle[idx] == NULL ) 191 return NULL; 280 if ( cont->handle[idx] == NULL ) { 281 err = roar_error; 282 roar_dl_para_unref(para); 283 roar_error = err; 284 return NULL; 285 } 192 286 193 287 cont->deprefc[idx] = 0; 194 288 cont->numhandles++; 195 289 290 roar_dl_para_unref(para); 196 291 roar_dl_ref(cont->handle[idx]); 197 292 return cont->handle[idx];
Note: See TracChangeset
for help on using the changeset viewer.