Loading src/Makefile.am +1 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,7 @@ liburd_aux_la_SOURCES = \ io/task-stats.cpp \ io/task-stats.hpp \ io/transferors.hpp \ io/transferors/transferor.hpp \ io/transferors/local-path-to-local-path.cpp \ io/transferors/local-path-to-local-path.hpp \ io/transferors/local-path-to-shared-path.cpp \ Loading src/io/task.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -41,8 +41,8 @@ namespace io { task::task(const iotask_id tid, const iotask_type type, const backend_ptr src_backend, const resource_info_ptr src_info, const backend_ptr dst_backend, const resource_info_ptr dst_info, const auth::credentials& creds, const TransferorFunctionType& tfun, const task_stats_ptr stats) const auth::credentials& creds, const transferor_ptr&& tx_ptr, const task_stats_ptr&& st_ptr) : m_id(tid), m_type(type), m_src_backend(src_backend), Loading @@ -50,8 +50,8 @@ task::task(const iotask_id tid, const iotask_type type, m_dst_backend(dst_backend), m_dst_info(dst_info), m_usr_credentials(creds), m_transferor(tfun), m_stats(stats) { } m_transferor(tx_ptr), m_stats(st_ptr) { } iotask_id task::id() const { return m_id; Loading Loading @@ -95,11 +95,10 @@ void task::operator()() const { } //TODO progress reporting ec = m_transferor(m_usr_credentials, src, dst); ec = m_transferor->transfer(m_usr_credentials, src, dst); //XXX should we rollback all previous changes? if(ec) { log_error("Conversion failed"); log_error("Transfer failed"); return; } Loading src/io/task.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -40,10 +40,9 @@ namespace norns { namespace io { using TransferorFunctionType = transferor_registry::CallableType; // forward declaration struct task_stats; struct transferor; /*! Descriptor for an I/O task */ struct task { Loading @@ -51,13 +50,14 @@ struct task { using backend_ptr = std::shared_ptr<storage::backend>; using resource_info_ptr = std::shared_ptr<data::resource_info>; using resource_ptr = std::shared_ptr<data::resource>; using transferor_ptr = std::shared_ptr<transferor>; using task_stats_ptr = std::shared_ptr<task_stats>; task(const iotask_id tid, const iotask_type type, const backend_ptr srd_backend, const resource_info_ptr src_info, const backend_ptr dst_backend, const resource_info_ptr dst_info, const auth::credentials& creds, const TransferorFunctionType& tfun, const task_stats_ptr stats); const auth::credentials& creds, const transferor_ptr&& tx_ptr, const task_stats_ptr&& st_ptr); iotask_id id() const; bool is_valid() const; Loading @@ -74,7 +74,7 @@ struct task { const backend_ptr m_dst_backend; const resource_info_ptr m_dst_info; const auth::credentials m_usr_credentials; const TransferorFunctionType m_transferor; const transferor_ptr m_transferor; resource_ptr m_src; resource_ptr m_dst; Loading src/io/transferor-registry.cpp +23 −9 Original line number Diff line number Diff line Loading @@ -31,19 +31,33 @@ namespace norns { namespace io { using CallableType = transferor_registry::CallableType; using ReturnType = transferor_registry::ReturnType; bool transferor_registry::add(const data::resource_type t1, const data::resource_type t2, std::shared_ptr<io::transferor>&& trp) { void transferor_registry::add(SrcType t1, DstType t2, CallableType&& func) { m_dispatcher.add(std::make_pair(t1, t2), std::forward<CallableType>(func)); using ValueType = std::shared_ptr<io::transferor>; if(m_transferors.count(std::make_pair(t1, t2)) == 0) { m_transferors.emplace(std::make_pair(t1, t2), std::forward<ValueType>(trp)); return true; } return false; } CallableType transferor_registry::get(SrcType t1, DstType t2) const { return m_dispatcher.get(std::make_pair(t1, t2)); std::shared_ptr<io::transferor> transferor_registry::get(const data::resource_type t1, const data::resource_type t2) const { using ValueType = std::shared_ptr<io::transferor>; if(m_transferors.count(std::make_pair(t1, t2)) == 0) { return ValueType(); } ReturnType transferor_registry::invoke(SrcType t1, DstType t2, CredType creds, ArgType arg1, ArgType arg2) const { return m_dispatcher.invoke(std::make_pair(t1, t2), creds, arg1, arg2); return m_transferors.at(std::make_pair(t1, t2)); } } // namespace io Loading src/io/transferor-registry.hpp +12 −16 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ enum class resource_type; namespace io { struct transferor; struct transferor_registry { struct transferor_hash { Loading @@ -55,23 +57,17 @@ struct transferor_registry { } }; using SrcType = const data::resource_type; using DstType = const data::resource_type; using CredType = const auth::credentials&; using ArgType = const std::shared_ptr<const data::resource>&; using ReturnType = std::error_code; using KeyType = std::pair<SrcType, DstType>; using KeyHash = transferor_hash; using DispatcherType = dispatch_table<KeyType, KeyHash, ReturnType, CredType, ArgType, ArgType>; using CallableType = DispatcherType::CallableType; void add(SrcType t1, DstType t2, CallableType&& func); CallableType get(SrcType t1, DstType t2) const; ReturnType invoke(SrcType t1, DstType t2, CredType creds, ArgType arg1, ArgType arg2) const; bool add(const data::resource_type t1, const data::resource_type t2, std::shared_ptr<io::transferor>&& tr); std::shared_ptr<io::transferor> get(const data::resource_type t1, const data::resource_type t2) const; DispatcherType m_dispatcher; std::unordered_map<std::pair< const data::resource_type, const data::resource_type>, std::shared_ptr<io::transferor>, transferor_hash> m_transferors; }; } // namespace io Loading Loading
src/Makefile.am +1 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,7 @@ liburd_aux_la_SOURCES = \ io/task-stats.cpp \ io/task-stats.hpp \ io/transferors.hpp \ io/transferors/transferor.hpp \ io/transferors/local-path-to-local-path.cpp \ io/transferors/local-path-to-local-path.hpp \ io/transferors/local-path-to-shared-path.cpp \ Loading
src/io/task.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -41,8 +41,8 @@ namespace io { task::task(const iotask_id tid, const iotask_type type, const backend_ptr src_backend, const resource_info_ptr src_info, const backend_ptr dst_backend, const resource_info_ptr dst_info, const auth::credentials& creds, const TransferorFunctionType& tfun, const task_stats_ptr stats) const auth::credentials& creds, const transferor_ptr&& tx_ptr, const task_stats_ptr&& st_ptr) : m_id(tid), m_type(type), m_src_backend(src_backend), Loading @@ -50,8 +50,8 @@ task::task(const iotask_id tid, const iotask_type type, m_dst_backend(dst_backend), m_dst_info(dst_info), m_usr_credentials(creds), m_transferor(tfun), m_stats(stats) { } m_transferor(tx_ptr), m_stats(st_ptr) { } iotask_id task::id() const { return m_id; Loading Loading @@ -95,11 +95,10 @@ void task::operator()() const { } //TODO progress reporting ec = m_transferor(m_usr_credentials, src, dst); ec = m_transferor->transfer(m_usr_credentials, src, dst); //XXX should we rollback all previous changes? if(ec) { log_error("Conversion failed"); log_error("Transfer failed"); return; } Loading
src/io/task.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -40,10 +40,9 @@ namespace norns { namespace io { using TransferorFunctionType = transferor_registry::CallableType; // forward declaration struct task_stats; struct transferor; /*! Descriptor for an I/O task */ struct task { Loading @@ -51,13 +50,14 @@ struct task { using backend_ptr = std::shared_ptr<storage::backend>; using resource_info_ptr = std::shared_ptr<data::resource_info>; using resource_ptr = std::shared_ptr<data::resource>; using transferor_ptr = std::shared_ptr<transferor>; using task_stats_ptr = std::shared_ptr<task_stats>; task(const iotask_id tid, const iotask_type type, const backend_ptr srd_backend, const resource_info_ptr src_info, const backend_ptr dst_backend, const resource_info_ptr dst_info, const auth::credentials& creds, const TransferorFunctionType& tfun, const task_stats_ptr stats); const auth::credentials& creds, const transferor_ptr&& tx_ptr, const task_stats_ptr&& st_ptr); iotask_id id() const; bool is_valid() const; Loading @@ -74,7 +74,7 @@ struct task { const backend_ptr m_dst_backend; const resource_info_ptr m_dst_info; const auth::credentials m_usr_credentials; const TransferorFunctionType m_transferor; const transferor_ptr m_transferor; resource_ptr m_src; resource_ptr m_dst; Loading
src/io/transferor-registry.cpp +23 −9 Original line number Diff line number Diff line Loading @@ -31,19 +31,33 @@ namespace norns { namespace io { using CallableType = transferor_registry::CallableType; using ReturnType = transferor_registry::ReturnType; bool transferor_registry::add(const data::resource_type t1, const data::resource_type t2, std::shared_ptr<io::transferor>&& trp) { void transferor_registry::add(SrcType t1, DstType t2, CallableType&& func) { m_dispatcher.add(std::make_pair(t1, t2), std::forward<CallableType>(func)); using ValueType = std::shared_ptr<io::transferor>; if(m_transferors.count(std::make_pair(t1, t2)) == 0) { m_transferors.emplace(std::make_pair(t1, t2), std::forward<ValueType>(trp)); return true; } return false; } CallableType transferor_registry::get(SrcType t1, DstType t2) const { return m_dispatcher.get(std::make_pair(t1, t2)); std::shared_ptr<io::transferor> transferor_registry::get(const data::resource_type t1, const data::resource_type t2) const { using ValueType = std::shared_ptr<io::transferor>; if(m_transferors.count(std::make_pair(t1, t2)) == 0) { return ValueType(); } ReturnType transferor_registry::invoke(SrcType t1, DstType t2, CredType creds, ArgType arg1, ArgType arg2) const { return m_dispatcher.invoke(std::make_pair(t1, t2), creds, arg1, arg2); return m_transferors.at(std::make_pair(t1, t2)); } } // namespace io Loading
src/io/transferor-registry.hpp +12 −16 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ enum class resource_type; namespace io { struct transferor; struct transferor_registry { struct transferor_hash { Loading @@ -55,23 +57,17 @@ struct transferor_registry { } }; using SrcType = const data::resource_type; using DstType = const data::resource_type; using CredType = const auth::credentials&; using ArgType = const std::shared_ptr<const data::resource>&; using ReturnType = std::error_code; using KeyType = std::pair<SrcType, DstType>; using KeyHash = transferor_hash; using DispatcherType = dispatch_table<KeyType, KeyHash, ReturnType, CredType, ArgType, ArgType>; using CallableType = DispatcherType::CallableType; void add(SrcType t1, DstType t2, CallableType&& func); CallableType get(SrcType t1, DstType t2) const; ReturnType invoke(SrcType t1, DstType t2, CredType creds, ArgType arg1, ArgType arg2) const; bool add(const data::resource_type t1, const data::resource_type t2, std::shared_ptr<io::transferor>&& tr); std::shared_ptr<io::transferor> get(const data::resource_type t1, const data::resource_type t2) const; DispatcherType m_dispatcher; std::unordered_map<std::pair< const data::resource_type, const data::resource_type>, std::shared_ptr<io::transferor>, transferor_hash> m_transferors; }; } // namespace io Loading