repositories
/
deb_libcec.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7068f33
)
cec: serial port locking on linux
author
Lars Op den Kamp
<lars@opdenkamp.eu>
Mon, 14 May 2012 14:57:46 +0000
(16:57 +0200)
committer
Lars Op den Kamp
<lars@opdenkamp.eu>
Mon, 14 May 2012 15:05:56 +0000
(17:05 +0200)
configure.ac
patch
|
blob
|
blame
|
history
debian/control
patch
|
blob
|
blame
|
history
src/lib/platform/posix/os-types.h
patch
|
blob
|
blame
|
history
src/lib/platform/posix/serialport.cpp
patch
|
blob
|
blame
|
history
src/lib/platform/sockets/serialport.h
patch
|
blob
|
blame
|
history
diff --git
a/configure.ac
b/configure.ac
index f8b8701be858a9fa009e3698083232941e0fdfed..b8d6031a1871832ede4f21f90b1c06b3acff8e62 100644
(file)
--- a/
configure.ac
+++ b/
configure.ac
@@
-8,7
+8,8
@@
has_libudev="yes"
case "${host}" in
*-*-linux*)
PKG_CHECK_MODULES([UDEV],[libudev],,[has_libudev="no"]; AC_MSG_WARN("library 'udev' is missing - adapter detection will not be available"))
case "${host}" in
*-*-linux*)
PKG_CHECK_MODULES([UDEV],[libudev],,[has_libudev="no"]; AC_MSG_WARN("library 'udev' is missing - adapter detection will not be available"))
- LIBS+=" -lrt"
+ AC_CHECK_HEADER(lockdev.h,, AC_MSG_ERROR("required library 'liblockdev' is missing"))
+ LIBS+=" -lrt -llockdev"
;;
*-apple-darwin*)
has_libudev="no";
;;
*-apple-darwin*)
has_libudev="no";
diff --git
a/debian/control
b/debian/control
index 570934984b4f57f395a546f2f01a66138760a0d2..fa8b7616060336c527e350d4a175e07af9a94c13 100644
(file)
--- a/
debian/control
+++ b/
debian/control
@@
-2,13
+2,13
@@
Source: libcec
Section: video
Priority: extra
Maintainer: Lars Op den Kamp <lars.opdenkamp@pulse-eight.com>
Section: video
Priority: extra
Maintainer: Lars Op den Kamp <lars.opdenkamp@pulse-eight.com>
-Build-Depends: debhelper (>= 7), libudev-dev, mime-support, locales, gawk, autotools-dev, autoconf, automake, pkg-config
+Build-Depends: debhelper (>= 7), libudev-dev, mime-support, locales, gawk, autotools-dev, autoconf, automake, pkg-config
, liblockdev1-dev
Standards-Version: 3.8.3
Homepage: http://www.pulse-eight.net/
Package: libcec
Architecture: any
Standards-Version: 3.8.3
Homepage: http://www.pulse-eight.net/
Package: libcec
Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}
, liblockdev1
Description: Pulse-Eight CEC adapter control library
With this library you can access your Pulse-Eight CEC adapter.
Description: Pulse-Eight CEC adapter control library
With this library you can access your Pulse-Eight CEC adapter.
diff --git
a/src/lib/platform/posix/os-types.h
b/src/lib/platform/posix/os-types.h
index b89b9cc2a57617f15ae69ddc5d9d65274cdd737c..a365635490f66d4a7b46e86211404abe4ac60de3 100644
(file)
--- a/
src/lib/platform/posix/os-types.h
+++ b/
src/lib/platform/posix/os-types.h
@@
-44,6
+44,10
@@
#include <semaphore.h>
#include <stdint.h>
#include <semaphore.h>
#include <stdint.h>
+extern "C" {
+#include <sys/types.h>
+}
+
#define LIBTYPE
#define DECLSPEC
#define LIBTYPE
#define DECLSPEC
diff --git
a/src/lib/platform/posix/serialport.cpp
b/src/lib/platform/posix/serialport.cpp
index cefc21201ef03ee41d17feea11e5cdc3aac9e529..2237b65b6565e629667b86db49f184e2cfed81a8 100644
(file)
--- a/
src/lib/platform/posix/serialport.cpp
+++ b/
src/lib/platform/posix/serialport.cpp
@@
-47,20
+47,33
@@
#ifndef IUCLC
#define IUCLC 0
#endif
#ifndef IUCLC
#define IUCLC 0
#endif
+#else
+#include <lockdev.h>
#endif
#endif
+
using namespace std;
using namespace PLATFORM;
void CSerialSocket::Close(void)
{
if (IsOpen())
using namespace std;
using namespace PLATFORM;
void CSerialSocket::Close(void)
{
if (IsOpen())
+ {
SocketClose(m_socket);
SocketClose(m_socket);
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ dev_unlock(m_strName.c_str(), m_lockPid);
+ #endif
+ }
}
void CSerialSocket::Shutdown(void)
{
if (IsOpen())
}
void CSerialSocket::Shutdown(void)
{
if (IsOpen())
+ {
SocketClose(m_socket);
SocketClose(m_socket);
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ dev_unlock(m_strName.c_str(), m_lockPid);
+ #endif
+ }
}
ssize_t CSerialSocket::Write(void* data, size_t len)
}
ssize_t CSerialSocket::Write(void* data, size_t len)
@@
-78,32
+91,51
@@
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
{
iTimeoutMs = 0;
if (IsOpen())
{
iTimeoutMs = 0;
if (IsOpen())
+ {
+ m_iError = EINVAL;
return false;
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__)
+ m_lockPid = dev_lock(m_strName.c_str());
+ if (m_lockPid != 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);
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
+ #endif
return false;
}
return false;
}
@@
-150,6
+182,9
@@
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);
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
+ #endif
return false;
}
return false;
}
diff --git
a/src/lib/platform/sockets/serialport.h
b/src/lib/platform/sockets/serialport.h
index eed05a001761f6add5dc1a0de1475ba5bb9dc240..a16e3ca72115a77279de9837bb8311f0ba025115 100644
(file)
--- a/
src/lib/platform/sockets/serialport.h
+++ b/
src/lib/platform/sockets/serialport.h
@@
-73,6
+73,8
@@
namespace PLATFORM
CCommonSocket<serial_socket_t>(INVALID_SERIAL_SOCKET_VALUE, strName),
#ifdef __WINDOWS__
m_iCurrentReadTimeout(MAXDWORD),
CCommonSocket<serial_socket_t>(INVALID_SERIAL_SOCKET_VALUE, strName),
#ifdef __WINDOWS__
m_iCurrentReadTimeout(MAXDWORD),
+ #else
+ m_lockPid(0),
#endif
m_bIsOpen(false),
m_iBaudrate(iBaudrate),
#endif
m_bIsOpen(false),
m_iBaudrate(iBaudrate),
@@
-99,6
+101,7
@@
namespace PLATFORM
protected:
#ifndef __WINDOWS__
struct termios m_options;
protected:
#ifndef __WINDOWS__
struct termios m_options;
+ pid_t m_lockPid;
#else
bool SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeoutMs);
DWORD m_iCurrentReadTimeout;
#else
bool SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeoutMs);
DWORD m_iCurrentReadTimeout;