summaryrefslogtreecommitdiffstats
path: root/mojo/edk/system/data_pipe.h
blob: d2b90bf1ab6a138f26dd358d7d03c7ace4f3bf94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_EDK_SYSTEM_DATA_PIPE_H_
#define MOJO_EDK_SYSTEM_DATA_PIPE_H_

#include <stddef.h>

#include "base/compiler_specific.h"
#include "mojo/edk/embedder/platform_handle_vector.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/system/macros.h"

namespace mojo {
namespace edk {
class RawChannel;

// Shared code between DataPipeConsumerDispatcher and
// DataPipeProducerDispatcher.
class MOJO_SYSTEM_IMPL_EXPORT DataPipe {
 public:
  // The default options for |MojoCreateDataPipe()|. (Real uses should obtain
  // this via |ValidateCreateOptions()| with a null |in_options|; this is
  // exposed directly for testing convenience.)
  static MojoCreateDataPipeOptions GetDefaultCreateOptions();

  // Validates and/or sets default options for |MojoCreateDataPipeOptions|. If
  // non-null, |in_options| must point to a struct of at least
  // |in_options->struct_size| bytes. |out_options| must point to a (current)
  // |MojoCreateDataPipeOptions| and will be entirely overwritten on success (it
  // may be partly overwritten on failure).
  static MojoResult ValidateCreateOptions(
      const MojoCreateDataPipeOptions* in_options,
      MojoCreateDataPipeOptions* out_options);

  // Helper methods used by DataPipeConsumerDispatcher and
  // DataPipeProducerDispatcher for serialization and deserialization.
  static void StartSerialize(bool have_channel_handle,
                             bool have_shared_memory,
                             size_t* max_size,
                             size_t* max_platform_handles);
  static void EndSerialize(const MojoCreateDataPipeOptions& options,
                           ScopedPlatformHandle channel_handle,
                           ScopedPlatformHandle shared_memory_handle,
                           size_t shared_memory_size,
                           void* destination,
                           size_t* actual_size,
                           PlatformHandleVector* platform_handles);
  static ScopedPlatformHandle Deserialize(
      const void* source,
      size_t size,
      PlatformHandleVector* platform_handles,
      MojoCreateDataPipeOptions* options,
      ScopedPlatformHandle* shared_memory_handle,
      size_t* shared_memory_size);
};

}  // namespace edk
}  // namespace mojo

#endif  // MOJO_EDK_SYSTEM_DATA_PIPE_H_