Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lestarch: adding a ready port to bytestreamdriver and the tcp implementors #853

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Drv/ByteStreamDriverModel/ByteStreamDriverComponentAi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<import_port_type>Drv/ByteStreamDriverModel/ByteStreamSendPortAi.xml</import_port_type>
<import_port_type>Drv/ByteStreamDriverModel/ByteStreamRecvPortAi.xml</import_port_type>
<import_port_type>Drv/ByteStreamDriverModel/ByteStreamPollPortAi.xml</import_port_type>
<import_port_type>Drv/ByteStreamDriverModel/ByteStreamReadyPortAi.xml</import_port_type>
<import_port_type>Fw/Log/LogPortAi.xml</import_port_type>
<import_port_type>Fw/Log/LogTextPortAi.xml</import_port_type>
<import_port_type>Fw/Time/TimePortAi.xml</import_port_type>
Expand All @@ -21,6 +22,9 @@
<port name="poll" data_type="Drv::ByteStreamPoll" kind="guarded_input" max_number="1">
</port>

<port name="ready" data_type="Drv::ByteStreamReady" kind="output" max_number="1">
</port>

<!-- Buffer request port used for incoming data -->
<port name="allocate" data_type="Fw::BufferGet" kind="output" max_number="1">
</port>
Expand Down
4 changes: 4 additions & 0 deletions Drv/ByteStreamDriverModel/ByteStreamReadyPortAi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<interface name="ByteStreamReady" namespace="Drv">
</interface>
1 change: 1 addition & 0 deletions Drv/ByteStreamDriverModel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamRecvPortAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamSendPortAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamPollPortAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamReadyPortAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamDriverComponentAi.xml"
)

Expand Down
9 changes: 7 additions & 2 deletions Drv/Ip/SocketReadTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ void SocketReadTask::startSocketTask(const Fw::StringBase &name,
}

SocketIpStatus SocketReadTask::open() {
return this->getSocketHandler().open();
SocketIpStatus status = this->getSocketHandler().open();
// Call connected any time the open is successful
if (Drv::SOCK_SUCCESS == status) {
this->connected();
}
return status;
}

void SocketReadTask::close() {
Expand All @@ -60,7 +65,7 @@ void SocketReadTask::readTask(void* pointer) {
do {
// Open a network connection if it has not already been open
if ((not self->getSocketHandler().isOpened()) and (not self->m_stop) and
((status = self->getSocketHandler().open()) != SOCK_SUCCESS)) {
((status = self->open()) != SOCK_SUCCESS)) {
Fw::Logger::logMsg("[WARNING] Failed to open port with status %d and errno %d\n", status, errno);
Os::Task::delay(SOCKET_RETRY_INTERVAL_MS);
}
Expand Down
5 changes: 5 additions & 0 deletions Drv/Ip/SocketReadTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class SocketReadTask {
*/
virtual void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) = 0;

/**
* \brief called when the IPv4 system has been connected
*/
virtual void connected() = 0;

/**
* \brief a task designed to read from the socket and output incoming data
*
Expand Down
7 changes: 7 additions & 0 deletions Drv/TcpClient/TcpClientComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ void TcpClientComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status
this->recv_out(0, buffer, (status == SOCK_SUCCESS) ? RECV_OK : RECV_ERROR);
}

void TcpClientComponentImpl::connected() {
if (isConnected_ready_OutputPort(0)) {
this->ready_out(0);
}

}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Drv/TcpClient/TcpClientComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class TcpClientComponentImpl : public ByteStreamDriverModelComponentBase, public
*/
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status);

/**
* \brief called when the IPv4 system has been connected
*/
void connected();


PRIVATE:

// ----------------------------------------------------------------------
Expand Down
25 changes: 19 additions & 6 deletions Drv/TcpClient/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ void Tester ::test_with_loop(U32 iterations, bool recv_thread) {
while (not m_spinner) {}
}
}
this->component.close();
// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
} else {
this->component.close();
}
server.close();
}
// Wait for the receiver to shutdown
if (recv_thread) {
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
}
server.shutdown();
ASSERT_from_ready_SIZE(iterations);
}

Tester ::Tester(void)
Expand Down Expand Up @@ -146,6 +149,10 @@ void Tester ::test_advanced_reconnect(void) {
delete[] recvBuffer.getData();
}

void Tester ::from_ready_handler(const NATIVE_INT_TYPE portNum) {
this->pushFromPortEntry_ready();
}

Fw::Buffer Tester ::
from_allocate_handler(
const NATIVE_INT_TYPE portNum,
Expand Down Expand Up @@ -193,6 +200,12 @@ Fw::Buffer Tester ::
this->get_from_recv(0)
);

// recv
this->component.set_ready_OutputPort(
0,
this->get_from_ready(0)
);

// allocate
this->component.set_allocate_OutputPort(
0,
Expand Down
6 changes: 6 additions & 0 deletions Drv/TcpClient/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ namespace Drv {
RecvStatus recvStatus
);

//! Handler for from_ready
//!
void from_ready_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);

//! Handler for from_allocate
//!
Fw::Buffer from_allocate_handler(
Expand Down
7 changes: 7 additions & 0 deletions Drv/TcpServer/TcpServerComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ void TcpServerComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status
this->recv_out(0, buffer, (status == SOCK_SUCCESS) ? RECV_OK : RECV_ERROR);
}

void TcpServerComponentImpl::connected() {
if (isConnected_ready_OutputPort(0)) {
this->ready_out(0);
}

}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Drv/TcpServer/TcpServerComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class TcpServerComponentImpl : public ByteStreamDriverModelComponentBase, public
*/
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status);

/**
* \brief called when the IPv4 system has been connected
*/
void connected();


PRIVATE:

// ----------------------------------------------------------------------
Expand Down
28 changes: 20 additions & 8 deletions Drv/TcpServer/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ void Tester ::test_with_loop(U32 iterations, bool recv_thread) {
while (not m_spinner) {}
}
}
this->component.close();
client.close();
}
// Wait for the receiver to shutdown
if (recv_thread) {
this->component.shutdown();
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
client.close(); // Client must be closed first or the server risks binding to an existing address
// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
this->component.shutdown();
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
} else {
this->component.close();
}
}
ASSERT_from_ready_SIZE(iterations);
}

Tester ::Tester(void)
Expand Down Expand Up @@ -143,6 +145,10 @@ void Tester ::from_recv_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& recvB
delete[] recvBuffer.getData();
}

void Tester ::from_ready_handler(const NATIVE_INT_TYPE portNum) {
this->pushFromPortEntry_ready();
}

Fw::Buffer Tester ::
from_allocate_handler(
const NATIVE_INT_TYPE portNum,
Expand Down Expand Up @@ -190,6 +196,12 @@ void Tester ::
this->get_from_recv(0)
);

// recv
this->component.set_ready_OutputPort(
0,
this->get_from_ready(0)
);

// allocate
this->component.set_allocate_OutputPort(
0,
Expand Down
6 changes: 6 additions & 0 deletions Drv/TcpServer/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace Drv {
RecvStatus recvStatus
);

//! Handler for from_ready
//!
void from_ready_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);

//! Handler for from_allocate
//!
Fw::Buffer from_allocate_handler(
Expand Down
6 changes: 6 additions & 0 deletions Drv/Udp/UdpComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ void UdpComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
this->recv_out(0, buffer, (status == SOCK_SUCCESS) ? RECV_OK : RECV_ERROR);
}

void UdpComponentImpl::connected() {
if (isConnected_ready_OutputPort(0)) {
this->ready_out(0);
}
}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions Drv/Udp/UdpComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class UdpComponentImpl : public ByteStreamDriverModelComponentBase, public Socke
*/
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status);

/**
* \brief called when the IPv4 system has been connected
*/
void connected();

PRIVATE:

// ----------------------------------------------------------------------
Expand Down
24 changes: 18 additions & 6 deletions Drv/Udp/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ void Tester::test_with_loop(U32 iterations, bool recv_thread) {
while (not m_spinner) {}
}
}
this->component.close();
// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
} else {
this->component.close();
}
udp2.close();
}
// Wait for the receiver to shutdown
if (recv_thread) {
this->component.stopSocketTask();
this->component.joinSocketTask(NULL);
}
ASSERT_from_ready_SIZE(iterations);
}

Tester ::Tester(void)
Expand Down Expand Up @@ -144,6 +146,10 @@ void Tester ::from_recv_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& recvB
delete[] recvBuffer.getData();
}

void Tester ::from_ready_handler(const NATIVE_INT_TYPE portNum) {
this->pushFromPortEntry_ready();
}

Fw::Buffer Tester ::
from_allocate_handler(
const NATIVE_INT_TYPE portNum,
Expand Down Expand Up @@ -191,6 +197,12 @@ void Tester ::
this->get_from_recv(0)
);

// recv
this->component.set_ready_OutputPort(
0,
this->get_from_ready(0)
);

// allocate
this->component.set_allocate_OutputPort(
0,
Expand Down
6 changes: 6 additions & 0 deletions Drv/Udp/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ namespace Drv {
RecvStatus recvStatus
);

//! Handler for from_ready
//!
void from_ready_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);

//! Handler for from_allocate
//!
Fw::Buffer from_allocate_handler(
Expand Down