IScriptModuleComms.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Reflection;
  29. using System.Collections.Generic;
  30. using OpenMetaverse;
  31. namespace OpenSim.Region.Framework.Interfaces
  32. {
  33. public delegate void ScriptCommand(UUID script, string id, string module, string command, string k);
  34. /// <summary>
  35. /// Interface for communication between OpenSim modules and in-world scripts
  36. /// </summary>
  37. ///
  38. /// See OpenSim.Region.ScriptEngine.Shared.Api.MOD_Api.modSendCommand() for information on receiving messages
  39. /// from scripts in OpenSim modules.
  40. public interface IScriptModuleComms
  41. {
  42. /// <summary>
  43. /// Modules can subscribe to this event to receive command invocations from in-world scripts
  44. /// </summary>
  45. event ScriptCommand OnScriptCommand;
  46. /// <summary>
  47. /// Register an instance method as a script call by method name
  48. /// </summary>
  49. /// <param name="target"></param>
  50. /// <param name="method"></param>
  51. void RegisterScriptInvocation(object target, string method);
  52. /// <summary>
  53. /// Register a static or instance method as a script call by method info
  54. /// </summary>
  55. /// <param name="target">If target is a Type object, will assume method is static.</param>
  56. /// <param name="method"></param>
  57. void RegisterScriptInvocation(object target, MethodInfo method);
  58. /// <summary>
  59. /// Register one or more instance methods as script calls by method name
  60. /// </summary>
  61. /// <param name="target"></param>
  62. /// <param name="methods"></param>
  63. void RegisterScriptInvocation(object target, string[] methods);
  64. /// <summary>
  65. /// Register one or more static methods as script calls by method name
  66. /// </summary>
  67. /// <param name="target"></param>
  68. /// <param name="methods"></param>
  69. void RegisterScriptInvocation(Type target, string[] methods);
  70. /// <summary>
  71. /// Automatically register script invocations by checking for methods
  72. /// with <see cref="ScriptInvocationAttribute"/>. Should only check
  73. /// public methods.
  74. /// </summary>
  75. /// <param name="target"></param>
  76. void RegisterScriptInvocations(IRegionModuleBase target);
  77. /// <summary>
  78. /// Returns an array of all registered script calls
  79. /// </summary>
  80. /// <returns></returns>
  81. Delegate[] GetScriptInvocationList();
  82. Delegate LookupScriptInvocation(string fname);
  83. string LookupModInvocation(string fname);
  84. Type[] LookupTypeSignature(string fname);
  85. Type LookupReturnType(string fname);
  86. object InvokeOperation(UUID hostId, UUID scriptId, string fname, params object[] parms);
  87. /// <summary>
  88. /// Send a link_message event to an in-world script
  89. /// </summary>
  90. /// <param name="scriptId"></param>
  91. /// <param name="code"></param>
  92. /// <param name="text"></param>
  93. /// <param name="key"></param>
  94. void DispatchReply(UUID scriptId, int code, string text, string key);
  95. /// <summary>
  96. /// Operation to for a region module to register a constant to be used
  97. /// by the script engine
  98. /// </summary>
  99. /// <param name="cname">
  100. /// The name of the constant. LSL convention is for constant names to
  101. /// be uppercase.
  102. /// </param>
  103. /// <param name="value">
  104. /// The value of the constant. Should be of a type that can be
  105. /// converted to one of <see cref="OpenSim.Region.ScriptEngine.Shared.LSL_Types"/>
  106. /// </param>
  107. void RegisterConstant(string cname, object value);
  108. /// <summary>
  109. /// Automatically register all constants on a region module by
  110. /// checking for fields with <see cref="ScriptConstantAttribute"/>.
  111. /// </summary>
  112. /// <param name="target"></param>
  113. void RegisterConstants(IRegionModuleBase target);
  114. /// <summary>
  115. /// Operation to check for a registered constant
  116. /// </summary>
  117. /// <param name="cname">Name of constant</param>
  118. /// <returns>Value of constant or null if none found.</returns>
  119. object LookupModConstant(string cname);
  120. Dictionary<string, object> GetConstants();
  121. // For use ONLY by the script API
  122. void RaiseEvent(UUID script, string id, string module, string command, string key);
  123. }
  124. [AttributeUsage(AttributeTargets.Method)]
  125. public class ScriptInvocationAttribute : Attribute
  126. { }
  127. [AttributeUsage(AttributeTargets.Field)]
  128. public class ScriptConstantAttribute : Attribute
  129. { }
  130. }