| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "flutter/runtime/embedder_resources.h" |
| 6 | |
| 7 | #include <cstring> |
| 8 | |
| 9 | #include "flutter/fml/logging.h" |
| 10 | |
| 11 | namespace flutter { |
| 12 | |
| 13 | using runtime::ResourcesEntry; |
| 14 | |
| 15 | EmbedderResources::EmbedderResources(ResourcesEntry* resources_table) |
| 16 | : resources_table_(resources_table) {} |
| 17 | |
| 18 | const int EmbedderResources::kNoSuchInstance = -1; |
| 19 | |
| 20 | int EmbedderResources::ResourceLookup(const char* path, const char** resource) { |
| 21 | for (int i = 0; resources_table_[i].path_ != nullptr; i++) { |
| 22 | const ResourcesEntry& entry = resources_table_[i]; |
| 23 | if (strcmp(s1: path, s2: entry.path_) == 0) { |
| 24 | *resource = entry.resource_; |
| 25 | FML_DCHECK(entry.length_ > 0); |
| 26 | return entry.length_; |
| 27 | } |
| 28 | } |
| 29 | return kNoSuchInstance; |
| 30 | } |
| 31 | |
| 32 | const char* EmbedderResources::Path(int idx) { |
| 33 | FML_DCHECK(idx >= 0); |
| 34 | ResourcesEntry* entry = At(idx); |
| 35 | if (entry == nullptr) { |
| 36 | return nullptr; |
| 37 | } |
| 38 | FML_DCHECK(entry->path_ != nullptr); |
| 39 | return entry->path_; |
| 40 | } |
| 41 | |
| 42 | ResourcesEntry* EmbedderResources::At(int idx) { |
| 43 | FML_DCHECK(idx >= 0); |
| 44 | for (int i = 0; resources_table_[i].path_ != nullptr; i++) { |
| 45 | if (idx == i) { |
| 46 | return &resources_table_[i]; |
| 47 | } |
| 48 | } |
| 49 | return nullptr; |
| 50 | } |
| 51 | |
| 52 | } // namespace flutter |
| 53 |
