PageRenderTime 17ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llplugin/llpluginprocesschild.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 113 lines | 59 code | 23 blank | 31 comment | 0 complexity | 162db347c6f2c534d0d46c715031b8b0 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpluginprocesschild.h
  3. * @brief LLPluginProcessChild handles the child side of the external-process plugin API.
  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_LLPLUGINPROCESSCHILD_H
  29. #define LL_LLPLUGINPROCESSCHILD_H
  30. #include "llpluginmessage.h"
  31. #include "llpluginmessagepipe.h"
  32. #include "llplugininstance.h"
  33. #include "llhost.h"
  34. #include "llpluginsharedmemory.h"
  35. class LLPluginInstance;
  36. class LLPluginProcessChild: public LLPluginMessagePipeOwner, public LLPluginInstanceMessageListener
  37. {
  38. LOG_CLASS(LLPluginProcessChild);
  39. public:
  40. LLPluginProcessChild();
  41. ~LLPluginProcessChild();
  42. void init(U32 launcher_port);
  43. void idle(void);
  44. void sleep(F64 seconds);
  45. void pump();
  46. // returns true if the plugin is in the steady state (processing messages)
  47. bool isRunning(void);
  48. // returns true if the plugin is unloaded or we're in an unrecoverable error state.
  49. bool isDone(void);
  50. void killSockets(void);
  51. F64 getSleepTime(void) const { return mSleepTime; };
  52. void sendMessageToPlugin(const LLPluginMessage &message);
  53. void sendMessageToParent(const LLPluginMessage &message);
  54. // Inherited from LLPluginMessagePipeOwner
  55. /* virtual */ void receiveMessageRaw(const std::string &message);
  56. // Inherited from LLPluginInstanceMessageListener
  57. /* virtual */ void receivePluginMessage(const std::string &message);
  58. private:
  59. enum EState
  60. {
  61. STATE_UNINITIALIZED,
  62. STATE_INITIALIZED, // init() has been called
  63. STATE_CONNECTED, // connected back to launcher
  64. STATE_PLUGIN_LOADING, // plugin library needs to be loaded
  65. STATE_PLUGIN_LOADED, // plugin library has been loaded
  66. STATE_PLUGIN_INITIALIZING, // plugin is processing init message
  67. STATE_RUNNING, // steady state (processing messages)
  68. STATE_UNLOADING, // plugin has sent shutdown_response and needs to be unloaded
  69. STATE_UNLOADED, // plugin has been unloaded
  70. STATE_ERROR, // generic bailout state
  71. STATE_DONE // state machine will sit in this state after either error or normal termination.
  72. };
  73. void setState(EState state);
  74. EState mState;
  75. LLHost mLauncherHost;
  76. LLSocket::ptr_t mSocket;
  77. std::string mPluginFile;
  78. std::string mPluginDir;
  79. LLPluginInstance *mInstance;
  80. typedef std::map<std::string, LLPluginSharedMemory*> sharedMemoryRegionsType;
  81. sharedMemoryRegionsType mSharedMemoryRegions;
  82. LLTimer mHeartbeat;
  83. F64 mSleepTime;
  84. F64 mCPUElapsed;
  85. bool mBlockingRequest;
  86. bool mBlockingResponseReceived;
  87. std::queue<std::string> mMessageQueue;
  88. void deliverQueuedMessages();
  89. };
  90. #endif // LL_LLPLUGINPROCESSCHILD_H