Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / mojo / system / shared_buffer_dispatcher.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
6 #define MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
7
8 #include "base/macros.h"
9 #include "mojo/system/raw_shared_buffer.h"
10 #include "mojo/system/simple_dispatcher.h"
11 #include "mojo/system/system_impl_export.h"
12
13 namespace mojo {
14 namespace system {
15
16 // TODO(vtl): We derive from SimpleDispatcher, even though we don't currently
17 // have anything that's waitable. I want to add a "transferrable" wait flag.
18 class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher {
19  public:
20   // Validates and/or sets default options. If non-null, |in_options| must point
21   // to a struct of at least |in_options->struct_size| bytes. |out_options| must
22   // point to a (current) |MojoCreateSharedBufferOptions| and will be entirely
23   // overwritten on success (it may be partly overwritten on failure).
24   static MojoResult ValidateOptions(
25       const MojoCreateSharedBufferOptions* in_options,
26       MojoCreateSharedBufferOptions* out_options);
27
28   // Static factory method: |validated_options| must be validated (obviously).
29   // On failure, |*result| will be left as-is.
30   static MojoResult Create(
31       const MojoCreateSharedBufferOptions& validated_options,
32       uint64_t num_bytes,
33       scoped_refptr<SharedBufferDispatcher>* result);
34
35   // |Dispatcher| public methods:
36   virtual Type GetType() const OVERRIDE;
37
38  private:
39   explicit SharedBufferDispatcher(
40       scoped_refptr<RawSharedBuffer> shared_buffer_);
41   virtual ~SharedBufferDispatcher();
42
43   // |Dispatcher| protected methods:
44   virtual void CloseImplNoLock() OVERRIDE;
45   virtual scoped_refptr<Dispatcher>
46       CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE;
47   virtual MojoResult DuplicateBufferHandleImplNoLock(
48       const MojoDuplicateBufferHandleOptions* options,
49       scoped_refptr<Dispatcher>* new_dispatcher) OVERRIDE;
50   virtual MojoResult MapBufferImplNoLock(
51       uint64_t offset,
52       uint64_t num_bytes,
53       MojoMapBufferFlags flags,
54       scoped_ptr<RawSharedBufferMapping>* mapping) OVERRIDE;
55
56   // |SimpleDispatcher| methods:
57   virtual MojoWaitFlags SatisfiedFlagsNoLock() const OVERRIDE;
58   virtual MojoWaitFlags SatisfiableFlagsNoLock() const OVERRIDE;
59
60   scoped_refptr<RawSharedBuffer> shared_buffer_;
61
62   DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher);
63 };
64
65 }  // namespace system
66 }  // namespace mojo
67
68 #endif  // MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_