-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathPollfds.java
More file actions
102 lines (90 loc) · 2.2 KB
/
Pollfds.java
File metadata and controls
102 lines (90 loc) · 2.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2018 Klaus Reimer <k@ailis.de>
* See LICENSE.md for licensing information.
*/
package org.usb4java;
import java.util.Iterator;
/**
* List of poll file descriptors as returned by {@link LibUsb#getPollfds(Context)}.
*
* @author Klaus Reimer (k@ailis.de)
*/
public final class Pollfds implements Iterable<Pollfd>
{
/** The native pointer to the pollfd array. */
private long pollfdsPointer;
/** The number of file descriptors in the list. */
private int size;
/**
* Package-private constructor to prevent manual instantiation. Structures are
* always created by JNI.
*/
Pollfds()
{
// Empty
}
/**
* Returns the native pointer.
*
* @return The native pointer.
*/
public long getPointer()
{
return this.pollfdsPointer;
}
/**
* Returns the number of poll file descriptors in the list.
*
* @return The number of poll file descriptors in the list.
*/
public int getSize()
{
return this.size;
}
/**
* Returns the poll file descriptor with the specified index.
*
* @param index
* The index.
* @return The poll file descriptor or null when index is out of bounds.
*/
public native Pollfd get(final int index);
@Override
public Iterator<Pollfd> iterator()
{
return new PollfdsIterator(this);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = (prime * result)
+ (int) (this.pollfdsPointer ^ (this.pollfdsPointer >>> 32));
return result;
}
@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (this.getClass() != obj.getClass())
{
return false;
}
final Pollfds other = (Pollfds) obj;
return this.pollfdsPointer == other.pollfdsPointer;
}
@Override
public String toString()
{
return String.format("libusb pollfd list 0x%x with size %d",
this.pollfdsPointer, this.size);
}
}