/// <summary> /// Delete a display. /// </summary> /// <param name="pDisplay">The display we want to delete.</param> public static void DeleteDisplay(Display pDisplay) { // Check we have good data. if (pDisplay == null) { throw new ArgumentNullException("Cannot delete a null display."); } if (pDisplay.IsDeleted()) { throw new ArgumentNullException("Cannot delete a deleted display."); } // Remove it from its surface, if attached. var pSurface = pDisplay.ActiveSurface; if (pSurface != null) { pSurface.Authority_DetachDisplay(pDisplay); } // Release any resources created for it. pDisplay.Authority_Delete(); // Remove it from the list of displays. Authority._ActiveDisplays.Remove(pDisplay); // Log the happening. That is a weird film btw. Log.Write("Display '" + pDisplay.ToString() + "' deleted.", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Remove a display from its current surface. Use with care. /// </summary> /// <remarks>N.B You must call 'pDisplay.Delete()' when you are finished with it if you don't put it back on a surface.</remarks> /// <param name="pDisplay">The display we want to remove from its surface.</param> public static void RemoveDisplay(Display pDisplay) { // Check we have good data. if (pDisplay == null) { throw new ArgumentNullException("Cannot remove a null display."); } if (pDisplay.IsDeleted()) { throw new ArgumentNullException("Cannot remove a deleted display."); } // Remove the view from the current surface. var pOldSurface = pDisplay.ActiveSurface; if (pOldSurface != null) { pDisplay.ActiveSurface.Authority_DetachDisplay(pDisplay); } // Remove it from the list of displays. Authority._ActiveDisplays.Remove(pDisplay); // Write a log message. Log.Write("Display '" + pDisplay.ToString() + "' removed.", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Show a display on a given surface. /// </summary> /// <remarks>This will throw exceptions if this is not possible. Ensure neither the display is already open or the surface is occupied.</remarks> /// <param name="pDisplay">The display to show.</param> /// <param name="pSurface">The surface to show it on.</param> public static void ShowDisplay(Display pDisplay, Surface pSurface) { // Check we have good data. if (pDisplay == null) { throw new ArgumentNullException("Cannot show null display."); } if (pSurface == null) { throw new ArgumentNullException("Cannot show display on a null surface."); } if (pDisplay.IsDeleted()) { throw new ArgumentNullException("Cannot show a deleted display."); } if (pSurface.IsDeleted()) { throw new ArgumentNullException("Cannot show display on a deleted surface."); } // Check neither the display or surface are occupied. if (pDisplay.ActiveSurface != null) { throw new Exception("Cannot show this display because it is already active somewhere else."); } if (pSurface.ActiveDisplay != null) { throw new Exception("Cannot show a display on this surface because it is currently occupied."); } // Attach it to the surface. pSurface.Authority_AttachDisplay(pDisplay); Authority._ActiveDisplays.Add(pDisplay); // Write a log message. Log.Write("Attached display '" + pDisplay.ToString() + "' to surface '" + pSurface.Identifier + "'", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Process a remote method invocation request from one display to another hosted on another surface. /// </summary> /// <param name="pDisplay">The display which called this api function.</param> /// <param name="pSurface">The surface which this display is hosted on.</param> /// <param name="sTargetSurface">The target surface which contains the display we want to call the function on.</param> /// <param name="sRemoteFunction">The name of the function on the active display on the target surface we want to call.</param> /// <param name="lArguments">A list of arguments to pass to that function.</param> /// <returns></returns> public static bool ProcessRMICall(Display pDisplay, Surface pSurface, String sTargetSurface, String sRemoteFunction, Awesomium.Core.JSValue[] lArguments) { // Check the display and surface are valid. if (pDisplay == null) throw new ArgumentNullException("Cannot process a display API request without a display."); if (pSurface == null) throw new ArgumentNullException("Cannot process a display API request without a surface."); // Check we have a valid request handler. if (sTargetSurface == null || sTargetSurface.Length == 0) { Log.Write("Cannot process a cross-surface RMI call without a target surface name.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; } // Check for a valid remote function. if (sRemoteFunction == null || sRemoteFunction.Length == 0) { Log.Write("Cannot process a cross-surface RMI call without a target function name.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; } // Attempt to find the target surface. var pTargetSurface = Authority.FindSurface(sTargetSurface); if (pTargetSurface == null) { Log.Write("Surface '"+sTargetSurface+"' not found. Cannot process a cross-surface RMI call without a valid target surface.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; } // Check there is a display on the surface. if (pTargetSurface.ActiveDisplay != null) { // Insert the calling surface name into the first argument. var l = new List<Awesomium.Core.JSValue>(lArguments); l.Insert(0, pSurface.Identifier); // Call the function on it and pass the data. pTargetSurface.ActiveDisplay.AsyncCallGlobalFunction(sRemoteFunction, l.ToArray()); return true; } // Otherwise we didn't do it. Log.Write("Could not process a cross-surface RMI call because the target surface did not have an active display.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; }
/// <summary> /// Process a display request. For example the calling JS would look like: Authority.request(handlername, somedata). /// </summary> /// <param name="pDisplay">The display which called this api function.</param> /// <param name="pSurface">The surface which this display is hosted on.</param> /// <param name="sRequestHandler">The name of the request handler.</param> /// <param name="dArguments">The table of arguments which were given in the data parameter.</param> /// <returns>True if the request was sucessfully handled. False if not.</returns> public static bool ProcessRequest(Display pDisplay, Surface pSurface, String sRequestHandler, Awesomium.Core.JSObject dArguments) { // Check the display and surface are valid. if (pDisplay == null) throw new ArgumentNullException("Cannot process a display API request without a display."); if (pSurface == null) throw new ArgumentNullException("Cannot process a display API request without a surface."); // Check we have a valid request handler. if (sRequestHandler == null || sRequestHandler.Length == 0) { Log.Write("Cannot process a display API request without a handler name.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; } // Make the request handler lower case. sRequestHandler = sRequestHandler.ToLower(); // Search the bound request handlers. DisplayAPI.IRequest pHandler = null; if (dRequestHandlers.TryGetValue(sRequestHandler, out pHandler)) { // If one is found, process the request and return the success condition. return pHandler.ProcessRequest(pDisplay, pSurface, dArguments); } // No handler for request. Log.Write("Authority could not find handler for request '" + sRequestHandler + "'.", pDisplay.ToString(), Log.Type.DisplayWarning); return false; }
/// <summary> /// Delete a display. /// </summary> /// <param name="pDisplay">The display we want to delete.</param> public static void DeleteDisplay(Display pDisplay) { // Check we have good data. if (pDisplay == null) throw new ArgumentNullException("Cannot delete a null display."); if (pDisplay.IsDeleted()) throw new ArgumentNullException("Cannot delete a deleted display."); // Remove it from its surface, if attached. var pSurface = pDisplay.ActiveSurface; if (pSurface != null) { pSurface.Authority_DetachDisplay(pDisplay); } // Release any resources created for it. pDisplay.Authority_Delete(); // Remove it from the list of displays. Authority._ActiveDisplays.Remove(pDisplay); // Log the happening. That is a weird film btw. Log.Write("Display '"+pDisplay.ToString()+"' deleted.", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Remove a display from its current surface. Use with care. /// </summary> /// <remarks>N.B You must call 'pDisplay.Delete()' when you are finished with it if you don't put it back on a surface.</remarks> /// <param name="pDisplay">The display we want to remove from its surface.</param> public static void RemoveDisplay(Display pDisplay) { // Check we have good data. if (pDisplay == null) throw new ArgumentNullException("Cannot remove a null display."); if (pDisplay.IsDeleted()) throw new ArgumentNullException("Cannot remove a deleted display."); // Remove the view from the current surface. var pOldSurface = pDisplay.ActiveSurface; if (pOldSurface != null) pDisplay.ActiveSurface.Authority_DetachDisplay(pDisplay); // Remove it from the list of displays. Authority._ActiveDisplays.Remove(pDisplay); // Write a log message. Log.Write("Display '"+pDisplay.ToString()+"' removed.", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Show a display on a given surface. /// </summary> /// <remarks>This will throw exceptions if this is not possible. Ensure neither the display is already open or the surface is occupied.</remarks> /// <param name="pDisplay">The display to show.</param> /// <param name="pSurface">The surface to show it on.</param> public static void ShowDisplay(Display pDisplay, Surface pSurface) { // Check we have good data. if (pDisplay == null) throw new ArgumentNullException("Cannot show null display."); if (pSurface == null) throw new ArgumentNullException("Cannot show display on a null surface."); if (pDisplay.IsDeleted()) throw new ArgumentNullException("Cannot show a deleted display."); if (pSurface.IsDeleted()) throw new ArgumentNullException("Cannot show display on a deleted surface."); // Check neither the display or surface are occupied. if (pDisplay.ActiveSurface != null) throw new Exception("Cannot show this display because it is already active somewhere else."); if (pSurface.ActiveDisplay != null) throw new Exception("Cannot show a display on this surface because it is currently occupied."); // Attach it to the surface. pSurface.Authority_AttachDisplay(pDisplay); Authority._ActiveDisplays.Add(pDisplay); // Write a log message. Log.Write("Attached display '"+pDisplay.ToString()+"' to surface '"+pSurface.Identifier+"'", AUTHORITY_LOG_SOURCE, Log.Type.DisplayInfo); }
/// <summary> /// Process a remote method invocation request from one display to another hosted on another surface. /// </summary> /// <param name="pDisplay">The display which called this api function.</param> /// <param name="pSurface">The surface which this display is hosted on.</param> /// <param name="sTargetSurface">The target surface which contains the display we want to call the function on.</param> /// <param name="sRemoteFunction">The name of the function on the active display on the target surface we want to call.</param> /// <param name="lArguments">A list of arguments to pass to that function.</param> /// <returns></returns> public static bool ProcessRMICall(Display pDisplay, Surface pSurface, String sTargetSurface, String sRemoteFunction, Awesomium.Core.JSValue[] lArguments) { // Check the display and surface are valid. if (pDisplay == null) { throw new ArgumentNullException("Cannot process a display API request without a display."); } if (pSurface == null) { throw new ArgumentNullException("Cannot process a display API request without a surface."); } // Check we have a valid request handler. if (sTargetSurface == null || sTargetSurface.Length == 0) { Log.Write("Cannot process a cross-surface RMI call without a target surface name.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); } // Check for a valid remote function. if (sRemoteFunction == null || sRemoteFunction.Length == 0) { Log.Write("Cannot process a cross-surface RMI call without a target function name.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); } // Attempt to find the target surface. var pTargetSurface = Authority.FindSurface(sTargetSurface); if (pTargetSurface == null) { Log.Write("Surface '" + sTargetSurface + "' not found. Cannot process a cross-surface RMI call without a valid target surface.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); } // Check there is a display on the surface. if (pTargetSurface.ActiveDisplay != null) { // Insert the calling surface name into the first argument. var l = new List <Awesomium.Core.JSValue>(lArguments); l.Insert(0, pSurface.Identifier); // Call the function on it and pass the data. pTargetSurface.ActiveDisplay.AsyncCallGlobalFunction(sRemoteFunction, l.ToArray()); return(true); } // Otherwise we didn't do it. Log.Write("Could not process a cross-surface RMI call because the target surface did not have an active display.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); }
/// <summary> /// Process a display request. For example the calling JS would look like: Authority.request(handlername, somedata). /// </summary> /// <param name="pDisplay">The display which called this api function.</param> /// <param name="pSurface">The surface which this display is hosted on.</param> /// <param name="sRequestHandler">The name of the request handler.</param> /// <param name="dArguments">The table of arguments which were given in the data parameter.</param> /// <returns>True if the request was sucessfully handled. False if not.</returns> public static bool ProcessRequest(Display pDisplay, Surface pSurface, String sRequestHandler, Awesomium.Core.JSObject dArguments) { // Check the display and surface are valid. if (pDisplay == null) { throw new ArgumentNullException("Cannot process a display API request without a display."); } if (pSurface == null) { throw new ArgumentNullException("Cannot process a display API request without a surface."); } // Check we have a valid request handler. if (sRequestHandler == null || sRequestHandler.Length == 0) { Log.Write("Cannot process a display API request without a handler name.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); } // Make the request handler lower case. sRequestHandler = sRequestHandler.ToLower(); // Search the bound request handlers. DisplayAPI.IRequest pHandler = null; if (dRequestHandlers.TryGetValue(sRequestHandler, out pHandler)) { // If one is found, process the request and return the success condition. return(pHandler.ProcessRequest(pDisplay, pSurface, dArguments)); } // No handler for request. Log.Write("Authority could not find handler for request '" + sRequestHandler + "'.", pDisplay.ToString(), Log.Type.DisplayWarning); return(false); }