Skip to content

Commit c84214a

Browse files
taketook34AksonovSergei
authored andcommitted
Issue #29. FIxed code style and class destructor check
1 parent 2a72541 commit c84214a

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

src/kpi_rover_ecu/include/IClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class IClient {
1414
virtual bool Receive(std::vector<std::uint8_t>& data) = 0;
1515
virtual int Init(std::string ip_address, int port) = 0;
1616
virtual void Destroy() = 0;
17-
// virtual ~IClient() = default;
17+
virtual ~IClient() = default;
1818

1919
IClient(const IClient&) = delete;
2020
IClient& operator=(const IClient&) = delete;

src/kpi_rover_ecu/include/ITransport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ITransport {
1414
virtual int Init() = 0;
1515
virtual void Start() = 0;
1616
virtual void Destroy() = 0;
17-
// virtual ~ITransport() = default;
17+
virtual ~ITransport() = default;
1818

1919
ITransport(const ITransport&) = delete;
2020
ITransport& operator=(const ITransport&) = delete;

src/kpi_rover_ecu/include/TCPTransport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TCPTransport : public ITransport {
2222
TCPTransport& operator=(const TCPTransport&) = delete;
2323
TCPTransport(TCPTransport&&) = delete;
2424
TCPTransport& operator=(TCPTransport&&) = delete;
25-
// ~TCPTransport() override;
25+
~TCPTransport() override;
2626

2727
bool Send(const std::vector<std::uint8_t>& data) override;
2828
bool Receive(std::vector<std::uint8_t>& data) override;

src/kpi_rover_ecu/include/UDPClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UDPClient : public IClient {
2323
bool Send(const std::vector<std::uint8_t>& data) override;
2424
bool Receive(std::vector<std::uint8_t>& data) override;
2525
void Destroy() override;
26-
// ~UDPClient() override;
26+
~UDPClient() override;
2727

2828
private:
2929
int sockfd_;

src/kpi_rover_ecu/src/KPIRoverECU.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool KPIRoverECU::Start() {
3131
processingThread_ = std::thread([this] { ProcessingThreadFunction(); });
3232
imuThread_ = std::thread([this] { IMUThreadFucntion(this->imu_controller_); });
3333

34-
if (!timerThread_.joinable() || !processingThread_.joinable() || !imuThread_.joinable() ) {
34+
if (!timerThread_.joinable() || !processingThread_.joinable() || !imuThread_.joinable()) {
3535
std::cout << "Error creating thread" << '\n';
3636
return false;
3737
}
@@ -49,7 +49,9 @@ void KPIRoverECU::IMUThreadFucntion(IMUController *workClass) {
4949
if (destination_address.empty()) {
5050
destination_address = tcp_transport_->GetClientIp();
5151
destination_port = tcp_transport_->GetClientPort();
52-
if (!destination_address.empty()) { udp_client_->Init(destination_address, destination_port); }
52+
if (!destination_address.empty()) {
53+
udp_client_->Init(destination_address, destination_port);
54+
}
5355

5456
} else {
5557
const std::vector<float> kImuData = workClass->GetData();
@@ -82,7 +84,6 @@ void KPIRoverECU::IMUThreadFucntion(IMUController *workClass) {
8284
}
8385
}
8486
udp_client_->Send(send_val);
85-
8687
}
8788
}
8889
rc_usleep(kTimerPrecision);

src/kpi_rover_ecu/src/TCPTransport.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ TCPTransport::TCPTransport(const char *ip_address, int port)
2626
strncpy(server_address_, ip_address, strlen(ip_address) + 1);
2727
}
2828

29-
// TCPTransport::~TCPTransport() {
30-
// running_ = false;
31-
// shutdown(sockfd_, SHUT_RDWR);
32-
// std::cout << "joining thread ... " << '\n';
33-
// acceptThread_.join();
34-
// std::cout << "closing socket" << '\n';
35-
// close(client_sockfd_);
36-
// close(sockfd_);
37-
// delete[] server_address_;
38-
// }
29+
TCPTransport::~TCPTransport() {
30+
running_ = false;
31+
shutdown(sockfd_, SHUT_RDWR);
32+
std::cout << "joining thread ... " << '\n';
33+
acceptThread_.join();
34+
std::cout << "closing socket" << '\n';
35+
close(client_sockfd_);
36+
close(sockfd_);
37+
delete[] server_address_;
38+
}
3939

4040
int TCPTransport::Init() {
4141
struct sockaddr_in serv_addr = {};

src/kpi_rover_ecu/src/UDPClient.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ void UDPClient::Destroy() {
5454
std::cout << "joining udp client socket ..." << '\n';
5555
}
5656

57-
// UDPClient::~UDPClient() {
58-
// shutdown(sockfd_, SHUT_WR);
57+
UDPClient::~UDPClient() {
58+
shutdown(sockfd_, SHUT_WR);
5959

60-
// close(sockfd_);
61-
// }
60+
close(sockfd_);
61+
std::cout << "joining udp client socket ..." << '\n';
62+
}

src/kpi_rover_ecu/src/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ int main(int argc, char* argv[]) {
109109

110110
kpi_rover_ecu.Stop();
111111
motors_processor.Destroy();
112-
tcp_transport.Destroy();
113-
udp_client.Destroy();
114112

115113
return 0;
116114
}

0 commit comments

Comments
 (0)