Some minor code refactors and fixed converter for 332bit builds

This commit is contained in:
WolverinDEV 2021-02-05 14:20:10 +01:00
parent c1085c84cf
commit c0790984ee
4 changed files with 14 additions and 12 deletions

View File

@ -34,7 +34,7 @@ CONVERTER_PRIMITIVE_ST(float, std::stof(std::string{str}));
CONVERTER_PRIMITIVE_ST(double, std::stod(std::string{str}));
CONVERTER_PRIMITIVE_ST(long_double, std::stold(std::string{str}));
CONVERTER_PRIMITIVE_ST(long_long_unsigned_int_t, std::stoull(std::string{str}));
//CONVERTER_PRIMITIVE_ST(long_long_unsigned_int_t, std::stoull(std::string{str}));
CONVERTER_ST(std__string, return std::string{str};, return std::any_cast<std__string>(value););
CONVERTER_ST(std__string_view, return str;, return std::string{std::any_cast<std__string_view>(value)};);

View File

@ -53,7 +53,7 @@ namespace ts {
CONVERTER_PRIMITIVE(int64_t);
CONVERTER_PRIMITIVE(uint64_t);
CONVERTER_PRIMITIVE(long_long_unsigned_int_t);
//CONVERTER_PRIMITIVE(long_long_unsigned_int_t);
typedef std::string std__string;
typedef std::string_view std__string_view;

View File

@ -1,6 +1,5 @@
#include "AcknowledgeManager.h"
#include <cmath>
#include <misc/endianness.h>
#include <algorithm>
using namespace ts;
@ -21,10 +20,10 @@ void AcknowledgeManager::reset() {
auto pending_entries = std::move(this->entries);
lock.unlock();
/* save because entries are not accessable anymore */
/* save because entries are not accessible anymore */
for(const auto& entry : pending_entries) {
if(entry->acknowledge_listener) {
entry->acknowledge_listener->executionFailed("reset");
(*entry->acknowledge_listener)(false);
}
}
}
@ -35,8 +34,9 @@ size_t AcknowledgeManager::awaiting_acknowledge() {
return this->entries.size();
}
void AcknowledgeManager::process_packet(uint8_t type, uint32_t id, void *ptr, std::unique_ptr<threads::Future<bool>> ack) {
void AcknowledgeManager::process_packet(uint8_t type, uint32_t id, void *ptr, std::unique_ptr<std::function<void(bool)>> ack) {
std::shared_ptr<Entry> entry{new Entry{}, [&](Entry* entry){
assert(this->destroy_packet);
this->destroy_packet(entry->packet_ptr);
delete entry;
}};
@ -62,7 +62,7 @@ bool AcknowledgeManager::process_acknowledge(uint8_t packet_type, uint16_t targe
PacketType target_type{packet_type == protocol::ACK_LOW ? PacketType::COMMAND_LOW : PacketType::COMMAND};
std::shared_ptr<Entry> entry;
std::unique_ptr<threads::Future<bool>> ack_listener;
std::unique_ptr<std::function<void(bool)>> ack_listener;
{
std::lock_guard lock{this->entry_lock};
for(auto it = this->entries.begin(); it != this->entries.end(); it++) {
@ -88,7 +88,9 @@ bool AcknowledgeManager::process_acknowledge(uint8_t packet_type, uint16_t targe
}
entry->acknowledged = true;
if(ack_listener) ack_listener->executionSucceed(true);
if(ack_listener) {
(*ack_listener)(true);
}
return true;
}

View File

@ -19,7 +19,7 @@ namespace ts::connection {
std::chrono::system_clock::time_point first_send;
std::chrono::system_clock::time_point next_resend;
std::unique_ptr<threads::Future<bool>> acknowledge_listener;
std::unique_ptr<std::function<void(bool)>> acknowledge_listener;
void* packet_ptr;
};
@ -32,7 +32,7 @@ namespace ts::connection {
size_t awaiting_acknowledge();
void reset();
void process_packet(uint8_t /* packet type */, uint32_t /* full packet id */, void* /* packet ptr */, std::unique_ptr<threads::Future<bool>> /* ack listener */);
void process_packet(uint8_t /* packet type */, uint32_t /* full packet id */, void* /* packet ptr */, std::unique_ptr<std::function<void(bool)>> /* ack listener */);
bool process_acknowledge(uint8_t /* packet type */, uint16_t /* packet id */, std::string& /* error */);
void execute_resend(
@ -45,7 +45,7 @@ namespace ts::connection {
[[nodiscard]] inline auto current_srtt() const { return this->srtt; }
[[nodiscard]] inline auto current_rttvar() const { return this->rttvar; }
void(*destroy_packet)(void* /* packet */);
void(*destroy_packet)(void* /* packet */){nullptr};
void* callback_data{nullptr};
callback_resend_failed_t callback_resend_failed{[](auto, auto){}}; /* must be valid all the time */