Flutter Engine
vmservice_object.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 "vmservice_object.h"
6 
7 #include <dirent.h>
8 #include <fuchsia/io/cpp/fidl.h>
9 #include <lib/syslog/global.h>
10 #include <zircon/status.h>
11 
12 #include <cerrno>
13 #include <string>
14 
15 #include "logging.h"
16 
17 namespace {
18 
19 bool ReadDirContents(const std::string& path, std::vector<std::string>* out) {
20  out->clear();
21  DIR* dir = opendir(path.c_str());
22  if (!dir) {
23  return false;
24  }
25  struct dirent* de;
26  errno = 0;
27  while ((de = readdir(dir)) != nullptr) {
28  out->push_back(de->d_name);
29  }
30  closedir(dir);
31  return !errno;
32 }
33 
34 } // namespace
35 
36 namespace dart_utils {
37 
38 void VMServiceObject::GetContents(LazyEntryVector* out_vector) const {
39  // List /tmp/dart.services if it exists, and push its contents as
40  // as the conrtents of this directory.
41  std::vector<std::string> files;
42  if (!ReadDirContents(kPortDir, &files)) {
43  FX_LOGF(ERROR, LOG_TAG,
44  "Failed to read Dart VM Service port directory '%s': %s", kPortDir,
45  strerror(errno));
46  return;
47  }
48  for (const auto& file : files) {
49  if ((file == ".") || (file == "..")) {
50  continue;
51  }
52  out_vector->push_back({std::stoul(file) + GetStartingId(), file,
53  fuchsia::io::MODE_TYPE_FILE});
54  }
55 }
56 
57 zx_status_t VMServiceObject::GetFile(Node** out_node,
58  uint64_t id,
59  std::string name) const {
60  return ZX_ERR_NOT_FOUND;
61 }
62 
63 } // namespace dart_utils
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
zx_status_t GetFile(Node **out_node, uint64_t id, std::string name) const override
static constexpr const char * kPortDir
#define LOG_TAG
Definition: logging.h:11
const char * name
Definition: fuchsia.cc:50
void GetContents(LazyEntryVector *out_vector) const override