Changeset 5816:6c593d184ef2 in roaraudio


Ignore:
Timestamp:
01/05/13 14:31:33 (8 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

improved service interface even more, allow creation of a simple interface object to access functions.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/roardl.h

    r5815 r5816  
    420420} 
    421421 
    422 const void * libroar_dl_service_get_api(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_lhandle ** lhandle); 
    423 #define roar_dl_service_get_api(para,servicename,serviceabi,type,lhandle) ((const struct type*)libroar_dl_service_get_api((para), (para)->appname, (para)->abiversion, (servicename), (serviceabi), 1, (lhandle))) 
     422struct roar_dl_service_api { 
     423 const void * api; 
     424 struct roar_dl_lhandle * lhandle; 
     425}; 
     426 
     427#define libroar_dl_service_apitype(type) \ 
     428union { \ 
     429 struct roar_dl_service_api interface; \ 
     430 const struct type * api; \ 
     431} 
     432 
     433int 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); 
     434#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)) 
     435#define roar_dl_service_get_api(para,servicename,serviceabi,api) libroar_dl_service_get_api((para), (para)->appname, (para)->abiversion, (servicename), (serviceabi), 1, (api)) 
     436 
     437int libroar_dl_service_free_api_real(struct roar_dl_service_api * api); 
     438#define libroar_dl_service_free_api(api) libroar_dl_service_free_api_real((struct roar_dl_service_api *)&(api)) 
     439 
     440#define libroar_dl_service_run_func(obj,name,type,...) ((type[3]){(type)roar_dl_context_restore((obj).interface.lhandle), ((obj).api->name(__VA_ARGS__)), (type)roar_dl_context_store((obj).interface.lhandle)})[1] 
     441#define libroar_dl_service_run_func_void(obj,name,...) do { roar_dl_context_restore((obj).interface.lhandle); (obj).api->name(__VA_ARGS__); roar_dl_context_store((obj).interface.lhandle); } while (0) 
     442#define libroar_dl_service_check_func(obj,name) ((obj).api->name != NULL) 
    424443 
    425444// Reg FN: 
  • libroar/roardl.c

    r5815 r5816  
    10281028} 
    10291029 
    1030 const void * libroar_dl_service_get_api(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_lhandle ** lhandle) { 
     1030int 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) { 
    10311031 const struct roar_dl_service * s; 
    10321032 struct __fnregs * c = NULL; 
    10331033 size_t i; 
     1034 int err; 
     1035 
     1036 if ( para == NULL || servicename == NULL || serviceabi == NULL || api == NULL ) { 
     1037  roar_err_set(ROAR_ERROR_FAULT); 
     1038  return -1; 
     1039 } 
     1040 
     1041 memset(api, 0, sizeof(struct roar_dl_service_api)); 
    10341042 
    10351043 for (i = 0; i < __MAX_FNREGS; i++) { 
     
    10621070   continue; 
    10631071 
    1064   if ( lhandle != NULL ) { 
    1065    if ( roar_dl_ref(c->lhandle) != 0 ) 
    1066     continue; 
    1067    *lhandle = c->lhandle; 
    1068   } 
    1069  
    1070   return s->get_api(s, para); 
     1072  if ( roar_dl_ref(c->lhandle) != 0 ) 
     1073   continue; 
     1074 
     1075  api->lhandle = c->lhandle; 
     1076 
     1077  api->api = s->get_api(s, para); 
     1078  if ( api->api == NULL ) { 
     1079   err = roar_error; 
     1080   roar_dl_unref(c->lhandle); 
     1081   api->lhandle = NULL; 
     1082   roar_error = err; 
     1083   return -1; 
     1084  } 
     1085 
     1086  return 0; 
    10711087 } 
    10721088 
    10731089 roar_err_set(ROAR_ERROR_NOENT); 
    1074  return NULL; 
     1090 return -1; 
     1091} 
     1092 
     1093int libroar_dl_service_free_api_real(struct roar_dl_service_api * api) { 
     1094 if ( api == NULL ) { 
     1095  roar_err_set(ROAR_ERROR_FAULT); 
     1096  return -1; 
     1097 } 
     1098 
     1099 roar_dl_unref(api->lhandle); 
     1100 
     1101 memset(api, 0, sizeof(struct roar_dl_service_api)); 
     1102 
     1103 return 0; 
    10751104} 
    10761105 
Note: See TracChangeset for help on using the changeset viewer.