PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLPLUGININSTANCE_H
  28. #define LL_LLPLUGININSTANCE_H
  29. #include "llstring.h"
  30. #include "llapr.h"
  31. #include "apr_dso.h"
  32. /**
  33. * @brief LLPluginInstanceMessageListener receives messages sent from the plugin loader shell to the plugin.
  34. */
  35. class LLPluginInstanceMessageListener
  36. {
  37. public:
  38. virtual ~LLPluginInstanceMessageListener();
  39. /** Plugin receives message from plugin loader shell. */
  40. virtual void receivePluginMessage(const std::string &message) = 0;
  41. };
  42. /**
  43. * @brief LLPluginInstance handles loading the dynamic library of a plugin and setting up its entry points for message passing.
  44. */
  45. class LLPluginInstance
  46. {
  47. LOG_CLASS(LLPluginInstance);
  48. public:
  49. LLPluginInstance(LLPluginInstanceMessageListener *owner);
  50. virtual ~LLPluginInstance();
  51. // Load a plugin dll/dylib/so
  52. // Returns 0 if successful, APR error code or error code returned from the plugin's init function on failure.
  53. int load(const std::string& plugin_dir, std::string &plugin_file);
  54. // Sends a message to the plugin.
  55. void sendMessage(const std::string &message);
  56. // TODO:DOC is this comment obsolete? can't find "send_count" anywhere in indra tree.
  57. // send_count is the maximum number of message to process from the send queue. If negative, it will drain the queue completely.
  58. // The receive queue is always drained completely.
  59. // Returns the total number of messages processed from both queues.
  60. void idle(void);
  61. /** The signature of the function for sending a message from plugin to plugin loader shell.
  62. *
  63. * @param[in] message_string Null-terminated C string
  64. * @param[in] user_data The opaque reference that the callee supplied during setup.
  65. */
  66. typedef void (*sendMessageFunction) (const char *message_string, void **user_data);
  67. /** The signature of the plugin init function. TODO:DOC check direction (pluging loader shell to plugin?)
  68. *
  69. * @param[in] host_user_data Data from plugin loader shell.
  70. * @param[in] plugin_send_function Function for sending from the plugin loader shell to plugin.
  71. */
  72. typedef int (*pluginInitFunction) (sendMessageFunction host_send_func, void *host_user_data, sendMessageFunction *plugin_send_func, void **plugin_user_data);
  73. /** Name of plugin init function */
  74. static const char *PLUGIN_INIT_FUNCTION_NAME;
  75. private:
  76. static void staticReceiveMessage(const char *message_string, void **user_data);
  77. void receiveMessage(const char *message_string);
  78. apr_dso_handle_t *mDSOHandle;
  79. void *mPluginUserData;
  80. sendMessageFunction mPluginSendMessageFunction;
  81. LLPluginInstanceMessageListener *mOwner;
  82. };
  83. #endif // LL_LLPLUGININSTANCE_H