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 #if defined(CS_DEBUG) || defined(CS_MEMORY_TRACKER) 00034 struct iObjectRegistry; 00035 #endif 00036 template<class T> 00037 class csRef; 00038 struct iStringArray; 00039 00051 typedef unsigned long scfInterfaceID; 00052 00056 typedef int scfInterfaceVersion; 00057 00058 // -- Some helpers needed below 00072 #define SCF_INTERFACE(Name,Major,Minor,Micro) \ 00073 struct InterfaceTraits { \ 00074 CS_DEPRECATION_WARNINGS_DISABLE \ 00075 typedef Name InterfaceType; \ 00076 CS_DEPRECATION_WARNINGS_ENABLE \ 00077 CS_FORCEINLINE static scfInterfaceVersion GetVersion() \ 00078 { return SCF_CONSTRUCT_VERSION(Major, Minor, Micro); } \ 00079 CS_FORCEINLINE static char const * GetName() { return #Name; } \ 00080 } 00081 00082 00084 #define SCF_CONSTRUCT_VERSION(Major,Minor,Micro) \ 00085 ((Major << 24) | (Minor << 16) | Micro) 00086 00087 00094 static CS_FORCEINLINE bool scfCompatibleVersion ( 00095 scfInterfaceVersion iVersion, scfInterfaceVersion iItfVersion) 00096 { 00097 return (((iVersion & 0xff000000) == (iItfVersion & 0xff000000)) 00098 && ((iVersion & 0x00ffffff) <= (iItfVersion & 0x00ffffff))) 00099 || iVersion == 0; 00100 } 00101 00105 struct scfInterfaceMetadata 00106 { 00108 const char* interfaceName; 00109 00111 scfInterfaceID interfaceID; 00112 00114 scfInterfaceVersion interfaceVersion; 00115 }; 00116 00120 struct scfInterfaceMetadataList 00121 { 00123 scfInterfaceMetadata* metadata; 00124 00126 size_t metadataCount; 00127 }; 00128 00129 // -- The main two SCF interfaces, iBase and iSCF 00130 00136 struct iBase 00137 { 00138 protected: 00143 virtual ~iBase() {} 00144 public: 00145 SCF_INTERFACE(iBase, 1, 1, 0); 00151 virtual void IncRef () = 0; 00160 virtual void DecRef () = 0; 00167 virtual int GetRefCount () = 0; 00176 virtual void *QueryInterface (scfInterfaceID iInterfaceID, int iVersion) = 0; 00186 virtual void AddRefOwner (void** ref_owner, CS::Threading::Mutex* mutex) = 0; 00193 virtual void RemoveRefOwner (void** ref_owner) = 0; 00194 00195 typedef csRef<iBase> WeakReferencedKeepAlive; 00196 00202 virtual scfInterfaceMetadataList* GetInterfaceMetadata () = 0; 00203 }; 00204 00206 typedef iBase* (*scfFactoryFunc)(iBase*); 00207 00214 struct iSCF : public virtual iBase 00215 { 00216 SCF_INTERFACE(iSCF, 3,0,0); 00228 static CS_CRYSTALSPACE_EXPORT iSCF* SCF; 00229 00230 #if defined(CS_DEBUG) || defined(CS_MEMORY_TRACKER) 00231 // This is EXTREMELY dirty but I see no other solution for now. 00232 // For debugging reasons I must have a global (global over the application 00233 // and all plugins)pointer to the object registry. I have no other 00234 // global object to tag this pointer on that except for iSCF. 00235 // This pointer is only here in debug mode though. That ensures that it 00236 // cannot be misused in real code. 00237 // If you know another solution for this problem? This global pointer 00238 // will be used by csDebuggingGraph in csutil. 00239 iObjectRegistry* object_reg; 00240 #endif 00241 00245 virtual void RegisterClasses (iDocument* metadata, 00246 const char* context = 0) = 0; 00247 00253 virtual void RegisterClasses (char const* xml, 00254 const char* context = 0) = 0; 00255 00259 virtual void RegisterClasses (const char* pluginPath, 00260 iDocument* metadata, const char* context = 0) = 0; 00261 00268 virtual bool ClassRegistered (const char *iClassID) = 0; 00269 00281 virtual iBase *CreateInstance (const char *iClassID) = 0; 00282 00288 virtual const char *GetClassDescription (const char *iClassID) = 0; 00289 00295 virtual const char *GetClassDependencies (const char *iClassID) = 0; 00296 00323 virtual csRef<iDocument> GetPluginMetadata (char const *iClassID) = 0; 00324 00331 virtual void UnloadUnusedModules () = 0; 00332 00343 virtual bool RegisterClass (const char *iClassID, 00344 const char *iLibraryName, const char *iFactoryClass, 00345 const char *Description, const char *Dependencies = 0, 00346 const char* context = 0) = 0; 00347 00354 virtual bool RegisterClass (scfFactoryFunc, const char *iClassID, 00355 const char *Description, const char *Dependencies = 0, 00356 const char* context = 0) = 0; 00357 00365 virtual bool RegisterFactoryFunc (scfFactoryFunc, const char *FactClass) = 0; 00366 00373 virtual bool UnregisterClass (const char *iClassID) = 0; 00374 00379 virtual char const* GetInterfaceName (scfInterfaceID) const = 0; 00380 00386 virtual scfInterfaceID GetInterfaceID (const char *iInterface) = 0; 00387 00394 virtual void Finish () = 0; 00395 00406 virtual csRef<iStringArray> QueryClassList (char const* pattern) = 0; 00407 00411 virtual void ScanPluginsPath (const char* path, bool recursive = false, 00412 const char* context = 0) = 0; 00413 00423 virtual bool RegisterPlugin (const char* path) = 0; 00424 }; 00425 00426 00427 //-- Interface traits 00428 00438 template <typename Interface> 00439 class scfInterfaceTraits 00440 { 00441 public: 00442 typedef typename Interface::InterfaceTraits::InterfaceType 00443 InterfaceType; 00444 00448 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceVersion GetVersion () 00449 { 00450 return Interface::InterfaceTraits::GetVersion (); 00451 } 00452 00460 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceID GetID () 00461 { 00462 scfInterfaceID& ID = GetMyID (); 00463 if (ID == (scfInterfaceID)(-1)) 00464 { 00465 ID = iSCF::SCF->GetInterfaceID (GetName ()); 00466 csStaticVarCleanup (CleanupID); 00467 } 00468 return ID; 00469 } 00470 00474 CS_FORCEINLINE_TEMPLATEMETHOD static char const* GetName () 00475 { 00476 return Interface::InterfaceTraits::GetName (); 00477 } 00478 00479 private: 00480 // This idiom is a Meyers singleton 00481 CS_FORCEINLINE_TEMPLATEMETHOD static scfInterfaceID& GetMyID () 00482 { 00483 static scfInterfaceID ID = (scfInterfaceID)-1; 00484 return ID; 00485 } 00486 static void CleanupID () 00487 { 00488 GetMyID () = (scfInterfaceID)-1; 00489 } 00490 }; 00491 00505 #define SCF_VERSION(Name,Major,Minor,Micro) \ 00506 struct Name; \ 00507 template<> \ 00508 class scfInterfaceTraits<Name> \ 00509 { \ 00510 public: \ 00511 typedef Name InterfaceType; \ 00512 static scfInterfaceVersion GetVersion() \ 00513 { return SCF_CONSTRUCT_VERSION(Major, Minor, Micro); } \ 00514 static char const* GetName () \ 00515 { return #Name; } \ 00516 static scfInterfaceID GetID () \ 00517 { scfInterfaceID& ID = GetMyID (); \ 00518 if (ID == (scfInterfaceID)(-1)) \ 00519 { ID = iSCF::SCF->GetInterfaceID (GetName ()); \ 00520 csStaticVarCleanup (CleanupID); } \ 00521 return ID; \ 00522 } \ 00523 private: \ 00524 static scfInterfaceID& GetMyID () \ 00525 { static scfInterfaceID ID = (scfInterfaceID)-1; return ID; } \ 00526 static void CleanupID () \ 00527 { GetMyID () = (scfInterfaceID)-1; } \ 00528 } 00529 00532 #endif 00533
Generated for Crystal Space 2.1 by doxygen 1.6.1
