/indra/newview/llcapabilitylistener.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 131 lines · 43 code · 13 blank · 75 comment · 0 complexity · 8d58f67986100f43e5a40cf6098d1e51 MD5 · raw file

  1. /**
  2. * @file llcapabilitylistener.h
  3. * @author Nat Goodspeed
  4. * @date 2009-01-07
  5. * @brief Provide an event-based API for capability requests
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #if ! defined(LL_LLCAPABILITYLISTENER_H)
  29. #define LL_LLCAPABILITYLISTENER_H
  30. #include "llevents.h" // LLEventPump
  31. #include "llsdmessage.h" // LLSDMessage::ArgError
  32. #include "llerror.h" // LOG_CLASS()
  33. class LLCapabilityProvider;
  34. class LLMessageSystem;
  35. class LLSD;
  36. class LLCapabilityListener
  37. {
  38. LOG_CLASS(LLCapabilityListener);
  39. public:
  40. LLCapabilityListener(const std::string& name, LLMessageSystem* messageSystem,
  41. const LLCapabilityProvider& provider,
  42. const LLUUID& agentID, const LLUUID& sessionID);
  43. /// Capability-request exception
  44. typedef LLSDMessage::ArgError ArgError;
  45. /// Get LLEventPump on which we listen for capability requests
  46. /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
  47. LLEventPump& getCapAPI() { return mEventPump; }
  48. /**
  49. * Base class for mapping an as-yet-undeployed capability name to a (pair
  50. * of) LLMessageSystem message(s). To map a capability name to such
  51. * messages, derive a subclass of CapabilityMapper and declare a static
  52. * instance in a translation unit known to be loaded. The mapping is not
  53. * region-specific. If an LLViewerRegion's capListener() receives a
  54. * request for a supported capability, it will use the capability's URL.
  55. * If not, it will look for an applicable CapabilityMapper subclass
  56. * instance.
  57. */
  58. class CapabilityMapper
  59. {
  60. public:
  61. /**
  62. * Base-class constructor. Typically your subclass constructor will
  63. * pass these parameters as literals.
  64. * @param cap the capability name handled by this (subclass) instance
  65. * @param reply the name of the response LLMessageSystem message. Omit
  66. * if the LLMessageSystem message you intend to send doesn't prompt a
  67. * reply message, or if you already handle that message in some other
  68. * way.
  69. */
  70. CapabilityMapper(const std::string& cap, const std::string& reply = "");
  71. virtual ~CapabilityMapper();
  72. /// query the capability name
  73. std::string getCapName() const { return mCapName; }
  74. /// query the reply message name
  75. std::string getReplyName() const { return mReplyName; }
  76. /**
  77. * Override this method to build the LLMessageSystem message we should
  78. * send instead of the requested capability message. DO NOT send that
  79. * message: that will be handled by the caller.
  80. */
  81. virtual void buildMessage(LLMessageSystem* messageSystem,
  82. const LLUUID& agentID,
  83. const LLUUID& sessionID,
  84. const std::string& capabilityName,
  85. const LLSD& payload) const = 0;
  86. /**
  87. * Override this method if you pass a non-empty @a reply
  88. * LLMessageSystem message name to the constructor: that is, if you
  89. * expect to receive an LLMessageSystem message in response to the
  90. * message you constructed in buildMessage(). If you don't pass a @a
  91. * reply message name, you need not override this method as it won't
  92. * be called.
  93. *
  94. * Using LLMessageSystem message-reading operations, your
  95. * readResponse() override should construct and return an LLSD object
  96. * of the form you expect to receive from the real implementation of
  97. * the capability you intend to invoke, when it finally goes live.
  98. */
  99. virtual LLSD readResponse(LLMessageSystem* messageSystem) const;
  100. private:
  101. const std::string mCapName;
  102. const std::string mReplyName;
  103. };
  104. private:
  105. /// Bind the LLCapabilityProvider passed to our ctor
  106. const LLCapabilityProvider& mProvider;
  107. /// Post an event to this LLEventPump to invoke a capability message on
  108. /// the bound LLCapabilityProvider's server
  109. /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
  110. LLEventStream mEventPump;
  111. LLMessageSystem* mMessageSystem;
  112. LLUUID mAgentID, mSessionID;
  113. /// listener to process capability requests
  114. bool capListener(const LLSD&);
  115. /// helper class for capListener()
  116. class CapabilityMappers;
  117. };
  118. #endif /* ! defined(LL_LLCAPABILITYLISTENER_H) */