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.system; 6 7 import org.chromium.mojo.system.Core.HandleSignalsState; 8 import org.chromium.mojo.system.DataPipe.ConsumerHandle; 9 import org.chromium.mojo.system.DataPipe.ProducerHandle; 10 11 import java.nio.ByteBuffer; 12 import java.util.List; 13 14 /** 15 * A handle that will always be invalid. 16 */ 17 public class InvalidHandle implements UntypedHandle, MessagePipeHandle, ConsumerHandle, 18 ProducerHandle, SharedBufferHandle { 19 20 /** 21 * Instance singleton. 22 */ 23 public static final InvalidHandle INSTANCE = new InvalidHandle(); 24 25 /** 26 * Private constructor. 27 */ InvalidHandle()28 private InvalidHandle() { 29 } 30 31 /** 32 * @see Handle#close() 33 */ 34 @Override close()35 public void close() { 36 // Do nothing. 37 } 38 39 /** 40 * @see Handle#querySignalsState() 41 */ 42 @Override querySignalsState()43 public HandleSignalsState querySignalsState() { 44 throw new MojoException(MojoResult.INVALID_ARGUMENT); 45 } 46 47 /** 48 * @see Handle#isValid() 49 */ 50 @Override isValid()51 public boolean isValid() { 52 return false; 53 } 54 55 /** 56 * @see Handle#getCore() 57 */ 58 @Override getCore()59 public Core getCore() { 60 return null; 61 } 62 63 /** 64 * @see org.chromium.mojo.system.Handle#pass() 65 */ 66 @Override pass()67 public InvalidHandle pass() { 68 return this; 69 } 70 71 /** 72 * @see Handle#toUntypedHandle() 73 */ 74 @Override toUntypedHandle()75 public UntypedHandle toUntypedHandle() { 76 return this; 77 } 78 79 /** 80 * @see Handle#releaseNativeHandle() 81 */ 82 @Override releaseNativeHandle()83 public int releaseNativeHandle() { 84 return 0; 85 } 86 87 /** 88 * @see UntypedHandle#toMessagePipeHandle() 89 */ 90 @Override toMessagePipeHandle()91 public MessagePipeHandle toMessagePipeHandle() { 92 return this; 93 } 94 95 /** 96 * @see UntypedHandle#toDataPipeConsumerHandle() 97 */ 98 @Override toDataPipeConsumerHandle()99 public ConsumerHandle toDataPipeConsumerHandle() { 100 return this; 101 } 102 103 /** 104 * @see UntypedHandle#toDataPipeProducerHandle() 105 */ 106 @Override toDataPipeProducerHandle()107 public ProducerHandle toDataPipeProducerHandle() { 108 return this; 109 } 110 111 /** 112 * @see UntypedHandle#toSharedBufferHandle() 113 */ 114 @Override toSharedBufferHandle()115 public SharedBufferHandle toSharedBufferHandle() { 116 return this; 117 } 118 119 /** 120 * @see SharedBufferHandle#duplicate(SharedBufferHandle.DuplicateOptions) 121 */ 122 @Override duplicate(DuplicateOptions options)123 public SharedBufferHandle duplicate(DuplicateOptions options) { 124 throw new MojoException(MojoResult.INVALID_ARGUMENT); 125 } 126 127 /** 128 * @see SharedBufferHandle#map(long, long, SharedBufferHandle.MapFlags) 129 */ 130 @Override map(long offset, long numBytes, MapFlags flags)131 public ByteBuffer map(long offset, long numBytes, MapFlags flags) { 132 throw new MojoException(MojoResult.INVALID_ARGUMENT); 133 } 134 135 /** 136 * @see SharedBufferHandle#unmap(java.nio.ByteBuffer) 137 */ 138 @Override unmap(ByteBuffer buffer)139 public void unmap(ByteBuffer buffer) { 140 throw new MojoException(MojoResult.INVALID_ARGUMENT); 141 } 142 143 /** 144 * @see DataPipe.ProducerHandle#writeData(java.nio.ByteBuffer, DataPipe.WriteFlags) 145 */ 146 @Override writeData(ByteBuffer elements, DataPipe.WriteFlags flags)147 public ResultAnd<Integer> writeData(ByteBuffer elements, DataPipe.WriteFlags flags) { 148 throw new MojoException(MojoResult.INVALID_ARGUMENT); 149 } 150 151 /** 152 * @see DataPipe.ProducerHandle#beginWriteData(int, DataPipe.WriteFlags) 153 */ 154 @Override beginWriteData(int numBytes, DataPipe.WriteFlags flags)155 public ByteBuffer beginWriteData(int numBytes, 156 DataPipe.WriteFlags flags) { 157 throw new MojoException(MojoResult.INVALID_ARGUMENT); 158 } 159 160 /** 161 * @see DataPipe.ProducerHandle#endWriteData(int) 162 */ 163 @Override endWriteData(int numBytesWritten)164 public void endWriteData(int numBytesWritten) { 165 throw new MojoException(MojoResult.INVALID_ARGUMENT); 166 } 167 168 /** 169 * @see DataPipe.ConsumerHandle#discardData(int, DataPipe.ReadFlags) 170 */ 171 @Override discardData(int numBytes, DataPipe.ReadFlags flags)172 public int discardData(int numBytes, DataPipe.ReadFlags flags) { 173 throw new MojoException(MojoResult.INVALID_ARGUMENT); 174 } 175 176 /** 177 * @see DataPipe.ConsumerHandle#readData(java.nio.ByteBuffer, DataPipe.ReadFlags) 178 */ 179 @Override readData(ByteBuffer elements, DataPipe.ReadFlags flags)180 public ResultAnd<Integer> readData(ByteBuffer elements, DataPipe.ReadFlags flags) { 181 throw new MojoException(MojoResult.INVALID_ARGUMENT); 182 } 183 184 /** 185 * @see DataPipe.ConsumerHandle#beginReadData(int, DataPipe.ReadFlags) 186 */ 187 @Override beginReadData(int numBytes, DataPipe.ReadFlags flags)188 public ByteBuffer beginReadData(int numBytes, 189 DataPipe.ReadFlags flags) { 190 throw new MojoException(MojoResult.INVALID_ARGUMENT); 191 } 192 193 /** 194 * @see DataPipe.ConsumerHandle#endReadData(int) 195 */ 196 @Override endReadData(int numBytesRead)197 public void endReadData(int numBytesRead) { 198 throw new MojoException(MojoResult.INVALID_ARGUMENT); 199 } 200 201 /** 202 * @see MessagePipeHandle#writeMessage(java.nio.ByteBuffer, java.util.List, 203 * MessagePipeHandle.WriteFlags) 204 */ 205 @Override writeMessage(ByteBuffer bytes, List<? extends Handle> handles, WriteFlags flags)206 public void writeMessage(ByteBuffer bytes, List<? extends Handle> handles, WriteFlags flags) { 207 throw new MojoException(MojoResult.INVALID_ARGUMENT); 208 } 209 210 /** 211 * @see MessagePipeHandle#readMessage(MessagePipeHandle.ReadFlags) 212 */ 213 @Override readMessage(ReadFlags flags)214 public ResultAnd<ReadMessageResult> readMessage(ReadFlags flags) { 215 throw new MojoException(MojoResult.INVALID_ARGUMENT); 216 } 217 218 } 219