...
This commit is contained in:
parent
b8383c1375
commit
4a9ecf8639
@ -1,5 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||
|
||||
|
||||
/* A VERY SIMPLE NETWORK SERVER IMPLEMENTATION */
|
||||
|
||||
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
|
||||
@ -79,8 +85,12 @@ public:
|
||||
static constexpr std::chrono::duration DEFAULT_RCV_TIMEOUT = std::chrono::hours(12);
|
||||
static constexpr std::chrono::duration DEFAULT_SND_TIMEOUT = std::chrono::milliseconds(2000);
|
||||
|
||||
MccNetworkServer(asio::io_context& ctx, LoggerT logger = MccNullLogger{})
|
||||
: _asioContext(ctx), _stopSignal(ctx), _restartSignal(ctx)
|
||||
// handle received message user function
|
||||
typedef std::function<std::vector<char>(std::string_view)> handle_message_func_t;
|
||||
|
||||
|
||||
MccNetworkServer(asio::io_context& ctx, const handle_message_func_t& func, LoggerT logger = MccNullLogger{})
|
||||
: _asioContext(ctx), _handleMessageFunc(func), _stopSignal(ctx), _restartSignal(ctx)
|
||||
{
|
||||
std::stringstream st;
|
||||
st << std::this_thread::get_id();
|
||||
@ -490,6 +500,8 @@ public:
|
||||
private:
|
||||
asio::io_context& _asioContext;
|
||||
|
||||
handle_message_func_t _handleMessageFunc;
|
||||
|
||||
asio::signal_set _stopSignal, _restartSignal;
|
||||
|
||||
std::set<asio::serial_port*> _serialPorts;
|
||||
@ -625,7 +637,7 @@ private:
|
||||
|
||||
bool do_read = true;
|
||||
|
||||
// main client request -- server respond cycle
|
||||
// main "client request -- server respond" cycle
|
||||
for (;;) {
|
||||
// receive message
|
||||
|
||||
@ -698,7 +710,8 @@ private:
|
||||
logDebug(std::format("A command [{}] was received from client (remote endpoint <{}>, thread ID = {})",
|
||||
comm, r_epn, thr_id));
|
||||
|
||||
auto resp = handleClientCommand(comm);
|
||||
// auto resp = handleClientCommand(comm);
|
||||
auto resp = _handleMessageFunc(comm);
|
||||
|
||||
// remove received message from the input stream buffer. NOTE: 'msg' is now invalidated!!!
|
||||
sbuff.consume(msg.size());
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||
|
||||
/* BASIC NETWORK PROTOCOL DEFINITIONS */
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include "mcc_angle.h"
|
||||
@ -52,17 +57,18 @@ static constexpr std::string_view MCC_COMMPROTO_COORD_KIND_XY = "XY";
|
||||
// : MccCoordPairKind::COORDS_KIND_GENERIC;
|
||||
// }
|
||||
|
||||
static constexpr MccCoordPairKind mcc_str2pairkind(traits::mcc_char_range auto const& spair)
|
||||
template <mcc::traits::mcc_char_range R>
|
||||
static constexpr MccCoordPairKind mcc_str2pairkind(R&& spair)
|
||||
{
|
||||
const auto hash = utils::FNV1aHash(spair);
|
||||
const auto hash = mcc::utils::FNV1aHash(std::forward<R>(spair));
|
||||
|
||||
return hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_RADEC_ICRS) ? MccCoordPairKind::COORDS_KIND_RADEC_ICRS
|
||||
: hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_RADEC) ? MccCoordPairKind::COORDS_KIND_RADEC_APP
|
||||
: hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_HADEC) ? MccCoordPairKind::COORDS_KIND_HADEC_APP
|
||||
: hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_AZZD) ? MccCoordPairKind::COORDS_KIND_AZZD
|
||||
: hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_AZALT) ? MccCoordPairKind::COORDS_KIND_AZALT
|
||||
: hash == utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_XY) ? MccCoordPairKind::COORDS_KIND_XY
|
||||
: MccCoordPairKind::COORDS_KIND_GENERIC;
|
||||
return hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_RADEC_ICRS) ? MccCoordPairKind::COORDS_KIND_RADEC_ICRS
|
||||
: hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_RADEC) ? MccCoordPairKind::COORDS_KIND_RADEC_APP
|
||||
: hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_HADEC) ? MccCoordPairKind::COORDS_KIND_HADEC_APP
|
||||
: hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_AZZD) ? MccCoordPairKind::COORDS_KIND_AZZD
|
||||
: hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_AZALT) ? MccCoordPairKind::COORDS_KIND_AZALT
|
||||
: hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_XY) ? MccCoordPairKind::COORDS_KIND_XY
|
||||
: MccCoordPairKind::COORDS_KIND_GENERIC;
|
||||
}
|
||||
|
||||
static constexpr std::string_view mcc_pairkind2str(MccCoordPairKind kind)
|
||||
@ -269,7 +275,7 @@ bool mcc_netmsg_construct(traits::mcc_output_char_range auto& msg,
|
||||
traits::mcc_input_char_range auto const& keyword,
|
||||
PTs... params)
|
||||
{
|
||||
const size_t hash = utils::FNV1aHash(keyword);
|
||||
const size_t hash = mcc::utils::FNV1aHash(keyword);
|
||||
if (!std::ranges::contains(MCC_COMMPROTO_VALID_KEYS_HASH, hash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user