source: roaraudio/include/libroar/roardl.h @ 5317:6b1045321fd6

Last change on this file since 5317:6b1045321fd6 was 5317:6b1045321fd6, checked in by phi, 12 years ago

updated plugin infrastructre

File size: 11.4 KB
Line 
1//roardl.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#ifndef _LIBROARROARDL_H_
37#define _LIBROARROARDL_H_
38
39#include "libroar.h"
40
41#define ROAR_DL_FLAG_DEFAULTS          -1
42#define ROAR_DL_FLAG_NONE               0x0000
43#define ROAR_DL_FLAG_STATIC             0x0001 /* plugins are linked statically -lfoo */
44
45#define ROAR_DL_HANDLE_DEFAULT          ((struct roar_dl_lhandle*)(void*)0)
46#define ROAR_DL_HANDLE_NEXT             ((struct roar_dl_lhandle*)(void*)1)
47
48#define ROAR_DL_FN_DSTR                 0
49#define ROAR_DL_FN_CDRIVER              1
50#define ROAR_DL_FN_TRANSCODER           2
51#define ROAR_DL_FN_DRIVER               3
52#define ROAR_DL_FN_SOURCE               4
53#define ROAR_DL_FN_FILTER               5
54#define ROAR_DL_FN_FF                   6 /* file format */
55#define ROAR_DL_FN_AUTH                 7
56#define ROAR_DL_FN_BRIDGE               8
57#define ROAR_DL_FN_ROARDSCHED           9
58#define ROAR_DL_FN_APPSCHED            10
59#define ROAR_DL_FN_PROTO               11
60#define ROAR_DL_FN_NOTIFY              12
61#define ROAR_DL_FN_INIT                13 /* global plugin instance init. should be avoided */
62//#define ROAR_DL_FN_               9
63#define ROAR_DL_FN_MAX                 24
64
65#define ROAR_DL_LIBPARA_VERSION         1
66#define ROAR_DL_LIBNAME_VERSION         0
67#define ROAR_DL_LIBINST_VERSION         1
68
69#define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst *                                          \
70                             _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para);  \
71                            struct roar_dl_libraryinst *                                          \
72                             _roaraudio_library_init(struct roar_dl_librarypara * para) {         \
73                              return _##lib##_roaraudio_library_init(para);                       \
74                            }                                                                     \
75                            struct roar_dl_libraryinst *                                          \
76                             _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para)   \
77
78#define ROAR_DL_PLUGIN_START(xlib) ROAR_DL_PLUGIN(xlib) {                                         \
79                                     static int _inited = 0;                                      \
80                                     static struct roar_dl_libraryinst lib;                       \
81                                     static struct roar_dl_libraryname libname;                   \
82                                     (void)para;                                                  \
83                                     if ( _inited )                                               \
84                                      return &lib;                                                \
85                                     memset(&lib, 0, sizeof(lib));                                \
86                                     lib.version = ROAR_DL_LIBINST_VERSION;                       \
87                                     lib.len     = sizeof(lib);                                   \
88                                     memset(&libname, 0, sizeof(libname));                        \
89                                     libname.version = ROAR_DL_LIBNAME_VERSION;                   \
90                                     libname.len     = sizeof(libname);                           \
91                                     libname.name = #xlib;                                        \
92                                     lib.libname  = &libname;                                     \
93                                     do
94
95#define ROAR_DL_PLUGIN_END          while(0);                                                     \
96                                    _inited = 1;                                                  \
97                                    return &lib;                                                  \
98                                   }
99
100#define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL
101#define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL
102#define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr))
103#define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func))
104#define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched))
105#define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \
106                                                 lib.global_data_init = &(init);       \
107                                                 lib.global_data_pointer = (void*)&(ptr)
108
109struct roar_dl_librarypara {
110 int version;               // version of this struct type (must be ROAR_DL_LIBPARA_VERSION)
111 size_t len;                // Length of this struct type (must be sizeof(struct roar_dl_librarypara)
112
113 size_t refc;               // Reference counter.
114
115 size_t argc;               // number of elements in argv
116 struct roar_keyval * argv; // Parameter for the plugin
117 void * args_store;         // Storage area for argv's data.
118                            // If not NULL this and argv will be freed.
119                            // If NULL argv will be left untouched.
120
121 void * binargv;            // A pointer with binary data arguments.
122                            // This can be used to pass any non-string data to
123                            // the plugin. Normally this is NULL or the pointer
124                            // to a struct with members of whatever is needed.
125
126 const char * appname;      // application name in common format:
127                            // Product/Version <VendorID/VendorName> (comments)
128                            // Version and comment are optional and should be avoided.
129                            // When no vendor ID is registered use <VendorName>.
130                            // The VendorName MUST NOT contain a slash and SHOULD
131                            // be as unique as possible.
132                            // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>,
133                            //           AnAPP <Musterman GbR>
134 const char * abiversion;   // The ABI version. For libraries this should be the SONAME.
135                            // For applications this should be the version of the release
136                            // which introduced the current ABI.
137                            // Examples: libroar2, 0.5.1
138 struct roar_notify_core * notifycore;
139};
140
141struct roar_dl_libraryname {
142 int      version;
143 size_t   len;
144 const char * name;        //Format: shortname
145 const char * libname;     //This is the same as appname in struct roar_dl_librarypara.
146                           //Format: Product <VendorID/VendorName> (comments)
147 const char * libversion;  //This is the pure version number of the library.
148 const char * abiversion;  //This is the same as abiversion in struct roar_dl_librarypara.
149                           //Format: Version
150 const char * description; //Free form.
151 const char * contact;     //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room
152 const char * authors;     //Other authors as free form.
153 const char * license;     //Format: LicenseName-Version (options)
154                           //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later).
155};
156
157struct roar_dl_librarydep {
158 int      version;
159 size_t   len;
160 const char * name;
161 const char * libname;
162 const char * abiversion;
163};
164
165struct roar_dl_libraryinst {
166 int      version;
167 size_t   len;
168 int    (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
169 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
170 struct roar_dl_libraryname * libname;
171 size_t  global_data_len;
172 void *  global_data_init;
173 void ** global_data_pointer;
174 struct roar_dl_librarydep * libdep;
175 size_t libdep_len;
176 struct roar_dl_appsched * appsched;
177};
178
179struct roar_dl_appsched {
180 int (*init)  (struct roar_dl_librarypara * para);
181 int (*free)  (struct roar_dl_librarypara * para);
182 int (*update)(struct roar_dl_librarypara * para);
183};
184
185enum roar_dl_appsched_trigger {
186 ROAR_DL_APPSCHED_INIT = 1,
187#define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT
188 ROAR_DL_APPSCHED_FREE,
189#define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE
190 ROAR_DL_APPSCHED_UPDATE
191#define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE
192};
193
194// parameter functions:
195struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv,
196                                              const char * appname, const char * abiversion);
197int roar_dl_para_ref                    (struct roar_dl_librarypara * para);
198int roar_dl_para_unref                  (struct roar_dl_librarypara * para);
199int roar_dl_para_check_version          (struct roar_dl_librarypara * para,
200                                         const char * appname, const char * abiversion);
201
202// 'core' dynamic loader functions.
203struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags,
204                                         int ra_init, struct roar_dl_librarypara * para);
205int                      roar_dl_close  (struct roar_dl_lhandle * lhandle);
206
207void                   * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type);
208
209int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle,
210                                         const char * prefix,
211                                         struct roar_dl_librarypara * para);
212
213const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle);
214
215// getting meta data:
216struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle);
217const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle);
218
219// context switching:
220// _restore() is to switch from main to library context. _store() is to store library context
221// and switch back to main context.
222int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle);
223int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle);
224
225// appsched:
226int                      roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger);
227
228#endif
229
230//ll
Note: See TracBrowser for help on using the repository browser.