mirnor refactor

This commit is contained in:
Green Sky 2022-10-03 03:54:16 +02:00
parent ad55a345b2
commit 97a5241fad
No known key found for this signature in database
4 changed files with 74 additions and 67 deletions

View File

@ -1,3 +1,6 @@
.h -> c header (public interface)
.hpp -> c++ header (private interface)
.cpp -> c++ source (private implementation)

View File

@ -9,6 +9,48 @@
//#include <optional>
//#include <algorithm>
bool _GroupKey::operator<(const _GroupKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] < rhs.data[i]) {
return true;
} else if (data[i] > rhs.data[i]) {
return false;
}
}
return false; // equal
}
bool _GroupKey::operator==(const _GroupKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] != rhs.data[i]) {
return false;
}
}
return true;
}
bool _PeerKey::operator<(const _PeerKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] < rhs.data[i]) {
return true;
} else if (data[i] > rhs.data[i]) {
return false;
}
}
return false; // equal
}
bool _PeerKey::operator==(const _PeerKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] != rhs.data[i]) {
return false;
}
}
return true;
}
NGC_EXT_CTX* NGC_EXT_new(void) {
auto* ctx = new NGC_EXT_CTX;
// TODO: this is likely not necessary
@ -22,17 +64,6 @@ void NGC_EXT_kill(NGC_EXT_CTX* ngc_ext_ctx) {
delete ngc_ext_ctx;
}
//static void _handle_HS1_REQUEST_LAST_IDS(
//Tox* tox,
//NGC_HS1* ngc_hs1_ctx,
//uint32_t group_number,
//uint32_t peer_number,
//const uint8_t *data,
//size_t length
//);
#define _EXT_HAVE(x, error) if ((length - curser) < (x)) { error; }
void NGC_EXT_handle_group_custom_packet(
Tox* tox,

View File

@ -14,62 +14,6 @@
//#include <algorithm>
#include <array>
struct _GroupKey {
std::array<uint8_t, TOX_GROUP_CHAT_ID_SIZE> data;
_GroupKey(void) = default;
_GroupKey(const _GroupKey& other) : data(other.data) {}
_GroupKey(_GroupKey&&) = delete;
bool operator<(const _GroupKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] < rhs.data[i]) {
return true;
} else if (data[i] > rhs.data[i]) {
return false;
}
}
return false; // equal
}
bool operator==(const _GroupKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] != rhs.data[i]) {
return false;
}
}
return true;
}
};
struct _PeerKey {
std::array<uint8_t, TOX_GROUP_PEER_PUBLIC_KEY_SIZE> data;
_PeerKey(void) = default;
_PeerKey(const _PeerKey& other) : data(other.data) {}
_PeerKey(_PeerKey&&) = delete;
bool operator<(const _PeerKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] < rhs.data[i]) {
return true;
} else if (data[i] > rhs.data[i]) {
return false;
}
}
return false; // equal
}
bool operator==(const _PeerKey& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] != rhs.data[i]) {
return false;
}
}
return true;
}
};
enum _PacketType : uint8_t {
// TODO: why?
INVALID = 0u,
@ -151,6 +95,28 @@ static const char* _pkgid2str(_PacketType type) {
#undef _EXT_CASE
}
struct _GroupKey {
std::array<uint8_t, TOX_GROUP_CHAT_ID_SIZE> data;
_GroupKey(void) = default;
_GroupKey(const _GroupKey& other) : data(other.data) {}
_GroupKey(_GroupKey&&) = delete;
bool operator<(const _GroupKey& rhs) const;
bool operator==(const _GroupKey& rhs) const;
size_t size(void) const { return data.size(); }
};
struct _PeerKey {
std::array<uint8_t, TOX_GROUP_PEER_PUBLIC_KEY_SIZE> data;
_PeerKey(void) = default;
_PeerKey(const _PeerKey& other) : data(other.data) {}
_PeerKey(_PeerKey&&) = delete;
bool operator<(const _PeerKey& rhs) const;
bool operator==(const _PeerKey& rhs) const;
size_t size(void) const { return data.size(); }
};
using handle_group_custom_packet_cb = void(*)(
Tox* tox,
NGC_EXT_CTX* ngc_ext_ctx,

View File

@ -11,6 +11,13 @@ bool NGC_FT1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_FT1_options* option
ngc_ext_ctx->ngc_ft1_ctx = new NGC_FT1;
ngc_ext_ctx->ngc_ft1_ctx->options = *options;
ngc_ext_ctx->callbacks[FT1_REQUEST] = nullptr;
ngc_ext_ctx->callbacks[FT1_INIT] = nullptr;
ngc_ext_ctx->callbacks[FT1_INIT_ACK] = nullptr;
ngc_ext_ctx->callbacks[FT1_DATA] = nullptr;
ngc_ext_ctx->callbacks[FT1_DATA_ACK] = nullptr;
ngc_ext_ctx->callbacks[FT1_DATA_FIN] = nullptr;
ngc_ext_ctx->callbacks[FT1_DATA_FIN_ACK] = nullptr;
//ngc_ext_ctx->callbacks[HS1_REQUEST_LAST_IDS] = _handle_HS1_REQUEST_LAST_IDS;
//ngc_ext_ctx->callbacks[HS1_RESPONSE_LAST_IDS] = _handle_HS1_RESPONSE_LAST_IDS;