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

Method open

src/SFML/Window/Unix/JoystickImpl.cpp:500–535  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

498
499////////////////////////////////////////////////////////////
500bool JoystickImpl::open(unsigned int index)
501{
502 if (index >= joystickList.size())
503 return false;
504
505 if (joystickList[index].plugged)
506 {
507 const std::string devnode = joystickList[index].deviceNode;
508
509 // Open the joystick's file descriptor (read-only and non-blocking)
510 m_file = ::open(devnode.c_str(), O_RDONLY | O_NONBLOCK);
511 if (m_file >= 0)
512 {
513 // Retrieve the axes mapping
514 ioctl(m_file, JSIOCGAXMAP, m_mapping.data());
515
516 // Get info
517 m_identification.name = getJoystickName(index);
518
519 if (udevContext)
520 {
521 m_identification.vendorId = getJoystickVendorId(index);
522 m_identification.productId = getJoystickProductId(index);
523 }
524
525 // Reset the joystick state
526 m_state = JoystickState();
527
528 return true;
529 }
530
531 err() << "Failed to open joystick " << devnode << ": " << errno << std::endl;
532 }
533
534 return false;
535}
536
537
538////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 4

getJoystickNameFunction · 0.85
getJoystickVendorIdFunction · 0.85
getJoystickProductIdFunction · 0.85
JoystickStateClass · 0.85

Tested by

no test coverage detected