aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llplugin/llpluginprocessparent.h
diff options
context:
space:
mode:
authorArmin Weatherwax2010-06-14 12:04:49 +0200
committerArmin Weatherwax2010-09-23 15:38:25 +0200
commit35df5441d3e2789663532c948731aff3a1e04728 (patch)
treeac7674289784a5f96106ea507637055a8dada78a /linden/indra/llplugin/llpluginprocessparent.h
parentChanged version to Experimental 2010.09.18 (diff)
downloadmeta-impy-35df5441d3e2789663532c948731aff3a1e04728.zip
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.gz
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.bz2
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.xz
llmediaplugins first step
Diffstat (limited to 'linden/indra/llplugin/llpluginprocessparent.h')
-rw-r--r--linden/indra/llplugin/llpluginprocessparent.h169
1 files changed, 169 insertions, 0 deletions
diff --git a/linden/indra/llplugin/llpluginprocessparent.h b/linden/indra/llplugin/llpluginprocessparent.h
new file mode 100644
index 0000000..00c60b5
--- /dev/null
+++ b/linden/indra/llplugin/llpluginprocessparent.h
@@ -0,0 +1,169 @@
1/**
2 * @file llpluginprocessparent.h
3 * @brief LLPluginProcessParent handles the parent side of the external-process plugin API.
4 *
5 * $LicenseInfo:firstyear=2008&license=viewergpl$
6 *
7 * Copyright (c) 2008-2009, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#ifndef LL_LLPLUGINPROCESSPARENT_H
34#define LL_LLPLUGINPROCESSPARENT_H
35
36#include "llapr.h"
37#include "llprocesslauncher.h"
38#include "llpluginmessage.h"
39#include "llpluginmessagepipe.h"
40#include "llpluginsharedmemory.h"
41
42#include "lliosocket.h"
43
44class LLPluginProcessParentOwner
45{
46public:
47 virtual ~LLPluginProcessParentOwner();
48 virtual void receivePluginMessage(const LLPluginMessage &message) = 0;
49 // This will only be called when the plugin has died unexpectedly
50 virtual void pluginLaunchFailed() {};
51 virtual void pluginDied() {};
52};
53
54class LLPluginProcessParent : public LLPluginMessagePipeOwner
55{
56 LOG_CLASS(LLPluginProcessParent);
57public:
58 LLPluginProcessParent(LLPluginProcessParentOwner *owner);
59 ~LLPluginProcessParent();
60
61 void init(const std::string &launcher_filename, const std::string &plugin_filename, bool debug, const std::string &user_data_path);
62 void idle(void);
63
64 // returns true if the plugin is on its way to steady state
65 bool isLoading(void);
66
67 // returns true if the plugin is in the steady state (processing messages)
68 bool isRunning(void);
69
70 // returns true if the process has exited or we've had a fatal error
71 bool isDone(void);
72
73 void killSockets(void);
74
75 // Go to the proper error state
76 void errorState(void);
77
78 void setSleepTime(F64 sleep_time, bool force_send = false);
79 F64 getSleepTime(void) const { return mSleepTime; };
80
81 void sendMessage(const LLPluginMessage &message);
82
83 void receiveMessage(const LLPluginMessage &message);
84
85 // Inherited from LLPluginMessagePipeOwner
86 void receiveMessageRaw(const std::string &message);
87
88 // This adds a memory segment shared with the client, generating a name for the segment. The name generated is guaranteed to be unique on the host.
89 // The caller must call removeSharedMemory first (and wait until getSharedMemorySize returns 0 for the indicated name) before re-adding a segment with the same name.
90 std::string addSharedMemory(size_t size);
91 // Negotiates for the removal of a shared memory segment. It is the caller's responsibility to ensure that nothing touches the memory
92 // after this has been called, since the segment will be unmapped shortly thereafter.
93 void removeSharedMemory(const std::string &name);
94 size_t getSharedMemorySize(const std::string &name);
95 void *getSharedMemoryAddress(const std::string &name);
96
97 // Returns the version string the plugin indicated for the message class, or an empty string if that class wasn't in the list.
98 std::string getMessageClassVersion(const std::string &message_class);
99
100 std::string getPluginVersion(void);
101
102 bool getDisableTimeout() { return mDisableTimeout; };
103 void setDisableTimeout(bool disable) { mDisableTimeout = disable; };
104
105 void setLaunchTimeout(F32 timeout) { mPluginLaunchTimeout = timeout; };
106 void setLockupTimeout(F32 timeout) { mPluginLockupTimeout = timeout; };
107
108 F64 getCPUUsage() { return mCPUUsage; };
109
110private:
111
112 enum EState
113 {
114 STATE_UNINITIALIZED,
115 STATE_INITIALIZED, // init() has been called
116 STATE_LISTENING, // listening for incoming connection
117 STATE_LAUNCHED, // process has been launched
118 STATE_CONNECTED, // process has connected
119 STATE_HELLO, // first message from the plugin process has been received
120 STATE_LOADING, // process has been asked to load the plugin
121 STATE_RUNNING, //
122 STATE_LAUNCH_FAILURE, // Failure before plugin loaded
123 STATE_ERROR, // generic bailout state
124 STATE_CLEANUP, // clean everything up
125 STATE_EXITING, // Tried to kill process, waiting for it to exit
126 STATE_DONE //
127
128 };
129 EState mState;
130 void setState(EState state);
131
132 bool pluginLockedUp();
133 bool pluginLockedUpOrQuit();
134
135 bool accept();
136
137 LLSocket::ptr_t mListenSocket;
138 LLSocket::ptr_t mSocket;
139 U32 mBoundPort;
140
141 LLProcessLauncher mProcess;
142
143 std::string mPluginFile;
144
145 std::string mUserDataPath;
146
147 LLPluginProcessParentOwner *mOwner;
148
149 typedef std::map<std::string, LLPluginSharedMemory*> sharedMemoryRegionsType;
150 sharedMemoryRegionsType mSharedMemoryRegions;
151
152 LLSD mMessageClassVersions;
153 std::string mPluginVersionString;
154
155 LLTimer mHeartbeat;
156 F64 mSleepTime;
157 F64 mCPUUsage;
158
159 bool mDisableTimeout;
160 bool mDebug;
161
162 LLProcessLauncher mDebugger;
163
164 F32 mPluginLaunchTimeout; // Somewhat longer timeout for initial launch.
165 F32 mPluginLockupTimeout; // If we don't receive a heartbeat in this many seconds, we declare the plugin locked up.
166
167};
168
169#endif // LL_LLPLUGINPROCESSPARENT_H