cec: drop shared_ptr and use a normal pointer. removed boost dependency
[deb_libcec.git] / src / lib / platform / serialport.h
1 #pragma once
2
3 /*
4 * boblight
5 * Copyright (C) Bob 2009
6 *
7 * boblight is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * boblight is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "os-dependent.h"
22 #include <cectypes.h>
23 #include <string>
24 #include <stdint.h>
25 #include "../AdapterCommunication.h"
26 #include "../platform/threads.h"
27
28 #ifndef __WINDOWS__
29 #include <termios.h>
30 #else
31 #include "../util/buffer.h"
32 #endif
33
34 namespace CEC
35 {
36 #define PAR_NONE 0
37 #define PAR_EVEN 1
38 #define PAR_ODD 2
39
40 class CSerialPort
41 {
42 public:
43 CSerialPort();
44 virtual ~CSerialPort();
45
46 bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE);
47 bool IsOpen();
48 void Close();
49
50 int8_t Write(CCECAdapterMessage *data);
51 int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
52
53 std::string GetError() { return m_error; }
54 std::string GetName() { return m_name; }
55
56 private:
57 bool SetBaudRate(uint32_t baudrate);
58
59 std::string m_error;
60 std::string m_name;
61 CMutex m_mutex;
62
63 #ifdef __WINDOWS__
64 bool SetTimeouts(bool bBlocking);
65
66 HANDLE m_handle;
67 bool m_bIsOpen;
68 uint32_t m_iBaudrate;
69 uint8_t m_iDatabits;
70 uint8_t m_iStopbits;
71 uint8_t m_iParity;
72 int64_t m_iTimeout;
73 CecBuffer<uint8_t> m_buffer;
74 HANDLE m_ovHandle;
75 #else
76 struct termios m_options;
77 int m_fd;
78 #endif
79 };
80 };