PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llplugin/llpluginmessagepipe.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 95 lines | 44 code | 16 blank | 35 comment | 0 complexity | 5ed1debe0b4b197b908f1b7e16eb3002 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpluginmessagepipe.h
  3. * @brief Classes that implement connections from the plugin system to pipes/pumps.
  4. *
  5. * @cond
  6. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. * @endcond
  27. */
  28. #ifndef LL_LLPLUGINMESSAGEPIPE_H
  29. #define LL_LLPLUGINMESSAGEPIPE_H
  30. #include "lliosocket.h"
  31. #include "llthread.h"
  32. class LLPluginMessagePipe;
  33. // Inherit from this to be able to receive messages from the LLPluginMessagePipe
  34. class LLPluginMessagePipeOwner
  35. {
  36. LOG_CLASS(LLPluginMessagePipeOwner);
  37. public:
  38. LLPluginMessagePipeOwner();
  39. virtual ~LLPluginMessagePipeOwner();
  40. // called with incoming messages
  41. virtual void receiveMessageRaw(const std::string &message) = 0;
  42. // called when the socket has an error
  43. virtual apr_status_t socketError(apr_status_t error);
  44. // called from LLPluginMessagePipe to manage the connection with LLPluginMessagePipeOwner -- do not use!
  45. virtual void setMessagePipe(LLPluginMessagePipe *message_pipe);
  46. protected:
  47. // returns false if writeMessageRaw() would drop the message
  48. bool canSendMessage(void);
  49. // call this to send a message over the pipe
  50. bool writeMessageRaw(const std::string &message);
  51. // call this to close the pipe
  52. void killMessagePipe(void);
  53. LLPluginMessagePipe *mMessagePipe;
  54. apr_status_t mSocketError;
  55. };
  56. class LLPluginMessagePipe
  57. {
  58. LOG_CLASS(LLPluginMessagePipe);
  59. public:
  60. LLPluginMessagePipe(LLPluginMessagePipeOwner *owner, LLSocket::ptr_t socket);
  61. virtual ~LLPluginMessagePipe();
  62. bool addMessage(const std::string &message);
  63. void clearOwner(void);
  64. bool pump(F64 timeout = 0.0f);
  65. bool pumpOutput();
  66. bool pumpInput(F64 timeout = 0.0f);
  67. protected:
  68. void processInput(void);
  69. // used internally by pump()
  70. void setSocketTimeout(apr_interval_time_t timeout_usec);
  71. LLMutex mInputMutex;
  72. std::string mInput;
  73. LLMutex mOutputMutex;
  74. std::string mOutput;
  75. std::string::size_type mOutputStartIndex;
  76. LLPluginMessagePipeOwner *mOwner;
  77. LLSocket::ptr_t mSocket;
  78. };
  79. #endif // LL_LLPLUGINMESSAGE_H