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_PUBLIC_BINDINGS_INTERFACE_H_
6 #define MOJO_PUBLIC_BINDINGS_INTERFACE_H_
10 #include "mojo/public/bindings/message.h"
11 #include "mojo/public/system/core_cpp.h"
16 // NoInterface is for use in cases when a non-existent or empty interface is
17 // needed (e.g., when the Mojom "Peer" attribute is not present).
21 class NoInterfaceStub : public MessageReceiver {
23 NoInterfaceStub(NoInterface* unused) {}
24 virtual bool Accept(Message* message) MOJO_OVERRIDE;
29 typedef NoInterfaceStub _Stub;
30 typedef NoInterface _Peer;
34 // AnyInterface is for use in cases where any interface would do (e.g., see the
35 // Shell::Connect method).
37 typedef NoInterface AnyInterface;
43 class InterfaceHandle : public MessagePipeHandle {
46 explicit InterfaceHandle(MojoHandle value) : MessagePipeHandle(value) {}
54 typedef InterfaceHandle<S> Handle;
55 typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle;
59 struct Interface<mojo::NoInterface> {
60 typedef MessagePipeHandle Handle;
61 typedef ScopedMessagePipeHandle ScopedHandle;
65 // InterfacePipe<S,P> is used to construct a MessagePipe with typed interfaces
68 template <typename S, typename P = typename S::_Peer>
72 typename Interface<S>::Handle h0;
73 typename Interface<P>::Handle h1;
74 MojoResult result MOJO_ALLOW_UNUSED =
75 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value());
76 assert(result == MOJO_RESULT_OK);
77 handle_to_self.reset(h0);
78 handle_to_peer.reset(h1);
81 typename Interface<S>::ScopedHandle handle_to_self;
82 typename Interface<P>::ScopedHandle handle_to_peer;
85 // TODO(darin): Once we have the ability to use C++11 features, consider
86 // defining a template alias for ScopedInterfaceHandle<S>.
90 #endif // MOJO_PUBLIC_BINDINGS_SCOPED_INTERFACE_H_