Changeset 5275:811818eb5b81 in roaraudio for roard


Ignore:
Timestamp:
11/19/11 22:54:26 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Improved plugin loader a lot (Closes: #190)

Location:
roard
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • roard/clients.c

    r5242 r5275  
    3838#ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD 
    3939#ifdef ROAR_HAVE_H_ESD 
    40  {ROAR_PROTO_ESOUND, NULL, emul_esd_check_client, NULL, NULL}, 
     40 {ROAR_PROTO_ESOUND, ROAR_SUBSYS_WAVEFORM, "EsounD emulation", NULL, emul_esd_check_client, NULL, NULL}, 
    4141#endif 
    4242#endif 
    4343#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
    44  {ROAR_PROTO_RPLAY, NULL, emul_rplay_check_client, NULL, NULL}, 
     44 {ROAR_PROTO_RPLAY, ROAR_SUBSYS_WAVEFORM, "RPlay emulation", NULL, emul_rplay_check_client, NULL, NULL}, 
    4545#endif 
    4646#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER 
    47  {ROAR_PROTO_GOPHER, NULL, emul_gopher_check_client, NULL, emul_gopher_flushed_client}, 
    48 #endif 
    49  {-1, NULL} 
     47 {ROAR_PROTO_GOPHER, ROAR_SUBSYS_WAVEFORM, "The Internet Gopher Protocol", NULL, emul_gopher_check_client, NULL, emul_gopher_flushed_client}, 
     48#endif 
     49 {-1, 0, NULL, NULL, NULL, NULL, NULL} 
    5050}; 
    5151 
     
    5858 for (i = 0; i < ROAR_CLIENTS_MAX; i++) 
    5959  g_clients[i] = NULL; 
     60 
     61 for (i = 0; g_proto[i].proto != -1; i++); 
     62 
     63 for (; i < MAX_PROTOS; i++) 
     64  g_proto[i].proto = -1; 
    6065 
    6166 return 0; 
     
    826831 memcpy(&(g_proto[i]), proto, sizeof(*g_proto)); 
    827832 
    828  i++; 
    829  
    830  memset(&(g_proto[i]), 0, sizeof(*g_proto)); 
    831  g_proto[i].proto = -1; 
    832  
    833  return 0; 
    834 } 
    835  
     833 return 0; 
     834} 
     835 
     836int clients_unregister_proto(int proto) { 
     837 const size_t len = sizeof(g_proto)/sizeof(*g_proto); 
     838 size_t i; 
     839 
     840 if ( proto < 0 ) { 
     841  roar_err_set(ROAR_ERROR_RANGE); 
     842  return -1; 
     843 } 
     844 
     845 for (i = 0; i < len; i++) { 
     846  if ( g_proto[i].proto == proto ) { 
     847   memset(&(g_proto[i]), 0, sizeof(*g_proto)); 
     848   g_proto[i].proto = -1; 
     849   return 0; 
     850  } 
     851 } 
     852 
     853 roar_err_set(ROAR_ERROR_NOENT); 
     854 return -1; 
     855} 
     856 
     857void print_protolist        (enum output_format format) { 
     858 const size_t len = sizeof(g_proto)/sizeof(*g_proto); 
     859 struct roard_proto * p; 
     860 char subsys[7] = "      "; 
     861 size_t i; 
     862 
     863 switch (format) { 
     864  case FORMAT_NATIVE: 
     865    printf("  Protocol Flag Subsys - Description\n"); 
     866    printf("------------------------------------------------------\n"); 
     867    printf("  roar          WM LRX - RoarAudio native protocol\n"); 
     868#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
     869    printf("  simple        WM LRX - PulseAudio simple protocol\n"); 
     870#endif 
     871#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
     872    printf("  rsound        W      - RSound emulation\n"); 
     873#endif 
     874   break; 
     875  case FORMAT_WIKI: 
     876    printf("||=Protocol =||=Flag =||=Subsys =||=Description              =||\n"); 
     877    printf("||roar       ||       ||WM LRX   ||RoarAudio native protocol  ||\n"); 
     878#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
     879    printf("||simple     ||       ||WM LRX   ||PulseAudio simple protocol ||\n"); 
     880#endif 
     881#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
     882    printf("||rsound     ||       ||W        ||RSound emulation           ||\n"); 
     883#endif 
     884   break; 
     885  case FORMAT_CSV: 
     886    printf("Protocol,Flag,Subsys,Description\n"); 
     887    printf("roar,,WM LRX,RoarAudio native protocol\n"); 
     888#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
     889    printf("simple,,WM LRX,PulseAudio simple protocol\n"); 
     890#endif 
     891#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
     892    printf("rsound,,W,RSound emulation\n"); 
     893#endif 
     894   break; 
     895  default: 
     896    roar_err_set(ROAR_ERROR_NOTSUP); 
     897    return; 
     898 } 
     899 
     900 for (i = 0; i < len; i++) { 
     901  p = &(g_proto[i]); 
     902  if ( p->proto == -1 ) 
     903   continue; 
     904 
     905  strncpy(subsys, "      ", 6); 
     906 
     907  if ( p->subsystems & ROAR_SUBSYS_WAVEFORM ) 
     908   subsys[0] = 'W'; 
     909  if ( p->subsystems & ROAR_SUBSYS_MIDI ) 
     910   subsys[1] = 'M'; 
     911  if ( p->subsystems & ROAR_SUBSYS_CB ) 
     912   subsys[2] = 'C'; 
     913  if ( p->subsystems & ROAR_SUBSYS_LIGHT ) 
     914   subsys[3] = 'L'; 
     915  if ( p->subsystems & ROAR_SUBSYS_RAW ) 
     916   subsys[4] = 'R'; 
     917  if ( p->subsystems & ROAR_SUBSYS_COMPLEX ) 
     918   subsys[5] = 'X'; 
     919 
     920  switch (format) { 
     921   case FORMAT_NATIVE: 
     922     printf("  %-13s %s - %s\n", roar_proto2str(p->proto), subsys, p->description); 
     923    break; 
     924   case FORMAT_WIKI: 
     925     printf("||%s || ||%s ||%s ||\n", roar_proto2str(p->proto), subsys, p->description); 
     926    break; 
     927   case FORMAT_CSV: 
     928     printf("%s,,%s,%s\n", roar_proto2str(p->proto), subsys, p->description); 
     929    break; 
     930  } 
     931 } 
     932} 
    836933 
    837934int client_stream_exec   (int client, int stream) { 
  • roard/include/client.h

    r5192 r5275  
    7676struct roard_proto { 
    7777 int proto; 
     78 int subsystems; 
     79 const char * description; 
    7880 int (*new_client)(int client, struct roar_vio_calls * vio, struct roard_listen * lsock); 
    7981 int (*check_client)(int client, struct roar_vio_calls * vio); 
     
    114116 
    115117// proto support 
    116 int clients_register_proto(struct roard_proto * proto); 
     118int clients_register_proto  (struct roard_proto * proto); 
     119int clients_unregister_proto(int proto); 
     120void print_protolist        (enum output_format format); 
    117121 
    118122// stream functions 
  • roard/include/plugins.h

    r5266 r5275  
    2929#include <roaraudio.h> 
    3030 
     31#define ROARD_DL_APPNAME    "roard <0/RoarAudio>" 
     32#define ROARD_DL_ABIVERSION NULL 
     33 
    3134struct roard_plugins_sched { 
    3235 int (*init)(void); 
     
    4043int plugins_update   (void); 
    4144 
    42 int plugins_load     (const char * filename); 
     45int plugins_load     (const char * filename, const char * args); 
    4346 
    4447int plugins_reg_sched(struct roard_plugins_sched * sched); 
     
    6265 ROARD_DL_REG__UNI_POST 
    6366 
     67// Register Scheduler callbacks: 
    6468#define ROARD_DL_REGFN_SCHED() ROAR_DL_PLUGIN_REG(ROAR_DL_FN_ROARDSCHED, __reg_sched) 
    6569 
     
    7074 ROARD_DL_REG__UNI_POST 
    7175 
     76// Register Protocol callbacks: 
    7277#define ROARD_DL_REGFN_PROTO() ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto) 
     78 
     79// Check version: 
     80#define ROARD_DL_CHECK_VERSIONS() ROAR_DL_PLUGIN_CHECK_VERSIONS(ROARD_DL_APPNAME, ROARD_DL_ABIVERSION) 
    7381 
    7482#endif 
  • roard/plugins.c

    r4708 r5275  
    3131 struct roar_dl_lhandle     * lhandle; 
    3232 struct roard_plugins_sched * sched; 
     33 int protocols[MAX_PROTOS]; 
    3334} g_plugins[MAX_PLUGINS]; 
    3435static struct _roard_plugin * _pp = NULL; 
     
    5354} 
    5455 
     56static 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 
    5574int plugins_init  (void) { 
    5675 int i; 
     
    6281   _pp->sched = NULL; 
    6382 
    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   } 
    6588 
    6689   if ( g_plugins[i].sched != NULL ) 
     
    80103 for (i = 0; i < MAX_PLUGINS; i++) { 
    81104  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])); 
    87106  } 
    88107 } 
     
    105124} 
    106125 
    107 int plugins_load  (const char * filename) { 
     126int plugins_load  (const char * filename, const char * args) { 
    108127 struct _roard_plugin * next = _find_free(); 
     128 struct roar_dl_librarypara * para; 
     129 int i; 
    109130 
    110131 if ( next == NULL ) 
    111132  return -1; 
    112133 
    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 
    114145 if ( next->lhandle == NULL ) { 
    115146  ROAR_ERR("plugins_load(filename='%s'): can not load plugin: %s", filename, roar_dl_errstr(NULL)); 
     
    130161 
    131162int plugins_reg_proto(struct roard_proto         * proto) { 
     163 int i; 
     164 
    132165 if ( _pp == NULL ) 
    133166  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 } 
    134179 
    135180 return clients_register_proto(proto); 
  • roard/roard.c

    r5257 r5275  
    260260 printf( 
    261261        " --plugin-load FILE    - Load plugin FILE\n" 
     262        " --plugin-args ARGS    - Arguments for the plugin\n" 
     263        "                         (must be given before the --plugin-load)\n" 
    262264       ); 
    263265 
     
    417419// printf("\n Options:\n\n"); 
    418420 printf("\n"); 
    419 } 
    420  
    421 static void list_proto (void) { 
    422  printf("  Protocol Flag Subsys - Description\n"); 
    423  printf("------------------------------------------------------\n"); 
    424  printf("  roar          WM LRX - RoarAudio native protocol\n"); 
    425 #if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD) 
    426  printf("  esd           W      - EsounD emulation\n"); 
    427 #endif 
    428 #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
    429  printf("  simple        WM LRX - PulseAudio simple protocol\n"); 
    430 #endif 
    431 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
    432  printf("  rsound        W      - RSound emulation\n"); 
    433 #endif 
    434 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
    435  printf("  rplay         W      - RPlay emulation\n"); 
    436 #endif 
    437 #ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER 
    438  printf("  gopher               - The Internet Gopher Protocol\n"); 
    439 #endif 
    440421} 
    441422 
     
    13801361 int    sysclocksync = 0; 
    13811362// char * server = ROAR_DEFAULT_SOCK_GLOBAL; 
     1363 const char * plugin_args = NULL; 
    13821364#ifdef ROAR_SUPPORT_LISTEN 
    13831365 int    port       = ROAR_DEFAULT_PORT; 
     
    17011683  } else if ( strcmp(k, "--plugin-load") == 0 ) { 
    17021684   _CKHAVEARGS(1); 
    1703    if ( plugins_load(argv[++i]) == -1 ) { 
     1685   if ( plugins_load(argv[++i], plugin_args) == -1 ) { 
    17041686    ROAR_ERR("Can not load plugin"); 
    17051687   } 
     1688   plugin_args = NULL; 
     1689  } else if ( strcmp(k, "--plugin-args") == 0 ) { 
     1690   _CKHAVEARGS(1); 
     1691   plugin_args = argv[++i]; 
    17061692 
    17071693  } else if ( strcmp(k, "--guest-acclev") == 0 ) { 
     
    21402126 
    21412127  } else if ( strcmp(k, "--list-proto") == 0 ) { 
    2142    list_proto(); 
     2128   print_protolist(print_format); 
    21432129   return 0; 
    21442130 
Note: See TracChangeset for help on using the changeset viewer.