| OLD | NEW |
| (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 } | |
| OLD | NEW |