Home | History | Annotate | Download | only in bindings
      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 package org.chromium.mojo.bindings;
      6 
      7 import org.chromium.mojo.system.MessagePipeHandle;
      8 
      9 /**
     10  * One end of the message pipe representing a request to create an implementation to be bound to it.
     11  * The other end of the pipe is bound to a proxy, which can be used immediately, while the
     12  * InterfaceRequest is being sent.
     13  * <p>
     14  * InterfaceRequest are built using |Interface.Manager|.
     15  *
     16  * @param <P> the type of the remote interface proxy.
     17  */
     18 public class InterfaceRequest<P extends Interface> implements HandleOwner<MessagePipeHandle> {
     19 
     20     /**
     21      * The handle which will be sent and will be connected to the implementation.
     22      */
     23     private final MessagePipeHandle mHandle;
     24 
     25     /**
     26      * Constructor.
     27      *
     28      * @param handle the handle which will be sent and will be connected to the implementation.
     29      */
     30     InterfaceRequest(MessagePipeHandle handle) {
     31         mHandle = handle;
     32     }
     33 
     34     /**
     35      * @see HandleOwner#passHandle()
     36      */
     37     @Override
     38     public MessagePipeHandle passHandle() {
     39         return mHandle.pass();
     40     }
     41 
     42     /**
     43      * @see java.io.Closeable#close()
     44      */
     45     @Override
     46     public void close() {
     47         mHandle.close();
     48     }
     49 
     50     /**
     51      * Returns an {@link InterfaceRequest} that wraps the given handle. This method is not type safe
     52      * and should be avoided unless absolutely necessary.
     53      */
     54     @SuppressWarnings("rawtypes")
     55     public static InterfaceRequest asInterfaceRequestUnsafe(MessagePipeHandle handle) {
     56         return new InterfaceRequest(handle);
     57     }
     58 }
     59