csutil/scf_interface.h
Go to the documentation of this file.00001 /* 00002 Crystal Space Shared Class Facility (SCF) 00003 This header contains the parts of SCF that is needed for defining 00004 new interfaces. 00005 00006 Copyright (C) 1999 by Andrew Zabolotny 00007 (C) 2005 by Marten Svanfeldt 00008 (C) 2005 by Michael Adams 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Library General Public 00012 License as published by the Free Software Foundation; either 00013 version 2 of the License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public 00021 License along with this library; if not, write to the Free 00022 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 */ 00024 00025 #ifndef __CSUTIL_SCF_INTERFACE_H__ 00026 #define __CSUTIL_SCF_INTERFACE_H__ 00027 00028 #include "csextern.h" 00029 00030 00031 // -- Forward declarations 00032 struct iDocument; 00033 struct iDocumentNode; 00034 #if defined(CS_DEBUG) || defined(CS_MEMORY_TRACKER) 00035 struct iObjectRegistry; 00036 #endif 00037 template<class T> 00038 class csRef; 00039 struct iStringArray; 00040 00052 typedef unsigned long scfInterfaceID; 00053 00057 typedef int scfInterfaceVersion; 00058 00059 // -- Some helpers needed below 00073 #define SCF_INTERFACE(Name,Major,Minor,Micro) \ 00074 struct InterfaceTraits { \ 00075 CS_DEPRECATION_WARNINGS_DISABLE \ 00076 typedef Name InterfaceType; \ 00077 CS_DEPRECATION_WARNINGS_ENABLE \ 00078 CS_FORCEINLINE static scfInterfaceVersion GetVersion() \ 00079 { return SCF_CONSTRUCT_VERSION(Major, Minor, Micro); } \ 00080 CS_FORCEINLINE static char const * GetName() { return #Name; } \ 00081 } 00082 00083 00085 #define SCF_CONSTRUCT_VERSION(Major,Minor,Micro) \ 00086 ((Major << 24) | (Minor << 16) | Micro) 00087 00088 00095 static CS_FORCEINLINE bool scfCompatibleVersion ( 00096 scfInterfaceVersion iVersion, scfInterfaceVersion iItfVersion) 00097 { 00098 return (((iVersion & 0xff000000) == (iItfVersion & 0xff000000)) 00099 && ((iVersion & 0x00ffffff) <= (iItfVersion & 0x00ffffff))) 00100 || iVersion == 0; 00101 } 00102 00106 struct scfInterfaceMetadata 00107 { 00109 const char* interfaceName; 00110 00112 scfInterfaceID interfaceID; 00113 00115 scfInterfaceVersion interfaceVersion; 00116 }; 00117 00121 struct scfInterfaceMetadataList 00122 { 00124 scfInterfaceMetadata* metadata; 00125 00127 size_t metadataCount; 00128 }; 00129 00130 // -- The main two SCF interfaces, iBase and iSCF 00131 00137 struct iBase 00138 { 00139 protected: 00144 virtual ~iBase() {} 00145 public: 00146 SCF_INTERFACE(iBase, 1, 1, 0); 00152 virtual void IncRef () = 0; 00161 virtual void DecRef () = 0; 00168 virtual int GetRefCount () = 0; 00177 virtual void *QueryInterface (scfInterfaceID iInterfaceID, int iVersion) = 0; 00187 virtual void AddRefOwner (void** ref_owner, CS::Threading::Mutex* mutex) = 0; 00194 virtual void RemoveRefOwner (void** ref_owner) = 0; 00195 00196 typedef csRef<iBase> WeakReferencedKeepAlive; 00197 00203 virtual scfInterfaceMetadataList* GetInterfaceMetadata () = 0; 00204 }; 00205 00207 typedef iBase* (*scfFactoryFunc)(iBase*); 00208 00215 struct iSCF : public virtual iBase 00216 { 00217 SCF_INTERFACE(iSCF, 4,0,0); 00229 static CS_CRYSTALSPACE_EXPORT iSCF* SCF; 00230 00231 #if defined(CS_DEBUG) || defined(CS_MEMORY_TRACKER) 00232 // This is EXTREMELY dirty but I see no other solution for now. 00233 // For debugging reasons I must have a global (global over the application 00234 // and all plugins)pointer to the object registry. I have no other 00235 // global object to tag this pointer on that except for iSCF. 00236 // This pointer is only here in debug mode though. That ensures that it 00237 // cannot be misused in real code. 00238 // If you know another solution for this problem? This global pointer 00239 // will be used by csDebuggingGraph in csutil. 00240 iObjectRegistry* object_reg; 00241 #endif 00242 00246 virtual void RegisterClasses (iDocument* metadata, 00247 const char* context = 0) = 0; 00248 00254 virtual void RegisterClasses (char const* xml, 00255 const char* context = 0) = 0; 00256 00260 virtual void RegisterClasses (const char* pluginPath, 00261 iDocument* metadata, const char* context = 0) = 0; 00262 00269 virtual bool ClassRegistered (const char *iClassID) = 0; 00270 00282 virtual iBase *CreateInstance (const char *iClassID) = 0; 00283 00289 virtual const char *GetClassDescription (const char *iClassID) = 0; 00290 00296 virtual const char *GetClassDependencies (const char *iClassID) = 0; 00297 00324 virtual csRef<iDocument> GetPluginMetadata (char const *iClassID) = 0; 00325 00331 virtual csRef<iDocumentNode> GetPluginMetadataNode (char const *iClassID) = 0; 00332 00339 virtual void UnloadUnusedModules () = 0; 00340 00351 virtual bool RegisterClass (const char *iClassID, 00352 const char *iLibraryName, const char *iFactoryClass, 00353 const char *Description, const char *Dependencies = 0, 00354 const char* context = 0) = 0; 00355 00362 virtual bool RegisterClass (scfFactoryFunc, const char *iClassID, 00363 const char *Description, const char *Dependencies = 0, 00364 const char* context = 0) = 0; 00365 00373 virtual bool RegisterFactoryFunc (scfFactoryFunc, const char *FactClass) = 0; 00374 00381 virtual bool UnregisterClass (const char *iClassID) = 0; 00382 00387 virtual char const* GetInterfaceName (scfInterfaceID) const = 0; 00388 00394 virtual scfInterfaceID GetInterfaceID (const char *iInterface) = 0; 00395 00402 virtual void Finish () = 0; 00403 00414 virtual csRef<iStringArray> QueryClassList (char const* pattern) = 0; 00415 00419 virtual void ScanPluginsPath (const char* path, bool recursive = false, 00420 const char* context = 0) = 0; 00421 00431 virtual bool RegisterPlugin (const char* path) = 0; 00432 }; 00433 00434 00435 //-- Interface traits 00436 00446 template <typename Interface> 00447 class scfInterfaceTraits 00448 { 00449 public: 00450 typedef typename Interface::InterfaceTraits::InterfaceType 00451 InterfaceType; 00452 00456 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceVersion GetVersion () 00457 { 00458 return Interface::InterfaceTraits::GetVersion (); 00459 } 00460 00468 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceID GetID () 00469 { 00470 scfInterfaceID& ID = GetMyID (); 00471 if (ID == (scfInterfaceID)(-1)) 00472 { 00473 ID = iSCF::SCF->GetInterfaceID (GetName ()); 00474 csStaticVarCleanup (CleanupID); 00475 } 00476 return ID; 00477 } 00478 00482 CS_FORCEINLINE_TEMPLATEMETHOD static char const* GetName () 00483 { 00484 return Interface::InterfaceTraits::GetName (); 00485 } 00486 00487 private: 00488 // This idiom is a Meyers singleton 00489 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceID& GetMyID () 00490 { 00491 static scfInterfaceID ID = (scfInterfaceID)-1; 00492 return ID; 00493 } 00494 static void CleanupID () 00495 { 00496 GetMyID () = (scfInterfaceID)-1; 00497 } 00498 }; 00499 00513 #define SCF_VERSION(Name,Major,Minor,Micro) \ 00514 struct Name; \ 00515 template<> \ 00516 class scfInterfaceTraits<Name> \ 00517 { \ 00518 public: \ 00519 typedef Name InterfaceType; \ 00520 static scfInterfaceVersion GetVersion() \ 00521 { return SCF_CONSTRUCT_VERSION(Major, Minor, Micro); } \ 00522 static char const* GetName () \ 00523 { return #Name; } \ 00524 static scfInterfaceID GetID () \ 00525 { scfInterfaceID& ID = GetMyID (); \ 00526 if (ID == (scfInterfaceID)(-1)) \ 00527 { ID = iSCF::SCF->GetInterfaceID (GetName ()); \ 00528 csStaticVarCleanup (CleanupID); } \ 00529 return ID; \ 00530 } \ 00531 private: \ 00532 static scfInterfaceID& GetMyID () \ 00533 { static scfInterfaceID ID = (scfInterfaceID)-1; return ID; } \ 00534 static void CleanupID () \ 00535 { GetMyID () = (scfInterfaceID)-1; } \ 00536 } 00537 00540 #endif 00541
Generated for Crystal Space 2.1 by doxygen 1.6.1
