events, compiles again
This commit is contained in:
parent
6e058a7596
commit
47b89ae577
@ -169,8 +169,6 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(ngc_ft1_ctx->cb_send_data.count(tf.file_kind));
|
|
||||||
|
|
||||||
// if chunks in flight < window size (2)
|
// if chunks in flight < window size (2)
|
||||||
//while (tf.ssb.size() < ngc_ft1_ctx->options.packet_window_size) {
|
//while (tf.ssb.size() < ngc_ft1_ctx->options.packet_window_size) {
|
||||||
int64_t can_packet_size {static_cast<int64_t>(peer.cca.canSend())};
|
int64_t can_packet_size {static_cast<int64_t>(peer.cca.canSend())};
|
||||||
@ -198,14 +196,26 @@ void NGCFT1::updateSendTransfer(float time_delta, uint32_t group_number, uint32_
|
|||||||
|
|
||||||
new_data.resize(chunk_size);
|
new_data.resize(chunk_size);
|
||||||
|
|
||||||
ngc_ft1_ctx->cb_send_data[tf.file_kind](
|
//ngc_ft1_ctx->cb_send_data[tf.file_kind](
|
||||||
tox,
|
//tox,
|
||||||
|
//group_number, peer_number,
|
||||||
|
//idx,
|
||||||
|
//tf.file_size_current,
|
||||||
|
//new_data.data(), new_data.size(),
|
||||||
|
//ngc_ft1_ctx->ud_send_data.count(tf.file_kind) ? ngc_ft1_ctx->ud_send_data.at(tf.file_kind) : nullptr
|
||||||
|
//);
|
||||||
|
assert(idx <= 0xffu);
|
||||||
|
// TODO: check return value
|
||||||
|
dispatch(
|
||||||
|
NGCFT1_Event::send_data,
|
||||||
|
Events::NGCFT1_send_data{
|
||||||
group_number, peer_number,
|
group_number, peer_number,
|
||||||
idx,
|
static_cast<uint8_t>(idx),
|
||||||
tf.file_size_current,
|
tf.file_size_current,
|
||||||
new_data.data(), new_data.size(),
|
new_data.data(), new_data.size(),
|
||||||
ngc_ft1_ctx->ud_send_data.count(tf.file_kind) ? ngc_ft1_ctx->ud_send_data.at(tf.file_kind) : nullptr
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
uint16_t seq_id = tf.ssb.add(std::move(new_data));
|
uint16_t seq_id = tf.ssb.add(std::move(new_data));
|
||||||
sendPKG_FT1_DATA(group_number, peer_number, idx, seq_id, tf.ssb.entries.at(seq_id).data.data(), tf.ssb.entries.at(seq_id).data.size());
|
sendPKG_FT1_DATA(group_number, peer_number, idx, seq_id, tf.ssb.entries.at(seq_id).data.data(), tf.ssb.entries.at(seq_id).data.size());
|
||||||
peer.cca.onSent({idx, seq_id}, chunk_size);
|
peer.cca.onSent({idx, seq_id}, chunk_size);
|
||||||
|
@ -16,49 +16,79 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
// TODO: events
|
namespace Events {
|
||||||
//typedef void NGC_FT1_recv_request_cb(
|
|
||||||
//Tox *tox,
|
|
||||||
//uint32_t group_number, uint32_t peer_number,
|
|
||||||
//const uint8_t* file_id, size_t file_id_size,
|
|
||||||
//void* user_data
|
|
||||||
//);
|
|
||||||
|
|
||||||
// return true to accept, false to deny
|
struct NGCFT1_recv_request {
|
||||||
//typedef bool NGC_FT1_recv_init_cb(
|
uint32_t group_number;
|
||||||
//Tox *tox,
|
uint32_t peer_number;
|
||||||
//uint32_t group_number, uint32_t peer_number,
|
|
||||||
//const uint8_t* file_id, size_t file_id_size,
|
|
||||||
//const uint8_t transfer_id,
|
|
||||||
//const size_t file_size,
|
|
||||||
//void* user_data
|
|
||||||
//);
|
|
||||||
|
|
||||||
//typedef void NGC_FT1_recv_data_cb(
|
NGCFT1_file_kind file_kind;
|
||||||
//Tox *tox,
|
|
||||||
|
|
||||||
//uint32_t group_number,
|
const uint8_t* file_id;
|
||||||
//uint32_t peer_number,
|
size_t file_id_size;
|
||||||
//uint8_t transfer_id,
|
};
|
||||||
|
|
||||||
//size_t data_offset, const uint8_t* data, size_t data_size,
|
struct NGCFT1_recv_init {
|
||||||
//void* user_data
|
uint32_t group_number;
|
||||||
//);
|
uint32_t peer_number;
|
||||||
|
|
||||||
// request to fill data_size bytes into data
|
NGCFT1_file_kind file_kind;
|
||||||
//typedef void NGC_FT1_send_data_cb(
|
|
||||||
//Tox *tox,
|
|
||||||
|
|
||||||
//uint32_t group_number,
|
const uint8_t* file_id;
|
||||||
//uint32_t peer_number,
|
size_t file_id_size;
|
||||||
//uint8_t transfer_id,
|
|
||||||
|
|
||||||
//size_t data_offset, uint8_t* data, size_t data_size,
|
const uint8_t transfer_id;
|
||||||
//void* user_data
|
const size_t file_size;
|
||||||
//);
|
|
||||||
|
|
||||||
|
// return true to accept, false to deny
|
||||||
|
bool& accept;
|
||||||
|
};
|
||||||
|
|
||||||
class NGCFT1 : public ToxEventI, public NGCEXTEventI {
|
struct NGCFT1_recv_data {
|
||||||
|
uint32_t group_number;
|
||||||
|
uint32_t peer_number;
|
||||||
|
|
||||||
|
uint8_t transfer_id;
|
||||||
|
|
||||||
|
size_t data_offset;
|
||||||
|
const uint8_t* data;
|
||||||
|
size_t data_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
// request to fill data_size bytes into data
|
||||||
|
struct NGCFT1_send_data {
|
||||||
|
uint32_t group_number;
|
||||||
|
uint32_t peer_number;
|
||||||
|
|
||||||
|
uint8_t transfer_id;
|
||||||
|
|
||||||
|
size_t data_offset;
|
||||||
|
uint8_t* data;
|
||||||
|
size_t data_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Events
|
||||||
|
|
||||||
|
enum class NGCFT1_Event : uint8_t {
|
||||||
|
recv_request,
|
||||||
|
recv_init,
|
||||||
|
recv_data,
|
||||||
|
send_data,
|
||||||
|
|
||||||
|
MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NGCFT1EventI {
|
||||||
|
using enumType = NGCFT1_Event;
|
||||||
|
virtual bool onEvent(const Events::NGCFT1_recv_request&) { return false; }
|
||||||
|
virtual bool onEvent(const Events::NGCFT1_recv_init&) { return false; }
|
||||||
|
virtual bool onEvent(const Events::NGCFT1_recv_data&) { return false; }
|
||||||
|
virtual bool onEvent(const Events::NGCFT1_send_data&) { return false; } // const?
|
||||||
|
};
|
||||||
|
|
||||||
|
using NGCFT1EventProviderI = EventProviderI<NGCFT1EventI>;
|
||||||
|
|
||||||
|
class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProviderI {
|
||||||
ToxI& _t;
|
ToxI& _t;
|
||||||
ToxEventProviderI& _tep;
|
ToxEventProviderI& _tep;
|
||||||
NGCEXTEventProviderI& _neep;
|
NGCEXTEventProviderI& _neep;
|
||||||
|
@ -33,11 +33,18 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToxI* tox_i = nullptr;
|
||||||
ToxEventProviderI* tox_event_provider_i = nullptr;
|
ToxEventProviderI* tox_event_provider_i = nullptr;
|
||||||
|
|
||||||
{ // make sure required types are loaded
|
{ // make sure required types are loaded
|
||||||
|
tox_i = RESOLVE_INSTANCE(ToxI);
|
||||||
tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI);
|
tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI);
|
||||||
|
|
||||||
|
if (tox_i == nullptr) {
|
||||||
|
std::cerr << "PLUGIN NGCEXT missing ToxI\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (tox_event_provider_i == nullptr) {
|
if (tox_event_provider_i == nullptr) {
|
||||||
std::cerr << "PLUGIN NGCEXT missing ToxEventProviderI\n";
|
std::cerr << "PLUGIN NGCEXT missing ToxEventProviderI\n";
|
||||||
return 2;
|
return 2;
|
||||||
@ -47,10 +54,12 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
// static store, could be anywhere tho
|
// static store, could be anywhere tho
|
||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_event_provider_i);
|
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_event_provider_i);
|
||||||
g_ngcft1 = std::make_unique<NGCFT1>(*tox_event_provider_i, *g_ngcextep.get());
|
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
||||||
|
|
||||||
// register types
|
// register types
|
||||||
PROVIDE_INSTANCE(NGCEXTEventProviderI, "NGCEXT", g_ngcextep.get());
|
PROVIDE_INSTANCE(NGCEXTEventProviderI, "NGCEXT", g_ngcextep.get());
|
||||||
|
|
||||||
|
PROVIDE_INSTANCE(NGCFT1EventProviderI, "NGCEXT", g_ngcft1.get());
|
||||||
PROVIDE_INSTANCE(NGCFT1, "NGCEXT", g_ngcft1.get());
|
PROVIDE_INSTANCE(NGCFT1, "NGCEXT", g_ngcft1.get());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user