Split plugin classes and derive AIFilePicker from BasicPluginBase (part 4).

Add back fixes that were in Singularity (in indra/media_plugins) but not
in imprudence.

Also:

Add "shutdown" plugin message and terminate file picker plugins cleanly.

The DSO (libbasic_plugin_filepicker.so) now tells the child process /
plugin loader (SLPlugin) to terminate (using the 'shutdown' message),
and AIFilePicker::finish_impl destroys the plugin object on the viewer
side when it's ... finished thus.

Also added a large comment that gives an overview of all classes
involved on the viewer side.

Additional fixes for filepicker.

Plugin refactor bug fix: mDeleteMe was uninitialized in AIPluginFilePicker.
This commit is contained in:
Aleric Inglewood
2011-05-06 16:29:43 +02:00
parent 16cd4c5c4b
commit c46c86ca4b
21 changed files with 129 additions and 55 deletions

View File

@@ -113,6 +113,9 @@ protected:
// Inherited from LLPluginProcessParentOwner.
/*virtual*/ void receivePluginMessage(LLPluginMessage const&);
// Inherited from LLPluginProcessParentOwner.
/*virtual*/ void receivedShutdown() { mPlugin->exitState(); }
//--------------------------------------
// Debug use only
//

View File

@@ -553,6 +553,15 @@ void LLPluginProcessChild::receivePluginMessage(const std::string &message)
}
}
}
else if (message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
{
std::string message_name = parsed.getName();
if(message_name == "shutdown")
{
// The plugin is finished.
setState(STATE_UNLOADING);
}
}
}
if(passMessage)

View File

@@ -88,7 +88,7 @@ private:
STATE_PLUGIN_LOADED, // plugin library has been loaded
STATE_PLUGIN_INITIALIZING, // plugin is processing init message
STATE_RUNNING, // steady state (processing messages)
STATE_UNLOADING, // plugin has sent shutdown_response and needs to be unloaded
STATE_UNLOADING, // plugin has sent shutdown and needs to be unloaded
STATE_UNLOADED, // plugin has been unloaded
STATE_ERROR, // generic bailout state
STATE_DONE // state machine will sit in this state after either error or normal termination.

View File

