Skip to content

Commit

Permalink
Teach //flutter/glue to build on Fuchsia (flutter#2898)
Browse files Browse the repository at this point in the history
  • Loading branch information
abarth authored Aug 10, 2016
1 parent a413ef0 commit 4a972e2
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 7 deletions.
25 changes: 19 additions & 6 deletions glue/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ source_set("glue") {
sources = [
"data_pipe_utils.cc",
"data_pipe_utils.h",
"drain_data_pipe_job.cc",
"drain_data_pipe_job.h",
"movable_wrapper.h",
"stack_trace.cc",
"stack_trace.h",
"task_runner_adaptor.cc",
"task_runner_adaptor.h",
"thread.cc",
"thread.h",
"trace_event.h",
]
Expand All @@ -24,7 +19,25 @@ source_set("glue") {
"//mojo/public/cpp/system",
]

if (!is_fuchsia) {
if (is_fuchsia) {
sources += [
"drain_data_pipe_job_fuchsia.cc",
"stack_trace_fuchsia.cc",
"thread_fuchsia.cc",
]

deps += [
"//lib/mtl",
]
} else {
sources += [
"drain_data_pipe_job_base.cc",
"stack_trace_base.cc",
"task_runner_adaptor.cc",
"task_runner_adaptor.h",
"thread_base.cc",
]

deps += [
"//base",
"//mojo/data_pipe_utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {

std::vector<char> buffer_;
ResultCallback callback_;
mojo::common::DataPipeDrainer drainer_;
DataPipeDrainer drainer_;

FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl);
};
Expand Down
43 changes: 43 additions & 0 deletions glue/drain_data_pipe_job_fuchsia.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/glue/drain_data_pipe_job.h"

#include <utility>

#include "lib/mtl/data_pipe/data_pipe_drainer.h"

using mtl::DataPipeDrainer;

namespace glue {

class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {
public:
explicit JobImpl(mojo::ScopedDataPipeConsumerHandle handle,
const ResultCallback& callback)
: callback_(callback), drainer_(this, std::move(handle)) {}

private:
// mojo::common::DataPipeDrainer::Client
void OnDataAvailable(const void* data, size_t num_bytes) override {
const char* bytes = static_cast<const char*>(data);
buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
}

void OnDataComplete() override { callback_(std::move(buffer_)); }

std::vector<char> buffer_;
ResultCallback callback_;
DataPipeDrainer drainer_;

FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl);
};

DrainDataPipeJob::DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle,
const ResultCallback& callback)
: impl_(new JobImpl(std::move(handle), callback)) {}

DrainDataPipeJob::~DrainDataPipeJob() {}

} // namespace glue
File renamed without changes.
11 changes: 11 additions & 0 deletions glue/stack_trace_fuchsia.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/glue/stack_trace.h"

namespace glue {

void PrintStackTrace() {}

} // namespace glue
File renamed without changes.
27 changes: 27 additions & 0 deletions glue/thread_fuchsia.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/glue/thread.h"

#include <utility>

#include "lib/mtl/threading/create_thread.h"

namespace glue {

class Thread::ThreadImpl {
public:
std::thread thread_;
};

Thread::Thread(std::string name) : impl_(new ThreadImpl()) {}

Thread::~Thread() {}

bool Thread::Start() {
impl_->thread_ = mtl::CreateThread(&task_runner_);
return true;
}

} // namespace glue

0 comments on commit 4a972e2

Please sign in to comment.