CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

plugmgr.h

00001 /*
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/scopedmutexlock.h"
00024 #include "csutil/csvector.h"
00025 #include "csutil/parray.h"
00026 #include "iutil/config.h"
00027 #include "iutil/plugin.h"
00028 
00029 struct iComponent;
00030 struct iObjectRegistry;
00031 
00036 class csPluginManager : public iPluginManager
00037 {
00038 private:
00040   csRef<csMutex> mutex;
00041 
00045   class csPlugin
00046   {
00047   public:
00049     iComponent *Plugin;
00051     char *ClassID;
00052 
00054     csPlugin (iComponent *iObject, const char *iClassID);
00056     virtual ~csPlugin ();
00057   };
00058 
00062   class csPluginsVector : public csVector
00063   {
00064   public:
00066     csPluginsVector (int iLimit, int iDelta) : csVector (iLimit, iDelta) {}
00068     virtual ~csPluginsVector () { DeleteAll (); }
00070     virtual int CompareKey (void* Item, const void* Key, int /*Mode*/) const
00071     {
00072       return ((csPlugin *)Item)->Plugin == Key ? 0 : 1;
00073     }
00075     csPlugin *Get (int idx)
00076     { return (csPlugin *)csVector::Get (idx); }
00077 
00078     virtual bool FreeItem (void* Item)
00079     { delete (csPlugin*)Item; return true; }
00080   };
00081 
00085   class csPluginOption
00086   {
00087   public:
00088     char *Name;
00089     csVariantType Type;
00090     int ID;
00091     bool Value;                         // If Type is CSVAR_BOOL
00092     iConfig *Config;
00093 
00094     csPluginOption (const char *iName, csVariantType iType, int iID,
00095       bool iValue, iConfig* iConfig)
00096     {
00097       Name = csStrNew (iName);
00098       Type = iType;
00099       ID = iID;
00100       Value = iValue;
00101       (Config = iConfig)->IncRef ();
00102     }
00103     virtual ~csPluginOption ()
00104     {
00105       Config->DecRef ();
00106       delete [] Name;
00107     }
00108   };
00109 
00111   void QueryOptions (iComponent *iObject);
00112 
00114   iObjectRegistry* object_reg;
00115 
00117   csPluginsVector Plugins;
00118 
00119   // List of all options for all plug-in modules.
00120   csPDelArray<csPluginOption> OptionList;
00121 
00122 public:
00124   csPluginManager (iObjectRegistry* object_reg);
00126   virtual ~csPluginManager ();
00127 
00128   SCF_DECLARE_IBASE;
00129 
00131   virtual iBase *LoadPlugin (const char *iClassID,
00132         const char *iInterface = NULL, int iVersion = 0,
00133         bool init = true);
00134 
00138   virtual iBase *QueryPlugin (const char *iInterface, int iVersion);
00140   virtual iBase *QueryPlugin (const char* iClassID,
00141           const char *iInterface, int iVersion);
00143   virtual bool UnloadPlugin (iComponent *iObject);
00145   virtual bool RegisterPlugin (const char *iClassID,
00146           iComponent *iObject);
00148   virtual csPtr<iPluginIterator> GetPlugins ();
00150   virtual void Clear ();
00151 };
00152 
00153 #endif // __CS_PLUGMGR_H__
00154 

Generated for Crystal Space by doxygen 1.2.14