iutil/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 00032 #include "csutil/scf.h" 00033 00034 00035 struct iComponent; 00036 00060 #define CS_QUERY_REGISTRY_PLUGIN(obj,object_reg,scf_id,interface) \ 00061 do { \ 00062 obj = CS_QUERY_REGISTRY(object_reg, interface); \ 00063 if (!obj.IsValid()) \ 00064 { \ 00065 csRef<iPluginManager> mgr = CS_QUERY_REGISTRY(object_reg,iPluginManager); \ 00066 if (!mgr.IsValid()) \ 00067 { \ 00068 csReport(object_reg, CS_REPORTER_SEVERITY_ERROR, \ 00069 "crystalspace.plugin.query", "Plugin manager missing from " \ 00070 "object-registry when attempting to query/load class: %s", scf_id); \ 00071 } \ 00072 obj = CS_LOAD_PLUGIN(mgr, scf_id, interface); \ 00073 if (!obj.IsValid()) \ 00074 { \ 00075 csReport(object_reg, CS_REPORTER_SEVERITY_WARNING, \ 00076 "crystalspace.plugin.query", "Failed to load class \"%s\" with " \ 00077 "interface \"" #interface "\"", scf_id); \ 00078 } \ 00079 if (!object_reg->Register(obj, #interface)) \ 00080 { \ 00081 csReport(object_reg, CS_REPORTER_SEVERITY_WARNING, \ 00082 "crystalspace.plugin.query", "Failed to register class \"%s\" with " \ 00083 "tag \"" #interface "\" in the object-registry.", scf_id); \ 00084 } \ 00085 } \ 00086 } while (0) 00087 00091 struct iPluginIterator : public virtual iBase 00092 { 00093 SCF_INTERFACE(iPluginIterator, 2,0,0); 00095 virtual bool HasNext () = 0; 00097 virtual iBase* Next () = 0; 00098 }; 00099 00111 struct iPluginManager : public virtual iBase 00112 { 00113 SCF_INTERFACE(iPluginManager, 2,0,0); 00119 virtual iBase *LoadPlugin (const char *classID, 00120 bool init = true) = 0; 00121 00129 virtual iBase *QueryPlugin (const char *iInterface, int iVersion) = 0; 00131 virtual iBase *QueryPlugin (const char* classID, 00132 const char *iInterface, int iVersion) = 0; 00134 virtual bool UnloadPlugin (iComponent *obj) = 0; 00136 virtual bool RegisterPlugin (const char *classID, iComponent *obj) = 0; 00137 00143 virtual csPtr<iPluginIterator> GetPlugins () = 0; 00145 virtual void Clear () = 0; 00146 00153 virtual void QueryOptions (iComponent* object) = 0; 00154 }; 00155 00156 00165 template<class Interface> 00166 inline csPtr<Interface> csQueryPluginClass (iPluginManager *mgr, 00167 const char* ClassID) 00168 { 00169 iBase* base = mgr->QueryPlugin (ClassID, 00170 scfInterfaceTraits<Interface>::GetName(), 00171 scfInterfaceTraits<Interface>::GetVersion()); 00172 00173 if (base == 0) return csPtr<Interface> (0); 00174 00175 Interface *x = (Interface*)base->QueryInterface ( 00176 scfInterfaceTraits<Interface>::GetID (), 00177 scfInterfaceTraits<Interface>::GetVersion ()); 00178 00179 base->DecRef (); //release our base interface 00180 00181 return csPtr<Interface> (x); 00182 } 00183 00188 #define CS_QUERY_PLUGIN_CLASS(Object,ClassID,Interface) \ 00189 csQueryPluginClass<Interface> (Object, ClassID) 00190 00197 template<class Interface> 00198 inline csPtr<Interface> csLoadPlugin (iPluginManager *mgr, 00199 const char* ClassID) 00200 { 00201 iBase* base = mgr->LoadPlugin (ClassID); 00202 00203 if (base == 0) return csPtr<Interface> (0); 00204 00205 Interface *x = (Interface*)base->QueryInterface ( 00206 scfInterfaceTraits<Interface>::GetID (), 00207 scfInterfaceTraits<Interface>::GetVersion ()); 00208 00209 base->DecRef (); //release our base interface 00210 00211 return csPtr<Interface> (x); 00212 } 00213 00218 #define CS_LOAD_PLUGIN(Object,ClassID,Interface) \ 00219 csLoadPlugin<Interface> (Object, ClassID) 00220 00225 inline csPtr<iBase> csLoadPluginAlways (iPluginManager *mgr, 00226 const char* ClassID) 00227 { 00228 iBase* base = mgr->LoadPlugin (ClassID); 00229 return csPtr<iBase> (base); 00230 } 00231 00236 #define CS_LOAD_PLUGIN_ALWAYS(Object,ClassID) \ 00237 csLoadPluginAlways (Object, ClassID) 00238 00241 #endif // __CS_IUTIL_PLUGIN_H__
Generated for Crystal Space by doxygen 1.4.6