michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_plugins_MiniShmParent_h michael@0: #define mozilla_plugins_MiniShmParent_h michael@0: michael@0: #include "MiniShmBase.h" michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: /** michael@0: * This class provides a lightweight shared memory interface for a parent michael@0: * process in Win32. michael@0: * This code assumes that there is a parent-child relationship between michael@0: * processes, as it creates inheritable handles. michael@0: * Note that this class is *not* an IPDL actor. michael@0: * michael@0: * @see MiniShmChild michael@0: */ michael@0: class MiniShmParent : public MiniShmBase michael@0: { michael@0: public: michael@0: MiniShmParent(); michael@0: virtual ~MiniShmParent(); michael@0: michael@0: static const unsigned int kDefaultMiniShmSectionSize; michael@0: michael@0: /** michael@0: * Initialize shared memory on the parent side. michael@0: * michael@0: * @param aObserver A MiniShmObserver object to receive event notifications. michael@0: * @param aTimeout Timeout in milliseconds. michael@0: * @param aSectionSize Desired size of the shared memory section. This is michael@0: * expected to be a multiple of 0x1000 (4KiB). michael@0: * @return nsresult error code michael@0: */ michael@0: nsresult michael@0: Init(MiniShmObserver* aObserver, const DWORD aTimeout, michael@0: const unsigned int aSectionSize = kDefaultMiniShmSectionSize); michael@0: michael@0: /** michael@0: * Destroys the shared memory section. Useful to explicitly release michael@0: * resources if it is known that they won't be needed again. michael@0: */ michael@0: void michael@0: CleanUp(); michael@0: michael@0: /** michael@0: * Provides a cookie string that should be passed to MiniShmChild michael@0: * during its initialization. michael@0: * michael@0: * @param aCookie A std::wstring variable to receive the cookie. michael@0: * @return nsresult error code michael@0: */ michael@0: nsresult michael@0: GetCookie(std::wstring& aCookie); michael@0: michael@0: virtual nsresult michael@0: Send() MOZ_OVERRIDE; michael@0: michael@0: bool michael@0: IsConnected() const; michael@0: michael@0: protected: michael@0: void michael@0: OnEvent() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void michael@0: FinalizeConnection(); michael@0: michael@0: unsigned int mSectionSize; michael@0: HANDLE mParentEvent; michael@0: HANDLE mParentGuard; michael@0: HANDLE mChildEvent; michael@0: HANDLE mChildGuard; michael@0: HANDLE mRegWait; michael@0: HANDLE mFileMapping; michael@0: LPVOID mView; michael@0: bool mIsConnected; michael@0: DWORD mTimeout; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(MiniShmParent); michael@0: }; michael@0: michael@0: } // namespace plugins michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_plugins_MiniShmParent_h michael@0: