Skip to content

Commit

Permalink
m_stop_message is now passed from the server to the client in the sam…
Browse files Browse the repository at this point in the history
…e manner as the other fifo parameters so we don't need to specify it in the client constructor arguments. The current working path for the server is also passed in this manner, so the child process knows what path to use for the fifo files, even if it is at a different path to the server.
  • Loading branch information
Sebastien Sikora committed Nov 29, 2021
1 parent 76aa474 commit d5a0aaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/satellite_terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SatTerm_Component {
class SatTerm_Server : public SatTerm_Component {
public:
SatTerm_Server(std::string const& identifier, std::string const& path_to_client_binary, bool display_messages = true, size_t stop_fifo_index = 0,
size_t sc_fifo_count = 1, size_t cs_fifo_count = 1, char end_char = '\n', std::string const& stop_message = "q");
size_t sc_fifo_count = 1, size_t cs_fifo_count = 1, char end_char = 3, std::string const& stop_message = "q");
~SatTerm_Server();

private:
Expand All @@ -97,8 +97,8 @@ class SatTerm_Server : public SatTerm_Component {
// Client derived class.
class SatTerm_Client : public SatTerm_Component {
public:
SatTerm_Client(std::string const& identifier, std::vector<std::string> rx_fifo_paths, std::vector<std::string> tx_fifo_paths, bool display_messages = true, char end_char = '\n', std::string const& stop_message = "q");
SatTerm_Client(std::string const& identifier, int argc, char* argv[], bool display_messages = true, char end_char = '\n', std::string const& stop_message = "q");
SatTerm_Client(std::string const& identifier, std::vector<std::string> rx_fifo_paths, std::vector<std::string> tx_fifo_paths, bool display_messages = true, char end_char = 3, std::string const& stop_message = "q");
SatTerm_Client(std::string const& identifier, int argc, char* argv[], bool display_messages = true, char end_char = 3);
~SatTerm_Client();

private:
Expand Down
12 changes: 6 additions & 6 deletions src/satterm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SatTerm_Client::SatTerm_Client(std::string const& identifier, std::vector<std::s
}

// Construct a client by parsing argv from the stipulated argument index (inclusive).
SatTerm_Client::SatTerm_Client(std::string const& identifier, int argc, char* argv[], bool display_messages, char end_char, std::string const& stop_message) {
SatTerm_Client::SatTerm_Client(std::string const& identifier, int argc, char* argv[], bool display_messages, char end_char) {
m_identifier = identifier;
m_display_messages = display_messages;

Expand All @@ -64,21 +64,21 @@ SatTerm_Client::SatTerm_Client(std::string const& identifier, int argc, char* ar
// before/if writing again.
m_component_type = "Client";
m_end_char = end_char;
m_stop_message = stop_message;

size_t argv_start_index = ParseVarargs(argc, argv);

if (argv_start_index != 0) {
std::string fifo_working_path = std::string(argv[argv_start_index]);
m_stop_message = std::string(argv[argv_start_index + 1]);
if (m_display_messages) {
std::string message = "Fifo working path is " + fifo_working_path;
std::cout << message << std::endl;
}

size_t tx_fifo_count = std::stoi(std::string(argv[argv_start_index + 1]));
size_t rx_fifo_count = std::stoi(std::string(argv[argv_start_index + 2]));
m_tx_fifo_paths = ParseFifoPaths(argv_start_index + 3, tx_fifo_count, argv);
m_rx_fifo_paths = ParseFifoPaths(argv_start_index + 3 + tx_fifo_count, rx_fifo_count, argv);
size_t tx_fifo_count = std::stoi(std::string(argv[argv_start_index + 2]));
size_t rx_fifo_count = std::stoi(std::string(argv[argv_start_index + 3]));
m_tx_fifo_paths = ParseFifoPaths(argv_start_index + 4, tx_fifo_count, argv);
m_rx_fifo_paths = ParseFifoPaths(argv_start_index + 4 + tx_fifo_count, rx_fifo_count, argv);

Configure();
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/satterm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pid_t SatTerm_Server::StartClient(std::string const& path_to_terminal_emulator_p
std::string arg_string = m_path_to_client_binary;
arg_string += " client_args";
arg_string += " " + std::string(working_path) + "/";
arg_string += " " + m_stop_message;
arg_string += " " + std::to_string(m_rx_fifo_paths.size());
arg_string += " " + std::to_string(m_tx_fifo_paths.size());
for (const auto& fifo_path : m_rx_fifo_paths) {
Expand All @@ -222,6 +223,7 @@ pid_t SatTerm_Server::StartClient(std::string const& path_to_terminal_emulator_p
arg_string += " " + fifo_path;
}

//~std::cout << "Full command is " << arg_string << std::endl;
for (const auto terminal_path : terminal_emulator_paths) {
// No need to check execv() return value. If it returns, you know it failed.
execl(terminal_path.c_str(), terminal_path.c_str(), "-e", arg_string.c_str(), (char*) NULL);
Expand Down

0 comments on commit d5a0aaa

Please sign in to comment.