Loading src/api/dispatch-table.hpp +4 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ #include <unordered_map> namespace norns { template <typename Key, typename Hash, typename DispatchReturn, typename... DispatchArgs> struct dispatch_table { Loading @@ -77,4 +79,6 @@ struct dispatch_table { std::unordered_map<Key, std::function<DispatchReturn(DispatchArgs...)>, Hash> m_callbacks; }; } // namespace norns #endif /* __DISPATCH_TABLE_HPP__ */ src/api/listener.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ #include "api/dispatch-table.hpp" namespace norns { namespace api { namespace ba = boost::asio; Loading Loading @@ -208,5 +209,6 @@ private: }; } // namespace api } // namespace norns #endif /* __API_LISTENER_HPP__ */ src/api/message.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ uint64_t ntohll(uint64_t x) { } namespace norns { namespace api { // class message implements simple "packing/unpacking" of protocol buffers messages Loading Loading @@ -175,5 +176,6 @@ private: }; } // namespace api } // namespace norns #endif /* __API_MESSAGE_HPP__ */ src/api/request.cpp +25 −16 Original line number Diff line number Diff line Loading @@ -79,36 +79,44 @@ bool is_valid(const norns::rpc::Request_Task_Resource& res) { return true; } resource_info_ptr create_from(const norns::rpc::Request_Task_Resource& res) { std::shared_ptr<norns::data::resource_info> create_from(const norns::rpc::Request_Task_Resource& res) { using norns::data::resource_info; using norns::data::memory_buffer; using norns::data::local_path; using norns::data::shared_path; using norns::data::remote_path; if(is_valid(res)) { if(res.type() & NORNS_PROCESS_MEMORY) { return std::make_shared<data::memory_buffer>(res.nsid(), return std::make_shared<memory_buffer>(res.nsid(), res.buffer().address(), res.buffer().size()); } else { // NORNS_POSIX_PATH if(res.type() & R_LOCAL) { return std::make_shared<data::local_path>(res.nsid(), return std::make_shared<local_path>(res.nsid(), res.path().datapath()); } else if(res.type() & R_SHARED) { return std::make_shared<data::shared_path>(res.nsid(), return std::make_shared<shared_path>(res.nsid(), res.path().datapath()); } else { // R_REMOTE return std::make_shared<data::remote_path>(res.nsid(), return std::make_shared<remote_path>(res.nsid(), res.path().hostname(), res.path().datapath()); } } } return resource_info_ptr(); return std::shared_ptr<resource_info>(); } } namespace norns { namespace api { using request_ptr = std::unique_ptr<request>; Loading @@ -126,8 +134,8 @@ request_ptr request::create_from_buffer(const std::vector<uint8_t>& buffer, int auto task = rpc_req.task(); auto optype = task.optype(); resource_info_ptr src_res = create_from(task.source()); resource_info_ptr dst_res = create_from(task.destination()); std::shared_ptr<data::resource_info> src_res = ::create_from(task.source()); std::shared_ptr<data::resource_info> dst_res = ::create_from(task.destination()); if(src_res != nullptr && dst_res != nullptr) { return std::make_unique<iotask_create_request>(optype, src_res, dst_res); Loading Loading @@ -261,7 +269,7 @@ std::string job_register_request::to_string() const { using boost::algorithm::join; using boost::adaptors::transformed; auto to_string = [](const backend_ptr& b) { auto to_string = [](const std::shared_ptr<storage::backend>& b) { return b->to_string(); }; Loading @@ -284,7 +292,7 @@ std::string job_update_request::to_string() const { using boost::algorithm::join; using boost::adaptors::transformed; auto to_string = [](const backend_ptr& b) { auto to_string = [](const std::shared_ptr<storage::backend>& b) { return b->to_string(); }; Loading Loading @@ -405,6 +413,7 @@ std::string iotask_status_request::to_string() const { } // namespace api } // namespace norns src/api/request.hpp +8 −7 Original line number Diff line number Diff line Loading @@ -58,6 +58,9 @@ #include "norns.h" namespace norns { // forward declarations namespace storage { class backend; Loading @@ -67,9 +70,6 @@ namespace data { struct resource_info; }; using backend_ptr = std::shared_ptr<storage::backend>; using resource_info_ptr = std::shared_ptr<data::resource_info>; namespace api { /*! Valid types for an API request */ Loading Loading @@ -170,8 +170,8 @@ using bad_request = detail::request_impl< using iotask_create_request = detail::request_impl< request_type::iotask_create, uint32_t, //XXX replace by enum class? resource_info_ptr, resource_info_ptr std::shared_ptr<data::resource_info>, std::shared_ptr<data::resource_info> >; using iotask_status_request = detail::request_impl< Loading @@ -187,14 +187,14 @@ using job_register_request = detail::request_impl< request_type::job_register, uint32_t, std::vector<std::string>, std::vector<backend_ptr> std::vector<std::shared_ptr<storage::backend>> >; using job_update_request = detail::request_impl< request_type::job_update, uint32_t, std::vector<std::string>, std::vector<backend_ptr> std::vector<std::shared_ptr<storage::backend>> >; using job_unregister_request = detail::request_impl< Loading Loading @@ -240,5 +240,6 @@ using backend_unregister_request = detail::request_impl< >; } // namespace api } // namespace norns #endif /* __API_REQUESTS_H__ */ Loading
src/api/dispatch-table.hpp +4 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ #include <unordered_map> namespace norns { template <typename Key, typename Hash, typename DispatchReturn, typename... DispatchArgs> struct dispatch_table { Loading @@ -77,4 +79,6 @@ struct dispatch_table { std::unordered_map<Key, std::function<DispatchReturn(DispatchArgs...)>, Hash> m_callbacks; }; } // namespace norns #endif /* __DISPATCH_TABLE_HPP__ */
src/api/listener.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ #include "api/dispatch-table.hpp" namespace norns { namespace api { namespace ba = boost::asio; Loading Loading @@ -208,5 +209,6 @@ private: }; } // namespace api } // namespace norns #endif /* __API_LISTENER_HPP__ */
src/api/message.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ uint64_t ntohll(uint64_t x) { } namespace norns { namespace api { // class message implements simple "packing/unpacking" of protocol buffers messages Loading Loading @@ -175,5 +176,6 @@ private: }; } // namespace api } // namespace norns #endif /* __API_MESSAGE_HPP__ */
src/api/request.cpp +25 −16 Original line number Diff line number Diff line Loading @@ -79,36 +79,44 @@ bool is_valid(const norns::rpc::Request_Task_Resource& res) { return true; } resource_info_ptr create_from(const norns::rpc::Request_Task_Resource& res) { std::shared_ptr<norns::data::resource_info> create_from(const norns::rpc::Request_Task_Resource& res) { using norns::data::resource_info; using norns::data::memory_buffer; using norns::data::local_path; using norns::data::shared_path; using norns::data::remote_path; if(is_valid(res)) { if(res.type() & NORNS_PROCESS_MEMORY) { return std::make_shared<data::memory_buffer>(res.nsid(), return std::make_shared<memory_buffer>(res.nsid(), res.buffer().address(), res.buffer().size()); } else { // NORNS_POSIX_PATH if(res.type() & R_LOCAL) { return std::make_shared<data::local_path>(res.nsid(), return std::make_shared<local_path>(res.nsid(), res.path().datapath()); } else if(res.type() & R_SHARED) { return std::make_shared<data::shared_path>(res.nsid(), return std::make_shared<shared_path>(res.nsid(), res.path().datapath()); } else { // R_REMOTE return std::make_shared<data::remote_path>(res.nsid(), return std::make_shared<remote_path>(res.nsid(), res.path().hostname(), res.path().datapath()); } } } return resource_info_ptr(); return std::shared_ptr<resource_info>(); } } namespace norns { namespace api { using request_ptr = std::unique_ptr<request>; Loading @@ -126,8 +134,8 @@ request_ptr request::create_from_buffer(const std::vector<uint8_t>& buffer, int auto task = rpc_req.task(); auto optype = task.optype(); resource_info_ptr src_res = create_from(task.source()); resource_info_ptr dst_res = create_from(task.destination()); std::shared_ptr<data::resource_info> src_res = ::create_from(task.source()); std::shared_ptr<data::resource_info> dst_res = ::create_from(task.destination()); if(src_res != nullptr && dst_res != nullptr) { return std::make_unique<iotask_create_request>(optype, src_res, dst_res); Loading Loading @@ -261,7 +269,7 @@ std::string job_register_request::to_string() const { using boost::algorithm::join; using boost::adaptors::transformed; auto to_string = [](const backend_ptr& b) { auto to_string = [](const std::shared_ptr<storage::backend>& b) { return b->to_string(); }; Loading @@ -284,7 +292,7 @@ std::string job_update_request::to_string() const { using boost::algorithm::join; using boost::adaptors::transformed; auto to_string = [](const backend_ptr& b) { auto to_string = [](const std::shared_ptr<storage::backend>& b) { return b->to_string(); }; Loading Loading @@ -405,6 +413,7 @@ std::string iotask_status_request::to_string() const { } // namespace api } // namespace norns
src/api/request.hpp +8 −7 Original line number Diff line number Diff line Loading @@ -58,6 +58,9 @@ #include "norns.h" namespace norns { // forward declarations namespace storage { class backend; Loading @@ -67,9 +70,6 @@ namespace data { struct resource_info; }; using backend_ptr = std::shared_ptr<storage::backend>; using resource_info_ptr = std::shared_ptr<data::resource_info>; namespace api { /*! Valid types for an API request */ Loading Loading @@ -170,8 +170,8 @@ using bad_request = detail::request_impl< using iotask_create_request = detail::request_impl< request_type::iotask_create, uint32_t, //XXX replace by enum class? resource_info_ptr, resource_info_ptr std::shared_ptr<data::resource_info>, std::shared_ptr<data::resource_info> >; using iotask_status_request = detail::request_impl< Loading @@ -187,14 +187,14 @@ using job_register_request = detail::request_impl< request_type::job_register, uint32_t, std::vector<std::string>, std::vector<backend_ptr> std::vector<std::shared_ptr<storage::backend>> >; using job_update_request = detail::request_impl< request_type::job_update, uint32_t, std::vector<std::string>, std::vector<backend_ptr> std::vector<std::shared_ptr<storage::backend>> >; using job_unregister_request = detail::request_impl< Loading Loading @@ -240,5 +240,6 @@ using backend_unregister_request = detail::request_impl< >; } // namespace api } // namespace norns #endif /* __API_REQUESTS_H__ */