source: roaraudio/include/libroar/roardl.h @ 5322:b40c1d7e6bb7

Last change on this file since 5322:b40c1d7e6bb7 was 5322:b40c1d7e6bb7, checked in by phi, 12 years ago

added a (dummy) pointer to a loader function so deps can be loaded.

File size: 11.6 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
109enum roar_dl_loadercmd {
110 ROAR_DL_LOADER_NOOP = 0
111};
112
113struct roar_dl_librarypara {
114 int version;               // version of this struct type (must be ROAR_DL_LIBPARA_VERSION)
115 size_t len;                // Length of this struct type (must be sizeof(struct roar_dl_librarypara)
116
117 size_t refc;               // Reference counter.
118
119 size_t argc;               // number of elements in argv
120 struct roar_keyval * argv; // Parameter for the plugin
121 void * args_store;         // Storage area for argv's data.
122                            // If not NULL this and argv will be freed.
123                            // If NULL argv will be left untouched.
124
125 void * binargv;            // A pointer with binary data arguments.
126                            // This can be used to pass any non-string data to
127                            // the plugin. Normally this is NULL or the pointer
128                            // to a struct with members of whatever is needed.
129
130 const char * appname;      // application name in common format:
131                            // Product/Version <VendorID/VendorName> (comments)
132                            // Version and comment are optional and should be avoided.
133                            // When no vendor ID is registered use <VendorName>.
134                            // The VendorName MUST NOT contain a slash and SHOULD
135                            // be as unique as possible.
136                            // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>,
137                            //           AnAPP <Musterman GbR>
138 const char * abiversion;   // The ABI version. For libraries this should be the SONAME.
139                            // For applications this should be the version of the release
140                            // which introduced the current ABI.
141                            // Examples: libroar2, 0.5.1
142 struct roar_notify_core * notifycore;
143 int (*loader)(struct roar_dl_librarypara * lhandle, enum roar_dl_loadercmd cmd, void * argp);
144};
145
146struct roar_dl_libraryname {
147 int      version;
148 size_t   len;
149 const char * name;        //Format: shortname
150 const char * libname;     //This is the same as appname in struct roar_dl_librarypara.
151                           //Format: Product <VendorID/VendorName> (comments)
152 const char * libversion;  //This is the pure version number of the library.
153 const char * abiversion;  //This is the same as abiversion in struct roar_dl_librarypara.
154                           //Format: Version
155 const char * description; //Free form.
156 const char * contact;     //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room
157 const char * authors;     //Other authors as free form.
158 const char * license;     //Format: LicenseName-Version (options)
159                           //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later).
160};
161
162struct roar_dl_librarydep {
163 int      version;
164 size_t   len;
165 const char * name;
166 const char * libname;
167 const char * abiversion;
168};
169
170struct roar_dl_libraryinst {
171 int      version;
172 size_t   len;
173 int    (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
174 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
175 struct roar_dl_libraryname * libname;
176 size_t  global_data_len;
177 void *  global_data_init;
178 void ** global_data_pointer;
179 struct roar_dl_librarydep * libdep;
180 size_t libdep_len;
181 struct roar_dl_appsched * appsched;
182};
183
184struct roar_dl_appsched {
185 int (*init)  (struct roar_dl_librarypara * para);
186 int (*free)  (struct roar_dl_librarypara * para);
187 int (*update)(struct roar_dl_librarypara * para);
188};
189
190enum roar_dl_appsched_trigger {
191 ROAR_DL_APPSCHED_INIT = 1,
192#define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT
193 ROAR_DL_APPSCHED_FREE,
194#define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE
195 ROAR_DL_APPSCHED_UPDATE
196#define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE
197};
198
199// parameter functions:
200struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv,
201                                              const char * appname, const char * abiversion);
202int roar_dl_para_ref                    (struct roar_dl_librarypara * para);
203int roar_dl_para_unref                  (struct roar_dl_librarypara * para);
204int roar_dl_para_check_version          (struct roar_dl_librarypara * para,
205                                         const char * appname, const char * abiversion);
206
207// 'core' dynamic loader functions.
208struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags,
209                                         int ra_init, struct roar_dl_librarypara * para);
210int                      roar_dl_ref    (struct roar_dl_lhandle * lhandle);
211int                      roar_dl_unref  (struct roar_dl_lhandle * lhandle);
212#define roar_dl_close(x) roar_dl_unref((x))
213
214void                   * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type);
215
216int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle,
217                                         const char * prefix,
218                                         struct roar_dl_librarypara * para);
219
220const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle);
221
222// getting meta data:
223struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle);
224const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle);
225
226// context switching:
227// _restore() is to switch from main to library context. _store() is to store library context
228// and switch back to main context.
229int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle);
230int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle);
231
232// appsched:
233int                      roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger);
234
235#endif
236
237//ll
Note: See TracBrowser for help on using the repository browser.