PageRenderTime 65ms CodeModel.GetById 59ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llchainio.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 135 lines | 47 code | 12 blank | 76 comment | 0 complexity | ac1286ded88eb50b62a94929dc760f5f MD5 | raw file
  1/** 
  2 * @file llchainio.h
  3 * @author Phoenix
  4 * @date 2005-08-04
  5 * @brief This class declares the interface for constructing io chains.
  6 *
  7 * $LicenseInfo:firstyear=2005&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#ifndef LL_LLCHAINIO_H
 30#define LL_LLCHAINIO_H
 31
 32#include "llpumpio.h"
 33
 34/** 
 35 * @class LLDeferredChain
 36 * @brief This class allows easy addition of a chain which will sleep
 37 * and then process another chain.
 38 */
 39class LLDeferredChain
 40{
 41public:
 42	/**
 43	 * @brief Add a chain to a pump in a finite # of seconds
 44	 *
 45	 * @prarm pump The pump to work on.
 46	 * @prarm in_seconds The number of seconds from now when chain should start.
 47	 * @prarm chain The chain to add in in_seconds seconds.
 48	 * @prarm chain_timeout timeout for chain on the pump.
 49	 * @return Returns true if the operation was queued.
 50	 */
 51	static bool addToPump(
 52		LLPumpIO* pump,
 53		F32 in_seconds,
 54		const LLPumpIO::chain_t& chain,
 55		F32 chain_timeout);
 56};
 57
 58/** 
 59 * @class LLChainIOFactory
 60 * @brief This class is an abstract base class for building io chains.
 61 *
 62 * This declares an abstract base class for a chain factory. The
 63 * factory is used to connect an input pipe to the first pipe in the
 64 * chain, and an output pipe to the last pipe in the chain. This will
 65 * allow easy construction for buffer based io like services to for
 66 * API centered IO while abstracting the input and output to simple
 67 * data passing.
 68 * To use this class, you should derive a class which implements the
 69 * <code>build</code> method.
 70 */
 71class LLChainIOFactory
 72{
 73public:
 74	// Constructor
 75	LLChainIOFactory();
 76
 77	// Destructor
 78	virtual ~LLChainIOFactory();
 79
 80	/** 
 81	 * @brief Build the chian with in as the first and end as the last
 82	 *
 83	 * The caller of the LLChainIOFactory is responsible for managing
 84	 * the memory of the in pipe. All of the chains generated by the
 85	 * factory will be ref counted as usual, so the caller will also
 86	 * need to break the links in the chain.
 87	 * @param chain The chain which will have new pipes appended
 88	 * @param context A context for use by this factory if you choose
 89	 * @retrun Returns true if the call was successful.
 90	 */
 91	virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const = 0;
 92
 93protected:
 94};
 95
 96/** 
 97 * @class LLSimpleIOFactory
 98 * @brief Basic implementation for making a factory that returns a
 99 * 'chain' of one object
100 */
101template<class Pipe>
102class LLSimpleIOFactory : public LLChainIOFactory
103{
104public:
105	virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
106	{
107		chain.push_back(LLIOPipe::ptr_t(new Pipe));
108		return true;
109	}
110};
111
112/** 
113 * @class LLCloneIOFactory
114 * @brief Implementation for a facory which copies a particular pipe.
115 */
116template<class Pipe>
117class LLCloneIOFactory : public LLChainIOFactory
118{
119public:
120	LLCloneIOFactory(Pipe* original) :
121		mHandle(original),
122		mOriginal(original) {}
123
124	virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
125	{
126		chain.push_back(LLIOPipe::ptr_t(new Pipe(*mOriginal)));
127		return true;
128	}
129
130protected:
131	LLIOPipe::ptr_t mHandle;
132	Pipe* mOriginal;
133};
134
135#endif // LL_LLCHAINIO_H