OLD | NEW |
| (Empty) |
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_PUBLIC_BINDINGS_INTERFACE_H_ | |
6 #define MOJO_PUBLIC_BINDINGS_INTERFACE_H_ | |
7 | |
8 #include <assert.h> | |
9 | |
10 #include "mojo/public/bindings/message.h" | |
11 #include "mojo/public/cpp/system/core.h" | |
12 | |
13 namespace mojo { | |
14 | |
15 | |
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). | |
18 | |
19 class NoInterface; | |
20 | |
21 class NoInterfaceStub : public MessageReceiver { | |
22 public: | |
23 NoInterfaceStub(NoInterface* unused) {} | |
24 virtual bool Accept(Message* message) MOJO_OVERRIDE; | |
25 virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder) | |
26 MOJO_OVERRIDE; | |
27 }; | |
28 | |
29 class NoInterface { | |
30 public: | |
31 typedef NoInterfaceStub _Stub; | |
32 typedef NoInterface _Peer; | |
33 }; | |
34 | |
35 | |
36 // AnyInterface is for use in cases where any interface would do (e.g., see the | |
37 // Shell::Connect method). | |
38 | |
39 typedef NoInterface AnyInterface; | |
40 | |
41 | |
42 // InterfaceHandle<S> | |
43 | |
44 template <typename S> | |
45 class InterfaceHandle : public MessagePipeHandle { | |
46 public: | |
47 InterfaceHandle() {} | |
48 explicit InterfaceHandle(MojoHandle value) : MessagePipeHandle(value) {} | |
49 }; | |
50 | |
51 | |
52 // Interface<S> | |
53 | |
54 template <typename S> | |
55 struct Interface { | |
56 typedef InterfaceHandle<S> Handle; | |
57 typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle; | |
58 }; | |
59 | |
60 template <> | |
61 struct Interface<mojo::NoInterface> { | |
62 typedef MessagePipeHandle Handle; | |
63 typedef ScopedMessagePipeHandle ScopedHandle; | |
64 }; | |
65 | |
66 | |
67 // InterfacePipe<S,P> is used to construct a MessagePipe with typed interfaces | |
68 // on either end. | |
69 | |
70 template <typename S, typename P = typename S::_Peer> | |
71 class InterfacePipe { | |
72 public: | |
73 InterfacePipe() { | |
74 typename Interface<S>::Handle h0; | |
75 typename Interface<P>::Handle h1; | |
76 MojoResult result MOJO_ALLOW_UNUSED = | |
77 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value()); | |
78 assert(result == MOJO_RESULT_OK); | |
79 handle_to_self.reset(h0); | |
80 handle_to_peer.reset(h1); | |
81 } | |
82 | |
83 typename Interface<S>::ScopedHandle handle_to_self; | |
84 typename Interface<P>::ScopedHandle handle_to_peer; | |
85 }; | |
86 | |
87 // TODO(darin): Once we have the ability to use C++11 features, consider | |
88 // defining a template alias for ScopedInterfaceHandle<S>. | |
89 | |
90 } // namespace mojo | |
91 | |
92 #endif // MOJO_PUBLIC_BINDINGS_SCOPED_INTERFACE_H_ | |
OLD | NEW |