Socket.cpp 506 B

1234567891011121314151617181920212223242526272829
  1. #include "Socket.h"
  2. #include <unistd.h>
  3. #include <bluetooth/bluetooth.h>
  4. #include <bluetooth/hci.h>
  5. #include <stdexcept>
  6. namespace PresenceDetection {
  7. namespace Bluetooth {
  8. Socket::Socket()
  9. {
  10. m_descriptor = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP);
  11. if (m_descriptor < 0)
  12. throw std::runtime_error("Can't create Bluetooth socket");
  13. }
  14. Socket::~Socket()
  15. {
  16. close(m_descriptor);
  17. }
  18. int Socket::Descriptor() const
  19. {
  20. return m_descriptor;
  21. }
  22. } // namespace Bluetooth
  23. } // namespace PresenceDetection