<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
+
<ItemGroup>
<ResourceCompile Include="libcec.rc" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
+
#include "devices/CECTV.h"
#include "implementations/CECCommandHandler.h"
#include "LibCEC.h"
+#include "platform/util/timeutils.h"
using namespace CEC;
using namespace std;
#include <string>
#include <cectypes.h>
#include "adapter/AdapterCommunication.h"
-#include "platform/os.h"
+#include "platform/util/buffer.h"
class CSerialPort;
#include "adapter/AdapterDetection.h"
#include "CECProcessor.h"
#include "devices/CECBusDevice.h"
-#include "platform/timeutils.h"
+#include "platform/util/timeutils.h"
+#include "platform/util/StdString.h"
using namespace std;
using namespace CEC;
#include <string>
#include <cec.h>
-#include "platform/os.h"
+#include "platform/util/buffer.h"
namespace CEC
{
#include "AdapterMessage.h"
#include "../CECProcessor.h"
-#include "../platform/serialport/serialport.h"
+#include "../platform/sockets/serialport.h"
+#include "../platform/util/timeutils.h"
#include "../LibCEC.h"
using namespace std;
return bGotFullMessage;
}
-std::string CAdapterCommunication::GetError(void) const
+CStdString CAdapterCommunication::GetError(void) const
{
- return m_port->GetError();
+ CStdString strError;
+ strError = m_port->GetError();
+ return strError;
}
bool CAdapterCommunication::StartBootloader(void)
*/
#include <cectypes.h>
-#include "../platform/os.h"
+#include "../platform/threads/threads.h"
+#include "../platform/util/buffer.h"
+#include "../platform/util/StdString.h"
namespace PLATFORM
{
bool Write(CCECAdapterMessage *data);
void Close(void);
bool IsOpen(void);
- std::string GetError(void) const;
+ CStdString GetError(void) const;
void *Process(void);
*/
#include "AdapterDetection.h"
-#include "../platform/os.h"
+#include "../platform/util/StdString.h"
#if defined(__APPLE__)
#include <dirent.h>
* http://www.pulse-eight.net/
*/
+#include "platform/util/StdString.h"
+
namespace CEC
{
typedef enum cec_adapter_message_state
#include "../implementations/SLCommandHandler.h"
#include "../implementations/VLCommandHandler.h"
#include "../LibCEC.h"
+#include "../platform/util/timeutils.h"
using namespace CEC;
using namespace PLATFORM;
#include <cectypes.h>
#include <set>
-#include "../platform/os.h"
+#include "../platform/threads/mutex.h"
+#include "../platform/util/StdString.h"
namespace CEC
{
#include <cectypes.h>
#include <vector>
-#include "../platform/os.h"
+#include "../platform/threads/mutex.h"
+#include "../platform/util/StdString.h"
namespace CEC
{
* http://www.pulse-eight.net/
*/
-#if defined(_WIN32) || defined(_WIN64)
-#ifndef __WINDOWS__
-#define __WINDOWS__
-#endif
+#if (defined(_WIN32) || defined(_WIN64))
#include "windows/os-types.h"
-#include "windows/os-threads.h"
#else
#include "posix/os-types.h"
-#include "posix/os-threads.h"
#endif
-
-#include "timeutils.h"
-#include "threads/threads.h"
-#include "buffer.h"
-#include "StdString.h"
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+
+#include "../os.h"
+#include "../util/timeutils.h"
+#include <stdio.h>
+#include <fcntl.h>
+
+namespace PLATFORM
+{
+ inline void SocketClose(socket_t socket)
+ {
+ if (socket != INVALID_SOCKET)
+ close(socket);
+ }
+
+ inline void SocketSetBlocking(socket_t socket, bool bSetTo)
+ {
+// return bSetTo ?
+// fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK) == 0 :
+// fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK) == 0;
+ fcntl(socket, F_SETFL, bSetTo ? FNDELAY : 0);
+ }
+
+ inline int64_t SocketWrite(socket_t socket, int *iError, uint8_t* data, uint32_t len)
+ {
+ fd_set port;
+
+ if (socket == -1)
+ {
+ *iError = EINVAL;
+ return -1;
+ }
+
+ int64_t iBytesWritten = 0;
+ struct timeval *tv;
+
+ while (iBytesWritten < len)
+ {
+ FD_ZERO(&port);
+ FD_SET(socket, &port);
+ int returnv = select(socket + 1, NULL, &port, NULL, tv);
+ if (returnv < 0)
+ {
+ *iError = errno;
+ return -1;
+ }
+ else if (returnv == 0)
+ {
+ *iError = ETIMEDOUT;
+ return -1;
+ }
+
+ returnv = write(socket, data + iBytesWritten, len - iBytesWritten);
+ if (returnv == -1)
+ {
+ *iError = errno;
+ return -1;
+ }
+ iBytesWritten += returnv;
+ }
+
+ return iBytesWritten;
+ }
+
+ inline int32_t SocketRead(socket_t socket, int *iError, uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0*/)
+ {
+ fd_set port;
+ struct timeval timeout, *tv;
+ int64_t iNow(0), iTarget(0);
+ int32_t iBytesRead = 0;
+ *iError = 0;
+
+ if (socket == -1)
+ {
+ *iError = EINVAL;
+ return -1;
+ }
+
+ if (iTimeoutMs > 0)
+ {
+ iNow = GetTimeMs();
+ iTarget = iNow + (int64_t) iTimeoutMs;
+ }
+
+ while (iBytesRead < (int32_t) len && (iTimeoutMs == 0 || iTarget > iNow))
+ {
+ if (iTimeoutMs == 0)
+ {
+ tv = NULL;
+ }
+ else
+ {
+ timeout.tv_sec = ((long int)iTarget - (long int)iNow) / (long int)1000.;
+ timeout.tv_usec = ((long int)iTarget - (long int)iNow) % (long int)1000.;
+ tv = &timeout;
+ }
+
+ FD_ZERO(&port);
+ FD_SET(socket, &port);
+ int32_t returnv = select(socket + 1, &port, NULL, NULL, tv);
+
+ if (returnv == -1)
+ {
+ *iError = errno;
+ return -1;
+ }
+ else if (returnv == 0)
+ {
+ break; //nothing to read
+ }
+
+ returnv = read(socket, data + iBytesRead, len - iBytesRead);
+ if (returnv == -1)
+ {
+ *iError = errno;
+ return -1;
+ }
+
+ iBytesRead += returnv;
+
+ if (iTimeoutMs > 0)
+ iNow = GetTimeMs();
+ }
+
+ return iBytesRead;
+ }
+}
#define LIBTYPE
#define DECLSPEC
+typedef int socket_t;
+#define INVALID_SOCKET (-1)
+#define SOCKET_ERROR (-1)
+
* http://www.pulse-eight.net/
*/
+#include "../os.h"
#include <stdio.h>
#include <fcntl.h>
-#include "../serialport/serialport.h"
-#include "../serialport/baudrate.h"
-#include "../timeutils.h"
+#include "../sockets/serialport.h"
+#include "../util/baudrate.h"
#if defined(__APPLE__)
#ifndef XCASE
CSerialPort::CSerialPort()
{
- m_fd = -1;
m_tostdout = false;
}
-CSerialPort::~CSerialPort()
-{
- Close();
-}
-
-int64_t CSerialPort::Write(uint8_t* data, uint32_t len)
-{
- fd_set port;
-
- CLockObject lock(m_mutex);
- if (m_fd == -1)
- {
- m_error = "port closed";
- return -1;
- }
-
- int64_t byteswritten = 0;
- struct timeval *tv;
-//TODO
-// struct timeval timeout, *tv;
-// if (data->transmit_timeout <= 0)
-// {
- tv = NULL;
-// }
-// else
-// {
-// timeout.tv_sec = (long int)data->transmit_timeout / (long int)1000.;
-// timeout.tv_usec = (long int)data->transmit_timeout % (long int)1000.;
-// tv = &timeout;
-// }
-
- while (byteswritten < len)
- {
- FD_ZERO(&port);
- FD_SET(m_fd, &port);
- int returnv = select(m_fd + 1, NULL, &port, NULL, tv);
- if (returnv < 0)
- {
- m_error = strerror(errno);
- return -1;
- }
- else if (returnv == 0)
- {
- m_error = "timeout";
- return -1;
- }
-
- returnv = write(m_fd, data + byteswritten, len - byteswritten);
- if (returnv == -1)
- {
- m_error = strerror(errno);
- return -1;
- }
- byteswritten += returnv;
- }
-
- //print what's written to stdout for debugging
- if (m_tostdout)
- {
- printf("%s write:", m_name.c_str());
- for (int i = 0; i < byteswritten; i++)
- printf(" %02x", data[i]);
-
- printf("\n");
- }
-
- return byteswritten;
-}
-
-int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0*/)
-{
- fd_set port;
- struct timeval timeout, *tv;
- int64_t now(0), target(0);
- int32_t bytesread = 0;
-
- CLockObject lock(m_mutex);
- if (m_fd == -1)
- {
- m_error = "port closed";
- return -1;
- }
-
- if (iTimeoutMs > 0)
- {
- now = GetTimeMs();
- target = now + (int64_t) iTimeoutMs;
- }
-
- while (bytesread < (int32_t) len && (iTimeoutMs == 0 || target > now))
- {
- if (iTimeoutMs == 0)
- {
- tv = NULL;
- }
- else
- {
- timeout.tv_sec = ((long int)target - (long int)now) / (long int)1000.;
- timeout.tv_usec = ((long int)target - (long int)now) % (long int)1000.;
- tv = &timeout;
- }
-
- FD_ZERO(&port);
- FD_SET(m_fd, &port);
- int32_t returnv = select(m_fd + 1, &port, NULL, NULL, tv);
-
- if (returnv == -1)
- {
- m_error = strerror(errno);
- return -1;
- }
- else if (returnv == 0)
- {
- break; //nothing to read
- }
-
- returnv = read(m_fd, data + bytesread, len - bytesread);
- if (returnv == -1)
- {
- m_error = strerror(errno);
- return -1;
- }
-
- bytesread += returnv;
-
- if (iTimeoutMs > 0)
- now = GetTimeMs();
- }
-
- //print what's read to stdout for debugging
- if (m_tostdout && bytesread > 0)
- {
- printf("%s read:", m_name.c_str());
- for (int i = 0; i < bytesread; i++)
- printf(" %02x", data[i]);
-
- printf("\n");
- }
-
- return bytesread;
-}
-
//setting all this stuff up is a pain in the ass
bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits /* = 8 */, uint8_t stopbits /* = 1 */, uint8_t parity /* = PAR_NONE */)
{
m_name = name;
- m_error = strerror(errno);
CLockObject lock(m_mutex);
if (databits < 5 || databits > 8)
{
- m_error = "Databits has to be between 5 and 8";
+ m_strError = "Databits has to be between 5 and 8";
return false;
}
if (stopbits != 1 && stopbits != 2)
{
- m_error = "Stopbits has to be 1 or 2";
+ m_strError = "Stopbits has to be 1 or 2";
return false;
}
if (parity != PAR_NONE && parity != PAR_EVEN && parity != PAR_ODD)
{
- m_error = "Parity has to be none, even or odd";
+ m_strError = "Parity has to be none, even or odd";
return false;
}
- m_fd = open(name.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
+ m_socket = open(name.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
- if (m_fd == -1)
+ if (m_socket == INVALID_SOCKET)
{
- m_error = strerror(errno);
+ m_strError = strerror(errno);
return false;
}
- fcntl(m_fd, F_SETFL, 0);
+ SocketSetBlocking(m_socket, false);
if (!SetBaudRate(baudrate))
- {
return false;
- }
m_options.c_cflag |= (CLOCAL | CREAD);
m_options.c_cflag &= ~HUPCL;
m_options.c_iflag &= ~(IXON | IXOFF | IXANY | BRKINT | INLCR | IGNCR | ICRNL | IUCLC | IMAXBEL);
m_options.c_oflag &= ~(OPOST | ONLCR | OCRNL);
- if (tcsetattr(m_fd, TCSANOW, &m_options) != 0)
+ if (tcsetattr(m_socket, TCSANOW, &m_options) != 0)
{
- m_error = strerror(errno);
+ m_strError = strerror(errno);
return false;
}
- //non-blocking port
- fcntl(m_fd, F_SETFL, FNDELAY);
+ SocketSetBlocking(m_socket, true);
return true;
}
-void CSerialPort::Close()
-{
- CLockObject lock(m_mutex);
- if (m_fd != -1)
- {
- close(m_fd);
- m_fd = -1;
- m_name = "";
- m_error = "";
- }
-}
-
bool CSerialPort::SetBaudRate(uint32_t baudrate)
{
int rate = IntToBaudrate(baudrate);
{
char buff[255];
sprintf(buff, "%i is not a valid baudrate", baudrate);
- m_error = buff;
+ m_strError = buff;
return false;
}
//get the current port attributes
- if (tcgetattr(m_fd, &m_options) != 0)
+ if (tcgetattr(m_socket, &m_options) != 0)
{
- m_error = strerror(errno);
+ m_strError = strerror(errno);
return false;
}
if (cfsetispeed(&m_options, rate) != 0)
{
- m_error = strerror(errno);
+ m_strError = strerror(errno);
return false;
}
if (cfsetospeed(&m_options, rate) != 0)
{
- m_error = strerror(errno);
+ m_strError = strerror(errno);
return false;
}
return true;
}
-
-bool CSerialPort::IsOpen()
-{
- CLockObject lock(m_mutex);
- return m_fd != -1;
-}
*/
#include "../os.h"
+#include "../util/buffer.h"
+
#include <string>
#include <stdint.h>
-#ifndef __WINDOWS__
+#if !defined(__WINDOWS__)
#include <termios.h>
+#include "socket.h"
#endif
namespace PLATFORM
#define PAR_EVEN 1
#define PAR_ODD 2
- class CSerialPort
+ class CSerialPort : public CSocket
{
public:
- CSerialPort();
- virtual ~CSerialPort();
+ CSerialPort(void);
+ virtual ~CSerialPort(void) {};
bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE);
- bool IsOpen();
- void Close();
-
- int64_t Write(uint8_t* data, uint32_t len);
- int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
- std::string GetError() { return m_error; }
- std::string GetName() { return m_name; }
+ CStdString GetName(void) const
+ {
+ CStdString strName;
+ strName = m_name;
+ return strName;
+ }
private:
bool SetBaudRate(uint32_t baudrate);
- std::string m_error;
std::string m_name;
- CMutex m_mutex;
bool m_tostdout;
#ifdef __WINDOWS__
HANDLE m_ovHandle;
#else
struct termios m_options;
- int m_fd;
#endif
};
};
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#include "../threads/mutex.h"
+#include "../util/StdString.h"
+
+#if defined(__WINDOWS__)
+#include "../windows/os-socket.h"
+#else
+#include "../posix/os-socket.h"
+#endif
+
+// Common socket operations
+
+namespace PLATFORM
+{
+ class CSocket : public PreventCopy
+ {
+ public:
+ CSocket(void) :
+ m_socket(INVALID_SOCKET) {};
+ virtual ~CSocket(void)
+ {
+ Close();
+ }
+
+ virtual bool IsOpen(void)
+ {
+ CLockObject lock(m_mutex);
+ return m_socket != INVALID_SOCKET &&
+ m_socket != SOCKET_ERROR;
+ }
+
+ virtual void Close(void)
+ {
+ CLockObject lock(m_mutex);
+ SocketClose(m_socket);
+ m_socket = INVALID_SOCKET;
+ m_strError = "";
+ }
+
+ int64_t Write(uint8_t* data, uint32_t len)
+ {
+ CLockObject lock(m_mutex);
+ int iError(0);
+ int64_t iReturn = SocketWrite(m_socket, &iError, data, len);
+ m_strError = strerror(iError);
+ return iReturn;
+ }
+
+ int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0)
+ {
+ CLockObject lock(m_mutex);
+ int iError(0);
+ int32_t iReturn = SocketRead(m_socket, &iError, data, len, iTimeoutMs);
+ m_strError = strerror(iError);
+ return iReturn;
+ }
+
+ virtual CStdString GetError(void) const
+ {
+ CStdString strReturn;
+ strReturn = m_strError;
+ return strReturn;
+ }
+
+ protected:
+ socket_t m_socket;
+ CStdString m_strError;
+ CMutex m_mutex;
+ };
+};
* http://www.pulse-eight.net/
*/
+#include "../os.h"
+
+#if defined(__WINDOWS__)
+#include "../windows/os-threads.h"
+#else
+#include "../posix/os-threads.h"
+#endif
+
namespace PLATFORM
{
class PreventCopy
* http://www.pulse-eight.net/
*/
-#include "os.h"
+#include "../threads/mutex.h"
#include <queue>
namespace PLATFORM
* http://www.pulse-eight.net/
*/
-#include <stdint.h>
+#include "../os.h"
+
#if defined(__APPLE__)
#include <mach/mach_time.h>
#include <CoreVideo/CVHostTime.h>
#include <sys/time.h>
#endif
-#include "os.h"
-
namespace PLATFORM
{
#if defined(__WINDOWS__)
* http://www.pulse-eight.net/
*/
+#if !defined(__WINDOWS__)
+#define __WINDOWS__
+#endif
+
#pragma warning(disable:4005) // Disable "warning C4005: '_WINSOCKAPI_' : macro redefinition"
#include <winsock2.h>
#pragma warning(default:4005)
* http://www.pulse-eight.net/
*/
-#include "../serialport/serialport.h"
-#include "../serialport/baudrate.h"
-#include "../timeutils.h"
+#include "../sockets/serialport.h"
+#include "../util/baudrate.h"
+#include "../util/timeutils.h"
using namespace std;
using namespace PLATFORM;