PageRenderTime 39ms CodeModel.GetById 34ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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