PageRenderTime 659ms CodeModel.GetById 240ms app.highlight 8ms RepoModel.GetById 195ms app.codeStats 1ms

/indra/llplugin/llplugininstance.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 99 lines | 32 code | 16 blank | 51 comment | 0 complexity | 75e12441c33143db20333cec1e04f9c4 MD5 | raw file
 1/** 
 2 * @file llplugininstance.h
 3 *
 4 * @cond
 5 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 * @endcond
26 */
27
28#ifndef LL_LLPLUGININSTANCE_H
29#define LL_LLPLUGININSTANCE_H
30
31#include "llstring.h"
32#include "llapr.h"
33
34#include "apr_dso.h"
35
36/**
37 * @brief LLPluginInstanceMessageListener receives messages sent from the plugin loader shell to the plugin.
38 */
39class LLPluginInstanceMessageListener
40{
41public:
42	virtual ~LLPluginInstanceMessageListener();
43   /** Plugin receives message from plugin loader shell. */
44	virtual void receivePluginMessage(const std::string &message) = 0;
45};
46
47/**
48 * @brief LLPluginInstance handles loading the dynamic library of a plugin and setting up its entry points for message passing.
49 */
50class LLPluginInstance
51{
52	LOG_CLASS(LLPluginInstance);
53public:
54	LLPluginInstance(LLPluginInstanceMessageListener *owner);
55	virtual ~LLPluginInstance();
56	
57	// Load a plugin dll/dylib/so
58	// Returns 0 if successful, APR error code or error code returned from the plugin's init function on failure.
59	int load(const std::string& plugin_dir, std::string &plugin_file);
60	
61	// Sends a message to the plugin.
62	void sendMessage(const std::string &message);
63	
64   // TODO:DOC is this comment obsolete? can't find "send_count" anywhere in indra tree.
65	// send_count is the maximum number of message to process from the send queue.  If negative, it will drain the queue completely.
66	// The receive queue is always drained completely.
67	// Returns the total number of messages processed from both queues.
68	void idle(void);
69	
70	/** The signature of the function for sending a message from plugin to plugin loader shell.
71    *
72	 * @param[in] message_string Null-terminated C string 
73    * @param[in] user_data The opaque reference that the callee supplied during setup.
74    */
75	typedef void (*sendMessageFunction) (const char *message_string, void **user_data);
76
77	/** The signature of the plugin init function. TODO:DOC check direction (pluging loader shell to plugin?)
78    *
79    * @param[in] host_user_data Data from plugin loader shell.
80    * @param[in] plugin_send_function Function for sending from the plugin loader shell to plugin.
81    */
82	typedef int (*pluginInitFunction) (sendMessageFunction host_send_func, void *host_user_data, sendMessageFunction *plugin_send_func, void **plugin_user_data);
83	
84   /** Name of plugin init function */
85	static const char *PLUGIN_INIT_FUNCTION_NAME;
86	
87private:
88	static void staticReceiveMessage(const char *message_string, void **user_data);
89	void receiveMessage(const char *message_string);
90
91	apr_dso_handle_t *mDSOHandle;
92	
93	void *mPluginUserData;
94	sendMessageFunction mPluginSendMessageFunction;
95	
96	LLPluginInstanceMessageListener *mOwner;
97};
98
99#endif // LL_LLPLUGININSTANCE_H