dom/plugins/ipc/MiniShmParent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/MiniShmParent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_plugins_MiniShmParent_h
    1.11 +#define mozilla_plugins_MiniShmParent_h
    1.12 +
    1.13 +#include "MiniShmBase.h"
    1.14 +
    1.15 +#include <string>
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace plugins {
    1.19 +
    1.20 +/**
    1.21 + * This class provides a lightweight shared memory interface for a parent 
    1.22 + * process in Win32.
    1.23 + * This code assumes that there is a parent-child relationship between 
    1.24 + * processes, as it creates inheritable handles.
    1.25 + * Note that this class is *not* an IPDL actor.
    1.26 + *
    1.27 + * @see MiniShmChild
    1.28 + */
    1.29 +class MiniShmParent : public MiniShmBase
    1.30 +{
    1.31 +public:
    1.32 +  MiniShmParent();
    1.33 +  virtual ~MiniShmParent();
    1.34 +
    1.35 +  static const unsigned int kDefaultMiniShmSectionSize;
    1.36 +
    1.37 +  /**
    1.38 +   * Initialize shared memory on the parent side.
    1.39 +   *
    1.40 +   * @param aObserver A MiniShmObserver object to receive event notifications.
    1.41 +   * @param aTimeout Timeout in milliseconds.
    1.42 +   * @param aSectionSize Desired size of the shared memory section. This is 
    1.43 +   *                     expected to be a multiple of 0x1000 (4KiB).
    1.44 +   * @return nsresult error code
    1.45 +   */
    1.46 +  nsresult
    1.47 +  Init(MiniShmObserver* aObserver, const DWORD aTimeout,
    1.48 +       const unsigned int aSectionSize = kDefaultMiniShmSectionSize);
    1.49 +
    1.50 +  /**
    1.51 +   * Destroys the shared memory section. Useful to explicitly release 
    1.52 +   * resources if it is known that they won't be needed again.
    1.53 +   */
    1.54 +  void
    1.55 +  CleanUp();
    1.56 +
    1.57 +  /**
    1.58 +   * Provides a cookie string that should be passed to MiniShmChild
    1.59 +   * during its initialization.
    1.60 +   *
    1.61 +   * @param aCookie A std::wstring variable to receive the cookie.
    1.62 +   * @return nsresult error code
    1.63 +   */
    1.64 +  nsresult
    1.65 +  GetCookie(std::wstring& aCookie);
    1.66 +
    1.67 +  virtual nsresult
    1.68 +  Send() MOZ_OVERRIDE;
    1.69 +
    1.70 +  bool
    1.71 +  IsConnected() const;
    1.72 +
    1.73 +protected:
    1.74 +  void
    1.75 +  OnEvent() MOZ_OVERRIDE;
    1.76 +
    1.77 +private:
    1.78 +  void
    1.79 +  FinalizeConnection();
    1.80 +
    1.81 +  unsigned int mSectionSize;
    1.82 +  HANDLE mParentEvent;
    1.83 +  HANDLE mParentGuard;
    1.84 +  HANDLE mChildEvent;
    1.85 +  HANDLE mChildGuard;
    1.86 +  HANDLE mRegWait;
    1.87 +  HANDLE mFileMapping;
    1.88 +  LPVOID mView;
    1.89 +  bool   mIsConnected;
    1.90 +  DWORD  mTimeout;
    1.91 +  
    1.92 +  DISALLOW_COPY_AND_ASSIGN(MiniShmParent);
    1.93 +};
    1.94 +
    1.95 +} // namespace plugins
    1.96 +} // namespace mozilla
    1.97 +
    1.98 +#endif // mozilla_plugins_MiniShmParent_h
    1.99 +

mercurial