MCPcopy Create free account
hub / github.com/SFML/SFML / open

Method open

src/SFML/Window/NetBSD/JoystickImpl.cpp:206–243  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

204
205////////////////////////////////////////////////////////////
206bool JoystickImpl::open(unsigned int index)
207{
208 if (isConnected(index))
209 {
210 // Open the joystick's file descriptor (read-only and non-blocking)
211 m_file = ::open(plugged[index].c_str(), O_RDONLY | O_NONBLOCK);
212 if (m_file >= 0)
213 {
214 // Reset the joystick state
215 m_state = JoystickState();
216
217 // Get the report descriptor
218 m_desc = hid_get_report_desc(m_file);
219 if (!m_desc)
220 {
221 ::close(m_file);
222 return false;
223 }
224
225 // And the id
226 if (ioctl(m_file, USB_GET_REPORT_ID, &m_id) < 0)
227 {
228 ::close(m_file);
229 return false;
230 }
231
232 // Then allocate a buffer for data retrieval
233 m_length = hid_report_size(m_desc, hid_input, m_id);
234 m_buffer.resize(m_length);
235
236 m_state.connected = true;
237
238 return true;
239 }
240 }
241
242 return false;
243}
244
245
246////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 4

isConnectedFunction · 0.85
JoystickStateClass · 0.85
closeFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected