mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-24 18:41:54 -06:00
Follow up to the MKS merge:
Reformatted for code conformity. Changed the xxx_ member variables to m_xxx Replaced std::list with std::deque
This commit is contained in:
parent
eddcd93e82
commit
56d5a340ce
4 changed files with 354 additions and 380 deletions
|
@ -2,91 +2,90 @@
|
|||
#define slic3r_Utils_TCPConsole_hpp_
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace Utils {
|
||||
namespace Utils {
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
class TCPConsole
|
||||
{
|
||||
public:
|
||||
TCPConsole();
|
||||
TCPConsole(const std::string& host_name, const std::string& port_name);
|
||||
~TCPConsole() {}
|
||||
class TCPConsole
|
||||
{
|
||||
public:
|
||||
TCPConsole() : m_resolver(m_io_context), m_socket(m_io_context) { set_defaults(); }
|
||||
TCPConsole(const std::string& host_name, const std::string& port_name) : m_resolver(m_io_context), m_socket(m_io_context)
|
||||
{ set_defaults(); set_remote(host_name, port_name); }
|
||||
~TCPConsole() = default;
|
||||
|
||||
void set_defaults()
|
||||
{
|
||||
newline_ = "\n";
|
||||
done_string_ = "ok";
|
||||
connect_timeout_ = std::chrono::milliseconds(5000);
|
||||
write_timeout_ = std::chrono::milliseconds(10000);
|
||||
read_timeout_ = std::chrono::milliseconds(10000);
|
||||
}
|
||||
void set_defaults()
|
||||
{
|
||||
m_newline = "\n";
|
||||
m_done_string = "ok";
|
||||
m_connect_timeout = std::chrono::milliseconds(5000);
|
||||
m_write_timeout = std::chrono::milliseconds(10000);
|
||||
m_read_timeout = std::chrono::milliseconds(10000);
|
||||
}
|
||||
|
||||
void set_line_delimiter(const std::string& newline) {
|
||||
newline_ = newline;
|
||||
}
|
||||
void set_command_done_string(const std::string& done_string) {
|
||||
done_string_ = done_string;
|
||||
}
|
||||
void set_line_delimiter(const std::string& newline) {
|
||||
m_newline = newline;
|
||||
}
|
||||
void set_command_done_string(const std::string& done_string) {
|
||||
m_done_string = done_string;
|
||||
}
|
||||
|
||||
void set_remote(const std::string& host_name, const std::string& port_name)
|
||||
{
|
||||
host_name_ = host_name;
|
||||
port_name_ = port_name;
|
||||
}
|
||||
void set_remote(const std::string& host_name, const std::string& port_name)
|
||||
{
|
||||
m_host_name = host_name;
|
||||
m_port_name = port_name;
|
||||
}
|
||||
|
||||
bool enqueue_cmd(const std::string& cmd) {
|
||||
// TODO: Add multithread protection to queue
|
||||
cmd_queue_.push_back(cmd);
|
||||
return true;
|
||||
}
|
||||
bool enqueue_cmd(const std::string& cmd) {
|
||||
// TODO: Add multithread protection to queue
|
||||
m_cmd_queue.push_back(cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool run_queue();
|
||||
std::string error_message() {
|
||||
return error_code_.message();
|
||||
}
|
||||
bool run_queue();
|
||||
std::string error_message() const { return m_error_code.message(); }
|
||||
|
||||
private:
|
||||
void handle_connect(const boost::system::error_code& ec);
|
||||
void handle_read(const boost::system::error_code& ec, std::size_t bytes_transferred);
|
||||
void handle_write(const boost::system::error_code& ec, std::size_t bytes_transferred);
|
||||
private:
|
||||
void handle_connect(const boost::system::error_code& ec);
|
||||
void handle_read(const boost::system::error_code& ec, std::size_t bytes_transferred);
|
||||
void handle_write(const boost::system::error_code& ec, std::size_t bytes_transferred);
|
||||
|
||||
void transmit_next_command();
|
||||
void wait_next_line();
|
||||
std::string extract_next_line();
|
||||
void transmit_next_command();
|
||||
void wait_next_line();
|
||||
std::string extract_next_line();
|
||||
|
||||
void set_deadline_in(std::chrono::steady_clock::duration);
|
||||
bool is_deadline_over();
|
||||
void set_deadline_in(std::chrono::steady_clock::duration);
|
||||
bool is_deadline_over() const;
|
||||
|
||||
std::string host_name_;
|
||||
std::string port_name_;
|
||||
std::string newline_;
|
||||
std::string done_string_;
|
||||
std::chrono::steady_clock::duration connect_timeout_;
|
||||
std::chrono::steady_clock::duration write_timeout_;
|
||||
std::chrono::steady_clock::duration read_timeout_;
|
||||
std::string m_host_name;
|
||||
std::string m_port_name;
|
||||
std::string m_newline;
|
||||
std::string m_done_string;
|
||||
std::chrono::steady_clock::duration m_connect_timeout;
|
||||
std::chrono::steady_clock::duration m_write_timeout;
|
||||
std::chrono::steady_clock::duration m_read_timeout;
|
||||
|
||||
std::list<std::string> cmd_queue_;
|
||||
std::deque<std::string> m_cmd_queue;
|
||||
|
||||
boost::asio::io_context io_context_;
|
||||
tcp::resolver resolver_;
|
||||
tcp::socket socket_;
|
||||
boost::asio::streambuf recv_buffer_;
|
||||
std::string send_buffer_;
|
||||
boost::asio::io_context m_io_context;
|
||||
tcp::resolver m_resolver;
|
||||
tcp::socket m_socket;
|
||||
boost::asio::streambuf m_recv_buffer;
|
||||
std::string m_send_buffer;
|
||||
|
||||
bool is_connected_;
|
||||
boost::system::error_code error_code_;
|
||||
std::chrono::steady_clock::time_point deadline_;
|
||||
};
|
||||
bool m_is_connected;
|
||||
boost::system::error_code m_error_code;
|
||||
std::chrono::steady_clock::time_point m_deadline;
|
||||
};
|
||||
|
||||
} // Utils
|
||||
} // Utils
|
||||
} // Slic3r
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue