PageRenderTime 553ms CodeModel.GetById 300ms app.highlight 5ms RepoModel.GetById 247ms app.codeStats 0ms

/indra/llplugin/llpluginmessagepipe.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 95 lines | 44 code | 16 blank | 35 comment | 0 complexity | 5ed1debe0b4b197b908f1b7e16eb3002 MD5 | raw file
 1/** 
 2 * @file llpluginmessagepipe.h
 3 * @brief Classes that implement connections from the plugin system to pipes/pumps.
 4 *
 5 * @cond
 6 * $LicenseInfo:firstyear=2008&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 * @endcond
27 */
28
29#ifndef LL_LLPLUGINMESSAGEPIPE_H
30#define LL_LLPLUGINMESSAGEPIPE_H
31
32#include "lliosocket.h"
33#include "llthread.h"
34
35class LLPluginMessagePipe;
36
37// Inherit from this to be able to receive messages from the LLPluginMessagePipe
38class LLPluginMessagePipeOwner
39{
40	LOG_CLASS(LLPluginMessagePipeOwner);
41public:
42	LLPluginMessagePipeOwner();
43	virtual ~LLPluginMessagePipeOwner();
44
45	// called with incoming messages
46	virtual void receiveMessageRaw(const std::string &message) = 0;
47	// called when the socket has an error
48	virtual apr_status_t socketError(apr_status_t error);
49
50	// called from LLPluginMessagePipe to manage the connection with LLPluginMessagePipeOwner -- do not use!
51	virtual void setMessagePipe(LLPluginMessagePipe *message_pipe);
52
53protected:
54	// returns false if writeMessageRaw() would drop the message
55	bool canSendMessage(void);
56	// call this to send a message over the pipe
57	bool writeMessageRaw(const std::string &message);
58	// call this to close the pipe
59	void killMessagePipe(void);
60	
61	LLPluginMessagePipe *mMessagePipe;
62	apr_status_t mSocketError;
63};
64
65class LLPluginMessagePipe
66{
67	LOG_CLASS(LLPluginMessagePipe);
68public:
69	LLPluginMessagePipe(LLPluginMessagePipeOwner *owner, LLSocket::ptr_t socket);
70	virtual ~LLPluginMessagePipe();
71	
72	bool addMessage(const std::string &message);
73	void clearOwner(void);
74	
75	bool pump(F64 timeout = 0.0f);
76	bool pumpOutput();
77	bool pumpInput(F64 timeout = 0.0f);
78		
79protected:	
80	void processInput(void);
81
82	// used internally by pump()
83	void setSocketTimeout(apr_interval_time_t timeout_usec);
84	
85	LLMutex mInputMutex;
86	std::string mInput;
87	LLMutex mOutputMutex;
88	std::string mOutput;
89	std::string::size_type mOutputStartIndex;
90
91	LLPluginMessagePipeOwner *mOwner;
92	LLSocket::ptr_t mSocket;
93};
94
95#endif // LL_LLPLUGINMESSAGE_H