LibCecSharp: fixed - set the primary LA in CecLogicalAddresses
[deb_libcec.git] / src / lib / platform / posix / serialport.cpp
index 2237b65b6565e629667b86db49f184e2cfed81a8..c1b3b22461bbc002b0dfc788573fc8ede862002d 100644 (file)
  *     http://www.pulse-eight.net/
  */
 
-#include "../os.h"
+#include "env.h"
 #include <stdio.h>
 #include <fcntl.h>
-#include "../sockets/serialport.h"
-#include "../util/baudrate.h"
-#include "../posix/os-socket.h"
+#include "lib/platform/sockets/serialport.h"
+#include "lib/platform/util/baudrate.h"
+#include "lib/platform/posix/os-socket.h"
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #ifndef XCASE
 using namespace std;
 using namespace PLATFORM;
 
+inline bool RemoveLock(const char *strDeviceName)
+{
+  #if !defined(__APPLE__) && !defined(__FreeBSD__)
+  return dev_unlock(strDeviceName, 0) == 0;
+  #else
+  void *tmp = (void*)strDeviceName; // silence unused warning
+  return true;
+  #endif
+}
+
 void CSerialSocket::Close(void)
 {
   if (IsOpen())
   {
     SocketClose(m_socket);
-    #if !defined(__APPLE__) && !defined(__FreeBSD__)
-    dev_unlock(m_strName.c_str(), m_lockPid);
-    #endif
+    RemoveLock(m_strName.c_str());
   }
 }
 
@@ -70,9 +78,7 @@ void CSerialSocket::Shutdown(void)
   if (IsOpen())
   {
     SocketClose(m_socket);
-    #if !defined(__APPLE__) && !defined(__FreeBSD__)
-    dev_unlock(m_strName.c_str(), m_lockPid);
-    #endif
+    RemoveLock(m_strName.c_str());
   }
 }
 
@@ -119,8 +125,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
   }
 
   #if !defined(__APPLE__) && !defined(__FreeBSD__)
-  m_lockPid = dev_lock(m_strName.c_str());
-  if (m_lockPid != 0)
+  if (dev_lock(m_strName.c_str()) != 0)
   {
     m_strError = "Couldn't lock the serial port";
     m_iError = EBUSY;
@@ -133,9 +138,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
   if (m_socket == INVALID_SERIAL_SOCKET_VALUE)
   {
     m_strError = strerror(errno);
-    #if !defined(__APPLE__) && !defined(__FreeBSD__)
-    m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
-    #endif
+    RemoveLock(m_strName.c_str());
     return false;
   }
 
@@ -182,9 +185,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
   if (tcsetattr(m_socket, TCSANOW, &m_options) != 0)
   {
     m_strError = strerror(errno);
-    #if !defined(__APPLE__) && !defined(__FreeBSD__)
-    m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
-    #endif
+    RemoveLock(m_strName.c_str());
     return false;
   }