aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/java/bindings/src/org/chromium/mojo/bindings/InterfaceRequest.java
blob: 61899b446798a2057e0a5b215a4a4aec25af21d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.mojo.bindings;

import org.chromium.mojo.system.MessagePipeHandle;

/**
 * One end of the message pipe representing a request to create an implementation to be bound to it.
 * The other end of the pipe is bound to a proxy, which can be used immediately, while the
 * InterfaceRequest is being sent.
 * <p>
 * InterfaceRequest are built using |Interface.Manager|.
 *
 * @param <P> the type of the remote interface proxy.
 */
public class InterfaceRequest<P extends Interface> implements HandleOwner<MessagePipeHandle> {

    /**
     * The handle which will be sent and will be connected to the implementation.
     */
    private final MessagePipeHandle mHandle;

    /**
     * Constructor.
     *
     * @param handle the handle which will be sent and will be connected to the implementation.
     */
    InterfaceRequest(MessagePipeHandle handle) {
        mHandle = handle;
    }

    /**
     * @see HandleOwner#passHandle()
     */
    @Override
    public MessagePipeHandle passHandle() {
        return mHandle.pass();
    }

    /**
     * @see java.io.Closeable#close()
     */
    @Override
    public void close() {
        mHandle.close();
    }

    /**
     * Returns an {@link InterfaceRequest} that wraps the given handle. This method is not type safe
     * and should be avoided unless absolutely necessary.
     */
    @SuppressWarnings("rawtypes")
    public static InterfaceRequest asInterfaceRequestUnsafe(MessagePipeHandle handle) {
        return new InterfaceRequest(handle);
    }
}