Changeset 5819:be1cf7f20f45 in roaraudio


Ignore:
Timestamp:
01/06/13 11:36:53 (7 years ago)
Author:
phi
Branch:
default
Message:

added a nice way of autoloading service plugins

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/roardl.h

    r5818 r5819  
    5151#define ROAR_DL_HANDLE_APPLICATION      ((struct roar_dl_lhandle*)(void*)3) 
    5252#define ROAR_DL_HANDLE_LIB              ((struct roar_dl_lhandle*)(void*)4) 
     53 
     54#define LIBROAR_DL_APPNAME              "libroar " ROAR_VSTR_ROARAUDIO 
     55#define LIBROAR_DL_ABIVERSION           "1.0beta9" 
    5356 
    5457#define ROAR_DL_FN_DSTR                 0 /* VIO and DSTR drivers */ 
     
    432435} 
    433436 
    434 int libroar_dl_service_get_api_real(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api); 
    435 #define libroar_dl_service_get_api(para,appname,appabi,servicename,serviceabi,universal,api) libroar_dl_service_get_api_real((para),(appname),(appabi),(servicename),(serviceabi),(universal),(struct roar_dl_service_api *)(api)) 
    436 #define roar_dl_service_get_api(para,servicename,serviceabi,api) libroar_dl_service_get_api((para), (para)->appname, (para)->abiversion, (servicename), (serviceabi), 1, (api)) 
     437int libroar_dl_service_get_api_real(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api, int retry); 
     438#define libroar_dl_service_get_api(para,appname,appabi,servicename,serviceabi,universal,api) libroar_dl_service_get_api_real((para),(appname),(appabi),(servicename),(serviceabi),(universal),(struct roar_dl_service_api *)(api), 1) 
     439#define roar_dl_service_get_api(para,servicename,serviceabi,api) libroar_dl_service_get_api((para), (para) == NULL ? NULL : ((struct roar_dl_librarypara *)(para))->appname, (para) == NULL ? NULL : ((struct roar_dl_librarypara *)(para))->abiversion, (servicename), (serviceabi), 1, (api)) 
    437440 
    438441int libroar_dl_service_free_api_real(struct roar_dl_service_api * api); 
  • libroar/roardl.c

    r5818 r5819  
    10281028} 
    10291029 
    1030 int libroar_dl_service_get_api_real(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api) { 
     1030static inline int __load_plugin_any_get_api(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api) { 
     1031 struct roar_dl_lhandle * lhandle = NULL; 
     1032 struct roar_dl_librarypara * mypara = NULL; 
     1033 char name[80]; 
     1034 int err; 
     1035 int ret; 
     1036 
     1037 mypara = roar_dl_para_new(NULL, NULL, LIBROAR_DL_APPNAME, LIBROAR_DL_ABIVERSION); 
     1038 if ( mypara == NULL ) 
     1039  return -1; 
     1040 
     1041 if ( serviceabi != NULL ) { 
     1042  snprintf(name, sizeof(name), "service-%s-%s", servicename, serviceabi); 
     1043  lhandle = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, mypara); 
     1044 } 
     1045 
     1046 if ( lhandle == NULL ) { 
     1047  snprintf(name, sizeof(name), "service-%s", servicename); 
     1048  lhandle = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, mypara); 
     1049 } 
     1050 
     1051 err = roar_error; 
     1052 roar_dl_para_unref(mypara); 
     1053 roar_error = err; 
     1054 
     1055 if ( lhandle == NULL ) 
     1056  return -1; 
     1057 
     1058 roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_INIT); 
     1059 
     1060 ret = libroar_dl_service_get_api_real(para, appname, appabi, servicename, serviceabi, universal, api, 0); 
     1061 
     1062 err = roar_error; 
     1063 roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_FREE); 
     1064 roar_dl_unref(lhandle); 
     1065 roar_error = err; 
     1066 
     1067 return ret; 
     1068} 
     1069 
     1070int libroar_dl_service_get_api_real(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api, int retry) { 
    10311071 const struct roar_dl_service * s; 
    10321072 struct __fnregs * c = NULL; 
     
    10341074 int err; 
    10351075 
    1036  if ( para == NULL || servicename == NULL || serviceabi == NULL || api == NULL ) { 
     1076 if ( servicename == NULL || serviceabi == NULL || api == NULL ) { 
    10371077  roar_err_set(ROAR_ERROR_FAULT); 
    10381078  return -1; 
     1079 } 
     1080 
     1081 if ( para != NULL ) { 
     1082  if ( roar_dl_para_ref(para) == -1 ) 
     1083   return -1; 
     1084 } else { 
     1085  para = roar_dl_para_new(NULL, NULL, NULL, NULL); 
     1086  if ( para == NULL ) 
     1087   return -1; 
    10391088 } 
    10401089 
     
    10821131   err = roar_error; 
    10831132   roar_dl_unref(c->lhandle); 
     1133   roar_dl_para_unref(para); 
    10841134   api->lhandle = NULL; 
    10851135   roar_error = err; 
     
    10871137  } 
    10881138 
     1139  roar_dl_para_unref(para); 
    10891140  return 0; 
    10901141 } 
    10911142 
     1143 if ( retry ) { 
     1144  if ( __load_plugin_any_get_api(para, appname, appabi, servicename, serviceabi, universal, api) == 0 ) { 
     1145   roar_dl_para_unref(para); 
     1146   return 0; 
     1147  } 
     1148 } 
     1149 
     1150 roar_dl_para_unref(para); 
    10921151 roar_err_set(ROAR_ERROR_NOENT); 
    10931152 return -1; 
Note: See TracChangeset for help on using the changeset viewer.