repositories
/
deb_libcec.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
only match one interface, not all three when detecting devices on linux and darwin
[deb_libcec.git]
/
src
/
lib
/
platform
/
posix
/
serialport.cpp
diff --git
a/src/lib/platform/posix/serialport.cpp
b/src/lib/platform/posix/serialport.cpp
index 31ae09b1cdd2d58261f25f92acbab9f587a84be0..c1b3b22461bbc002b0dfc788573fc8ede862002d 100644
(file)
--- a/
src/lib/platform/posix/serialport.cpp
+++ b/
src/lib/platform/posix/serialport.cpp
@@
-30,12
+30,12
@@
* http://www.pulse-eight.net/
*/
* http://www.pulse-eight.net/
*/
-#include "
../os
.h"
+#include "
env
.h"
#include <stdio.h>
#include <fcntl.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
#if defined(__APPLE__) || defined(__FreeBSD__)
#ifndef XCASE
@@
-47,60
+47,98
@@
#ifndef IUCLC
#define IUCLC 0
#endif
#ifndef IUCLC
#define IUCLC 0
#endif
+#else
+#include <lockdev.h>
#endif
#endif
+
using namespace std;
using namespace PLATFORM;
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)
{
void CSerialSocket::Close(void)
{
- SocketClose(m_socket);
+ if (IsOpen())
+ {
+ SocketClose(m_socket);
+ RemoveLock(m_strName.c_str());
+ }
}
void CSerialSocket::Shutdown(void)
{
}
void CSerialSocket::Shutdown(void)
{
- SocketClose(m_socket);
+ if (IsOpen())
+ {
+ SocketClose(m_socket);
+ RemoveLock(m_strName.c_str());
+ }
}
ssize_t CSerialSocket::Write(void* data, size_t len)
{
}
ssize_t CSerialSocket::Write(void* data, size_t len)
{
- return
SocketWrite(m_socket, &m_iError, data, len)
;
+ return
IsOpen() ? SocketWrite(m_socket, &m_iError, data, len) : -1
;
}
ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
{
}
ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
{
- return
SocketRead(m_socket, &m_iError, data, len, iTimeoutMs)
;
+ return
IsOpen() ? SocketRead(m_socket, &m_iError, data, len, iTimeoutMs) : -1
;
}
//setting all this stuff up is a pain in the ass
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
{
iTimeoutMs = 0;
}
//setting all this stuff up is a pain in the ass
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
{
iTimeoutMs = 0;
- CLockObject lock(m_mutex);
+ if (IsOpen())
+ {
+ m_iError = EINVAL;
+ return false;
+ }
if (m_iDatabits != SERIAL_DATA_BITS_FIVE && m_iDatabits != SERIAL_DATA_BITS_SIX &&
m_iDatabits != SERIAL_DATA_BITS_SEVEN && m_iDatabits != SERIAL_DATA_BITS_EIGHT)
{
m_strError = "Databits has to be between 5 and 8";
if (m_iDatabits != SERIAL_DATA_BITS_FIVE && m_iDatabits != SERIAL_DATA_BITS_SIX &&
m_iDatabits != SERIAL_DATA_BITS_SEVEN && m_iDatabits != SERIAL_DATA_BITS_EIGHT)
{
m_strError = "Databits has to be between 5 and 8";
+ m_iError = EINVAL;
return false;
}
if (m_iStopbits != SERIAL_STOP_BITS_ONE && m_iStopbits != SERIAL_STOP_BITS_TWO)
{
m_strError = "Stopbits has to be 1 or 2";
return false;
}
if (m_iStopbits != SERIAL_STOP_BITS_ONE && m_iStopbits != SERIAL_STOP_BITS_TWO)
{
m_strError = "Stopbits has to be 1 or 2";
+ m_iError = EINVAL;
return false;
}
if (m_iParity != SERIAL_PARITY_NONE && m_iParity != SERIAL_PARITY_EVEN && m_iParity != SERIAL_PARITY_ODD)
{
m_strError = "Parity has to be none, even or odd";
return false;
}
if (m_iParity != SERIAL_PARITY_NONE && m_iParity != SERIAL_PARITY_EVEN && m_iParity != SERIAL_PARITY_ODD)
{
m_strError = "Parity has to be none, even or odd";
+ m_iError = EINVAL;
+ return false;
+ }
+
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ if (dev_lock(m_strName.c_str()) != 0)
+ {
+ m_strError = "Couldn't lock the serial port";
+ m_iError = EBUSY;
return false;
}
return false;
}
+ #endif
m_socket = open(m_strName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (m_socket == INVALID_SERIAL_SOCKET_VALUE)
{
m_strError = strerror(errno);
m_socket = open(m_strName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (m_socket == INVALID_SERIAL_SOCKET_VALUE)
{
m_strError = strerror(errno);
+ RemoveLock(m_strName.c_str());
return false;
}
return false;
}
@@
-147,6
+185,7
@@
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
if (tcsetattr(m_socket, TCSANOW, &m_options) != 0)
{
m_strError = strerror(errno);
if (tcsetattr(m_socket, TCSANOW, &m_options) != 0)
{
m_strError = strerror(errno);
+ RemoveLock(m_strName.c_str());
return false;
}
return false;
}