diff --git a/branches/iomanager/Projects/SAMufasaGUI/project1.lpi b/branches/iomanager/Projects/SAMufasaGUI/project1.lpi
index 12a6d28..11b3923 100644
--- a/branches/iomanager/Projects/SAMufasaGUI/project1.lpi
+++ b/branches/iomanager/Projects/SAMufasaGUI/project1.lpi
@@ -10,7 +10,7 @@
-
+
@@ -140,8 +140,8 @@
-
-
+
+
@@ -190,8 +190,8 @@
-
-
+
+
@@ -269,8 +269,8 @@
-
-
+
+
@@ -2057,123 +2057,123 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -2210,12 +2210,6 @@
-
-
-
-
-
-
diff --git a/branches/iomanager/Projects/SAMufasaGUI/testunit.pas b/branches/iomanager/Projects/SAMufasaGUI/testunit.pas
index 42eba47..2383d37 100644
--- a/branches/iomanager/Projects/SAMufasaGUI/testunit.pas
+++ b/branches/iomanager/Projects/SAMufasaGUI/testunit.pas
@@ -527,9 +527,13 @@ begin
Writeln('The script hasn''t stopped yet, so we cannot start a new one.');
exit;
end;
+ AppPath:= MainDir + DS;
+ includePath:= LoadSettingDef('Settings/Includes/Path', IncludeTrailingPathDelimiter(ExpandFileName(MainDir+ DS + '..' + DS + '..' + ds)) + 'Includes' + DS);
+ fontPath := LoadSettingDef('Settings/Fonts/Path', IncludeTrailingPathDelimiter(ExpandFileName(MainDir+ DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
+ PluginsPath := LoadSettingDef('Settings/Plugins/Path', ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
ScriptErrorLine:= -1;
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
- ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
+ ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo,PluginsPath);
{$IFNDEF TERMINALWRITELN}
ScriptThread.SetDebug(@formWriteln);
ScriptThread.DebugMemo := Self.Memo1;
@@ -547,16 +551,6 @@ begin
if ScriptFile <> '' then
ScriptPath := ExtractFileDir(ScriptFile);
- AppPath:= MainDir + DS;
- includePath:= LoadSettingDef('Settings/Includes/Path',
- IncludeTrailingPathDelimiter(ExpandFileName(MainDir+
- DS + '..' + DS + '..' + ds)) + 'Includes' + DS);
- fontPath := LoadSettingDef('Settings/Fonts/Path',
- IncludeTrailingPathDelimiter(ExpandFileName(MainDir+
- DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
-
- PluginsPath := LoadSettingDef('Settings/Plugins/Path',
- ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
if not DirectoryExists(PluginsPath) and not assigned(PluginsGlob) then
begin
if FirstRun then
diff --git a/branches/iomanager/Units/MMLAddon/mmlpsthread.pas b/branches/iomanager/Units/MMLAddon/mmlpsthread.pas
index 3956f99..f2a48d5 100644
--- a/branches/iomanager/Units/MMLAddon/mmlpsthread.pas
+++ b/branches/iomanager/Units/MMLAddon/mmlpsthread.pas
@@ -111,7 +111,7 @@ type
procedure SetDebug( writelnProc : TWritelnProc );
procedure SetDbgImg( DebugImageInfo : TDbgImgInfo);
procedure SetPaths(ScriptP,AppP,IncludeP,PluginP,FontP : string);
- constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo);
+ constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
destructor Destroy; override;
end;
threadvar
@@ -210,11 +210,11 @@ end;
}
-constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo);
+constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
begin
SyncInfo:= TheSyncInfo;
SetLength(PluginsToLoad,0);
- Client := TClient.Create;
+ Client := TClient.Create(plugin_dir);
PSScript := TPSScript.Create(nil);
PSScript.UsePreProcessor:= True;
PSScript.OnNeedFile := @RequireFile;
diff --git a/branches/iomanager/Units/MMLCore/client.pas b/branches/iomanager/Units/MMLCore/client.pas
index c4d133e..9360098 100644
--- a/branches/iomanager/Units/MMLCore/client.pas
+++ b/branches/iomanager/Units/MMLCore/client.pas
@@ -41,7 +41,7 @@ It binds all the components together.
type
TClient = class(TObject)
- constructor Create;
+ constructor Create(plugin_dir: string);
destructor Destroy; override;
public
@@ -57,11 +57,11 @@ type
implementation
// Possibly pass arguments to a default window.
-constructor TClient.Create;
+constructor TClient.Create(plugin_dir: string);
begin
inherited Create;
- IOManager:= TIOManager.Create('./Plugins');
+ IOManager:= TIOManager.Create(plugin_dir);
MFiles := TMFiles.Create;
MFinder := TMFinder.Create(Self);
MBitmaps := TMBitmaps.Create(self);
diff --git a/trunk/Projects/SAMufasaGUI/project1.lpi b/trunk/Projects/SAMufasaGUI/project1.lpi
index 5c2e033..fb9a1d7 100644
--- a/trunk/Projects/SAMufasaGUI/project1.lpi
+++ b/trunk/Projects/SAMufasaGUI/project1.lpi
@@ -2001,7 +2001,7 @@
-
+
@@ -2104,24 +2104,20 @@
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
@@ -2131,7 +2127,8 @@
-
+
+
diff --git a/trunk/Units/MMLAddon/plugins.pas b/trunk/Units/MMLAddon/plugins.pas
index 0d48c52..35bdaf7 100644
--- a/trunk/Units/MMLAddon/plugins.pas
+++ b/trunk/Units/MMLAddon/plugins.pas
@@ -34,7 +34,7 @@ unit plugins;
interface
uses
- Classes, SysUtils,dynlibs;
+ Classes, SysUtils, dynlibs;
type
TMPluginMethod = record
@@ -44,31 +44,45 @@ type
TMPlugin = record
Methods : Array of TMPluginMethod;
- dllHandle : TLibHandle;
- filename : string;
MethodLen : integer;
end;
TMPluginArray = array of TMPlugin;
- { TMPlugins }
+ TGenericLib = record
+ filename: string;
+ handle: TLibHandle;
+ end;
+ TGenericLibArray = array of TGenericLib;
- TMPlugins = class (TObject)
- private
- Plugins : TMPluginArray;
- PluginLen : integer;
- procedure FreePlugins;
- public
- PluginDirs : TStringList;
- procedure ValidateDirs;
- procedure LoadPluginsDir( DirIndex : integer);
- function LoadPlugin(PluginName : string) : integer;
- property Count : integer read PluginLen;
- property MPlugins : TMPluginArray read Plugins;
- constructor Create;
- destructor Destroy;override;
+ TGenericLoader = class(TObject)
+ private
+ PluginLen : integer;
+ Loaded: TGenericLibArray;
+ procedure FreePlugins;
+ protected
+ function InitPlugin(plugin: TLibHandle): boolean; virtual; abstract;
+ public
+ PluginDirs : TStringList;
+ constructor Create;
+ destructor Destroy; override;
+ procedure ValidateDirs;
+ procedure LoadPluginsDir(DirIndex : integer);
+ function LoadPlugin(PluginName : string) : integer;
end;
+ { TMPlugins }
+
+ TMPlugins = class (TGenericLoader)
+ private
+ Plugins : TMPluginArray;
+ NumPlugins : integer;
+ protected
+ function InitPlugin(plugin: TLibHandle): boolean; override;
+ public
+ property MPlugins : TMPluginArray read Plugins;
+ property Count : integer read NumPlugins;
+ end;
implementation
@@ -77,24 +91,24 @@ uses
{ TMPlugins }
-procedure TMPlugins.FreePlugins;
+procedure TGenericLoader.FreePlugins;
var
I : integer;
begin
for i := 0 to PluginLen - 1 do
begin;
- if (Plugins[i].dllHandle > 0) then
+ if (Loaded[i].handle > 0) then
try
Writeln(inttostr(I));
- FreeLibrary(Plugins[i].dllHandle);
+ FreeLibrary(Loaded[i].handle);
except
end;
end;
- SetLength(Plugins,0);
+ SetLength(Loaded,0);
PluginLen:= 0;
end;
-procedure TMPlugins.ValidateDirs;
+procedure TGenericLoader.ValidateDirs;
var
i : integer;
TempStr : string;
@@ -115,7 +129,7 @@ begin
end;
end;
-procedure TMPlugins.LoadPluginsDir(DirIndex: integer);
+procedure TGenericLoader.LoadPluginsDir(DirIndex: integer);
var
PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF}
FileSearcher : TSearchRec;
@@ -133,16 +147,10 @@ begin
FindClose(FileSearcher);
end;
-function TMPlugins.LoadPlugin(PluginName: string): Integer;
+
+function TGenericLoader.LoadPlugin(PluginName: string): Integer;
var
i, ii : integer;
- pntrArrc : function : integer; stdcall;
- GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall;
- GetTypeCount : function : Integer; stdcall;
- GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall;
- PD : PChar;
- pntr : Pointer;
- arrc : integer;
Status : LongInt;
PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF}
begin
@@ -162,51 +170,66 @@ begin
if ii = -1 then
raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]);
for i := 0 to PluginLen - 1 do
- if Plugins[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then
+ if Loaded[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then
Exit(i);
- pd := StrAlloc(255);
- SetLength(Plugins,PluginLen + 1);
+ SetLength(Loaded,PluginLen + 1);
Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]]));
- Plugins[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt;
- Plugins[PluginLen].dllHandle:= LoadLibrary(PChar(Plugins[PluginLen].filename));
- if Plugins[PluginLen].dllHandle = 0 then
- Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
- Pointer(pntrArrc) := GetProcAddress(Plugins[PluginLen].dllHandle, PChar('GetFunctionCount'));
- if @pntrArrc = nil then
- Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
- arrc := pntrArrc();
- SetLength(Plugins[PluginLen].Methods, ArrC);
- Pointer(GetFuncInfo) := GetProcAddress(Plugins[PluginLen].dllHandle, PChar('GetFunctionInfo'));
- if @GetFuncInfo = nil then
- Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
- Plugins[PluginLen].MethodLen := Arrc;
- for ii := 0 to ArrC-1 do
- begin;
- if (GetFuncInfo(ii, pntr, pd) < 0) then
- Continue;
- Plugins[Pluginlen].Methods[ii].FuncPtr := pntr;
- Plugins[Pluginlen].Methods[ii].FuncStr := pd;
- end;
+ Loaded[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt;
+ Loaded[PluginLen].handle:= LoadLibrary(PChar(Loaded[PluginLen].filename));
+ if Loaded[PluginLen].handle = 0 then
+ Raise Exception.CreateFMT('Error loading plugin %s',[Loaded[PluginLen].filename]);
+ if InitPlugin(Loaded[PluginLen].handle) then
+ inc(PluginLen)
+ else
+ FreeLibrary(Loaded[PluginLen].handle);
Result := PluginLen;
- inc(PluginLen);
- StrDispose(pd);
-
end;
-constructor TMPlugins.Create;
+constructor TGenericLoader.Create;
begin
inherited Create;
PluginLen := 0;
PluginDirs := TStringList.Create;
end;
-destructor TMPlugins.Destroy;
+destructor TGenericLoader.Destroy;
begin
FreePlugins;
PluginDirs.Free;
inherited Destroy;
end;
+function TMPlugins.InitPlugin(plugin: TLibHandle): boolean;
+var
+ pntrArrc : function : integer; stdcall;
+ GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall;
+ GetTypeCount : function : Integer; stdcall;
+ GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall;
+ PD : PChar;
+ pntr : Pointer;
+ arrc, ii : integer;
+begin
+ Pointer(pntrArrc) := GetProcAddress(plugin, PChar('GetFunctionCount'));
+ if @pntrArrc = nil then begin result:= false; exit; end;
+ Pointer(GetFuncInfo) := GetProcAddress(plugin, PChar('GetFunctionInfo'));
+ if @GetFuncInfo = nil then begin result:= false; exit; end;
+ arrc := pntrArrc();
+ SetLength(Plugins,NumPlugins+1);
+ Plugins[NumPlugins].MethodLen := Arrc;
+ SetLength(Plugins[NumPlugins].Methods, ArrC);
+ pd := StrAlloc(255);
+ for ii := 0 to ArrC-1 do
+ begin;
+ if (GetFuncInfo(ii, pntr, pd) < 0) then
+ Continue;
+ Plugins[NumPlugins].Methods[ii].FuncPtr := pntr;
+ Plugins[NumPlugins].Methods[ii].FuncStr := pd;
+ end;
+ StrDispose(pd);
+ inc(NumPlugins);
+ result:= true;
+end;
+
end.