]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Call entrypoint on scripts so they can perform initialization
authorMichael Giagnocavo <mgg@giagnocavo.net>
Tue, 28 Jul 2009 18:45:47 +0000 (18:45 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Tue, 28 Jul 2009 18:45:47 +0000 (18:45 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14399 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_managed/managed/ScriptPluginManager.cs

index 7b0192d036f0d981718fa66d1112bc5c0333fa28..76fb84910c4735dd5728fc95fca7f88be2f49f2a 100644 (file)
@@ -43,6 +43,7 @@ using System.Reflection.Emit;
 namespace FreeSWITCH {\r
 \r
     public enum ScriptContextType {\r
+        None,\r
         App,\r
         Api,\r
         ApiBackground,\r
@@ -151,6 +152,11 @@ namespace FreeSWITCH {
         }\r
 \r
         bool processAssembly(string fileName, Assembly asm) {\r
+            // Call the entrypoint once, to initialize apps that need their main called\r
+            var entryPoint = getEntryDelegate(asm.EntryPoint);\r
+            try { entryPoint(); } catch {  }\r
+\r
+            // Check for loading\r
             var allTypes = asm.GetExportedTypes();\r
             if (!RunLoadNotify(allTypes)) return false;\r
 \r
@@ -159,7 +165,6 @@ namespace FreeSWITCH {
             AddAppPlugins(allTypes);\r
 \r
             // Add the script executors\r
-            var entryPoint = getEntryDelegate(asm.EntryPoint);\r
             var name = Path.GetFileName(fileName);\r
             var aliases = new List<string> { name };\r
             this.ApiExecutors.Add(new ApiPluginExecutor(name, aliases, () => new ScriptApiWrapper(entryPoint)));\r
@@ -181,6 +186,7 @@ namespace FreeSWITCH {
                 try {\r
                     entryPoint();\r
                 } finally {\r
+                    Script.contextType = ScriptContextType.None;\r
                     Script.context = null;\r
                 }\r
             }\r
@@ -191,6 +197,7 @@ namespace FreeSWITCH {
                 try {\r
                     entryPoint();\r
                 } finally {\r
+                    Script.contextType = ScriptContextType.None;\r
                     Script.context = null;\r
                 }\r
             }\r
@@ -210,6 +217,7 @@ namespace FreeSWITCH {
                 try {\r
                     entryPoint();\r
                 } finally {\r
+                    Script.contextType = ScriptContextType.None;\r
                     Script.context = null;\r
                 }\r
             }\r