PageRenderTime 36ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llplugin/llpluginsharedmemory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 125 lines | 31 code | 15 blank | 79 comment | 1 complexity | eb07b5137374496ea8a4778177d5bc11 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpluginsharedmemory.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_LLPLUGINSHAREDMEMORY_H
  28. #define LL_LLPLUGINSHAREDMEMORY_H
  29. class LLPluginSharedMemoryPlatformImpl;
  30. /**
  31. * @brief LLPluginSharedMemory manages a shared memory segment for use by the LLPlugin API.
  32. *
  33. */
  34. class LLPluginSharedMemory
  35. {
  36. LOG_CLASS(LLPluginSharedMemory);
  37. public:
  38. LLPluginSharedMemory();
  39. ~LLPluginSharedMemory();
  40. // Parent will use create/destroy, child will use attach/detach.
  41. // Message transactions will ensure child attaches after parent creates and detaches before parent destroys.
  42. /**
  43. * Creates a shared memory segment, with a name which is guaranteed to be unique on the host at the current time. Used by parent.
  44. * Message transactions will (? TODO:DOC - should? must?) ensure child attaches after parent creates and detaches before parent destroys.
  45. *
  46. * @param[in] size Shared memory size in TODO:DOC units = bytes?.
  47. *
  48. * @return False for failure, true for success.
  49. */
  50. bool create(size_t size);
  51. /**
  52. * Destroys a shared memory segment. Used by parent.
  53. * Message transactions will (? TODO:DOC - should? must?) ensure child attaches after parent creates and detaches before parent destroys.
  54. *
  55. * @return True. TODO:DOC - always returns true. Is this the intended behavior?
  56. */
  57. bool destroy(void);
  58. /**
  59. * Creates and attaches a name to a shared memory segment. TODO:DOC what's the difference between attach() and create()?
  60. *
  61. * @param[in] name Name to attach to memory segment
  62. * @param[in] size Size of memory segment TODO:DOC in bytes?
  63. *
  64. * @return False on failure, true otherwise.
  65. */
  66. bool attach(const std::string &name, size_t size);
  67. /**
  68. * Detaches shared memory segment.
  69. *
  70. * @return False on failure, true otherwise.
  71. */
  72. bool detach(void);
  73. /**
  74. * Checks if shared memory is mapped to a non-null address.
  75. *
  76. * @return True if memory address is non-null, false otherwise.
  77. */
  78. bool isMapped(void) const { return (mMappedAddress != NULL); };
  79. /**
  80. * Get pointer to shared memory.
  81. *
  82. * @return Pointer to shared memory.
  83. */
  84. void *getMappedAddress(void) const { return mMappedAddress; };
  85. /**
  86. * Get size of shared memory.
  87. *
  88. * @return Size of shared memory in bytes. TODO:DOC are bytes the correct unit?
  89. */
  90. size_t getSize(void) const { return mSize; };
  91. /**
  92. * Get name of shared memory.
  93. *
  94. * @return Name of shared memory.
  95. */
  96. std::string getName() const { return mName; };
  97. private:
  98. bool map(void);
  99. bool unmap(void);
  100. bool close(void);
  101. bool unlink(void);
  102. std::string mName;
  103. size_t mSize;
  104. void *mMappedAddress;
  105. bool mNeedsDestroy;
  106. LLPluginSharedMemoryPlatformImpl *mImpl;
  107. static int sSegmentNumber;
  108. static std::string createName();
  109. };
  110. #endif // LL_LLPLUGINSHAREDMEMORY_H