• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 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(function() {
6  var internal = mojo.internal;
7
8  // Constants ----------------------------------------------------------------
9  var kInterfaceIdNamespaceMask = 0x80000000;
10  var kMasterInterfaceId = 0x00000000;
11  var kInvalidInterfaceId = 0xFFFFFFFF;
12
13  // ---------------------------------------------------------------------------
14
15  function InterfacePtrInfo(handle, version) {
16    this.handle = handle;
17    this.version = version;
18  }
19
20  InterfacePtrInfo.prototype.isValid = function() {
21    return this.handle instanceof MojoHandle;
22  };
23
24  InterfacePtrInfo.prototype.close = function() {
25    if (!this.isValid())
26      return;
27
28    this.handle.close();
29    this.handle = null;
30    this.version = 0;
31  };
32
33  function AssociatedInterfacePtrInfo(interfaceEndpointHandle, version) {
34    this.interfaceEndpointHandle = interfaceEndpointHandle;
35    this.version = version;
36  }
37
38  AssociatedInterfacePtrInfo.prototype.isValid = function() {
39    return this.interfaceEndpointHandle.isValid();
40  };
41
42  // ---------------------------------------------------------------------------
43
44  function InterfaceRequest(handle) {
45    this.handle = handle;
46  }
47
48  InterfaceRequest.prototype.isValid = function() {
49    return this.handle instanceof MojoHandle;
50  };
51
52  InterfaceRequest.prototype.close = function() {
53    if (!this.isValid())
54      return;
55
56    this.handle.close();
57    this.handle = null;
58  };
59
60  function AssociatedInterfaceRequest(interfaceEndpointHandle) {
61    this.interfaceEndpointHandle = interfaceEndpointHandle;
62  }
63
64  AssociatedInterfaceRequest.prototype.isValid = function() {
65    return this.interfaceEndpointHandle.isValid();
66  };
67
68  AssociatedInterfaceRequest.prototype.resetWithReason = function(reason) {
69    this.interfaceEndpointHandle.reset(reason);
70  };
71
72  function isMasterInterfaceId(interfaceId) {
73    return interfaceId === kMasterInterfaceId;
74  }
75
76  function isValidInterfaceId(interfaceId) {
77    return interfaceId !== kInvalidInterfaceId;
78  }
79
80  function hasInterfaceIdNamespaceBitSet(interfaceId) {
81    if (interfaceId >= 2 * kInterfaceIdNamespaceMask) {
82      throw new Error("Interface ID should be a 32-bit unsigned integer.");
83    }
84    return interfaceId >= kInterfaceIdNamespaceMask;
85  }
86
87  mojo.InterfacePtrInfo = InterfacePtrInfo;
88  mojo.InterfaceRequest = InterfaceRequest;
89  mojo.AssociatedInterfacePtrInfo = AssociatedInterfacePtrInfo;
90  mojo.AssociatedInterfaceRequest = AssociatedInterfaceRequest;
91  internal.isMasterInterfaceId = isMasterInterfaceId;
92  internal.isValidInterfaceId = isValidInterfaceId;
93  internal.hasInterfaceIdNamespaceBitSet = hasInterfaceIdNamespaceBitSet;
94  internal.kInvalidInterfaceId = kInvalidInterfaceId;
95  internal.kMasterInterfaceId = kMasterInterfaceId;
96  internal.kInterfaceIdNamespaceMask = kInterfaceIdNamespaceMask;
97})();
98