| #include "redfish_to_uhm_trie.hpp" |
| |
| #include <memory> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
| |
| #include "absl/strings/str_split.h" |
| #include "redfish_to_uhm_mapping.pb.h" |
| #include "redfish_to_uhm_mapping_value.hpp" |
| #include "redfish_to_uhm_trie_node.hpp" |
| |
| namespace devpath_plugin { |
| |
| namespace { |
| |
| std::vector<std::string> SplitPath(std::string_view path) { |
| std::vector<std::string> segments; |
| for (std::string_view segment : absl::StrSplit(path, '/')) { |
| if (!segment.empty()) { |
| segments.push_back(std::string(segment)); |
| } |
| } |
| return segments; |
| } |
| |
| } // namespace |
| |
| void RedfishToUhmTrie::Insert( |
| const ::devpath_plugin::Key& key, |
| const std::shared_ptr<const RedfishToUhmMappingValue>& value) { |
| std::vector<std::string> segments = SplitPath(key.redfish_url_pattern()); |
| RedfishToUhmTrieNode* current = &root_; |
| for (const std::string& segment : segments) { |
| current = current->GetOrCreateChild(segment); |
| } |
| current->SetValue(value); |
| } |
| |
| std::shared_ptr<const RedfishToUhmMappingValue> |
| RedfishToUhmTrie::GetMappingFromUrl(const ::devpath_plugin::Key& key) const { |
| std::vector<std::string> segments = SplitPath(key.redfish_url_pattern()); |
| const RedfishToUhmTrieNode* current = &root_; |
| for (const std::string& segment : segments) { |
| current = current->GetChild(segment); |
| if (current == nullptr) { |
| return nullptr; |
| } |
| } |
| return current->GetValue(); |
| } |
| |
| } // namespace devpath_plugin |