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