Changeset 5275:811818eb5b81 in roaraudio for roard/plugins.c
- Timestamp:
- 11/19/11 22:54:26 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/plugins.c
r4708 r5275 31 31 struct roar_dl_lhandle * lhandle; 32 32 struct roard_plugins_sched * sched; 33 int protocols[MAX_PROTOS]; 33 34 } g_plugins[MAX_PLUGINS]; 34 35 static struct _roard_plugin * _pp = NULL; … … 53 54 } 54 55 56 static void inline plugins_delete(struct _roard_plugin * plugin) { 57 int i; 58 59 if ( plugin->sched != NULL ) 60 if ( plugin->sched->free != NULL ) 61 plugin->sched->free(); 62 63 for (i = 0; i < MAX_PROTOS; i++) { 64 if ( plugin->protocols[i] != -1 ) { 65 clients_unregister_proto(plugin->protocols[i]); 66 } 67 } 68 69 roar_dl_close(plugin->lhandle); 70 memset(plugin, 0, sizeof(struct _roard_plugin)); 71 plugin->lhandle = NULL; 72 } 73 55 74 int plugins_init (void) { 56 75 int i; … … 62 81 _pp->sched = NULL; 63 82 64 roar_dl_ra_init(g_plugins[i].lhandle, NULL); 83 if ( roar_dl_ra_init(g_plugins[i].lhandle, NULL, NULL) == -1 ) { 84 ROAR_WARN("plugins_init(void): Can not RA init lib at %p: %s", g_plugins[i].lhandle, roar_error2str(roar_error)); 85 plugins_delete(&(g_plugins[i])); 86 continue; 87 } 65 88 66 89 if ( g_plugins[i].sched != NULL ) … … 80 103 for (i = 0; i < MAX_PLUGINS; i++) { 81 104 if ( g_plugins[i].lhandle != NULL ) { 82 if ( g_plugins[i].sched != NULL ) 83 if ( g_plugins[i].sched->free != NULL ) 84 g_plugins[i].sched->free(); 85 86 roar_dl_close(g_plugins[i].lhandle); 105 plugins_delete(&(g_plugins[i])); 87 106 } 88 107 } … … 105 124 } 106 125 107 int plugins_load (const char * filename ) {126 int plugins_load (const char * filename, const char * args) { 108 127 struct _roard_plugin * next = _find_free(); 128 struct roar_dl_librarypara * para; 129 int i; 109 130 110 131 if ( next == NULL ) 111 132 return -1; 112 133 113 next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */); 134 for (i = 0; i < MAX_PROTOS; i++) 135 next->protocols[i] = -1; 136 137 if ( (para = roar_dl_para_new(args, NULL, ROARD_DL_APPNAME, ROARD_DL_ABIVERSION)) == NULL ) { 138 ROAR_WARN("Can not load plugin (allocate para set): %s: %s", filename, roar_error2str(roar_error)); 139 return -1; 140 } 141 142 next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_DEFAUTS, 0 /* we delay this until plugins_init() */, para); 143 roar_dl_para_unref(para); 144 114 145 if ( next->lhandle == NULL ) { 115 146 ROAR_ERR("plugins_load(filename='%s'): can not load plugin: %s", filename, roar_dl_errstr(NULL)); … … 130 161 131 162 int plugins_reg_proto(struct roard_proto * proto) { 163 int i; 164 132 165 if ( _pp == NULL ) 133 166 return -1; 167 168 for (i = 0; i < MAX_PROTOS; i++) { 169 if ( _pp->protocols[i] == -1 ) { 170 _pp->protocols[i] = proto->proto; 171 break; 172 } 173 } 174 175 if ( i == MAX_PROTOS ) { 176 roar_err_set(ROAR_ERROR_NOMEM); 177 return -1; 178 } 134 179 135 180 return clients_register_proto(proto);
Note: See TracChangeset
for help on using the changeset viewer.