[3353] | 1 | //plugins.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011 |
---|
[3353] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[3353] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
[3355] | 28 | #define MAX_PLUGINS 8 |
---|
| 29 | |
---|
[3362] | 30 | static struct _roard_plugin { |
---|
| 31 | struct roar_dl_lhandle * lhandle; |
---|
| 32 | struct roard_plugins_sched * sched; |
---|
| 33 | } g_plugins[MAX_PLUGINS]; |
---|
| 34 | static struct _roard_plugin * _pp = NULL; |
---|
[3355] | 35 | |
---|
[3362] | 36 | static struct _roard_plugin * _find_free(void) { |
---|
[3355] | 37 | int i; |
---|
| 38 | |
---|
| 39 | for (i = 0; i < MAX_PLUGINS; i++) { |
---|
[3362] | 40 | if ( g_plugins[i].lhandle == NULL ) { |
---|
| 41 | memset(&(g_plugins[i]), 0, sizeof(struct _roard_plugin)); |
---|
[3355] | 42 | return &(g_plugins[i]); |
---|
[3362] | 43 | } |
---|
[3355] | 44 | } |
---|
| 45 | |
---|
| 46 | return NULL; |
---|
| 47 | } |
---|
| 48 | |
---|
[3354] | 49 | int plugins_preinit (void) { |
---|
[3355] | 50 | memset(g_plugins, 0, sizeof(g_plugins)); |
---|
| 51 | |
---|
[3354] | 52 | return 0; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | int plugins_init (void) { |
---|
[3355] | 56 | int i; |
---|
| 57 | |
---|
| 58 | for (i = 0; i < MAX_PLUGINS; i++) { |
---|
[3362] | 59 | if ( g_plugins[i].lhandle != NULL ) { |
---|
| 60 | _pp = &(g_plugins[i]); |
---|
| 61 | |
---|
[4682] | 62 | _pp->sched = NULL; |
---|
| 63 | |
---|
[3362] | 64 | roar_dl_ra_init(g_plugins[i].lhandle, NULL); |
---|
| 65 | |
---|
[4682] | 66 | if ( g_plugins[i].sched != NULL ) |
---|
| 67 | if ( g_plugins[i].sched->init != NULL ) |
---|
| 68 | g_plugins[i].sched->init(); |
---|
[3362] | 69 | |
---|
| 70 | _pp = NULL; |
---|
[3355] | 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
[3354] | 74 | return 0; |
---|
| 75 | } |
---|
[3353] | 76 | |
---|
[3354] | 77 | int plugins_free (void) { |
---|
[3355] | 78 | int i; |
---|
| 79 | |
---|
| 80 | for (i = 0; i < MAX_PLUGINS; i++) { |
---|
[3362] | 81 | if ( g_plugins[i].lhandle != NULL ) { |
---|
[4682] | 82 | if ( g_plugins[i].sched != NULL ) |
---|
| 83 | if ( g_plugins[i].sched->free != NULL ) |
---|
| 84 | g_plugins[i].sched->free(); |
---|
[3362] | 85 | |
---|
| 86 | roar_dl_close(g_plugins[i].lhandle); |
---|
[3355] | 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
[3357] | 90 | return plugins_preinit(); |
---|
[3354] | 91 | } |
---|
| 92 | |
---|
[3362] | 93 | int plugins_update (void) { |
---|
| 94 | int ret = 0; |
---|
| 95 | int i; |
---|
| 96 | |
---|
| 97 | for (i = 0; i < MAX_PLUGINS; i++) |
---|
| 98 | if ( g_plugins[i].lhandle != NULL ) |
---|
[4682] | 99 | if ( g_plugins[i].sched != NULL ) |
---|
| 100 | if ( g_plugins[i].sched->update != NULL ) |
---|
| 101 | if ( g_plugins[i].sched->update() == -1 ) |
---|
| 102 | ret = -1; |
---|
[3362] | 103 | |
---|
| 104 | return ret; |
---|
| 105 | } |
---|
| 106 | |
---|
[3354] | 107 | int plugins_load (const char * filename) { |
---|
[3362] | 108 | struct _roard_plugin * next = _find_free(); |
---|
[3355] | 109 | |
---|
| 110 | if ( next == NULL ) |
---|
| 111 | return -1; |
---|
| 112 | |
---|
[3362] | 113 | next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */); |
---|
[3365] | 114 | if ( next->lhandle == NULL ) { |
---|
| 115 | ROAR_ERR("plugins_load(filename='%s'): can not load plugin: %s", filename, roar_dl_errstr(NULL)); |
---|
[3355] | 116 | return -1; |
---|
[3365] | 117 | } |
---|
[3355] | 118 | |
---|
| 119 | return 0; |
---|
[3354] | 120 | } |
---|
[3353] | 121 | |
---|
[3362] | 122 | int plugins_reg_sched(struct roard_plugins_sched * sched) { |
---|
| 123 | if ( _pp == NULL ) |
---|
| 124 | return -1; |
---|
| 125 | |
---|
| 126 | _pp->sched = sched; |
---|
| 127 | |
---|
| 128 | return 0; |
---|
| 129 | } |
---|
| 130 | |
---|
[4680] | 131 | int plugins_reg_proto(struct roard_proto * proto) { |
---|
| 132 | if ( _pp == NULL ) |
---|
| 133 | return -1; |
---|
| 134 | |
---|
| 135 | return clients_register_proto(proto); |
---|
| 136 | } |
---|
| 137 | |
---|
[3353] | 138 | //ll |
---|