ft data cb
This commit is contained in:
parent
4afd13f70e
commit
9edf3fcf2f
60
ngc_ft1.cpp
60
ngc_ft1.cpp
@ -11,8 +11,10 @@
|
||||
struct NGC_FT1 {
|
||||
NGC_FT1_options options;
|
||||
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_recv_request_cb*> cb_request;
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_recv_init_cb*> cb_init;
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_recv_request_cb*> cb_recv_request;
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_recv_init_cb*> cb_recv_init;
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_recv_data_cb*> cb_recv_data;
|
||||
std::unordered_map<NGC_FT1_file_kind, NGC_FT1_send_data_cb*> cb_send_data;
|
||||
|
||||
struct Group {
|
||||
struct Peer {
|
||||
@ -94,8 +96,6 @@ bool NGC_FT1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_FT1_options* option
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -105,6 +105,35 @@ void NGC_FT1_kill(NGC_EXT_CTX* ngc_ext_ctx) {
|
||||
ngc_ext_ctx->ngc_ft1_ctx = nullptr;
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_recv_request(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_request_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_recv_request[file_kind] = callback;
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_recv_init(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_init_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_recv_init[file_kind] = callback;
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_recv_data(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_data_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_recv_data[file_kind] = callback;
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_send_data(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_send_data_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_send_data[file_kind] = callback;
|
||||
}
|
||||
|
||||
|
||||
// iterate
|
||||
|
||||
void NGC_FT1_send_request(
|
||||
@ -145,14 +174,6 @@ void NGC_FT1_send_request_private(
|
||||
_send_pkg_FT1_REQUEST(tox, group_number, peer_number, file_kind, file_id, file_id_size);
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_recv_request(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_request_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_request[file_kind] = callback;
|
||||
}
|
||||
|
||||
|
||||
bool NGC_FT1_send_init_private(
|
||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
@ -205,13 +226,6 @@ bool NGC_FT1_send_init_private(
|
||||
return true;
|
||||
}
|
||||
|
||||
void NGC_FT1_register_callback_recv_init(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_init_cb* callback) {
|
||||
assert(ngc_ext_ctx);
|
||||
assert(ngc_ext_ctx->ngc_ft1_ctx);
|
||||
|
||||
ngc_ext_ctx->ngc_ft1_ctx->cb_init[file_kind] = callback;
|
||||
}
|
||||
|
||||
static bool _send_pkg_FT1_REQUEST(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t file_kind, const uint8_t* file_id, size_t file_id_size) {
|
||||
// - 1 byte packet id
|
||||
// - 1 byte (TODO: more?) file_kind
|
||||
@ -341,8 +355,8 @@ static void _handle_FT1_REQUEST(
|
||||
fprintf(stderr, "]\n");
|
||||
|
||||
NGC_FT1_recv_request_cb* fn_ptr = nullptr;
|
||||
if (ngc_ext_ctx->ngc_ft1_ctx->cb_request.count(file_kind)) {
|
||||
fn_ptr = ngc_ext_ctx->ngc_ft1_ctx->cb_request.at(file_kind);
|
||||
if (ngc_ext_ctx->ngc_ft1_ctx->cb_recv_request.count(file_kind)) {
|
||||
fn_ptr = ngc_ext_ctx->ngc_ft1_ctx->cb_recv_request.at(file_kind);
|
||||
}
|
||||
if (fn_ptr) {
|
||||
fn_ptr(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser);
|
||||
@ -396,8 +410,8 @@ static void _handle_FT1_INIT(
|
||||
// did we allready ack this and the other side just did not see the ack?
|
||||
|
||||
NGC_FT1_recv_init_cb* fn_ptr = nullptr;
|
||||
if (ngc_ext_ctx->ngc_ft1_ctx->cb_init.count(file_kind)) {
|
||||
fn_ptr = ngc_ext_ctx->ngc_ft1_ctx->cb_init.at(file_kind);
|
||||
if (ngc_ext_ctx->ngc_ft1_ctx->cb_recv_init.count(file_kind)) {
|
||||
fn_ptr = ngc_ext_ctx->ngc_ft1_ctx->cb_recv_init.at(file_kind);
|
||||
}
|
||||
bool accept_ft;
|
||||
if (fn_ptr) {
|
||||
|
11
ngc_ft1.h
11
ngc_ft1.h
@ -89,6 +89,17 @@ typedef bool NGC_FT1_recv_init_cb(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t g
|
||||
|
||||
void NGC_FT1_register_callback_recv_init(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_init_cb* callback);
|
||||
|
||||
// ========== data ==========
|
||||
|
||||
typedef void NGC_FT1_recv_data_cb(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size);
|
||||
|
||||
void NGC_FT1_register_callback_recv_data(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_recv_data_cb* callback);
|
||||
|
||||
typedef void NGC_FT1_send_data_cb(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t** data, size_t* data_size);
|
||||
|
||||
void NGC_FT1_register_callback_send_data(NGC_EXT_CTX* ngc_ext_ctx, NGC_FT1_file_kind file_kind, NGC_FT1_send_data_cb* callback);
|
||||
|
||||
|
||||
// ========== peer online/offline ==========
|
||||
//void NGC_FT1_peer_online(Tox* tox, NGC_FT1* ngc_hs1_ctx, uint32_t group_number, uint32_t peer_number, bool online);
|
||||
|
||||
|
Reference in New Issue
Block a user