Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28270/src/classes
Modified Files:
MModule.cpp
Log Message:
1. show all modules in modules dialog and allow the user to prevent them
from being loaded instead of asking him to select those which he wants
to be loaded
2. removed support for .mmd files from MModule, nobody used it for ages
anyhow
3. MModule::GetProvider() now looks among all modules, not just loaded ones
Index: MModule.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MModule.cpp,v
retrieving revision 1.87
retrieving revision 1.88
diff -b -u -2 -r1.87 -r1.88
--- MModule.cpp 12 Jan 2004 17:48:29 -0000 1.87
+++ MModule.cpp 11 Jul 2004 00:07:17 -0000 1.88
@@ -47,4 +47,10 @@
// ----------------------------------------------------------------------------
+// options we use here
+// ----------------------------------------------------------------------------
+
+extern const MOption MP_MODULES_DONT_LOAD;
+
+// ----------------------------------------------------------------------------
// function prototypes
// ----------------------------------------------------------------------------
@@ -63,6 +69,4 @@
#define DLL_EXTENSION wxDynamicLibrary::GetDllExt()
-#define MMD_SIGNATURE "Mahogany-Module-Definition"
-
// the trace mask used by module loading code
#define M_TRACE_MODULES _T("mmodule")
@@ -354,33 +358,23 @@
MModule::GetProvider(const wxString &interfaceName)
{
- MModuleList::iterator i;
- for(i = GetMModuleList()->begin();
- i != GetMModuleList()->end();
- i++)
- {
- MModuleListEntry *me = *i;
- if( me->m_Interface == interfaceName )
+ RefCounter<MModuleListing> listing(ListAvailableModules(interfaceName));
+ if ( !listing )
{
-#if 0 // creating them on the fly is wrong!
-#ifdef USE_MODULES_STATIC
- if( !me->m_Module )
- {
- // create the module on the fly
- int errorCode;
- me->m_Module = (*(me->m_InitFunc))(
- M_VERSION_MAJOR, M_VERSION_MINOR, M_VERSION_RELEASE,
- &gs_MInterface, &errorCode);
+ wxLogWarning(_("No modules implementing \"%s\" interface found."),
+ interfaceName.c_str());
+ return NULL;
}
-#endif
-#endif
- if ( me->m_Module )
+
+ if ( listing->Count() > 1 )
{
- me->m_Module->IncRef();
- return me->m_Module;
- }
- }
+ wxLogWarning(_("Several modules implement \"%s\" interface, you "
+ "should probably disable all but one of them using the "
+ "\"Edit|Modules...\" menu command."),
+ interfaceName.c_str());
+
+ // still return something
}
- return NULL; // not found
+ return LoadModule((*listing)[0].GetName());
}
@@ -495,9 +489,18 @@
// this function can list all loaded modules (default) or do other things as
// well depending on the parameters values, so the name is a bit unfortunate
-static MModuleListing * DoListLoadedModules(bool listall = false,
- const String& interfaceName = _T(""),
- bool loadableOnly = false)
+static MModuleListing *
+DoListLoadedModules(bool listall = false, const String& interfaceName = _T(""))
{
-#ifndef USE_MODULES_STATIC
+#ifdef USE_MODULES_STATIC
+ wxArrayString modulesNot;
+
+ // only exclude modules to ignore if we're looking for modules implementing
+ // some interface, not if we want (really) all modules
+ if ( listall && !interfaceName.empty() )
+ {
+ const String modulesDontLoad = READ_APPCONFIG(MP_MODULES_DONT_LOAD);
+ modulesNot = strutil_restore_array(modulesDontLoad);
+ }
+#else
// this function only works for loaded modules in dynamic case
ASSERT_MSG( !listall, _T("this mode is not supported with dynamic modules") );
@@ -520,13 +523,13 @@
(interfaceName.empty() || me->m_Interface == interfaceName) )
{
- // check that the module is "loadable" if requested
- String desc = me->m_Description;
- if ( !loadableOnly || !desc.empty() )
+ // also ignore the modules excluded by user
+ if ( !listall || modulesNot.Index(me->m_Name) == wxNOT_FOUND )
{
- MModuleListingEntryImpl entry
+ MModuleListingEntryImpl
+ entry
(
me->m_Name, // module name
me->m_Interface,
- desc,
+ me->m_Description,
_T(""), // long description
String(me->m_Version) + _(" (builtin)"),
@@ -549,13 +552,9 @@
}
- // check that the module is "loadable" if requested
- String desc = m->GetDescription();
- if ( !loadableOnly || !desc.empty() )
- {
MModuleListingEntryImpl entry
(
m->GetName(), // module name
m->GetInterface(),
- desc,
+ m->GetDescription(),
_T(""), // long description
m->GetVersion(),
@@ -565,5 +564,4 @@
(*listing)[count++] = entry;
}
- }
#endif // USE_MODULES_STATIC/!USE_MODULES_STATIC
@@ -583,15 +581,8 @@
/* static */
MModuleListing *
-MModule::ListLoadableModules()
-{
- return ListAvailableModules(_T(""), true /* loadable only */);
-}
-
-/* static */
-MModuleListing *
-MModule::ListAvailableModules(const String& interfaceName, bool loadableOnly)
+MModule::ListAvailableModules(const String& interfaceName)
{
#ifdef USE_MODULES_STATIC
- return DoListLoadedModules(true, interfaceName, loadableOnly);
+ return DoListLoadedModules(true, interfaceName);
#else // !USE_MODULES_STATIC
kbStringList modules;
@@ -614,5 +605,5 @@
#endif // DEBUG
- // First, build list of all .mmd and .so files in module directories
+ // First, build list of all .dll/.so files in module directories
wxString extDll = DLL_EXTENSION;
@@ -628,21 +619,4 @@
if ( wxPathExists(pathname) )
{
- // first look for MMDs
- pathname << _T("*.mmd");
- filename = wxFindFirstFile(pathname);
- while( filename.length() )
- {
- wxSplitPath(filename, NULL, &basename, NULL);
- if ( moduleNames.Index(basename) == wxNOT_FOUND )
- {
- moduleNames.Add(basename);
-
- modules.push_back(new wxString(filename));
- }
-
- filename = wxFindNextFile();
- }
-
- // now restart with the DLLs
pathname = dirs[i];
pathname << "*" << extDll;
@@ -650,5 +624,4 @@
while ( filename.length() )
{
- // only add if we hadn't found a matching .mmd for it
wxSplitPath(filename, NULL, &basename, NULL);
if ( moduleNames.Index(basename) == wxNOT_FOUND )
@@ -664,31 +637,10 @@
}
- // the components of MMD file format
- enum
- {
- MMD_LINE_SIGNATURE,
- MMD_LINE_NAME,
- MMD_LINE_INTERFACE,
- MMD_LINE_VERSION,
- MMD_LINE_AUTHOR,
- MMD_LINE_LAST
- };
-
- static const wxChar *MMD_HEADERS[] =
- {
- MMD_SIGNATURE,
- _T("Name:"),
- _T("Interface:"),
- _T("Version:"),
- _T("Author:"),
- };
-
- ASSERT_MSG( WXSIZEOF(MMD_HEADERS) == MMD_LINE_LAST,
- _T("forgot to update the constants describing MMD format") );
-
// Second: load list info:
+ const String modulesDontLoad = READ_APPCONFIG(MP_MODULES_DONT_LOAD);
+ const wxArrayString modulesNot = strutil_restore_array(modulesDontLoad);
+
MModuleListingImpl *listing = MModuleListingImpl::Create(modules.size());
kbStringList::iterator it;
- bool errorflag;
size_t count = 0;
for(it = modules.begin(); it != modules.end(); it ++)
@@ -696,78 +648,19 @@
filename = **it;
- // it's either a .mmd file in which case we just read its contents or a
- // .so file in which case we load it and call its GetMModuleInfo()
- if ( filename.Right(4) == _T(".mmd") )
- {
- errorflag = false;
- wxTextFile tf(filename);
- if(! tf.Open())
- {
- errorflag = true;
- }
- else
- {
- // check that we have all required lines
- if(tf.GetLineCount() < MMD_LINE_LAST)
- {
- errorflag = true;
- }
- else
- {
- // check that the first MMD_LINE_LAST lines are correct and get
- // the values of the fields too
- wxString headerValues[MMD_LINE_LAST];
- for ( size_t line = 0; !errorflag && (line < MMD_LINE_LAST); line++ )
- {
- if ( !tf[line].StartsWith(MMD_HEADERS[line], &headerValues[line]) )
- errorflag = TRUE;
- }
-
- if ( !errorflag )
- {
- String interfaceModule = headerValues[MMD_LINE_INTERFACE];
-
- // take all modules if interfaceName is empty, otherwise only
- // take those which implement the given interface
- if ( !interfaceName || interfaceName == interfaceModule )
- {
- String description;
- for(size_t l = MMD_LINE_LAST + 1; l < tf.GetLineCount(); l++)
- description << tf[l] << _T('\n');
-
- String name;
- wxSplitPath((**it), NULL, &name, NULL);
- MModuleListingEntryImpl entry(
- name, // module name
+ wxDynamicLibrary dll(filename);
+ MModule_GetModulePropFuncType
+ getProps = dll.IsLoaded() ?
+ (MModule_GetModulePropFuncType)
+ dll.GetSymbol(MMODULE_GETPROPERTY_FUNCTION) : NULL;
- headerValues[MMD_LINE_INTERFACE],
- headerValues[MMD_LINE_NAME],
- description,
- headerValues[MMD_LINE_VERSION],
- headerValues[MMD_LINE_AUTHOR]);
- (*listing)[count++] = entry;
- }
- }
- }
- }
- if(errorflag)
+ if ( !getProps )
{
- wxLogWarning(_("Cannot parse MMD file for module '%s'."),
+ // this is not our module
+ wxLogWarning(_("Shared library '%s' is not a Mahogany module."),
filename.c_str());
- }
- }
- else // it's not an .mmd, get info from .so/.dll directly
- {
- errorflag = true;
- wxDynamicLibrary dll(filename);
- if ( dll.IsLoaded() )
- {
- MModule_GetModulePropFuncType getProps =
- (MModule_GetModulePropFuncType)
- dll.GetSymbol(MMODULE_GETPROPERTY_FUNCTION);
+ continue;
+ }
- if ( getProps )
- {
const ModuleProperty *props = (*getProps)();
@@ -780,24 +673,32 @@
MMODULE_INTERFACE_PROP);
- if ( !interfaceName || interfaceName == interfaceModule )
+ const String name = GetMModuleProperty(props, MMODULE_NAME_PROP);
+ if ( !interfaceName.empty() )
{
- // check if it is loadable if necessary
- String desc = GetMModuleProperty(props, MMODULE_DESC_PROP);
- if ( !loadableOnly || !desc.empty() )
+ if ( interfaceName != interfaceModule )
{
- String name;
- wxSplitPath(filename, NULL, &name, NULL);
+ // wrong interface, we're not interested in this one
+ continue;
+ }
+
+ // note that this check is only done for a specific interface, if
+ // all modules are requested, then return really all of them
+ if ( modulesNot.Index(name) != wxNOT_FOUND )
+ {
+ // this module was excluded by user
+ continue;
+ }
+ }
+
MModuleListingEntryImpl entry(
name,
interfaceModule,
- desc,
+ GetMModuleProperty(props, MMODULE_DESC_PROP),
GetMModuleProperty(props, MMODULE_DESCRIPTION_PROP),
GetMModuleProperty(props, MMODULE_VERSION_PROP),
- GetMModuleProperty(props, MMODULE_AUTHOR_PROP));
- (*listing)[count++] = entry;
- }
- }
+ GetMModuleProperty(props, MMODULE_AUTHOR_PROP)
+ );
- errorflag = false;
+ (*listing)[count++] = entry;
}
else // no properties in this module??
@@ -805,15 +706,4 @@
wxLogWarning(_("Mahogany module '%s' is probably corrupted"),
filename.c_str());
-
- errorflag = true;
- }
- }
- }
-
- if ( errorflag )
- {
- wxLogWarning(_("Shared library '%s' is not a Mahogany module."),
- filename.c_str());
- }
}
}
@@ -916,5 +806,6 @@
// ----------------------------------------------------------------------------
-const wxChar *GetMModuleProperty(const ModuleProperty *table, const wxChar *name)
+const wxChar *
+GetMModuleProperty(const ModuleProperty *table, const wxChar *name)
{
while ( table->name )
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates