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;
|
||||
}
|
||||
|
||||
assert(ngc_ft1_ctx->cb_send_data.count(tf.file_kind));
|
||||
|
||||
// if chunks in flight < window size (2)
|
||||
//while (tf.ssb.size() < ngc_ft1_ctx->options.packet_window_size) {
|
||||
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);
|
||||
|
||||
ngc_ft1_ctx->cb_send_data[tf.file_kind](
|
||||
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
|
||||
//ngc_ft1_ctx->cb_send_data[tf.file_kind](
|
||||
//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,
|
||||
static_cast<uint8_t>(idx),
|
||||
tf.file_size_current,
|
||||
new_data.data(), new_data.size(),
|
||||
}
|
||||
);
|
||||
|
||||
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());
|
||||
peer.cca.onSent({idx, seq_id}, chunk_size);
|
||||
|
@ -16,49 +16,79 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
// TODO: 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
|
||||
//);
|
||||
namespace Events {
|
||||
|
||||
// return true to accept, false to deny
|
||||
//typedef bool NGC_FT1_recv_init_cb(
|
||||
//Tox *tox,
|
||||
//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
|
||||
//);
|
||||
struct NGCFT1_recv_request {
|
||||
uint32_t group_number;
|
||||
uint32_t peer_number;
|
||||
|
||||
//typedef void NGC_FT1_recv_data_cb(
|
||||
//Tox *tox,
|
||||
NGCFT1_file_kind file_kind;
|
||||
|
||||
//uint32_t group_number,
|
||||
//uint32_t peer_number,
|
||||
//uint8_t transfer_id,
|
||||
const uint8_t* file_id;
|
||||
size_t file_id_size;
|
||||
};
|
||||
|
||||
//size_t data_offset, const uint8_t* data, size_t data_size,
|
||||
//void* user_data
|
||||
//);
|
||||
struct NGCFT1_recv_init {
|
||||
uint32_t group_number;
|
||||
uint32_t peer_number;
|
||||
|
||||
// request to fill data_size bytes into data
|
||||
//typedef void NGC_FT1_send_data_cb(
|
||||
//Tox *tox,
|
||||
NGCFT1_file_kind file_kind;
|
||||
|
||||
//uint32_t group_number,
|
||||
//uint32_t peer_number,
|
||||
//uint8_t transfer_id,
|
||||
const uint8_t* file_id;
|
||||
size_t file_id_size;
|
||||
|
||||
//size_t data_offset, uint8_t* data, size_t data_size,
|
||||
//void* user_data
|
||||
//);
|
||||
const uint8_t transfer_id;
|
||||
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;
|
||||
ToxEventProviderI& _tep;
|
||||
NGCEXTEventProviderI& _neep;
|
||||
|
@ -33,11 +33,18 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ToxI* tox_i = nullptr;
|
||||
ToxEventProviderI* tox_event_provider_i = nullptr;
|
||||
|
||||
{ // make sure required types are loaded
|
||||
tox_i = RESOLVE_INSTANCE(ToxI);
|
||||
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) {
|
||||
std::cerr << "PLUGIN NGCEXT missing ToxEventProviderI\n";
|
||||
return 2;
|
||||
@ -47,10 +54,12 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
||||
// static store, could be anywhere tho
|
||||
// construct with fetched dependencies
|
||||
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
|
||||
PROVIDE_INSTANCE(NGCEXTEventProviderI, "NGCEXT", g_ngcextep.get());
|
||||
|
||||
PROVIDE_INSTANCE(NGCFT1EventProviderI, "NGCEXT", g_ngcft1.get());
|
||||
PROVIDE_INSTANCE(NGCFT1, "NGCEXT", g_ngcft1.get());
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user