Flutter Engine
embedder_resources.cc
Go to the documentation of this file.
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 
16  : resources_table_(resources_table) {}
17 
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(path, 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
const char * Path(int idx)
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
static const int kNoSuchInstance
#define FML_DCHECK(condition)
Definition: logging.h:86
const char * path_
int length_
EmbedderResources(runtime::ResourcesEntry *resources_table)
int ResourceLookup(const char *path, const char **resource)
const char * resource_