PageRenderTime 41ms CodeModel.GetById 18ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/llpipeutil.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 163 lines | 92 code | 25 blank | 46 comment | 0 complexity | cdac9994c913b72d2370b3f00f1bb3ae MD5 | raw file
  1/** 
  2 * @file llpipeutil.h
  3 * @date 2006-05-18
  4 * @brief Utility pipe fittings for injecting and extracting strings
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLPIPEUTIL_H
 29#define LL_LLPIPEUTIL_H
 30
 31#include "lliopipe.h"
 32
 33
 34/**
 35 * @brief Simple function which pumps for the specified time.
 36 */
 37F32 pump_loop(LLPumpIO* pump, F32 seconds);
 38
 39/**
 40 * @brief Simple class which writes a string and then marks the stream
 41 * as done.
 42 */
 43class LLPipeStringInjector : public LLIOPipe
 44{
 45public:
 46	LLPipeStringInjector(const std::string& string)
 47		: mString(string)
 48		{ }
 49	  
 50protected:
 51    virtual EStatus process_impl(
 52		const LLChannelDescriptors& channels,
 53		buffer_ptr_t& buffer,
 54		bool& eos,
 55		LLSD& context,
 56		LLPumpIO* pump);
 57
 58private:
 59	std::string mString;
 60};
 61
 62
 63class LLPipeStringExtractor : public LLIOPipe
 64{
 65public:
 66	LLPipeStringExtractor() : mDone(false) { }
 67	
 68	bool done() { return mDone; }
 69	std::string string() { return mString; }
 70	
 71protected:
 72	// LLIOPipe API implementation.
 73	virtual EStatus process_impl(
 74        const LLChannelDescriptors& channels,
 75        LLIOPipe::buffer_ptr_t& buffer,
 76        bool& eos,
 77        LLSD& context,
 78        LLPumpIO* pump);
 79
 80private:
 81	bool mDone;
 82	std::string mString;
 83};
 84
 85/**
 86 * @brief Generate a specified number of bytes of random data
 87 */
 88class LLIOFuzz : public LLIOPipe
 89{
 90public:
 91	LLIOFuzz(int byte_count) : mByteCount(byte_count) {}
 92	  
 93protected:
 94    virtual EStatus process_impl(
 95		const LLChannelDescriptors& channels,
 96		buffer_ptr_t& buffer,
 97		bool& eos,
 98		LLSD& context,
 99		LLPumpIO* pump);
100
101private:
102	int mByteCount;
103};
104
105/**
106 * @brief Generate some ascii fuz
107 */
108class LLIOASCIIFuzz : public LLIOPipe
109{
110public:
111	LLIOASCIIFuzz(int byte_count) : mByteCount(byte_count) {}
112	  
113protected:
114    virtual EStatus process_impl(
115		const LLChannelDescriptors& channels,
116		buffer_ptr_t& buffer,
117		bool& eos,
118		LLSD& context,
119		LLPumpIO* pump);
120
121private:
122	int mByteCount;
123};
124
125
126/**
127 * @brief Pipe that does nothing except return STATUS_OK
128 */
129class LLIONull : public LLIOPipe
130{
131public:
132	LLIONull() {}
133	  
134protected:
135    virtual EStatus process_impl(
136		const LLChannelDescriptors& channels,
137		buffer_ptr_t& buffer,
138		bool& eos,
139		LLSD& context,
140		LLPumpIO* pump);
141};
142
143/**
144 * @brief Pipe that sleeps, and then responds later.
145 */
146class LLIOSleeper : public LLIOPipe
147{
148public:
149	LLIOSleeper() : mRespond(false) {}
150	  
151protected:
152    virtual EStatus process_impl(
153		const LLChannelDescriptors& channels,
154		buffer_ptr_t& buffer,
155		bool& eos,
156		LLSD& context,
157		LLPumpIO* pump);
158private:
159	bool mRespond;
160
161};
162
163#endif // LL_LLPIPEUTIL_H