Changeset 5275:811818eb5b81 in roaraudio


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)

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5272 r5275  
    55        * Removed old functions from API (Closes: #186, See: #130) 
    66        * Removed old roarclients (See: #130) 
     7        * Improved plugin loader a lot (Closes: #190) 
    78 
    89v. 0.4 - Fri Nov 11 2011 20:12 CET 
  • doc/man1/roard.1

    r5159 r5275  
    152152.SH "PLUGINS" 
    153153.TP 
    154 \fB--plugin-load\fR 
     154\fB--plugin-load FILENAME\fR 
    155155Load the given plugin. 
     156 
     157.TP 
     158\fB--plugin-args ARGS\fR 
     159Arguments for the plugin. 
     160(must be given before the --plugin-load). 
    156161 
    157162.SH "SECURITY" 
  • include/libroar/roardl.h

    r4708 r5275  
    5757#define ROAR_DL_FN_PROTO               11 
    5858//#define ROAR_DL_FN_               9 
    59 #define ROAR_DL_FN_MAX                 16 
     59#define ROAR_DL_FN_MAX                 24 
    6060 
    61 #define ROAR_DL_LIBPARA_VERSION         0 
    62 #define ROAR_DL_LIBINST_VERSION         0 
     61#define ROAR_DL_LIBPARA_VERSION         1 
     62#define ROAR_DL_LIBNAME_VERSION         0 
     63#define ROAR_DL_LIBINST_VERSION         1 
    6364 
    6465#define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst *                                          \ 
     
    7475                                     static int _inited = 0;                                      \ 
    7576                                     static struct roar_dl_libraryinst lib;                       \ 
     77                                     static struct roar_dl_libraryname libname;                   \ 
    7678                                     (void)para;                                                  \ 
    7779                                     if ( _inited )                                               \ 
     
    8082                                     lib.version = ROAR_DL_LIBINST_VERSION;                       \ 
    8183                                     lib.len     = sizeof(lib);                                   \ 
     84                                     memset(&libname, 0, sizeof(libname));                        \ 
     85                                     libname.version = ROAR_DL_LIBNAME_VERSION;                   \ 
     86                                     libname.len     = sizeof(libname);                           \ 
     87                                     libname.name = #xlib;                                        \ 
     88                                     lib.libname  = &libname;                                     \ 
    8289                                     do 
    8390 
     
    8794                                   } 
    8895 
     96#define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL 
     97#define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL 
    8998#define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr)) 
    9099#define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func)) 
    91100 
    92101struct roar_dl_librarypara { 
    93  int version; 
    94  size_t len; 
     102 int version;               // version of this struct type (must be ROAR_DL_LIBPARA_VERSION) 
     103 size_t len;                // Length of this struct type (must be sizeof(struct roar_dl_librarypara) 
     104 
     105 size_t refc;               // Reference counter. 
     106 
     107 size_t argc;               // number of elements in argv 
     108 struct roar_keyval * argv; // Parameter for the plugin 
     109 void * args_store;         // Storage area for argv's data. 
     110                            // If not NULL this and argv will be freed. 
     111                            // If NULL argv will be left untouched. 
     112 
     113 void * binargv;            // A pointer with binary data arguments. 
     114                            // This can be used to pass any non-string data to 
     115                            // the plugin. Normally this is NULL or the pointer 
     116                            // to a struct with members of whatever is needed. 
     117 
     118 const char * appname;      // application name in common format: 
     119                            // Product/Version <VendorID/VendorName> (comments) 
     120                            // Version and comment are optional and should be avoided. 
     121                            // When no vendor ID is registered use <VendorName>. 
     122                            // The VendorName MUST NOT contain a slash and SHOULD 
     123                            // be as unique as possible. 
     124                            // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>, 
     125                            //           AnAPP <Musterman GbR> 
     126 const char * abiversion;   // The ABI version. For libraries this should be the SONAME. 
     127                            // For applications this should be the version of the release 
     128                            // which introduced the current ABI. 
     129                            // Examples: libroar2, 0.5.1 
     130}; 
     131 
     132struct roar_dl_libraryname { 
     133 int      version; 
     134 size_t   len; 
     135 const char * name;        //Format: shortname 
     136 const char * libversion;  //Format: Product/Version <VendorID/VendorName> (comments) 
     137 const char * description; //Free form. 
     138 const char * contact;     //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room 
     139 const char * authors;     //Other authors as free form. 
     140 const char * license;     //Format: LicenseName-Version (options) 
     141                           //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later). 
    95142}; 
    96143 
     
    100147 int    (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); 
    101148 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); 
     149 struct roar_dl_libraryname * libname; 
    102150}; 
    103151 
    104 struct roar_dl_lhandle { 
    105  struct roar_dl_librarypara * para; 
    106  struct roar_dl_libraryinst * lib; 
    107 #if defined(ROAR_HAVE_LIBDL) 
    108  void * handle; 
    109 #else 
    110  char dummy[8]; 
    111 #endif 
    112 }; 
     152struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, 
     153                                              const char * appname, const char * abiversion); 
     154int roar_dl_para_ref                    (struct roar_dl_librarypara * para); 
     155int roar_dl_para_unref                  (struct roar_dl_librarypara * para); 
     156int roar_dl_para_check_version          (struct roar_dl_librarypara * para, 
     157                                         const char * appname, const char * abiversion); 
    113158 
    114 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, int ra_init); 
    115 int                      roar_dl_close(struct roar_dl_lhandle * lhandle); 
     159struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags, 
     160                                         int ra_init, struct roar_dl_librarypara * para); 
     161int                      roar_dl_close  (struct roar_dl_lhandle * lhandle); 
    116162 
    117 void                   * roar_dl_getsym(struct roar_dl_lhandle * lhandle, const char * sym, int type); 
     163void                   * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type); 
    118164 
    119 int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, const char * prefix); 
     165int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, 
     166                                         const char * prefix, 
     167                                         struct roar_dl_librarypara * para); 
    120168 
    121 char *                   roar_dl_errstr(struct roar_dl_lhandle * lhandle); 
     169const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle); 
     170 
     171struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle); 
     172const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle); 
    122173 
    123174#endif 
  • libroar/roardl.c

    r5270 r5275  
    4040#endif 
    4141 
     42struct roar_dl_lhandle { 
     43 struct roar_dl_librarypara * para; 
     44 struct roar_dl_libraryinst * lib; 
     45#if defined(ROAR_HAVE_LIBDL) 
     46 void * handle; 
     47#endif 
     48}; 
     49 
     50 
     51struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, 
     52                                              const char * appname, const char * abiversion) { 
     53 struct roar_dl_librarypara * ret = roar_mm_malloc(sizeof(struct roar_dl_librarypara)); 
     54 ssize_t argc; 
     55 int err; 
     56 
     57 if ( ret == NULL ) 
     58  return NULL; 
     59 
     60 memset(ret, 0, sizeof(struct roar_dl_librarypara)); 
     61 
     62 ret->version    = ROAR_DL_LIBPARA_VERSION; 
     63 ret->len        = sizeof(struct roar_dl_librarypara); 
     64 ret->refc       = 1; 
     65 ret->argc       = 0; 
     66 ret->argv       = NULL; 
     67 ret->args_store = NULL; 
     68 ret->binargv    = binargv; 
     69 ret->appname    = appname; 
     70 ret->abiversion = abiversion; 
     71 
     72 if ( args != NULL ) { 
     73  ret->args_store = roar_mm_strdup(args); 
     74  if ( ret->args_store == NULL ) { 
     75   err = roar_error; 
     76   roar_mm_free(ret); 
     77   roar_error = err; 
     78   return NULL; 
     79  } 
     80 
     81  argc = roar_keyval_split(&(ret->argv), ret->args_store, NULL, NULL, 0); 
     82  if ( argc == -1 ) { 
     83   err = roar_error; 
     84   roar_mm_free(ret->args_store); 
     85   roar_mm_free(ret); 
     86   roar_error = err; 
     87   return NULL; 
     88  } 
     89 
     90  ret->argc = argc; 
     91 } 
     92 
     93 return ret; 
     94} 
     95 
     96int roar_dl_para_ref                    (struct roar_dl_librarypara * para) { 
     97 if ( para == NULL ) { 
     98  roar_err_set(ROAR_ERROR_FAULT); 
     99  return -1; 
     100 } 
     101 
     102 para->refc++; 
     103 
     104 return 0; 
     105} 
     106 
     107int roar_dl_para_unref                  (struct roar_dl_librarypara * para) { 
     108 if ( para == NULL ) { 
     109  roar_err_set(ROAR_ERROR_FAULT); 
     110  return -1; 
     111 } 
     112 
     113 para->refc--; 
     114 
     115 if ( para->refc == 0 ) { 
     116  if ( para->args_store != NULL ) { 
     117   roar_mm_free(para->args_store); 
     118   roar_mm_free(para->argv); 
     119  } 
     120  roar_mm_free(para); 
     121 } 
     122 
     123 return 0; 
     124} 
     125int roar_dl_para_check_version          (struct roar_dl_librarypara * para, 
     126                                         const char * appname, const char * abiversion) { 
     127 if ( para == NULL ) { 
     128  roar_err_set(ROAR_ERROR_FAULT); 
     129  return -1; 
     130 } 
     131 
     132 // check if both appnames are NULL or non-NULL. 
     133 if ( (para->appname == NULL && appname != NULL) || (para->appname != NULL && appname == NULL) ) { 
     134  roar_err_set(ROAR_ERROR_BADVERSION); 
     135  return -1; 
     136 } 
     137 
     138 // check if the appname matches if given. 
     139 if ( para->appname != NULL && !!strcmp(para->appname, appname) ) { 
     140  roar_err_set(ROAR_ERROR_BADVERSION); 
     141  return -1; 
     142 } 
     143 
     144 // check if both ABI versions are NULL or non-NULL. 
     145 if ( (para->abiversion == NULL && abiversion != NULL) || (para->abiversion != NULL && abiversion == NULL) ) { 
     146  roar_err_set(ROAR_ERROR_BADVERSION); 
     147  return -1; 
     148 } 
     149 
     150 // check if the ABI versions matches if given. 
     151 if ( para->abiversion != NULL && !!strcmp(para->abiversion, abiversion) ) { 
     152  roar_err_set(ROAR_ERROR_BADVERSION); 
     153  return -1; 
     154 } 
     155 
     156 return 0; 
     157} 
     158 
     159 
    42160#if defined(ROAR_HAVE_LIBDL) 
    43161static void * _roardl2ldl (struct roar_dl_lhandle * lhandle) { 
     
    52170#endif 
    53171 
    54 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, int ra_init) { 
     172struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, 
     173                                      int ra_init, struct roar_dl_librarypara * para) { 
    55174 struct roar_dl_lhandle * ret = NULL; 
     175 int err; 
    56176 
    57177 // early errors just return. 
    58178 
    59  if ( flags != ROAR_DL_FLAG_DEFAUTS ) 
    60   return NULL; 
     179 if ( flags != ROAR_DL_FLAG_DEFAUTS ) { 
     180  roar_err_set(ROAR_ERROR_NOTSUP); 
     181  return NULL; 
     182 } 
    61183 
    62184 if ( (ret = roar_mm_malloc(sizeof(struct roar_dl_lhandle))) == NULL ) 
     
    80202#else 
    81203 roar_mm_free(ret); 
     204 roar_err_set(ROAR_ERROR_NOSYS); 
    82205 return NULL; 
    83206#endif 
    84207 
    85  if ( ret == NULL ) 
    86   return NULL; 
     208 ret->para = para; 
    87209 
    88210 if ( ra_init ) { 
    89   roar_dl_ra_init(ret, NULL); 
    90  } 
     211  if ( roar_dl_ra_init(ret, NULL, para) == -1 ) { 
     212   err = roar_error; 
     213   ROAR_WARN("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not init RA lib: %s", filename, flags, ra_init, para, roar_error2str(err)); 
     214#if defined(ROAR_HAVE_LIBDL) 
     215   dlclose(ret->handle); 
     216#endif 
     217   roar_mm_free(ret); 
     218   roar_error = err; 
     219   return NULL; 
     220  } 
     221 } 
     222 
     223 if ( para != NULL ) 
     224  roar_dl_para_ref(para); 
    91225 
    92226 return ret; 
     
    96230 int ret = -1; 
    97231 
    98  if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) 
    99   return -1; 
    100  if ( lhandle == ROAR_DL_HANDLE_NEXT ) 
    101   return -1; 
     232 if ( lhandle == ROAR_DL_HANDLE_DEFAULT || lhandle == ROAR_DL_HANDLE_NEXT ) { 
     233  roar_err_set(ROAR_ERROR_BADFH); 
     234  return -1; 
     235 } 
    102236 
    103237 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) 
     
    110244#endif 
    111245 
     246 if ( lhandle->para != NULL ) 
     247  roar_dl_para_unref(lhandle->para); 
     248 
    112249 roar_mm_free(lhandle); 
    113250 
     
    129266} 
    130267 
    131 int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, const char * prefix) { 
     268int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, 
     269                                         const char * prefix, 
     270                                         struct roar_dl_librarypara * para) { 
    132271#define _SUFFIX "_roaraudio_library_init" 
    133272 char name[80] = _SUFFIX; 
    134273 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 
    135274 struct roar_dl_libraryinst * lib; 
    136  struct roar_dl_librarypara * para = NULL; 
    137275 int i; 
    138276 
     
    141279   return -1; 
    142280 } else { 
    143   para = lhandle->para; 
     281  if ( para == NULL ) 
     282   para = lhandle->para; 
    144283 } 
    145284 
     
    181320} 
    182321 
    183 char *                  roar_dl_errstr(struct roar_dl_lhandle * lhandle) { 
     322const char * roar_dl_errstr(struct roar_dl_lhandle * lhandle) { 
    184323#if defined(ROAR_HAVE_LIBDL) 
    185324 (void)lhandle; 
     
    190329} 
    191330 
     331struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle) { 
     332 if ( (void*)lhandle < (void*)128 ) { 
     333  roar_err_set(ROAR_ERROR_NOTSUP); 
     334  return NULL; 
     335 } 
     336 
     337 if ( lhandle->para == NULL ) { 
     338  roar_err_set(ROAR_ERROR_NOENT); 
     339  return NULL; 
     340 } 
     341 
     342 if ( roar_dl_para_ref(lhandle->para) == -1 ) 
     343  return NULL; 
     344 
     345 return lhandle->para; 
     346} 
     347 
     348const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle) { 
     349 if ( (void*)lhandle < (void*)128 ) { 
     350  roar_err_set(ROAR_ERROR_NOTSUP); 
     351  return NULL; 
     352 } 
     353 
     354 if ( lhandle->lib == NULL ) { 
     355  roar_err_set(ROAR_ERROR_BADLIB); 
     356  return NULL; 
     357 } 
     358 
     359 if ( lhandle->lib->libname == NULL ) { 
     360  roar_err_set(ROAR_ERROR_NOENT); 
     361  return NULL; 
     362 } 
     363 
     364 if ( lhandle->lib->libname->version != ROAR_DL_LIBNAME_VERSION ) { 
     365  roar_err_set(ROAR_ERROR_BADVERSION); 
     366  return NULL; 
     367 } 
     368 
     369 if ( lhandle->lib->libname->len != sizeof(struct roar_dl_libraryname) ) { 
     370  roar_err_set(ROAR_ERROR_HOLE); 
     371  return NULL; 
     372 } 
     373 
     374 return lhandle->lib->libname; 
     375} 
     376 
    192377//ll 
  • libroar/vio_dstr.c

    r5270 r5275  
    289289 
    290290static void _roar_vio_dstr_init_otherlibs (void) { 
    291  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroardsp"); 
    292  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroareio"); 
    293  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarlight"); 
    294  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarmidi"); 
     291 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroardsp",   NULL); 
     292 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroareio",   NULL); 
     293 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarlight", NULL); 
     294 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarmidi",  NULL); 
    295295} 
    296296 
  • plugins/roard/listenpty.c

    r5267 r5275  
    5959 
    6060ROAR_DL_PLUGIN_START(roard_discard_protocol) { 
     61 ROARD_DL_CHECK_VERSIONS(); 
     62 
     63 libname.license = "GPL-3.0"; 
     64 
    6165 ROARD_DL_REGFN_SCHED(); 
    6266} ROAR_DL_PLUGIN_END 
  • plugins/universal/protocol-daytime.c

    r5193 r5275  
    5959 
    6060static struct roard_proto proto[1] = { 
    61  {ROAR_PROTO_DAYTIME, new_client, NULL, NULL, flushed_client} 
     61 {ROAR_PROTO_DAYTIME, ROAR_SUBSYS_NONE, "The Internet daytime protocol", new_client, NULL, NULL, flushed_client} 
    6262}; 
    6363 
     
    6565 
    6666ROAR_DL_PLUGIN_START(roard_daytime_protocol) { 
     67 ROARD_DL_CHECK_VERSIONS(); 
     68 
     69 libname.license = "GPL-3.0"; 
     70 
    6771 ROARD_DL_REGFN_PROTO(); 
    6872} ROAR_DL_PLUGIN_END 
  • plugins/universal/protocol-discard.c

    r5264 r5275  
    4242 
    4343static struct roard_proto proto[1] = { 
    44  {ROAR_PROTO_DISCARD, NULL, check_client, NULL, NULL} 
     44 {ROAR_PROTO_DISCARD, ROAR_SUBSYS_NONE, "Discard all data send to the server", NULL, check_client, NULL, NULL} 
    4545}; 
    4646 
     
    4848 
    4949ROAR_DL_PLUGIN_START(roard_discard_protocol) { 
     50 ROARD_DL_CHECK_VERSIONS(); 
     51 
     52 libname.license = "GPL-3.0";  
     53 
    5054 ROARD_DL_REGFN_PROTO(); 
    5155} ROAR_DL_PLUGIN_END 
  • plugins/universal/protocol-echo.c

    r5193 r5275  
    5757 
    5858static struct roard_proto proto[1] = { 
    59  {ROAR_PROTO_ECHO, NULL, check_client, NULL, NULL} 
     59 {ROAR_PROTO_ECHO, ROAR_SUBSYS_NONE, "Send all data send to the server back to the client", NULL, check_client, NULL, NULL} 
    6060}; 
    6161 
     
    6363 
    6464ROAR_DL_PLUGIN_START(roard_echo_protocol) { 
     65 ROARD_DL_CHECK_VERSIONS(); 
     66 
     67 libname.license = "GPL-3.0"; 
     68 
    6569 ROARD_DL_REGFN_PROTO(); 
    6670} ROAR_DL_PLUGIN_END 
  • 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.