From 5d41f07c0f257aa5816d8e01694dbcae44da396e Mon Sep 17 00:00:00 2001 From: mcsauder Date: Mon, 1 Jul 2019 14:50:15 -0600 Subject: [PATCH] Apply linux specific #ifdef __linux__ encapsulation of the GetAvailableSerialPort() methods to allow compilation on MAC OS. --- src/SerialPort.cpp | 7 +++++++ src/SerialStreamBuf.cpp | 6 ++++++ src/libserial/SerialPort.h | 2 ++ src/libserial/SerialStreamBuf.h | 2 ++ test/SerialPortUnitTests.cpp | 4 ++++ test/SerialPortUnitTests.h | 2 ++ test/SerialStreamUnitTests.cpp | 4 ++++ test/SerialStreamUnitTests.h | 2 ++ 8 files changed, 29 insertions(+) diff --git a/src/SerialPort.cpp b/src/SerialPort.cpp index 6fbb1847..05a3fbec 100644 --- a/src/SerialPort.cpp +++ b/src/SerialPort.cpp @@ -285,12 +285,15 @@ namespace LibSerial */ int GetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Gets a list of available serial ports. * @return Returns a std::vector of std::strings with the name of * each available serial port. */ std::vector GetAvailableSerialPorts() const ; +#endif + /** * @brief Reads the specified number of bytes from the serial port. * The method will timeout if no data is received in the @@ -679,11 +682,13 @@ namespace LibSerial return mImpl->GetNumberOfBytesAvailable() ; } +#ifdef __linux__ std::vector SerialPort::GetAvailableSerialPorts() const { return mImpl->GetAvailableSerialPorts() ; } +#endif void SerialPort::Read(DataBuffer& dataBuffer, @@ -1858,6 +1863,7 @@ namespace LibSerial return number_of_bytes_available ; } +#ifdef __linux__ inline std::vector SerialPort::Implementation::GetAvailableSerialPorts() const @@ -1902,6 +1908,7 @@ namespace LibSerial return serial_port_names ; } +#endif inline void diff --git a/src/SerialStreamBuf.cpp b/src/SerialStreamBuf.cpp index 09202c1d..9f1afba0 100644 --- a/src/SerialStreamBuf.cpp +++ b/src/SerialStreamBuf.cpp @@ -283,12 +283,14 @@ namespace LibSerial */ int GetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Gets a list of available serial ports. * @return Returns a std::vector of std::strings with the name of * each available serial port. */ std::vector GetAvailableSerialPorts() const ; +#endif /** * @brief Writes up to n characters from the character sequence at @@ -590,11 +592,13 @@ namespace LibSerial return mImpl->GetNumberOfBytesAvailable() ; } +#ifdef __linux__ std::vector SerialStreamBuf::GetAvailableSerialPorts() const { return mImpl->GetAvailableSerialPorts() ; } +#endif std::streambuf* SerialStreamBuf::setbuf(char_type* character, std::streamsize numberOfBytes) @@ -924,12 +928,14 @@ namespace LibSerial return mSerialPort.GetNumberOfBytesAvailable() ; } +#ifdef __linux__ inline std::vector SerialStreamBuf::Implementation::GetAvailableSerialPorts() const { return mSerialPort.GetAvailableSerialPorts() ; } +#endif inline std::streamsize diff --git a/src/libserial/SerialPort.h b/src/libserial/SerialPort.h index 19a6fcc5..229b369c 100644 --- a/src/libserial/SerialPort.h +++ b/src/libserial/SerialPort.h @@ -297,12 +297,14 @@ namespace LibSerial */ int GetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Gets a list of available serial ports. * @return Returns a std::vector of std::strings with the name of * each available serial port. */ std::vector GetAvailableSerialPorts() const ; +#endif /** * @brief Reads the specified number of bytes from the serial port. diff --git a/src/libserial/SerialStreamBuf.h b/src/libserial/SerialStreamBuf.h index f2de97e5..8843c9fe 100644 --- a/src/libserial/SerialStreamBuf.h +++ b/src/libserial/SerialStreamBuf.h @@ -300,12 +300,14 @@ namespace LibSerial */ int GetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Gets a list of available serial ports. * @return Returns a std::vector of std::strings with the name of * each available serial port. */ std::vector GetAvailableSerialPorts() const ; +#endif protected: diff --git a/test/SerialPortUnitTests.cpp b/test/SerialPortUnitTests.cpp index 64022b4d..984ceeb3 100644 --- a/test/SerialPortUnitTests.cpp +++ b/test/SerialPortUnitTests.cpp @@ -782,6 +782,7 @@ SerialPortUnitTests::testSerialPortGetNumberOfBytesAvailable() ASSERT_FALSE(serialPort2.IsOpen()) ; } +#ifdef __linux__ void SerialPortUnitTests::testSerialPortGetAvailableSerialPorts() { @@ -804,6 +805,7 @@ SerialPortUnitTests::testSerialPortGetAvailableSerialPorts() ASSERT_FALSE(serialPort1.IsOpen()) ; ASSERT_FALSE(serialPort2.IsOpen()) ; } +#endif void SerialPortUnitTests::testSerialPortReadDataBufferWriteDataBuffer() @@ -1234,6 +1236,7 @@ TEST_F(SerialPortUnitTests, testSerialPortGetNumberOfBytesAvailable) } } +#ifdef __linux__ TEST_F(SerialPortUnitTests, testSerialPortGetAvailableSerialPorts) { SCOPED_TRACE("Serial Port GetAvailableSerialPorts() Test") ; @@ -1243,6 +1246,7 @@ TEST_F(SerialPortUnitTests, testSerialPortGetAvailableSerialPorts) testSerialPortGetAvailableSerialPorts() ; } } +#endif TEST_F(SerialPortUnitTests, testSerialPortReadDataBufferWriteDataBuffer) { diff --git a/test/SerialPortUnitTests.h b/test/SerialPortUnitTests.h index 3da68af4..2a649c81 100644 --- a/test/SerialPortUnitTests.h +++ b/test/SerialPortUnitTests.h @@ -166,10 +166,12 @@ namespace LibSerial */ void testSerialPortGetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Tests for correct functionality of the GetAvailableSerialPorts() method. */ void testSerialPortGetAvailableSerialPorts() ; +#endif /** * @brief Tests for correct functionality of the ReadDataBuffer() and WriteDataBuffer() methods. diff --git a/test/SerialStreamUnitTests.cpp b/test/SerialStreamUnitTests.cpp index 7f766356..21d6e73d 100644 --- a/test/SerialStreamUnitTests.cpp +++ b/test/SerialStreamUnitTests.cpp @@ -804,6 +804,7 @@ SerialStreamUnitTests::testSerialStreamGetNumberOfBytesAvailable() ASSERT_FALSE(serialStream2.IsOpen()) ; } +#ifdef __linux__ void SerialStreamUnitTests::testSerialStreamGetAvailableSerialPorts() { @@ -826,6 +827,7 @@ SerialStreamUnitTests::testSerialStreamGetAvailableSerialPorts() ASSERT_FALSE(serialStream1.IsOpen()) ; ASSERT_FALSE(serialStream2.IsOpen()) ; } +#endif void SerialStreamUnitTests::testSerialStreamReadByteWriteByte() @@ -1143,6 +1145,7 @@ TEST_F(SerialStreamUnitTests, testSerialStreamGetNumberOfBytesAvailable) } } +#ifdef __linux__ TEST_F(SerialStreamUnitTests, testSerialStreamGetAvailableSerialPorts) { SCOPED_TRACE("Serial Stream GetAvailableSerialPorts() Test") ; @@ -1152,6 +1155,7 @@ TEST_F(SerialStreamUnitTests, testSerialStreamGetAvailableSerialPorts) testSerialStreamGetAvailableSerialPorts() ; } } +#endif TEST_F(SerialStreamUnitTests, testSerialStreamReadByteWriteByte) { diff --git a/test/SerialStreamUnitTests.h b/test/SerialStreamUnitTests.h index f5f0156c..03439152 100644 --- a/test/SerialStreamUnitTests.h +++ b/test/SerialStreamUnitTests.h @@ -167,10 +167,12 @@ namespace LibSerial */ void testSerialStreamGetNumberOfBytesAvailable() ; +#ifdef __linux__ /** * @brief Tests for correct functionality of the GetAvailableSerialPorts() method. */ void testSerialStreamGetAvailableSerialPorts() ; +#endif /** * @brief Tests for correct functionality of the ReadByte() and WriteByte() methods.