Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: mojo/public/go/bindings/interface.go

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/go/bindings/encoder.go ('k') | mojo/public/go/bindings/invalid_handle.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 package bindings
6
7 import (
8 "fmt"
9 "mojo/public/go/system"
10 )
11
12 // MessagePipeHandleOwner owns a message pipe handle, it can only pass it
13 // invalidating itself or close it.
14 type MessagePipeHandleOwner struct {
15 handle system.MessagePipeHandle
16 }
17
18 // PassMessagePipe passes ownership of the underlying message pipe handle to
19 // the newly created handle object, invalidating the underlying handle object
20 // in the process.
21 func (o *MessagePipeHandleOwner) PassMessagePipe() system.MessagePipeHandle {
22 if o.handle == nil {
23 return &InvalidHandle{}
24 }
25 return o.handle.ToUntypedHandle().ToMessagePipeHandle()
26 }
27
28 // Close closes the underlying handle.
29 func (o *MessagePipeHandleOwner) Close() {
30 if o.handle != nil {
31 o.handle.Close()
32 }
33 }
34
35 // NewMessagePipeHandleOwner creates |MessagePipeHandleOwner| that owns the
36 // provided message pipe handle.
37 func NewMessagePipeHandleOwner(handle system.MessagePipeHandle) MessagePipeHandl eOwner {
38 return MessagePipeHandleOwner{handle}
39 }
40
41 // InterfaceRequest represents a request from a remote client for an
42 // implementation of mojo interface over a specified message pipe. The
43 // implementor of the interface should remove the message pipe by calling
44 // PassMessagePipe() and attach it to the implementation.
45 type InterfaceRequest struct {
46 MessagePipeHandleOwner
47 }
48
49 // InterfacePointer owns a message pipe handle with an implementation of mojo
50 // interface attached to the other end of the message pipe. The client of the
51 // interface should remove the message pipe by calling PassMessagePipe() and
52 // attach it to the proxy.
53 type InterfacePointer struct {
54 MessagePipeHandleOwner
55 }
56
57 // CreateMessagePipeForInterface creates a message pipe with interface request
58 // on one end and interface pointer on the other end. The interface request
59 // should be attached to appropriate mojo interface implementation and
60 // the interface pointer should be attached to mojo interface proxy.
61 func CreateMessagePipeForMojoInterface() (InterfaceRequest, InterfacePointer) {
62 r, h0, h1 := system.GetCore().CreateMessagePipe(nil)
63 if r != system.MOJO_RESULT_OK {
64 panic(fmt.Sprintf("can't create a message pipe: %v", r))
65 }
66 return InterfaceRequest{MessagePipeHandleOwner{h0}}, InterfacePointer{Me ssagePipeHandleOwner{h1}}
67 }
OLDNEW
« no previous file with comments | « mojo/public/go/bindings/encoder.go ('k') | mojo/public/go/bindings/invalid_handle.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698