diff --git a/README.md b/README.md index 9c89fb2..0d3b69c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ .h -> c header (public interface) + .hpp -> c++ header (private interface) + .cpp -> c++ source (private implementation) + diff --git a/ngc_ext_common.cpp b/ngc_ext_common.cpp index fe2f95e..3f35e76 100644 --- a/ngc_ext_common.cpp +++ b/ngc_ext_common.cpp @@ -9,6 +9,48 @@ //#include //#include + +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, diff --git a/ngc_ext_common.hpp b/ngc_ext_common.hpp index 7557c45..5472379 100644 --- a/ngc_ext_common.hpp +++ b/ngc_ext_common.hpp @@ -14,62 +14,6 @@ //#include #include -struct _GroupKey { - std::array 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 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 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 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, diff --git a/ngc_ft1.cpp b/ngc_ft1.cpp index 2ed1743..1ff73ff 100644 --- a/ngc_ft1.cpp +++ b/ngc_ft1.cpp @@ -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;