source: roaraudio/roard/plugins.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 2.7 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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#define MAX_PLUGINS    8
29
30static struct _roard_plugin {
31 struct roar_dl_lhandle     * lhandle;
32 struct roard_plugins_sched * sched;
33} g_plugins[MAX_PLUGINS];
34static struct _roard_plugin * _pp = NULL;
35
36static struct _roard_plugin * _find_free(void) {
37 int i;
38
39 for (i = 0; i < MAX_PLUGINS; i++) {
40  if ( g_plugins[i].lhandle == NULL ) {
41   memset(&(g_plugins[i]), 0, sizeof(struct _roard_plugin));
42   return &(g_plugins[i]);
43  }
44 }
45
46 return NULL;
47}
48
49int plugins_preinit  (void) {
50 memset(g_plugins, 0, sizeof(g_plugins));
51
52 return 0;
53}
54
55int plugins_init  (void) {
56 int i;
57
58 for (i = 0; i < MAX_PLUGINS; i++) {
59  if ( g_plugins[i].lhandle != NULL ) {
60   _pp = &(g_plugins[i]);
61
62   roar_dl_ra_init(g_plugins[i].lhandle, NULL);
63
64   if ( g_plugins[i].sched->init != NULL )
65    g_plugins[i].sched->init();
66
67   _pp = NULL;
68  }
69 }
70
71 return 0;
72}
73
74int plugins_free  (void) {
75 int i;
76
77 for (i = 0; i < MAX_PLUGINS; i++) {
78  if ( g_plugins[i].lhandle != NULL ) {
79   if ( g_plugins[i].sched->free != NULL )
80    g_plugins[i].sched->free();
81
82   roar_dl_close(g_plugins[i].lhandle);
83  }
84 }
85
86 return plugins_preinit();
87}
88
89int plugins_update   (void) {
90 int ret = 0;
91 int i;
92
93 for (i = 0; i < MAX_PLUGINS; i++)
94  if ( g_plugins[i].lhandle != NULL )
95   if ( g_plugins[i].sched->update != NULL )
96    if ( g_plugins[i].sched->update() == -1 )
97     ret = -1;
98
99 return ret;
100}
101
102int plugins_load  (const char * filename) {
103 struct _roard_plugin * next = _find_free();
104
105 if ( next == NULL )
106  return -1;
107
108 next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */);
109 if ( next->lhandle == NULL ) {
110  ROAR_ERR("plugins_load(filename='%s'): can not load plugin: %s", filename, roar_dl_errstr(NULL));
111  return -1;
112 }
113
114 return 0;
115}
116
117int plugins_reg_sched(struct roard_plugins_sched * sched) {
118 if ( _pp == NULL )
119  return -1;
120
121 _pp->sched = sched;
122
123 return 0;
124}
125
126//ll
Note: See TracBrowser for help on using the repository browser.