1 /* 2 MPEG Maaate: An Australian MPEG audio analysis toolkit 3 Copyright (C) 2000 Commonwealth Scientific and Industrial Research Organisation 4 (CSIRO), Australia. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 22 #ifndef PLUGINS_H 23 #define PLUGINS_H 24 25 // for checking files 26 #include <sys/types.h> 27 #include <sys/stat.h> 28 29 #include "module.H" 30 #include "tier2Platform.h" 31 32 #if (defined (WIN32) || (_WIN32)) 33 #include "dirent.h" 34 #endif 35 36 37 #ifdef __cplusplus 38 39 #include <string> 40 #include <list> 41 42 using namespace std; 43 44 45 //-------------------------------------------------------------------------- 46 47 #define MAAATE_PLUGIN_API_MAJOR 1 48 #define MAAATE_PLUGIN_API_MINOR 0 49 #define MAAATE_PLUGIN_API_REVISION 0 50 51 // class to open one plugin library (just a support class for plugin class) 52 class CSAPI_TIER2 PluginLibrary { 53 public: 54 // open a library with dlopen and call its initialisation function, thus 55 // loading and creating the list of contained modules 56 PluginLibrary(string filename); 57 58 // close a library with dlclose 59 ~PluginLibrary(); 60 61 // Get the name of the library filename()62 string filename () { return name; } 63 64 // Get the list of modules accessible from this library this is kept 65 // for information on the library's content. The Plugins class then 66 // contains a list of all the activated modules for an application. Modules()67 list<Module> * Modules () { return &modList; } 68 69 private: 70 // keep name for Plugins class 71 string name; 72 73 // keep handle to opened library for destructor 74 #if (defined (WIN32) || (_WIN32)) 75 HINSTANCE hLib; 76 #else 77 void * plib; 78 #endif 79 80 // contains all modules accessible from this library, 81 // created with initialisation function 82 list<Module> modList; 83 84 }; 85 86 87 // class to load all plugin libraries and 88 // administrate a list of the modules contained therein 89 class CSAPI_TIER2 Plugins { 90 public: 91 // default constructor Plugins()92 Plugins() { modList.clear(); }; 93 94 // Load every module that Maaate is aware of. 95 void AddLibrariesMaaatePath (); 96 97 // add statically linked modules to the module list 98 void AddStaticModules(); 99 100 // functions to open libraries, thus creating PluginLibrary instances, 101 // and appending to the class' module list 102 // 103 // - all modules contained in one library 104 bool AddLibrary(string filename); 105 // - all modules contained in all libraries in a directory 106 void AddLibraries(string dirname); 107 // - all modules contained in all libraries of all directories specified in a 108 // colon-separated path list 109 void AddLibrariesPath(string pathlist); 110 // - a module of a library (only if removed before) 111 void AddModule(Module * module); 112 113 // destructs a PluginLibrary and unloads all its modules 114 void RemoveLibrary (string name); 115 // removes one module from the module list 116 // and adds it to the removed list 117 void RemoveModule (Module * module); 118 119 // return a list of available modules for an application Modules()120 list<Module> * Modules () { return &modList; } 121 122 // get a specific module of a given name 123 Module * GetModule (string name); 124 125 // return a list of available modules for a library 126 list<Module> * LibraryModules(string name); 127 128 private: 129 // all available modules from all libraries 130 list<Module> modList; 131 132 list<Module> removedList; 133 134 }; 135 136 extern "C" { 137 #else /* __cplusplus */ 138 typedef struct Plugins Plugins; 139 #endif 140 141 CSAPI_TIER2 Plugins * maaateA_new_plugins(); 142 143 CSAPI_TIER2 void maaateA_delete_plugins(Plugins * plugin); 144 145 CSAPI_TIER2 void maaateA_add_libraries_maaate_path (Plugins * plugin); 146 147 CSAPI_TIER2 void maaateA_add_static_modules(Plugins * plugin); 148 149 CSAPI_TIER2 int maaateA_add_library(Plugins * plugin, char * filename); 150 151 CSAPI_TIER2 void maaateA_add_libraries(Plugins * plugin, char * dirname); 152 153 CSAPI_TIER2 void maaateA_add_libraries_path(Plugins * plugin, char * pathlist); 154 155 CSAPI_TIER2 void maaateA_add_module(Plugins * plugin, Module * module); 156 157 CSAPI_TIER2 void maaateA_remove_library(Plugins * plugin, char * name); 158 159 CSAPI_TIER2 void maaateA_remove_module(Plugins * plugin, Module * module); 160 161 CSAPI_TIER2 ModuleList * maaateA_modules(Plugins * plugin); 162 163 CSAPI_TIER2 Module * maaateA_get_module(Plugins * plugin, char * name); 164 165 CSAPI_TIER2 ModuleList * maaateA_library_modules(Plugins * plugin, char * name); 166 167 #ifdef __cplusplus 168 } 169 #endif /* __cplusplus */ 170 171 #endif 172