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.
5 #ifndef MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
6 #define MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
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"
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 {
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);
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,
33 scoped_refptr<SharedBufferDispatcher>* result);
35 // |Dispatcher| public methods:
36 virtual Type GetType() const OVERRIDE;
39 explicit SharedBufferDispatcher(
40 scoped_refptr<RawSharedBuffer> shared_buffer_);
41 virtual ~SharedBufferDispatcher();
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(
53 MojoMapBufferFlags flags,
54 scoped_ptr<RawSharedBufferMapping>* mapping) OVERRIDE;
56 // |SimpleDispatcher| methods:
57 virtual MojoWaitFlags SatisfiedFlagsNoLock() const OVERRIDE;
58 virtual MojoWaitFlags SatisfiableFlagsNoLock() const OVERRIDE;
60 scoped_refptr<RawSharedBuffer> shared_buffer_;
62 DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher);
68 #endif // MOJO_SYSTEM_SHARED_BUFFER_DISPATCHER_H_