PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/lldispatcher.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 113 lines | 45 code | 14 blank | 54 comment | 0 complexity | e8a6a2456b7286f173fb5b493822c69c MD5 | raw file
  1/** 
  2 * @file lldispatcher.h
  3 * @brief LLDispatcher class header file.
  4 *
  5 * $LicenseInfo:firstyear=2004&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 */
 26
 27#ifndef LL_LLDISPATCHER_H
 28#define LL_LLDISPATCHER_H
 29
 30#include <map>
 31#include <vector>
 32#include <string>
 33
 34class LLDispatcher;
 35class LLMessageSystem;
 36class LLUUID;
 37
 38//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 39// Class LLDispatchHandler
 40//
 41// Abstract base class for handling dispatches. Derive your own
 42// classes, construct them, and add them to the dispatcher you want to
 43// use.
 44//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 45
 46class LLDispatchHandler
 47{
 48public:
 49	typedef std::vector<std::string> sparam_t;
 50	//typedef std::vector<S32> iparam_t;
 51	LLDispatchHandler() {}
 52	virtual ~LLDispatchHandler() {}
 53	virtual bool operator()(
 54		const LLDispatcher* dispatcher,
 55		const std::string& key,
 56		const LLUUID& invoice,
 57		const sparam_t& string) = 0;
 58	//const iparam_t& integers) = 0;
 59};
 60
 61//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 62// Class LLDispatcher
 63//
 64// Basic utility class that handles dispatching keyed operations to
 65// function objects implemented as LLDispatchHandler derivations.
 66//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 67class LLDispatcher
 68{
 69public:
 70	typedef std::string key_t;
 71	typedef std::vector<std::string> keys_t;
 72	typedef std::vector<std::string> sparam_t;
 73	//typedef std::vector<S32> iparam_t;
 74
 75	// construct a dispatcher.
 76	LLDispatcher();
 77	virtual ~LLDispatcher();
 78
 79	// Returns if they keyed handler exists in this dispatcher.
 80	bool isHandlerPresent(const key_t& name) const;
 81
 82	// copy all known keys onto keys_t structure
 83	void copyAllHandlerNames(keys_t& names) const;
 84
 85	// Call this method with the name of the request that has come
 86	// in. If the handler is present, it is called with the params and
 87	// returns the return value from 
 88	bool dispatch(
 89		const key_t& name,
 90		const LLUUID& invoice,
 91		const sparam_t& strings) const;
 92	//const iparam_t& itegers) const;
 93
 94	// Add a handler. If one with the same key already exists, its
 95	// pointer is returned, otherwise returns NULL. This object does
 96	// not do memory management of the LLDispatchHandler, and relies
 97	// on the caller to delete the object if necessary.
 98	LLDispatchHandler* addHandler(const key_t& name, LLDispatchHandler* func);
 99
100	// Helper method to unpack the dispatcher message bus
101	// format. Returns true on success.
102	static bool unpackMessage(
103		LLMessageSystem* msg,
104		key_t& method,
105		LLUUID& invoice,
106		sparam_t& parameters);
107
108protected:
109	typedef std::map<key_t, LLDispatchHandler*> dispatch_map_t;
110	dispatch_map_t mHandlers;
111};
112
113#endif // LL_LLDISPATCHER_H