source: roaraudio/roard/plugins.c @ 3362:2bf10ee217b5

Last change on this file since 3362:2bf10ee217b5 was 3362:2bf10ee217b5, checked in by phi, 14 years ago

support plugin sched events

File size: 2.6 KB
Line 
1//plugins.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of roard 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 *  RoarAudio 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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#define MAX_PLUGINS    8
28
29static struct _roard_plugin {
30 struct roar_dl_lhandle     * lhandle;
31 struct roard_plugins_sched * sched;
32} g_plugins[MAX_PLUGINS];
33static struct _roard_plugin * _pp = NULL;
34
35static struct _roard_plugin * _find_free(void) {
36 int i;
37
38 for (i = 0; i < MAX_PLUGINS; i++) {
39  if ( g_plugins[i].lhandle == NULL ) {
40   memset(&(g_plugins[i]), 0, sizeof(struct _roard_plugin));
41   return &(g_plugins[i]);
42  }
43 }
44
45 return NULL;
46}
47
48int plugins_preinit  (void) {
49 memset(g_plugins, 0, sizeof(g_plugins));
50
51 return 0;
52}
53
54int plugins_init  (void) {
55 int i;
56
57 for (i = 0; i < MAX_PLUGINS; i++) {
58  if ( g_plugins[i].lhandle != NULL ) {
59   _pp = &(g_plugins[i]);
60
61   roar_dl_ra_init(g_plugins[i].lhandle, NULL);
62
63   if ( g_plugins[i].sched->init != NULL )
64    g_plugins[i].sched->init();
65
66   _pp = NULL;
67  }
68 }
69
70 return 0;
71}
72
73int plugins_free  (void) {
74 int i;
75
76 for (i = 0; i < MAX_PLUGINS; i++) {
77  if ( g_plugins[i].lhandle != NULL ) {
78   if ( g_plugins[i].sched->free != NULL )
79    g_plugins[i].sched->free();
80
81   roar_dl_close(g_plugins[i].lhandle);
82  }
83 }
84
85 return plugins_preinit();
86}
87
88int plugins_update   (void) {
89 int ret = 0;
90 int i;
91
92 for (i = 0; i < MAX_PLUGINS; i++)
93  if ( g_plugins[i].lhandle != NULL )
94   if ( g_plugins[i].sched->update != NULL )
95    if ( g_plugins[i].sched->update() == -1 )
96     ret = -1;
97
98 return ret;
99}
100
101int plugins_load  (const char * filename) {
102 struct _roard_plugin * next = _find_free();
103
104 if ( next == NULL )
105  return -1;
106
107 next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */);
108 if ( next->lhandle == NULL )
109  return -1;
110
111 return 0;
112}
113
114int plugins_reg_sched(struct roard_plugins_sched * sched) {
115 if ( _pp == NULL )
116  return -1;
117
118 _pp->sched = sched;
119
120 return 0;
121}
122
123//ll
Note: See TracBrowser for help on using the repository browser.