@@ -1001,6 +1001,11 @@ void LLPluginProcessParent::receiveMessage(const LLPluginMessage &message)
LL_DEBUGS("Plugin") << "cpu usage reported as " << mCPUUsage << LL_ENDL;
}
else if(message_name == "shutdown")
{
LL_INFOS("Plugin") << "received shutdown message" << LL_ENDL;
mOwner->receivedShutdown();
}
else if(message_name == "shm_add_response")
{
// Nothing to do here.

View File

@@ -53,6 +53,7 @@ public:
virtual ~LLPluginProcessParentOwner();
virtual void receivePluginMessage(const LLPluginMessage &message) = 0;
virtual bool receivePluginMessageEarly(const LLPluginMessage &message) {return false;};
virtual void receivedShutdown() = 0;
// This will only be called when the plugin has died unexpectedly
virtual void pluginLaunchFailed() {};
virtual void pluginDied() {};
@@ -88,6 +89,9 @@ public:
// Go to the proper error state
void errorState(void);
// Go to exit state.
void exitState(void) { setState(STATE_EXITING); }
void setSleepTime(F64 sleep_time, bool force_send = false);
F64 getSleepTime(void) const { return mSleepTime; };

View File

@@ -4031,7 +4031,7 @@ void LLViewerWindow::saveImageNumbered(LLPointer<LLImageFormatted> image)
void LLViewerWindow::saveImageNumbered_filepicker_callback(LLPointer<LLImageFormatted> image, std::string const& extension, AIFilePicker* filepicker, bool success)
{
llassert((bool)*filepicker == success);
if (success)
if (success && !filepicker->isCanceled())
{
// Copy the directory + file name
std::string filepath = filepicker->getFilename();
@@ -4041,7 +4041,7 @@ void LLViewerWindow::saveImageNumbered_filepicker_callback(LLPointer<LLImageForm
saveImageNumbered_continued(image, extension);
}
delete filepicker;
filepicker->deleteMe();
}
void LLViewerWindow::saveImageNumbered_continued(LLPointer<LLImageFormatted> image, std::string const& extension)

View File

@@ -314,7 +314,11 @@ void AIFilePicker::abort_impl(void)
void AIFilePicker::finish_impl(void)
{
mPluginManager = NULL; // This deletes the plugin, since mPluginManager is a LLPointer.
if (mPluginManager)
{
mPluginManager->destroyPlugin();
mPluginManager = NULL;
}
mFilter.clear(); // Check that open is called before calling run (again).
}

View File

@@ -67,6 +67,56 @@ enum ESaveFilter
FFSAVE_LSL
};
/*
AIFilePicker is an AIStateMachine, that has a LLViewerPluginManager (mPluginManager)
to manage a plugin that runs the actual filepicker in a separate process.
The relationship with the plugin is as follows:
new AIFilePicker
AIFilePicker::mPluginManager = new LLViewerPluginManager
LLPluginProcessParentOwner LLPluginMessagePipeOwner
| | LLPluginMessagePipeOwner::mOwner = LLPluginProcessParentOwner
| | LLPluginMessagePipeOwner::mMessagePipe = LLPluginMessagePipe
| | LLPluginMessagePipeOwner::receiveMessageRaw calls
v | LLPluginProcessParent::receiveMessageRaw
LLPluginClassBasic v
| LLPluginClassBasic::mPlugin = new LLPluginProcessParent ---> new LLPluginMessagePipe
| LLPluginProcessParent::mOwner = (LLPluginProcessParentOwner*)LLPluginClassBasic
| LLPluginProcessParent::sendMessage calls
| LLPluginMessagePipeOwner::writeMessageRaw calls
| mMessagePipe->LLPluginMessagePipe::addMessage
| LLPluginProcessParent::receiveMessageRaw calls
| LLPluginProcessParent::receiveMessage calls
| LLPluginProcessParentOwner::receivePluginMessage == AIPluginFilePicker::receivePluginMessage
|
| LLPluginClassBasic::sendMessage calls mPlugin->LLPluginProcessParent::sendMessage
|
v
LLViewerPluginManager::mPluginBase = new AIPluginFilePicker
AIPluginFilePicker::receivePluginMessage calls
AIFilePicker::receivePluginMessage
AIPluginFilePicker::mStateMachine = AIFilePicker
Where the entry point to send messages to the plugin is LLPluginClassBasic::sendMessage,
and the end point for messages received from the plugin is AIFilePicker::receivePluginMessage.
Termination happens by receiving the "canceled" or "done" message,
which sets the state to AIFilePicker_canceled or AIFilePicker_done
respectively, causing a call to AIStateMachine::finish(), which calls
AIFilePicker::finish_impl which destroys the plugin (mPluginBase)
and the plugin manager (mPluginManager).
AIStateMachine::finish() also calls the registered callback function,
which should call AIStateMachine::deleteMe(), causing the AIFilePicker
to be deleted.
*/
// A file picker state machine.
//
// Before calling run(), call open() to pass needed parameters.
@@ -151,7 +201,8 @@ public:
static std::string launcher_name(void) { return gDirUtilp->getLLPluginLauncher(); }
static char const* plugin_basename(void) { return "basic_plugin_filepicker"; }
/*virtual*/ void receivePluginMessage(LLPluginMessage const& message) { mStateMachine->receivePluginMessage(message); }
/*virtual*/ void receivePluginMessage(LLPluginMessage const& message) { mStateMachine->receivePluginMessage(message); }
/*virtual*/ void receivedShutdown(void) { /* Nothing -- we terminate on deletion (from AIStateMachine::mainloop) */ }
private:
AIFilePicker* mStateMachine;

View File

@@ -46,10 +46,9 @@
///
/// @param[in] send_message_function Function for sending messages from plugin to plugin loader shell
/// @param[in] plugin_instance Message data for messages from plugin to plugin loader shell
BasicPluginBase::BasicPluginBase(LLPluginInstance::sendMessageFunction send_message_function, LLPluginInstance* plugin_instance)
BasicPluginBase::BasicPluginBase(LLPluginInstance::sendMessageFunction send_message_function, LLPluginInstance* plugin_instance) :
mPluginInstance(plugin_instance), mSendMessageFunction(send_message_function), mDeleteMe(false)
{
mSendMessageFunction = send_message_function;
mPluginInstance = plugin_instance;
}
/**
@@ -79,6 +78,12 @@ void BasicPluginBase::staticReceiveMessage(char const* message_string, BasicPlug
// This is the loaded DSO.
//
// Call this function to send 'message' to the viewer.
// Note: mSendMessageFunction points to LLPluginInstance::staticReceiveMessage, so indirectly this
// just calls LLPluginInstance::receiveMessage (mPluginInstance->receiveMessage) where
// mPluginInstance is the LLPluginInstance created in LLPluginProcessChild::idle during
// state STATE_PLUGIN_LOADING. That function then immediately calls mOwner->receivePluginMessage
// which is implemented as LLPluginProcessChild::receivePluginMessage, the same
// LLPluginProcessChild object that created the LLPluginInstance.
/**
* Send message to plugin loader shell.
*
@@ -91,6 +96,17 @@ void BasicPluginBase::sendMessage(const LLPluginMessage &message)
mSendMessageFunction(output.c_str(), &mPluginInstance);
}
/**
* Send shutdown message to the plugin loader shell.
*
* This will cause the SLPlugin process that loaded this DSO to be terminated.
*/
void BasicPluginBase::sendShutdownMessage(void)
{
LLPluginMessage shutdownmessage(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shutdown");
sendMessage(shutdownmessage);
}
#if LL_WINDOWS
# define LLSYMEXPORT __declspec(dllexport)
#elif LL_LINUX

View File

@@ -57,6 +57,9 @@ public:
// This function is actually called and then calls the member function above.
static void staticReceiveMessage(char const* message_string, BasicPluginBase** self_ptr);
// Shoot down the whole process.
void sendShutdownMessage(void);
protected:
void sendMessage(LLPluginMessage const& message);

View File

@@ -49,7 +49,6 @@
MediaPluginBase::MediaPluginBase(LLPluginInstance::sendMessageFunction send_message_function, LLPluginInstance* plugin_instance)
: BasicPluginBase(send_message_function, plugin_instance)
{
mDeleteMe = false;
mPixels = 0;
mWidth = 0;
mHeight = 0;

View File

@@ -17,13 +17,13 @@ include_directories(
### basic_plugin_example
if(NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
if(NOT WORD_SIZE EQUAL 32)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
endif (NOT WORD_SIZE EQUAL 32)
set(basic_plugin_example_SOURCE_FILES
basic_plugin_example.cpp

View File

@@ -28,13 +28,13 @@ include_directories(
### media_plugin_example
if(NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
if(NOT WORD_SIZE EQUAL 32)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
endif (NOT WORD_SIZE EQUAL 32)
set(media_plugin_example_SOURCE_FILES
media_plugin_example.cpp

View File

@@ -19,13 +19,13 @@ include_directories(
### basic_plugin_filepicker
if(NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
if(NOT WORD_SIZE EQUAL 32)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (NOT CMAKE_SIZEOF_VOID_P MATCHES 4)
endif (NOT WORD_SIZE EQUAL 32)
set(basic_plugin_filepicker_SOURCE_FILES
basic_plugin_filepicker.cpp

View File

@@ -150,6 +150,10 @@ void FilepickerPlugin::receiveMessage(char const* message_string)
message.setValue("plugin_version", plugin_version);
sendMessage(message);
}
else if (message_name == "cleanup")
{
// We have no resources that need care. Just do nothing.
}
else if (message_name == "idle")
{
// This whole message should not have existed imho -- Aleric
@@ -213,6 +217,8 @@ void FilepickerPlugin::receiveMessage(char const* message_string)
message.setValueLLSD("filenames", filenames);
sendMessage(message);
}
// We're done. Exit the whole application.
sendShutdownMessage();
}
else
{

View File

@@ -1048,7 +1048,7 @@ void LLFilePickerBase::chooser_responder(GtkWidget *widget, gint response, gpoin
if (response == GTK_RESPONSE_ACCEPT)
{
GSList *file_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget));
g_slist_foreach(file_list, (GFunc)add_to_selectedfiles, user_data);
g_slist_foreach(file_list, (GFunc)add_to_selectedfiles, picker);
g_slist_foreach(file_list, (GFunc)g_free, NULL);
g_slist_free (file_list);
}

View File

@@ -652,7 +652,7 @@ bool
MediaPluginGStreamer010::getTimePos(double &sec_out)
{
bool got_position = false;
if (mPlaybin)
if (mDoneInit && mPlaybin)
{
gint64 pos;
GstFormat timefmt = GST_FORMAT_TIME;

View File

@@ -40,6 +40,10 @@
#if defined(LL_DARWIN)
#include <QuickTime/QuickTime.h>
#elif defined(LL_WINDOWS)
#undef __STDC_CONSTANT_MACROS //Needed, as boost/unordered_map.hpp already defines INT32_C, etc.
#if defined(_MSC_VER) && _MSC_VER >= 1600
#define _STDINT_H //Visual Studio 2010 includes its own stdint header already
#endif
#include "MacTypes.h"
#include "QTML.h"
#include "Movies.h"

View File

@@ -51,9 +51,9 @@ set(media_plugin_webkit_LINK_LIBRARIES
# Select which VolumeCatcher implementation to use
if (LINUX)
if (PULSEAUDIO)
if (PULSEAUDIO_FOUND)
list(APPEND media_plugin_webkit_SOURCE_FILES linux_volume_catcher.cpp)
endif (PULSEAUDIO)
endif (PULSEAUDIO_FOUND)
list(APPEND media_plugin_webkit_LINK_LIBRARIES
${UI_LIBRARIES} # for glib/GTK
)

View File

@@ -42,9 +42,8 @@
5) Keep a list of all living audio players that we care about, adjust the volumes of all of them when we get a new setVolume() call
*/
# include <set> //imprudence
#include "linden_common.h"
# include <set>
#include "volume_catcher.h"

View File

@@ -79,20 +79,6 @@ extern "C" {
}
#endif
#ifdef LL_STANDALONE
#include <qglobal.h>
#elif defined(LL_LINUX)
// We don't provide Qt headers for non-standalone, therefore define this here.
// Our prebuilt is built with QT_NAMESPACE undefined.
#define QT_MANGLE_NAMESPACE(name) name
#define Q_INIT_RESOURCE(name) \
do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); \
QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (0)
#else
// Apparently this symbol doesn't exist in the windows and Mac tar balls provided by LL.
#define Q_INIT_RESOURCE(name) /*nothing*/
#endif
////////////////////////////////////////////////////////////////////////////////
//
class MediaPluginWebKit :
@@ -138,6 +124,7 @@ private:
F32 mBackgroundR;
F32 mBackgroundG;
F32 mBackgroundB;
std::string mTarget;
VolumeCatcher mVolumeCatcher;
@@ -326,11 +313,7 @@ private:
LLQtWebKit::getInstance()->enableJavascript( mJavascriptEnabled );
// create single browser window
#if LLQTWEBKIT_API_VERSION >= 2
mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow(mWidth, mHeight /*, mTarget*/ ); // We don't have mTarget yet.
#else
mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow( mWidth, mHeight );
#endif
mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow(mWidth, mHeight, mTarget);
// tell LLQtWebKit about the size of the browser window
LLQtWebKit::getInstance()->setSize( mBrowserWindowId, mWidth, mHeight );
@@ -537,16 +520,9 @@ private:
void onClickLinkHref(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_href");
#if LLQTWEBKIT_API_VERSION >= 2
message.setValue("uri", event.getEventUri());
message.setValue("target", event.getStringValue());
message.setValue("uuid", event.getStringValue2());
#else
// This will work as long as we don't need "uuid", which will be needed for MoaP.
message.setValue("uri", event.getStringValue());
message.setValue("target", event.getStringValue2());
message.setValueU32("target_type", event.getLinkType());
#endif
sendMessage(message);
}
@@ -555,11 +531,7 @@ private:
void onClickLinkNoFollow(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_nofollow");
#if LLQTWEBKIT_API_VERSION >= 2
message.setValue("uri", event.getEventUri());
#else
message.setValue("uri", event.getStringValue());
#endif
sendMessage(message);
}
@@ -744,9 +716,6 @@ MediaPluginWebKit::MediaPluginWebKit(LLPluginInstance::sendMessageFunction send_
mJavascriptEnabled = true; // default to on
mPluginsEnabled = true; // default to on
mUserAgent = "LLPluginMedia Web Browser";
// Initialize WebCore resource.
Q_INIT_RESOURCE(WebCore);
}
MediaPluginWebKit::~MediaPluginWebKit()
@@ -773,6 +742,8 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
{
if(message_name == "init")
{
mTarget = message_in.getValue("target");
LLPluginMessage message("base", "init_response");
LLSD versions = LLSD::emptyMap();
versions[LLPLUGIN_MESSAGE_CLASS_BASE] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION;
@@ -1082,7 +1053,7 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown media message: " << message_string << std::endl;
};
}
}
else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER)
{