solanaceae_tox/solanaceae/tox_messages/tox_transfer_manager.hpp

90 lines
3.0 KiB
C++
Raw Permalink Normal View History

2023-07-24 13:20:53 +02:00
#pragma once
#include <solanaceae/toxcore/tox_event_interface.hpp>
#include <solanaceae/object_store/object_store.hpp>
2023-07-24 13:20:53 +02:00
#include <solanaceae/message3/registry_message_model.hpp>
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
#include "./backends/tox_ft_filesystem.hpp"
// switch to fwd or remove
2024-05-26 18:57:36 +02:00
#include <solanaceae/file/file2.hpp>
2023-07-24 13:20:53 +02:00
#include <entt/container/dense_map.hpp>
#include <string_view>
#include <memory>
// fwd
struct ToxI;
class ToxTransferManager : public RegistryMessageModelEventI, public ObjectStoreEventI, public ToxEventI {
public:
static constexpr const char* version {"2"};
2023-07-24 13:20:53 +02:00
protected:
2024-10-06 11:14:54 +02:00
RegistryMessageModelI& _rmm;
2024-10-24 15:55:44 +02:00
RegistryMessageModelI::SubscriptionReference _rmm_sr;
2023-07-24 13:20:53 +02:00
Contact3Registry& _cr;
ToxContactModel2& _tcm;
ToxI& _t;
2024-10-24 15:55:44 +02:00
ToxEventProviderI::SubscriptionReference _tep_sr;
ObjectStore2& _os;
2024-10-24 15:55:44 +02:00
ObjectStore2::SubscriptionReference _os_sr;
Backends::ToxFTFilesystem _ftb;
2023-07-24 13:20:53 +02:00
bool _in_obj_update_event {false};
entt::dense_map<uint64_t, ObjectHandle> _friend_sending_lookup;
entt::dense_map<uint64_t, ObjectHandle> _friend_receiving_lookup;
2023-07-24 13:20:53 +02:00
protected:
void toxFriendLookupAdd(ObjectHandle o);
void toxFriendLookupRemove(ObjectHandle o);
2023-07-24 13:20:53 +02:00
ObjectHandle toxFriendLookupSending(const uint32_t friend_number, const uint32_t file_number) const;
ObjectHandle toxFriendLookupReceiving(const uint32_t friend_number, const uint32_t file_number) const;
2023-07-24 13:20:53 +02:00
public:
ToxTransferManager(
2024-10-06 11:14:54 +02:00
RegistryMessageModelI& rmm,
Contact3Registry& cr,
ToxContactModel2& tcm,
ToxI& t,
ToxEventProviderI& tep,
ObjectStore2& os
);
2023-07-24 13:20:53 +02:00
virtual ~ToxTransferManager(void);
virtual void iterate(void);
public: // TODO: private?
Message3Handle toxSendFilePath(const Contact3 c, uint32_t file_kind, std::string_view file_name, std::string_view file_path, std::vector<uint8_t> file_id = {});
2023-07-24 13:20:53 +02:00
bool resume(ObjectHandle transfer);
bool pause(ObjectHandle transfer);
// move to "file" backend?
bool setFileI(ObjectHandle transfer, std::unique_ptr<File2I>&& new_file); // note, does not emplace FileInfoLocal
bool setFilePath(ObjectHandle transfer, std::string_view file_path);
bool setFilePathDir(ObjectHandle transfer, std::string_view file_path);
2023-07-24 13:20:53 +02:00
// calls setFileI() and resume()
bool accept(ObjectHandle transfer, std::string_view file_path, bool path_is_file);
2023-07-24 13:20:53 +02:00
protected: // (r)mm
bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override;
protected: // os
//bool onEvent(const ObjectStore::Events::ObjectConstruct&) override;
bool onEvent(const ObjectStore::Events::ObjectUpdate&) override;
bool onEvent(const ObjectStore::Events::ObjectDestory&) override;
2023-07-24 13:20:53 +02:00
protected: // events
virtual bool onToxEvent(const Tox_Event_Friend_Connection_Status* e) override;
virtual bool onToxEvent(const Tox_Event_File_Recv* e) override;
virtual bool onToxEvent(const Tox_Event_File_Recv_Control* e) override;
virtual bool onToxEvent(const Tox_Event_File_Recv_Chunk* e) override;
virtual bool onToxEvent(const Tox_Event_File_Chunk_Request* e) override;
};