PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llplugin/llpluginmessage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 137 lines | 53 code | 28 blank | 56 comment | 0 complexity | 8b9d0a7d8054ec4f8eaa555a37381b42 MD5 | raw file
  1/** 
  2 * @file llpluginmessage.h
  3 *
  4 * @cond
  5 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 * @endcond
 26 */
 27
 28#ifndef LL_LLPLUGINMESSAGE_H
 29#define LL_LLPLUGINMESSAGE_H
 30
 31#include "llsd.h"
 32
 33/**
 34 * @brief LLPluginMessage encapsulates the serialization/deserialization of messages passed to and from plugins.
 35 */
 36class LLPluginMessage
 37{
 38	LOG_CLASS(LLPluginMessage);
 39public:
 40	LLPluginMessage();
 41	LLPluginMessage(const LLPluginMessage &p);
 42	LLPluginMessage(const std::string &message_class, const std::string &message_name);
 43	~LLPluginMessage();
 44	
 45	// reset all internal state
 46	void clear(void);
 47	
 48	// Sets the message class and name
 49	// Also has the side-effect of clearing any key/value pairs in the message.
 50	void setMessage(const std::string &message_class, const std::string &message_name);
 51	
 52	// Sets a key/value pair in the message
 53	void setValue(const std::string &key, const std::string &value);
 54	void setValueLLSD(const std::string &key, const LLSD &value);
 55	void setValueS32(const std::string &key, S32 value);
 56	void setValueU32(const std::string &key, U32 value);
 57	void setValueBoolean(const std::string &key, bool value);
 58	void setValueReal(const std::string &key, F64 value);
 59	void setValuePointer(const std::string &key, void *value);
 60	
 61	std::string getClass(void) const;
 62	std::string getName(void) const;
 63	
 64	// Returns true if the specified key exists in this message (useful for optional parameters)
 65	bool hasValue(const std::string &key) const;
 66	
 67	// get the value of a particular key as a string.  If the key doesn't exist in the message, an empty string will be returned.
 68	std::string getValue(const std::string &key) const;
 69
 70	// get the value of a particular key as LLSD.  If the key doesn't exist in the message, a null LLSD will be returned.
 71	LLSD getValueLLSD(const std::string &key) const;
 72	
 73	// get the value of a key as a S32.  If the value wasn't set as a S32, behavior is undefined.
 74	S32 getValueS32(const std::string &key) const;
 75	
 76	// get the value of a key as a U32.  Since there isn't an LLSD type for this, we use a hexadecimal string instead.
 77	U32 getValueU32(const std::string &key) const;
 78
 79	// get the value of a key as a Boolean.
 80	bool getValueBoolean(const std::string &key) const;
 81
 82	// get the value of a key as a float.
 83	F64 getValueReal(const std::string &key) const;
 84
 85	// get the value of a key as a pointer.
 86	void* getValuePointer(const std::string &key) const;
 87
 88	// Flatten the message into a string
 89	std::string generate(void) const;
 90
 91	// Parse an incoming message into component parts
 92	// (this clears out all existing state before starting the parse)
 93	// Returns -1 on failure, otherwise returns the number of key/value pairs in the message.
 94	int parse(const std::string &message);
 95	
 96	
 97private:
 98	
 99	LLSD mMessage;
100
101};
102
103/**
104 * @brief Listener for plugin messages.
105 */
106class LLPluginMessageListener
107{
108public:
109	virtual ~LLPluginMessageListener();
110   /** Plugin receives message from plugin loader shell. */
111	virtual void receivePluginMessage(const LLPluginMessage &message) = 0;
112	
113};
114
115/**
116 * @brief Dispatcher for plugin messages.
117 *
118 * Manages the set of plugin message listeners and distributes messages to plugin message listeners.
119 */
120class LLPluginMessageDispatcher
121{
122public:
123	virtual ~LLPluginMessageDispatcher();
124	
125	void addPluginMessageListener(LLPluginMessageListener *);
126	void removePluginMessageListener(LLPluginMessageListener *);
127protected:
128	void dispatchPluginMessage(const LLPluginMessage &message);
129
130   /** A set of message listeners. */
131	typedef std::set<LLPluginMessageListener*> listener_set_t;
132   /** The set of message listeners. */
133	listener_set_t mListeners;
134};
135
136
137#endif // LL_LLPLUGINMESSAGE_H