Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
plugin.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2001 by Jorrit Tyberghein 00003 Copyright (C) 1999 by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_IUTIL_PLUGIN_H__ 00021 #define __CS_IUTIL_PLUGIN_H__ 00022 00031 #include "csutil/scf.h" 00032 00033 00034 struct iComponent; 00035 00059 #define CS_QUERY_REGISTRY_PLUGIN(obj,object_reg,scf_id,interface) \ 00060 do { \ 00061 obj = CS_QUERY_REGISTRY(object_reg, interface); \ 00062 if (!obj.IsValid()) \ 00063 { \ 00064 csRef<iPluginManager> mgr = CS_QUERY_REGISTRY(object_reg,iPluginManager); \ 00065 if (!mgr.IsValid()) \ 00066 { \ 00067 csReport(object_reg, CS_REPORTER_SEVERITY_ERROR, \ 00068 "crystalspace.plugin.query", "Plugin manager missing from " \ 00069 "object-registry when attempting to query/load class: %s", scf_id); \ 00070 } \ 00071 obj = CS_LOAD_PLUGIN(mgr, scf_id, interface); \ 00072 if (!obj.IsValid()) \ 00073 { \ 00074 csReport(object_reg, CS_REPORTER_SEVERITY_WARNING, \ 00075 "crystalspace.plugin.query", "Failed to load class \"%s\" with " \ 00076 "interface \"" #interface "\"", scf_id); \ 00077 } \ 00078 if (!object_reg->Register(obj, #interface)) \ 00079 { \ 00080 csReport(object_reg, CS_REPORTER_SEVERITY_WARNING, \ 00081 "crystalspace.plugin.query", "Failed to register class \"%s\" with " \ 00082 "tag \"" #interface "\" in the object-registry.", scf_id); \ 00083 } \ 00084 } \ 00085 } while (0) 00086 00087 SCF_VERSION (iPluginIterator, 0, 0, 1); 00088 00092 struct iPluginIterator : public iBase 00093 { 00095 virtual bool HasNext () = 0; 00097 virtual iBase* Next () = 0; 00098 }; 00099 00100 SCF_VERSION (iPluginManager, 0, 2, 0); 00101 00116 struct iPluginManager : public iBase 00117 { 00123 virtual iBase *LoadPlugin (const char *classID, 00124 bool init = true) = 0; 00125 00133 virtual iBase *QueryPlugin (const char *iInterface, int iVersion) = 0; 00135 virtual iBase *QueryPlugin (const char* classID, 00136 const char *iInterface, int iVersion) = 0; 00138 virtual bool UnloadPlugin (iComponent *obj) = 0; 00140 virtual bool RegisterPlugin (const char *classID, iComponent *obj) = 0; 00141 00147 virtual csPtr<iPluginIterator> GetPlugins () = 0; 00149 virtual void Clear () = 0; 00150 00157 virtual void QueryOptions (iComponent* object) = 0; 00158 }; 00159 00160 00169 template<class Interface> 00170 inline csPtr<Interface> csQueryPluginClass (iPluginManager *mgr, 00171 const char* ClassID) 00172 { 00173 iBase* base = mgr->QueryPlugin (ClassID, 00174 scfInterfaceTraits<Interface>::GetName(), 00175 scfInterfaceTraits<Interface>::GetVersion()); 00176 00177 if (base == 0) return csPtr<Interface> (0); 00178 00179 Interface *x = (Interface*)base->QueryInterface ( 00180 scfInterfaceTraits<Interface>::GetID (), 00181 scfInterfaceTraits<Interface>::GetVersion ()); 00182 00183 if (x) base->DecRef (); //release our base interface 00184 00185 return csPtr<Interface> (x); 00186 } 00187 00192 #define CS_QUERY_PLUGIN_CLASS(Object,ClassID,Interface) \ 00193 csQueryPluginClass<Interface> (Object, ClassID) 00194 00201 template<class Interface> 00202 inline csPtr<Interface> csLoadPlugin (iPluginManager *mgr, 00203 const char* ClassID) 00204 { 00205 iBase* base = mgr->LoadPlugin (ClassID); 00206 00207 if (base == 0) return csPtr<Interface> (0); 00208 00209 Interface *x = (Interface*)base->QueryInterface ( 00210 scfInterfaceTraits<Interface>::GetID (), 00211 scfInterfaceTraits<Interface>::GetVersion ()); 00212 00213 if (x) base->DecRef (); //release our base interface 00214 00215 return csPtr<Interface> (x); 00216 } 00217 00222 #define CS_LOAD_PLUGIN(Object,ClassID,Interface) \ 00223 csLoadPlugin<Interface> (Object, ClassID) 00224 00229 inline csPtr<iBase> csLoadPluginAlways (iPluginManager *mgr, 00230 const char* ClassID) 00231 { 00232 iBase* base = mgr->LoadPlugin (ClassID); 00233 return csPtr<iBase> (base); 00234 } 00235 00240 #define CS_LOAD_PLUGIN_ALWAYS(Object,ClassID) \ 00241 csLoadPluginAlways (Object, ClassID) 00242 00245 #endif // __CS_IUTIL_PLUGIN_H__
Generated for Crystal Space by doxygen 1.4.4