#pragma once #include #include #include #include #include "./backends/tox_ft_filesystem.hpp" // switch to fwd or remove #include #include #include #include // fwd struct ToxI; class ToxTransferManager : public RegistryMessageModelEventI, public ObjectStoreEventI, public ToxEventI { public: static constexpr const char* version {"2"}; protected: RegistryMessageModelI& _rmm; RegistryMessageModelI::SubscriptionReference _rmm_sr; Contact3Registry& _cr; ToxContactModel2& _tcm; ToxI& _t; ToxEventProviderI::SubscriptionReference _tep_sr; ObjectStore2& _os; ObjectStore2::SubscriptionReference _os_sr; Backends::ToxFTFilesystem _ftb; bool _in_obj_update_event {false}; entt::dense_map _friend_sending_lookup; entt::dense_map _friend_receiving_lookup; protected: void toxFriendLookupAdd(ObjectHandle o); void toxFriendLookupRemove(ObjectHandle o); 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; public: ToxTransferManager( RegistryMessageModelI& rmm, Contact3Registry& cr, ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep, ObjectStore2& os ); 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 file_id = {}); bool resume(ObjectHandle transfer); bool pause(ObjectHandle transfer); // move to "file" backend? bool setFileI(ObjectHandle transfer, std::unique_ptr&& 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); // calls setFileI() and resume() bool accept(ObjectHandle transfer, std::string_view file_path, bool path_is_file); 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; 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; };