llcapabilitylistener.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  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=viewergpl$
  8.  * 
  9.  * Copyright (c) 2009-2010, Linden Research, Inc.
  10.  * 
  11.  * Second Life Viewer Source Code
  12.  * The source code in this file ("Source Code") is provided by Linden Lab
  13.  * to you under the terms of the GNU General Public License, version 2.0
  14.  * ("GPL"), unless you have obtained a separate licensing agreement
  15.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  16.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18.  * 
  19.  * There are special exceptions to the terms and conditions of the GPL as
  20.  * it is applied to this Source Code. View the full text of the exception
  21.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  22.  * online at
  23.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24.  * 
  25.  * By copying, modifying or distributing this software, you acknowledge
  26.  * that you have read and understood your obligations described above,
  27.  * and agree to abide by those obligations.
  28.  * 
  29.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31.  * COMPLETENESS OR PERFORMANCE.
  32.  * $/LicenseInfo$
  33.  */
  34. #if ! defined(LL_LLCAPABILITYLISTENER_H)
  35. #define LL_LLCAPABILITYLISTENER_H
  36. #include "llevents.h"               // LLEventPump
  37. #include "llsdmessage.h"            // LLSDMessage::ArgError
  38. #include "llerror.h"                // LOG_CLASS()
  39. class LLCapabilityProvider;
  40. class LLMessageSystem;
  41. class LLSD;
  42. class LLCapabilityListener
  43. {
  44.     LOG_CLASS(LLCapabilityListener);
  45. public:
  46.     LLCapabilityListener(const std::string& name, LLMessageSystem* messageSystem,
  47.                          const LLCapabilityProvider& provider,
  48.                          const LLUUID& agentID, const LLUUID& sessionID);
  49.     /// Capability-request exception
  50.     typedef LLSDMessage::ArgError ArgError;
  51.     /// Get LLEventPump on which we listen for capability requests
  52.     /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
  53.     LLEventPump& getCapAPI() { return mEventPump; }
  54.     /**
  55.      * Base class for mapping an as-yet-undeployed capability name to a (pair
  56.      * of) LLMessageSystem message(s). To map a capability name to such
  57.      * messages, derive a subclass of CapabilityMapper and declare a static
  58.      * instance in a translation unit known to be loaded. The mapping is not
  59.      * region-specific. If an LLViewerRegion's capListener() receives a
  60.      * request for a supported capability, it will use the capability's URL.
  61.      * If not, it will look for an applicable CapabilityMapper subclass
  62.      * instance.
  63.      */
  64.     class CapabilityMapper
  65.     {
  66.     public:
  67.         /**
  68.          * Base-class constructor. Typically your subclass constructor will
  69.          * pass these parameters as literals.
  70.          * @param cap the capability name handled by this (subclass) instance
  71.          * @param reply the name of the response LLMessageSystem message. Omit
  72.          * if the LLMessageSystem message you intend to send doesn't prompt a
  73.          * reply message, or if you already handle that message in some other
  74.          * way.
  75.          */
  76.         CapabilityMapper(const std::string& cap, const std::string& reply = "");
  77.         virtual ~CapabilityMapper();
  78.         /// query the capability name
  79.         std::string getCapName() const { return mCapName; }
  80.         /// query the reply message name
  81.         std::string getReplyName() const { return mReplyName; }
  82.         /**
  83.          * Override this method to build the LLMessageSystem message we should
  84.          * send instead of the requested capability message. DO NOT send that
  85.          * message: that will be handled by the caller.
  86.          */
  87.         virtual void buildMessage(LLMessageSystem* messageSystem,
  88.                                   const LLUUID& agentID,
  89.                                   const LLUUID& sessionID,
  90.                                   const std::string& capabilityName,
  91.                                   const LLSD& payload) const = 0;
  92.         /**
  93.          * Override this method if you pass a non-empty @a reply
  94.          * LLMessageSystem message name to the constructor: that is, if you
  95.          * expect to receive an LLMessageSystem message in response to the
  96.          * message you constructed in buildMessage(). If you don't pass a @a
  97.          * reply message name, you need not override this method as it won't
  98.          * be called.
  99.          *
  100.          * Using LLMessageSystem message-reading operations, your
  101.          * readResponse() override should construct and return an LLSD object
  102.          * of the form you expect to receive from the real implementation of
  103.          * the capability you intend to invoke, when it finally goes live.
  104.          */
  105.         virtual LLSD readResponse(LLMessageSystem* messageSystem) const;
  106.     private:
  107.         const std::string mCapName;
  108.         const std::string mReplyName;
  109.     };
  110. private:
  111.     /// Bind the LLCapabilityProvider passed to our ctor
  112.     const LLCapabilityProvider& mProvider;
  113.     /// Post an event to this LLEventPump to invoke a capability message on
  114.     /// the bound LLCapabilityProvider's server
  115.     /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
  116.     LLEventStream mEventPump;
  117.     LLMessageSystem* mMessageSystem;
  118.     LLUUID mAgentID, mSessionID;
  119.     /// listener to process capability requests
  120.     bool capListener(const LLSD&);
  121.     /// helper class for capListener()
  122.     class CapabilityMappers;
  123. };
  124. #endif /* ! defined(LL_LLCAPABILITYLISTENER_H) */