PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llplugin/llpluginprocesschild.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 113 lines | 59 code | 23 blank | 31 comment | 0 complexity | 162db347c6f2c534d0d46c715031b8b0 MD5 | raw file
  1/** 
  2 * @file llpluginprocesschild.h
  3 * @brief LLPluginProcessChild handles the child side of the external-process plugin API. 
  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_LLPLUGINPROCESSCHILD_H
 30#define LL_LLPLUGINPROCESSCHILD_H
 31
 32#include "llpluginmessage.h"
 33#include "llpluginmessagepipe.h"
 34#include "llplugininstance.h"
 35#include "llhost.h"
 36#include "llpluginsharedmemory.h"
 37
 38class LLPluginInstance;
 39
 40class LLPluginProcessChild: public LLPluginMessagePipeOwner, public LLPluginInstanceMessageListener
 41{
 42	LOG_CLASS(LLPluginProcessChild);
 43public:
 44	LLPluginProcessChild();
 45	~LLPluginProcessChild();
 46
 47	void init(U32 launcher_port);
 48	void idle(void);
 49	void sleep(F64 seconds);
 50	void pump();
 51
 52	// returns true if the plugin is in the steady state (processing messages)
 53	bool isRunning(void);
 54	
 55	// returns true if the plugin is unloaded or we're in an unrecoverable error state.	
 56	bool isDone(void);
 57	
 58	void killSockets(void);
 59
 60	F64 getSleepTime(void) const { return mSleepTime; };
 61	
 62	void sendMessageToPlugin(const LLPluginMessage &message);
 63	void sendMessageToParent(const LLPluginMessage &message);
 64	
 65	// Inherited from LLPluginMessagePipeOwner
 66	/* virtual */ void receiveMessageRaw(const std::string &message);
 67
 68	// Inherited from LLPluginInstanceMessageListener
 69	/* virtual */ void receivePluginMessage(const std::string &message);
 70	
 71private:
 72
 73	enum EState
 74	{
 75		STATE_UNINITIALIZED,
 76		STATE_INITIALIZED,			// init() has been called
 77		STATE_CONNECTED,			// connected back to launcher
 78		STATE_PLUGIN_LOADING,		// plugin library needs to be loaded
 79		STATE_PLUGIN_LOADED,		// plugin library has been loaded
 80		STATE_PLUGIN_INITIALIZING,	// plugin is processing init message
 81		STATE_RUNNING,				// steady state (processing messages)
 82		STATE_UNLOADING,			// plugin has sent shutdown_response and needs to be unloaded
 83		STATE_UNLOADED,				// plugin has been unloaded
 84		STATE_ERROR,				// generic bailout state
 85		STATE_DONE					// state machine will sit in this state after either error or normal termination.
 86	};
 87	void setState(EState state);
 88
 89	EState mState;
 90	
 91	LLHost mLauncherHost;
 92	LLSocket::ptr_t mSocket;
 93	
 94	std::string mPluginFile;
 95	std::string mPluginDir;
 96
 97	LLPluginInstance *mInstance;
 98
 99	typedef std::map<std::string, LLPluginSharedMemory*> sharedMemoryRegionsType;
100	sharedMemoryRegionsType mSharedMemoryRegions;
101	
102	LLTimer mHeartbeat;
103	F64		mSleepTime;
104	F64		mCPUElapsed;
105	bool	mBlockingRequest;
106	bool	mBlockingResponseReceived;
107	std::queue<std::string> mMessageQueue;
108	
109	void deliverQueuedMessages();
110	
111};
112
113#endif // LL_LLPLUGINPROCESSCHILD_H