+++ /dev/null
-/* \r
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_cli\r
- * Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>\r
- *\r
- * Version: MPL 1.1\r
- *\r
- * The contents of this file are subject to the Mozilla Public License Version\r
- * 1.1 (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- * http://www.mozilla.org/MPL/\r
- *\r
- * Software distributed under the License is distributed on an "AS IS" basis,\r
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
- * for the specific language governing rights and limitations under the\r
- * License.\r
- *\r
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_cli\r
- *\r
- * The Initial Developer of the Original Code is\r
- * Michael Giagnocavo <mgg@packetrino.com>\r
- * Portions created by the Initial Developer are Copyright (C)\r
- * the Initial Developer. All Rights Reserved.\r
- *\r
- * Contributor(s):\r
- * \r
- * Michael Giagnocavo <mgg@packetrino.com>\r
- * \r
- * AppFunction.cs -- Base class for API functions\r
- *\r
- */\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace FreeSWITCH\r
-{\r
- public abstract class ApiFunction\r
- {\r
- protected static bool Load() { return true; }\r
-\r
- public abstract void ExecuteBackground(string args);\r
-\r
- public abstract void Execute(FreeSWITCH.Native.Stream stream, FreeSWITCH.Native.Event evt, string args);\r
- }\r
-}\r
+++ /dev/null
-/* \r
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_cli\r
- * Copyright (C) 2008, Michael Giagnocavo <mgg@packetrino.com>\r
- *\r
- * Version: MPL 1.1\r
- *\r
- * The contents of this file are subject to the Mozilla Public License Version\r
- * 1.1 (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- * http://www.mozilla.org/MPL/\r
- *\r
- * Software distributed under the License is distributed on an "AS IS" basis,\r
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
- * for the specific language governing rights and limitations under the\r
- * License.\r
- *\r
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_cli\r
- *\r
- * The Initial Developer of the Original Code is\r
- * Michael Giagnocavo <mgg@packetrino.com>\r
- * Portions created by the Initial Developer are Copyright (C)\r
- * the Initial Developer. All Rights Reserved.\r
- *\r
- * Contributor(s):\r
- * \r
- * Michael Giagnocavo <mgg@packetrino.com>\r
- * \r
- * AppFunction.cs -- Base class for applications\r
- *\r
- */\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using System.Threading;\r
-\r
-namespace FreeSWITCH\r
-{\r
- public abstract class AppFunction\r
- {\r
- protected static bool Load() { return true; }\r
-\r
- protected Native.ManagedSession Session { get; private set; }\r
-\r
- protected string Arguments { get; private set; }\r
-\r
- public bool IsAvailable\r
- {\r
- get\r
- {\r
- if (this.Session == null) return false;\r
- return this.Session.Ready();\r
- }\r
- }\r
-\r
- /// <summary>Determines if the thread used for Run will have Abort called on it on hangup. Defaults to false.</summary>\r
- protected virtual bool AbortOnHangup { get { return false; } }\r
- bool abortable = false;\r
- readonly object abortLock = new object();\r
- Thread runThread;\r
- internal void AbortRun()\r
- {\r
- if (!AbortOnHangup) return;\r
- if (runThread == Thread.CurrentThread) {\r
- Log.WriteLine(LogLevel.Warning, "Thread will not be aborted because Hangup was called from the Run thread.");\r
- return;\r
- }\r
- lock (abortLock) {\r
- if (abortable) {\r
- Log.WriteLine(LogLevel.Critical, "Aborting run thread.");\r
- runThread.Abort();\r
- }\r
- }\r
- }\r
-\r
- protected Guid Uuid { get; private set; }\r
-\r
- internal void RunInternal(FreeSWITCH.Native.ManagedSession session, string args)\r
- {\r
- this.Session = session;\r
- this.Arguments = args;\r
- Session.AppToAbort = this;\r
- try { this.Uuid = new Guid(Session.GetUuid()); }\r
- catch { }\r
- try {\r
- runThread = Thread.CurrentThread;\r
- lock (abortLock) abortable = true;\r
- Run();\r
- }\r
- catch (ThreadAbortException) {\r
- Log.WriteLine(LogLevel.Critical, "Run thread aborted.");\r
- Thread.ResetAbort();\r
- }\r
- finally {\r
- lock (abortLock) { abortable = false; }\r
- if (runThread.ThreadState == ThreadState.AbortRequested) {\r
- try { Thread.ResetAbort(); }\r
- catch { }\r
- }\r
- }\r
- }\r
-\r
- protected abstract void Run();\r
- }\r
-}\r