source: roaraudio/libroar/plugincontainer.c @ 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: 4.5 KB
Line 
1//plugincontainer.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 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#include "libroar.h"
37
38#define MAX_PLUGINS 64
39
40struct roar_plugincontainer {
41 size_t refc;
42 struct roar_dl_librarypara * default_para;
43 struct roar_dl_lhandle * handle[MAX_PLUGINS];
44 // TODO: add a depref counter so we do not unload libs we depend on.
45};
46
47static struct roar_plugincontainer * _new_init(void) {
48 struct roar_plugincontainer * ret = roar_mm_malloc(sizeof(struct roar_plugincontainer));
49 if ( ret == NULL )
50  return NULL;
51
52 memset(ret, 0, sizeof(struct roar_plugincontainer));
53
54 ret->refc = 1;
55
56 return ret;
57}
58
59struct roar_plugincontainer * roar_plugincontainer_new(struct roar_dl_librarypara * default_para) {
60 struct roar_plugincontainer * ret = _new_init();
61 int err;
62
63 if ( ret == NULL )
64  return NULL;
65
66 if ( default_para != NULL ) {
67  if ( roar_dl_para_ref(default_para) == -1 ) {
68   err = roar_error;
69   roar_plugincontainer_unref(ret);
70   roar_err_set(err);
71   return NULL;
72  }
73  ret->default_para = default_para;
74 }
75
76 return ret;
77}
78
79struct roar_plugincontainer * roar_plugincontainer_new_simple(const char * appname, const char * abiversion) {
80 struct roar_plugincontainer * ret;
81 struct roar_dl_librarypara * para = roar_dl_para_new(NULL, NULL, appname, abiversion);
82 int err;
83
84 ret = roar_plugincontainer_new(para);
85 err = roar_error;
86
87 roar_dl_para_unref(para);
88
89 roar_err_set(err);
90 return ret;
91}
92
93int roar_plugincontainer_ref(struct roar_plugincontainer * cont) {
94 if ( cont == NULL ) {
95  roar_err_set(ROAR_ERROR_FAULT);
96  return -1;
97 }
98
99 cont->refc++;
100
101 return 0;
102}
103
104int roar_plugincontainer_unref(struct roar_plugincontainer * cont) {
105 size_t i;
106
107 if ( cont == NULL ) {
108  roar_err_set(ROAR_ERROR_FAULT);
109  return -1;
110 }
111
112 cont->refc--;
113
114 if ( cont->refc )
115  return 0;
116
117 for (i = 0; i < MAX_PLUGINS; i++) {
118  if ( cont->handle[i] == NULL )
119   continue;
120
121  roar_dl_close(cont->handle[i]);
122 }
123
124 if ( cont->default_para != NULL )
125  roar_dl_para_unref(cont->default_para);
126
127 roar_mm_free(cont);
128
129 return 0;
130}
131
132// plugin loading and unloading:
133int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para);
134int roar_plugincontainer_unload(struct roar_plugincontainer * cont, const char * name) {
135 // get b name, then call roar_plugincontainer_unload_lhandle().
136 roar_err_set(ROAR_ERROR_NOSYS);
137 return -1;
138}
139
140int roar_plugincontainer_unload_lhandle(struct roar_plugincontainer * cont, struct roar_dl_lhandle * lhandle) {
141 size_t i;
142
143 if ( cont == NULL ) {
144  roar_err_set(ROAR_ERROR_FAULT);
145  return -1;
146 }
147
148 if ( lhandle == NULL ) {
149  roar_err_set(ROAR_ERROR_INVAL);
150  return -1;
151 }
152
153 for (i = 0; i < MAX_PLUGINS; i++) {
154  if ( cont->handle[i] == lhandle ) {
155   roar_dl_close(cont->handle[i]);
156   cont->handle[i] = NULL;
157   return 0;
158  }
159 }
160
161 roar_err_set(ROAR_ERROR_NOENT);
162 return -1;
163}
164
165// appsched:
166int roar_plugincontainer_appsched_trigger(struct roar_plugincontainer * cont, enum roar_dl_appsched_trigger trigger) {
167 size_t i;
168
169 if ( cont == NULL ) {
170  roar_err_set(ROAR_ERROR_FAULT);
171  return -1;
172 }
173
174 for (i = 0; i < MAX_PLUGINS; i++) {
175  if ( cont->handle[i] == NULL )
176   continue;
177
178  roar_dl_appsched_trigger(cont->handle[i], trigger);
179 }
180
181 return 0;
182}
183
184//ll
Note: See TracBrowser for help on using the repository browser.