Skip to content

Commit

Permalink
Merge pull request #147 from crayzeewulf/linux_specific_ifdefs
Browse files Browse the repository at this point in the history
Apply linux specific #ifdef __linux__ encapsulation of the GetAvailableSerialPort() methods.
  • Loading branch information
crayzeewulf committed Jul 2, 2019
2 parents c6d9da9 + 5d41f07 commit 8eabea1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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
Expand Down Expand Up @@ -679,11 +682,13 @@ namespace LibSerial
return mImpl->GetNumberOfBytesAvailable() ;
}

#ifdef __linux__
std::vector<std::string>
SerialPort::GetAvailableSerialPorts() const
{
return mImpl->GetAvailableSerialPorts() ;
}
#endif

void
SerialPort::Read(DataBuffer& dataBuffer,
Expand Down Expand Up @@ -1858,6 +1863,7 @@ namespace LibSerial
return number_of_bytes_available ;
}

#ifdef __linux__
inline
std::vector<std::string>
SerialPort::Implementation::GetAvailableSerialPorts() const
Expand Down Expand Up @@ -1902,6 +1908,7 @@ namespace LibSerial

return serial_port_names ;
}
#endif

inline
void
Expand Down
6 changes: 6 additions & 0 deletions src/SerialStreamBuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetAvailableSerialPorts() const ;
#endif

/**
* @brief Writes up to n characters from the character sequence at
Expand Down Expand Up @@ -590,11 +592,13 @@ namespace LibSerial
return mImpl->GetNumberOfBytesAvailable() ;
}

#ifdef __linux__
std::vector<std::string>
SerialStreamBuf::GetAvailableSerialPorts() const
{
return mImpl->GetAvailableSerialPorts() ;
}
#endif

std::streambuf*
SerialStreamBuf::setbuf(char_type* character, std::streamsize numberOfBytes)
Expand Down Expand Up @@ -924,12 +928,14 @@ namespace LibSerial
return mSerialPort.GetNumberOfBytesAvailable() ;
}

#ifdef __linux__
inline
std::vector<std::string>
SerialStreamBuf::Implementation::GetAvailableSerialPorts() const
{
return mSerialPort.GetAvailableSerialPorts() ;
}
#endif

inline
std::streamsize
Expand Down
2 changes: 2 additions & 0 deletions src/libserial/SerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetAvailableSerialPorts() const ;
#endif

/**
* @brief Reads the specified number of bytes from the serial port.
Expand Down
2 changes: 2 additions & 0 deletions src/libserial/SerialStreamBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetAvailableSerialPorts() const ;
#endif

protected:

Expand Down
4 changes: 4 additions & 0 deletions test/SerialPortUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ SerialPortUnitTests::testSerialPortGetNumberOfBytesAvailable()
ASSERT_FALSE(serialPort2.IsOpen()) ;
}

#ifdef __linux__
void
SerialPortUnitTests::testSerialPortGetAvailableSerialPorts()
{
Expand All @@ -804,6 +805,7 @@ SerialPortUnitTests::testSerialPortGetAvailableSerialPorts()
ASSERT_FALSE(serialPort1.IsOpen()) ;
ASSERT_FALSE(serialPort2.IsOpen()) ;
}
#endif

void
SerialPortUnitTests::testSerialPortReadDataBufferWriteDataBuffer()
Expand Down Expand Up @@ -1234,6 +1236,7 @@ TEST_F(SerialPortUnitTests, testSerialPortGetNumberOfBytesAvailable)
}
}

#ifdef __linux__
TEST_F(SerialPortUnitTests, testSerialPortGetAvailableSerialPorts)
{
SCOPED_TRACE("Serial Port GetAvailableSerialPorts() Test") ;
Expand All @@ -1243,6 +1246,7 @@ TEST_F(SerialPortUnitTests, testSerialPortGetAvailableSerialPorts)
testSerialPortGetAvailableSerialPorts() ;
}
}
#endif

TEST_F(SerialPortUnitTests, testSerialPortReadDataBufferWriteDataBuffer)
{
Expand Down
2 changes: 2 additions & 0 deletions test/SerialPortUnitTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/SerialStreamUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ SerialStreamUnitTests::testSerialStreamGetNumberOfBytesAvailable()
ASSERT_FALSE(serialStream2.IsOpen()) ;
}

#ifdef __linux__
void
SerialStreamUnitTests::testSerialStreamGetAvailableSerialPorts()
{
Expand All @@ -826,6 +827,7 @@ SerialStreamUnitTests::testSerialStreamGetAvailableSerialPorts()
ASSERT_FALSE(serialStream1.IsOpen()) ;
ASSERT_FALSE(serialStream2.IsOpen()) ;
}
#endif

void
SerialStreamUnitTests::testSerialStreamReadByteWriteByte()
Expand Down Expand Up @@ -1143,6 +1145,7 @@ TEST_F(SerialStreamUnitTests, testSerialStreamGetNumberOfBytesAvailable)
}
}

#ifdef __linux__
TEST_F(SerialStreamUnitTests, testSerialStreamGetAvailableSerialPorts)
{
SCOPED_TRACE("Serial Stream GetAvailableSerialPorts() Test") ;
Expand All @@ -1152,6 +1155,7 @@ TEST_F(SerialStreamUnitTests, testSerialStreamGetAvailableSerialPorts)
testSerialStreamGetAvailableSerialPorts() ;
}
}
#endif

TEST_F(SerialStreamUnitTests, testSerialStreamReadByteWriteByte)
{
Expand Down
2 changes: 2 additions & 0 deletions test/SerialStreamUnitTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8eabea1

Please sign in to comment.