|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_plugins_MiniShmParent_h |
|
8 #define mozilla_plugins_MiniShmParent_h |
|
9 |
|
10 #include "MiniShmBase.h" |
|
11 |
|
12 #include <string> |
|
13 |
|
14 namespace mozilla { |
|
15 namespace plugins { |
|
16 |
|
17 /** |
|
18 * This class provides a lightweight shared memory interface for a parent |
|
19 * process in Win32. |
|
20 * This code assumes that there is a parent-child relationship between |
|
21 * processes, as it creates inheritable handles. |
|
22 * Note that this class is *not* an IPDL actor. |
|
23 * |
|
24 * @see MiniShmChild |
|
25 */ |
|
26 class MiniShmParent : public MiniShmBase |
|
27 { |
|
28 public: |
|
29 MiniShmParent(); |
|
30 virtual ~MiniShmParent(); |
|
31 |
|
32 static const unsigned int kDefaultMiniShmSectionSize; |
|
33 |
|
34 /** |
|
35 * Initialize shared memory on the parent side. |
|
36 * |
|
37 * @param aObserver A MiniShmObserver object to receive event notifications. |
|
38 * @param aTimeout Timeout in milliseconds. |
|
39 * @param aSectionSize Desired size of the shared memory section. This is |
|
40 * expected to be a multiple of 0x1000 (4KiB). |
|
41 * @return nsresult error code |
|
42 */ |
|
43 nsresult |
|
44 Init(MiniShmObserver* aObserver, const DWORD aTimeout, |
|
45 const unsigned int aSectionSize = kDefaultMiniShmSectionSize); |
|
46 |
|
47 /** |
|
48 * Destroys the shared memory section. Useful to explicitly release |
|
49 * resources if it is known that they won't be needed again. |
|
50 */ |
|
51 void |
|
52 CleanUp(); |
|
53 |
|
54 /** |
|
55 * Provides a cookie string that should be passed to MiniShmChild |
|
56 * during its initialization. |
|
57 * |
|
58 * @param aCookie A std::wstring variable to receive the cookie. |
|
59 * @return nsresult error code |
|
60 */ |
|
61 nsresult |
|
62 GetCookie(std::wstring& aCookie); |
|
63 |
|
64 virtual nsresult |
|
65 Send() MOZ_OVERRIDE; |
|
66 |
|
67 bool |
|
68 IsConnected() const; |
|
69 |
|
70 protected: |
|
71 void |
|
72 OnEvent() MOZ_OVERRIDE; |
|
73 |
|
74 private: |
|
75 void |
|
76 FinalizeConnection(); |
|
77 |
|
78 unsigned int mSectionSize; |
|
79 HANDLE mParentEvent; |
|
80 HANDLE mParentGuard; |
|
81 HANDLE mChildEvent; |
|
82 HANDLE mChildGuard; |
|
83 HANDLE mRegWait; |
|
84 HANDLE mFileMapping; |
|
85 LPVOID mView; |
|
86 bool mIsConnected; |
|
87 DWORD mTimeout; |
|
88 |
|
89 DISALLOW_COPY_AND_ASSIGN(MiniShmParent); |
|
90 }; |
|
91 |
|
92 } // namespace plugins |
|
93 } // namespace mozilla |
|
94 |
|
95 #endif // mozilla_plugins_MiniShmParent_h |
|
96 |