Socket.cpp 507 B

123456789101112131415161718192021222324252627282930
  1. #include <stdexcept>
  2. #include <unistd.h>
  3. #include <bluetooth/bluetooth.h>
  4. #include <bluetooth/hci.h>
  5. #include "Socket.h"
  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