PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 29#if ! defined(LL_LLCAPABILITYLISTENER_H)
 30#define LL_LLCAPABILITYLISTENER_H
 31
 32#include "llevents.h"               // LLEventPump
 33#include "llsdmessage.h"            // LLSDMessage::ArgError
 34#include "llerror.h"                // LOG_CLASS()
 35
 36class LLCapabilityProvider;
 37class LLMessageSystem;
 38class LLSD;
 39
 40class LLCapabilityListener
 41{
 42    LOG_CLASS(LLCapabilityListener);
 43public:
 44    LLCapabilityListener(const std::string& name, LLMessageSystem* messageSystem,
 45                         const LLCapabilityProvider& provider,
 46                         const LLUUID& agentID, const LLUUID& sessionID);
 47
 48    /// Capability-request exception
 49    typedef LLSDMessage::ArgError ArgError;
 50    /// Get LLEventPump on which we listen for capability requests
 51    /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
 52    LLEventPump& getCapAPI() { return mEventPump; }
 53
 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
107    private:
108        const std::string mCapName;
109        const std::string mReplyName;
110    };
111
112private:
113    /// Bind the LLCapabilityProvider passed to our ctor
114    const LLCapabilityProvider& mProvider;
115
116    /// Post an event to this LLEventPump to invoke a capability message on
117    /// the bound LLCapabilityProvider's server
118    /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
119    LLEventStream mEventPump;
120
121    LLMessageSystem* mMessageSystem;
122    LLUUID mAgentID, mSessionID;
123
124    /// listener to process capability requests
125    bool capListener(const LLSD&);
126
127    /// helper class for capListener()
128    class CapabilityMappers;
129};
130
131#endif /* ! defined(LL_LLCAPABILITYLISTENER_H) */