llplugininstance.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @file llplugininstance.h
  3. * @brief LLPluginInstance handles loading the dynamic library of a plugin and setting up its entry points for message passing.
  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. #ifndef LL_LLPLUGININSTANCE_H
  33. #define LL_LLPLUGININSTANCE_H
  34. #include "llapr.h"
  35. #include "llstring.h"
  36. #include "apr_dso.h"
  37. // LLPluginInstanceMessageListener receives messages sent from the plugin
  38. // loader shell to the plugin.
  39. class LLPluginInstanceMessageListener
  40. {
  41. public:
  42. virtual ~LLPluginInstanceMessageListener() {}
  43. // Plugin receives message from plugin loader shell.
  44. virtual void receivePluginMessage(const std::string& message) = 0;
  45. };
  46. // LLPluginInstance handles loading the dynamic library of a plugin and setting
  47. // up its entry points for message passing.
  48. class LLPluginInstance
  49. {
  50. protected:
  51. LOG_CLASS(LLPluginInstance);
  52. public:
  53. LLPluginInstance(LLPluginInstanceMessageListener* owner);
  54. virtual ~LLPluginInstance();
  55. // Loads a plugin dll/dylib/so
  56. // Returns 0 if successful, APR error code or error code returned from
  57. // the plugin's init function on failure.
  58. int load(const std::string& plugin_dir, const std::string& plugin_file);
  59. // Sends a message to the plugin.
  60. void sendMessage(const std::string &message);
  61. // The signature of the method for sending a message from plugin to plugin
  62. // loader shell. 'message' is a nul-terminated C string and 'data' is the
  63. // opaque reference that the callee supplied during setup.
  64. typedef void (*sendMessageFunction) (const char* message, void** data);
  65. // The signature of the plugin init function. *TODO: check direction
  66. // (pluging loader shell to plugin ?)
  67. // 'host_user_data' is the data from plugin loader shell.
  68. // 'plugin_send_function' is the method for sending from the plugin loader
  69. // shell to plugin.
  70. typedef int (*pluginInitFunction)(sendMessageFunction host_send_func,
  71. void* host_user_data,
  72. sendMessageFunction* plugin_send_func,
  73. void** plugin_user_data);
  74. private:
  75. static void staticReceiveMessage(const char* message, void** data);
  76. void receiveMessage(const char* message);
  77. public:
  78. // Name of plugin init function
  79. static const char* PLUGIN_INIT_FUNCTION_NAME;
  80. private:
  81. LLPluginInstanceMessageListener* mOwner;
  82. apr_dso_handle_t* mDSOHandle;
  83. void* mPluginUserData;
  84. sendMessageFunction mPluginSendMessageFunction;
  85. };
  86. #endif // LL_LLPLUGININSTANCE_H