Add plugin options to skip autoreload
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14654 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
ca8dfda04a
commit
c6be531b4b
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.4.0")]
|
[assembly: AssemblyVersion("1.0.5.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.4.0")]
|
[assembly: AssemblyFileVersion("1.0.5.0")]
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -133,7 +133,17 @@ namespace FreeSWITCH {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void watcher_Changed(object sender, FileSystemEventArgs e) {
|
static void watcher_Changed(object sender, FileSystemEventArgs e) {
|
||||||
Action<string> queueFile = x => { lock (watcherLock) { watcherFiles.Add(x); } };
|
Action<string> queueFile = fileName => {
|
||||||
|
var currentPi = pluginInfos.FirstOrDefault(p => string.Compare(fileName, p.FileName, StringComparison.OrdinalIgnoreCase) == 0);
|
||||||
|
if (currentPi != null) {
|
||||||
|
var noReload = currentPi.Manager.ApiExecutors.Any(x => (x.PluginOptions & PluginOptions.NoAutoReload) == PluginOptions.NoAutoReload) ||
|
||||||
|
currentPi.Manager.AppExecutors.Any(x => (x.PluginOptions & PluginOptions.NoAutoReload) == PluginOptions.NoAutoReload);
|
||||||
|
if (noReload) return;
|
||||||
|
}
|
||||||
|
lock (watcherLock) {
|
||||||
|
watcherFiles.Add(fileName);
|
||||||
|
}
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
if (!initialLoadComplete) return;
|
if (!initialLoadComplete) return;
|
||||||
var file = e.FullPath;
|
var file = e.FullPath;
|
||||||
|
|
|
@ -88,4 +88,14 @@ namespace FreeSWITCH {
|
||||||
bool Load();
|
bool Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum PluginOptions {
|
||||||
|
None = 0,
|
||||||
|
NoAutoReload = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IPluginOptionsProvider {
|
||||||
|
PluginOptions GetOptions();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,15 @@ namespace FreeSWITCH {
|
||||||
public string Name { get { return name; } }
|
public string Name { get { return name; } }
|
||||||
readonly string name;
|
readonly string name;
|
||||||
|
|
||||||
protected PluginExecutor(string name, List<string> aliases) {
|
public PluginOptions PluginOptions { get { return pluginOptions; } }
|
||||||
|
readonly PluginOptions pluginOptions;
|
||||||
|
|
||||||
|
protected PluginExecutor(string name, List<string> aliases, PluginOptions pluginOptions) {
|
||||||
if (string.IsNullOrEmpty(name)) throw new ArgumentException("No name provided.");
|
if (string.IsNullOrEmpty(name)) throw new ArgumentException("No name provided.");
|
||||||
if (aliases == null || aliases.Count == 0) throw new ArgumentException("No aliases provided.");
|
if (aliases == null || aliases.Count == 0) throw new ArgumentException("No aliases provided.");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.aliases = aliases.Distinct().ToList();
|
this.aliases = aliases.Distinct().ToList();
|
||||||
|
this.pluginOptions = pluginOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
int useCount = 0;
|
int useCount = 0;
|
||||||
|
@ -85,8 +89,8 @@ namespace FreeSWITCH {
|
||||||
|
|
||||||
readonly Func<IAppPlugin> createPlugin;
|
readonly Func<IAppPlugin> createPlugin;
|
||||||
|
|
||||||
public AppPluginExecutor(string name, List<string> aliases, Func<IAppPlugin> creator)
|
public AppPluginExecutor(string name, List<string> aliases, Func<IAppPlugin> creator, PluginOptions pluginOptions)
|
||||||
: base(name, aliases) {
|
: base(name, aliases, pluginOptions) {
|
||||||
if (creator == null) throw new ArgumentNullException("Creator cannot be null.");
|
if (creator == null) throw new ArgumentNullException("Creator cannot be null.");
|
||||||
this.createPlugin = creator;
|
this.createPlugin = creator;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +121,8 @@ namespace FreeSWITCH {
|
||||||
|
|
||||||
readonly Func<IApiPlugin> createPlugin;
|
readonly Func<IApiPlugin> createPlugin;
|
||||||
|
|
||||||
public ApiPluginExecutor(string name, List<string> aliases, Func<IApiPlugin> creator)
|
public ApiPluginExecutor(string name, List<string> aliases, Func<IApiPlugin> creator, PluginOptions pluginOptions)
|
||||||
: base(name, aliases) {
|
: base(name, aliases, pluginOptions) {
|
||||||
if (creator == null) throw new ArgumentNullException("Creator cannot be null.");
|
if (creator == null) throw new ArgumentNullException("Creator cannot be null.");
|
||||||
this.createPlugin = creator;
|
this.createPlugin = creator;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +200,7 @@ namespace FreeSWITCH {
|
||||||
var pluginTypes = allTypes.Where(x => ty.IsAssignableFrom(x) && !x.IsAbstract).ToList();
|
var pluginTypes = allTypes.Where(x => ty.IsAssignableFrom(x) && !x.IsAbstract).ToList();
|
||||||
if (pluginTypes.Count == 0) return true;
|
if (pluginTypes.Count == 0) return true;
|
||||||
foreach (var pt in pluginTypes) {
|
foreach (var pt in pluginTypes) {
|
||||||
var load = ((ILoadNotificationPlugin)Activator.CreateInstance(pt, false));
|
var load = ((ILoadNotificationPlugin)Activator.CreateInstance(pt, true));
|
||||||
if (!load.Load()) {
|
if (!load.Load()) {
|
||||||
Log.WriteLine(LogLevel.Notice, "Type {0} requested no loading. Assembly will not be loaded.", pt.FullName);
|
Log.WriteLine(LogLevel.Notice, "Type {0} requested no loading. Assembly will not be loaded.", pt.FullName);
|
||||||
return false;
|
return false;
|
||||||
|
@ -205,20 +209,29 @@ namespace FreeSWITCH {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void AddApiPlugins(Type[] allTypes) {
|
protected PluginOptions GetOptions(Type[] allTypes) {
|
||||||
|
var ty = typeof(IPluginOptionsProvider);
|
||||||
|
var pluginTypes = allTypes.Where(x => ty.IsAssignableFrom(x) && !x.IsAbstract).ToList();
|
||||||
|
return pluginTypes.Aggregate(PluginOptions.None, (opts, t) => {
|
||||||
|
var x = ((IPluginOptionsProvider)Activator.CreateInstance(t, true));
|
||||||
|
return opts | x.GetOptions();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void AddApiPlugins(Type[] allTypes, PluginOptions pluginOptions) {
|
||||||
var iApiTy = typeof(IApiPlugin);
|
var iApiTy = typeof(IApiPlugin);
|
||||||
foreach (var ty in allTypes.Where(x => iApiTy.IsAssignableFrom(x) && !x.IsAbstract)) {
|
foreach (var ty in allTypes.Where(x => iApiTy.IsAssignableFrom(x) && !x.IsAbstract)) {
|
||||||
var del = CreateConstructorDelegate<IApiPlugin>(ty);
|
var del = CreateConstructorDelegate<IApiPlugin>(ty);
|
||||||
var exec = new ApiPluginExecutor(ty.FullName, new List<string> { ty.FullName, ty.Name }, del);
|
var exec = new ApiPluginExecutor(ty.FullName, new List<string> { ty.FullName, ty.Name }, del, pluginOptions);
|
||||||
this.ApiExecutors.Add(exec);
|
this.ApiExecutors.Add(exec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void AddAppPlugins(Type[] allTypes) {
|
protected void AddAppPlugins(Type[] allTypes, PluginOptions pluginOptions) {
|
||||||
var iAppTy = typeof(IAppPlugin);
|
var iAppTy = typeof(IAppPlugin);
|
||||||
foreach (var ty in allTypes.Where(x => iAppTy.IsAssignableFrom(x) && !x.IsAbstract)) {
|
foreach (var ty in allTypes.Where(x => iAppTy.IsAssignableFrom(x) && !x.IsAbstract)) {
|
||||||
var del = CreateConstructorDelegate<IAppPlugin>(ty);
|
var del = CreateConstructorDelegate<IAppPlugin>(ty);
|
||||||
var exec = new AppPluginExecutor(ty.FullName, new List<string> { ty.FullName, ty.Name }, del);
|
var exec = new AppPluginExecutor(ty.FullName, new List<string> { ty.FullName, ty.Name }, del, pluginOptions);
|
||||||
this.AppExecutors.Add(exec);
|
this.AppExecutors.Add(exec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,8 +296,10 @@ namespace FreeSWITCH {
|
||||||
var allTypes = asm.GetExportedTypes();
|
var allTypes = asm.GetExportedTypes();
|
||||||
if (!RunLoadNotify(allTypes)) return false;
|
if (!RunLoadNotify(allTypes)) return false;
|
||||||
|
|
||||||
AddApiPlugins(allTypes);
|
var opts = GetOptions(allTypes);
|
||||||
AddAppPlugins(allTypes);
|
|
||||||
|
AddApiPlugins(allTypes, opts);
|
||||||
|
AddAppPlugins(allTypes, opts);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,14 +161,15 @@ namespace FreeSWITCH {
|
||||||
if (!RunLoadNotify(allTypes)) return false;
|
if (!RunLoadNotify(allTypes)) return false;
|
||||||
|
|
||||||
// Scripts can specify classes too
|
// Scripts can specify classes too
|
||||||
AddApiPlugins(allTypes);
|
var opts = GetOptions(allTypes);
|
||||||
AddAppPlugins(allTypes);
|
AddApiPlugins(allTypes, opts);
|
||||||
|
AddAppPlugins(allTypes, opts);
|
||||||
|
|
||||||
// Add the script executors
|
// Add the script executors
|
||||||
var name = Path.GetFileName(fileName);
|
var name = Path.GetFileName(fileName);
|
||||||
var aliases = new List<string> { name };
|
var aliases = new List<string> { name };
|
||||||
this.ApiExecutors.Add(new ApiPluginExecutor(name, aliases, () => new ScriptApiWrapper(entryPoint)));
|
this.ApiExecutors.Add(new ApiPluginExecutor(name, aliases, () => new ScriptApiWrapper(entryPoint), opts));
|
||||||
this.AppExecutors.Add(new AppPluginExecutor(name, aliases, () => new ScriptAppWrapper(entryPoint)));
|
this.AppExecutors.Add(new AppPluginExecutor(name, aliases, () => new ScriptAppWrapper(entryPoint), opts));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue