IScriptModuleComms.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 OpenMetaverse;
  30. namespace OpenSim.Region.Framework.Interfaces
  31. {
  32. public delegate void ScriptCommand(UUID script, string id, string module, string command, string k);
  33. /// <summary>
  34. /// Interface for communication between OpenSim modules and in-world scripts
  35. /// </summary>
  36. ///
  37. /// See OpenSim.Region.ScriptEngine.Shared.Api.MOD_Api.modSendCommand() for information on receiving messages
  38. /// from scripts in OpenSim modules.
  39. public interface IScriptModuleComms
  40. {
  41. /// <summary>
  42. /// Modules can subscribe to this event to receive command invocations from in-world scripts
  43. /// </summary>
  44. event ScriptCommand OnScriptCommand;
  45. /// <summary>
  46. /// Register an instance method as a script call by method name
  47. /// </summary>
  48. /// <param name="target"></param>
  49. /// <param name="method"></param>
  50. void RegisterScriptInvocation(object target, string method);
  51. /// <summary>
  52. /// Register a static or instance method as a script call by method info
  53. /// </summary>
  54. /// <param name="target">If target is a Type object, will assume method is static.</param>
  55. /// <param name="method"></param>
  56. void RegisterScriptInvocation(object target, MethodInfo method);
  57. /// <summary>
  58. /// Register one or more instance methods as script calls by method name
  59. /// </summary>
  60. /// <param name="target"></param>
  61. /// <param name="methods"></param>
  62. void RegisterScriptInvocation(object target, string[] methods);
  63. /// <summary>
  64. /// Register one or more static methods as script calls by method name
  65. /// </summary>
  66. /// <param name="target"></param>
  67. /// <param name="methods"></param>
  68. void RegisterScriptInvocation(Type target, string[] methods);
  69. /// <summary>
  70. /// Automatically register script invocations by checking for methods
  71. /// with <see cref="ScriptInvocationAttribute"/>. Should only check
  72. /// public methods.
  73. /// </summary>
  74. /// <param name="target"></param>
  75. void RegisterScriptInvocations(IRegionModuleBase target);
  76. /// <summary>
  77. /// Returns an array of all registered script calls
  78. /// </summary>
  79. /// <returns></returns>
  80. Delegate[] GetScriptInvocationList();
  81. Delegate LookupScriptInvocation(string fname);
  82. string LookupModInvocation(string fname);
  83. Type[] LookupTypeSignature(string fname);
  84. Type LookupReturnType(string fname);
  85. object InvokeOperation(UUID hostId, UUID scriptId, string fname, params object[] parms);
  86. /// <summary>
  87. /// Send a link_message event to an in-world script
  88. /// </summary>
  89. /// <param name="scriptId"></param>
  90. /// <param name="code"></param>
  91. /// <param name="text"></param>
  92. /// <param name="key"></param>
  93. void DispatchReply(UUID scriptId, int code, string text, string key);
  94. /// <summary>
  95. /// Operation to for a region module to register a constant to be used
  96. /// by the script engine
  97. /// </summary>
  98. /// <param name="cname">
  99. /// The name of the constant. LSL convention is for constant names to
  100. /// be uppercase.
  101. /// </param>
  102. /// <param name="value">
  103. /// The value of the constant. Should be of a type that can be
  104. /// converted to one of <see cref="OpenSim.Region.ScriptEngine.Shared.LSL_Types"/>
  105. /// </param>
  106. void RegisterConstant(string cname, object value);
  107. /// <summary>
  108. /// Automatically register all constants on a region module by
  109. /// checking for fields with <see cref="ScriptConstantAttribute"/>.
  110. /// </summary>
  111. /// <param name="target"></param>
  112. void RegisterConstants(IRegionModuleBase target);
  113. /// <summary>
  114. /// Operation to check for a registered constant
  115. /// </summary>
  116. /// <param name="cname">Name of constant</param>
  117. /// <returns>Value of constant or null if none found.</returns>
  118. object LookupModConstant(string cname);
  119. // For use ONLY by the script API
  120. void RaiseEvent(UUID script, string id, string module, string command, string key);
  121. }
  122. [AttributeUsage(AttributeTargets.Method)]
  123. public class ScriptInvocationAttribute : Attribute
  124. { }
  125. [AttributeUsage(AttributeTargets.Field)]
  126. public class ScriptConstantAttribute : Attribute
  127. { }
  128. }