MccGenericNetworkServer: fix client session thread pool behavior in
destructor
This commit is contained in:
parent
43638f383f
commit
a825a6935b
@ -106,6 +106,9 @@ AsibFM700ServoController::error_t AsibFM700ServoController::hardwareInit()
|
||||
|
||||
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareSetState(hardware_state_t state)
|
||||
{
|
||||
static thread_local coordval_pair_t cvalpair{.X{0.0, 0.0}, .Y{0.0, 0.0}};
|
||||
static thread_local coordpair_t cpair{.X = 0.0, .Y = 0.0};
|
||||
|
||||
// time point from sidservo library is 'double' number represented UNIXTIME with
|
||||
// microseconds/nanoseconds precision
|
||||
double tp = std::chrono::duration<double>(state.time_point.time_since_epoch()).count();
|
||||
@ -113,9 +116,16 @@ AsibFM700ServoController::error_t AsibFM700ServoController::hardwareSetState(har
|
||||
std::lock_guard lock{*_setStateMutex};
|
||||
|
||||
// according to"SiTech protocol notes" X is DEC-axis and Y is HA-axis
|
||||
coordval_pair_t cvalpair{.X{.val = state.Y, .t = tp}, .Y{.val = state.X, .t = tp}};
|
||||
coordpair_t cpair{.X = state.Y, .Y = state.X};
|
||||
// coordpair_t cpair{.X = state.Y, .Y = state.X + mcc::MccAngle(1.0_degs)};
|
||||
// coordval_pair_t cvalpair{.X{.val = state.Y, .t = tp}, .Y{.val = state.X, .t = tp}};
|
||||
// coordpair_t cpair{.X = state.Y, .Y = state.X};
|
||||
// coordpair_t cpair{.X = state.Y + mcc::MccAngle(1.0_degs), .Y = state.X + mcc::MccAngle(1.0_degs)};
|
||||
|
||||
|
||||
cvalpair.X = {.val = state.Y, .t = tp};
|
||||
cvalpair.Y = {.val = state.X, .t = tp};
|
||||
|
||||
cpair.X = state.Y;
|
||||
cpair.Y = state.X;
|
||||
|
||||
// correctTo is asynchronous function!!!
|
||||
//
|
||||
|
||||
@ -188,7 +188,7 @@ public:
|
||||
std::stringstream st;
|
||||
st << std::this_thread::get_id();
|
||||
|
||||
logInfo(std::format("Create generic network server instance (thread ID = {})", st.str()));
|
||||
logInfo(std::format("Create MccGenericNetworkServer class instance (thread ID = {})", st.str()));
|
||||
}
|
||||
|
||||
// MccNetworkServer(asio::io_context& ctx, const handle_message_func_t& func, LoggerT logger = MccNullLogger{})
|
||||
@ -208,6 +208,10 @@ public:
|
||||
logInfo(std::format("Delete generic network server instance (thread ID = {}) ...", st.str()));
|
||||
|
||||
stopListening();
|
||||
|
||||
_sessionThreadPool.stop();
|
||||
_sessionThreadPool.join();
|
||||
|
||||
disconnectClients();
|
||||
}
|
||||
|
||||
@ -585,8 +589,15 @@ public:
|
||||
_stopSignal.async_wait([this](std::error_code, int signo) {
|
||||
logInfo(std::format("Stop signal was received (signo = {})", signo));
|
||||
|
||||
stopListening();
|
||||
disconnectClients();
|
||||
// _handleMessageFunc(MCC_COMMPROTO_KEYWORD_STOP_STR);
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
// stopListening();
|
||||
|
||||
// _sessionThreadPool.stop();
|
||||
// _sessionThreadPool.join();
|
||||
|
||||
// disconnectClients();
|
||||
|
||||
_asioContext.stop();
|
||||
});
|
||||
@ -913,10 +924,21 @@ class MccGenericMountNetworkServer : public MccGenericNetworkServer<LoggerT>
|
||||
public:
|
||||
using typename base_t::handle_message_func_result_t;
|
||||
|
||||
using base_t::logDebug;
|
||||
using base_t::logError;
|
||||
using base_t::logInfo;
|
||||
using base_t::logTrace;
|
||||
using base_t::logWarn;
|
||||
|
||||
template <mcc_generic_mount_c MountT, typename... LoggerCtorArgsTs>
|
||||
MccGenericMountNetworkServer(asio::io_context& ctx, MountT& mount, LoggerCtorArgsTs&&... log_args)
|
||||
: base_t(ctx, {}, std::forward<LoggerCtorArgsTs>(log_args)...)
|
||||
{
|
||||
std::stringstream st;
|
||||
st << std::this_thread::get_id();
|
||||
|
||||
logInfo(std::format("Create MccGenericMountNetworkServer class instance (thread ID = {})", st.str()));
|
||||
|
||||
// to avoid possible compiler optimization (one needs to catch 'mount' strictly by reference)
|
||||
auto* mount_ptr = &mount;
|
||||
|
||||
@ -939,15 +961,27 @@ public:
|
||||
|
||||
return output_msg.template byteRepr<typename base_t::handle_message_func_result_t>();
|
||||
};
|
||||
|
||||
// special functor (used in the destructor)
|
||||
_stopMountFunc = [mount_ptr]() { mount_ptr->stopMount(); };
|
||||
}
|
||||
|
||||
virtual ~MccGenericMountNetworkServer() {}
|
||||
virtual ~MccGenericMountNetworkServer()
|
||||
{
|
||||
std::stringstream st;
|
||||
st << std::this_thread::get_id();
|
||||
|
||||
_stopMountFunc();
|
||||
|
||||
logInfo(std::format("Delete MccGenericMountNetworkServer class instance (thread ID = {})", st.str()));
|
||||
}
|
||||
|
||||
protected:
|
||||
MccCoordinateSerializer::SerializedCoordFormat _coordFormat{
|
||||
MccCoordinateSerializer::SerializedCoordFormat::CFMT_SGM};
|
||||
MccCoordinateSerializer::SexagesimalCoordPrec _coordPrec{2, 1};
|
||||
|
||||
std::function<void()> _stopMountFunc{};
|
||||
|
||||
template <typename RESULT_MSG_T, typename INPUT_MSG_T, mcc_generic_mount_c MountT>
|
||||
RESULT_MSG_T handleMessage(const INPUT_MSG_T& input_msg, MountT* mount_ptr)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user