|
plugmgr.h00001 /* 00002 Copyright (C) 1998-2001 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_PLUGMGR_H__ 00020 #define __CS_PLUGMGR_H__ 00021 00022 #include "csutil/scf.h" 00023 #include "csutil/csvector.h" 00024 #include "csutil/typedvec.h" 00025 #include "iutil/config.h" 00026 #include "iutil/plugin.h" 00027 00028 struct iComponent; 00029 struct iObjectRegistry; 00030 00034 class csPluginManager : public iPluginManager 00035 { 00036 private: 00037 /* 00038 * This is a private structure used to keep the list of plugins. 00039 */ 00040 class csPlugin 00041 { 00042 public: 00043 // The plugin itself 00044 iComponent *Plugin; 00045 // The class ID of the plugin 00046 char *ClassID; 00047 00048 // Construct the object that represents a plugin 00049 csPlugin (iComponent *iObject, const char *iClassID); 00050 // Free storage 00051 virtual ~csPlugin (); 00052 }; 00053 00054 /* 00055 * This is a superset of csVector that can find by pointer a plugin. 00056 */ 00057 class csPluginsVector : public csVector 00058 { 00059 public: 00060 // Create the vector 00061 csPluginsVector (int iLimit, int iDelta) : csVector (iLimit, iDelta) {} 00062 // Destroy the vector. 00063 virtual ~csPluginsVector () { DeleteAll (); } 00064 // Find a plugin by its address 00065 virtual int CompareKey (csSome Item, csConstSome Key, int /*Mode*/) const 00066 { 00067 return ((csPlugin *)Item)->Plugin == Key ? 0 : 1; 00068 } 00069 // Overrided Get() to avoid typecasts 00070 csPlugin *Get (int idx) 00071 { return (csPlugin *)csVector::Get (idx); } 00072 00073 virtual bool FreeItem (csSome Item) 00074 { delete (csPlugin*)Item; return true; } 00075 }; 00076 00077 /* 00078 * Class to collect all options for all plug-in modules in the system. 00079 */ 00080 class csPluginOption 00081 { 00082 public: 00083 char *Name; 00084 csVariantType Type; 00085 int ID; 00086 bool Value; // If Type is CSVAR_BOOL 00087 iConfig *Config; 00088 00089 csPluginOption (const char *iName, csVariantType iType, int iID, 00090 bool iValue, iConfig* iConfig) 00091 { 00092 Name = csStrNew (iName); 00093 Type = iType; 00094 ID = iID; 00095 Value = iValue; 00096 (Config = iConfig)->IncRef (); 00097 } 00098 virtual ~csPluginOption () 00099 { 00100 Config->DecRef (); 00101 delete [] Name; 00102 } 00103 }; 00104 00105 // Query all options supported by given plugin and place into OptionList 00106 void QueryOptions (iComponent *iObject); 00107 00108 // The object registry. 00109 iObjectRegistry* object_reg; 00110 00112 csPluginsVector Plugins; 00113 00115 CS_DECLARE_TYPED_VECTOR (csOptionVector, csPluginOption) OptionList; 00116 00117 public: 00119 csPluginManager (iObjectRegistry* object_reg); 00121 virtual ~csPluginManager (); 00122 00123 SCF_DECLARE_IBASE; 00124 00125 virtual iBase *LoadPlugin (const char *iClassID, 00126 const char *iInterface = NULL, int iVersion = 0); 00127 virtual iBase *QueryPlugin (const char *iInterface, int iVersion); 00128 virtual iBase *QueryPlugin (const char* iClassID, 00129 const char *iInterface, int iVersion); 00130 virtual bool UnloadPlugin (iComponent *iObject); 00131 virtual bool RegisterPlugin (const char *iClassID, 00132 iComponent *iObject); 00133 virtual int GetPluginCount (); 00134 virtual iBase* GetPlugin (int idx); 00135 virtual void Clear (); 00136 }; 00137 00138 #endif // __CS_PLUGMGR_H__ 00139 Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |