Flutter Engine
The Flutter Engine
log_state.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/fml/platform/fuchsia/log_state.h"
6
7#include <fidl/fuchsia.logger/cpp/fidl.h>
8#include <lib/component/incoming/cpp/protocol.h>
9#include <lib/fidl/cpp/channel.h>
10#include <lib/fidl/cpp/wire/internal/transport_channel.h>
11#include <lib/zx/socket.h>
12#include <zircon/assert.h>
13#include <zircon/types.h>
14
15#include <atomic>
16#include <initializer_list>
17#include <memory>
18#include <mutex>
19#include <string>
20#include <utility>
21#include <vector>
22
23#include "flutter/fml/platform/fuchsia/log_interest_listener.h"
24
25namespace fml {
26
28 // Get channel to log sink
29 auto client_end = component::Connect<fuchsia_logger::LogSink>();
30 ZX_ASSERT(client_end.is_ok());
31 fidl::SyncClient log_sink(std::move(*client_end));
32
33 // Attempts to create a kernel socket object should never fail.
34 zx::socket local, remote;
35 zx::socket::create(ZX_SOCKET_DATAGRAM, &local, &remote);
36 auto result = log_sink->ConnectStructured({{.socket = std::move(remote)}});
37 ZX_ASSERT_MSG(result.is_ok(), "%s",
38 result.error_value().FormatDescription().c_str());
39
40 // Wait for the first interest change to set the initial minimum logging
41 // level (should return quickly).
42 auto interest_result = log_sink->WaitForInterestChange();
43 ZX_ASSERT_MSG(interest_result.is_ok(), "%s",
44 interest_result.error_value().FormatDescription().c_str());
45 LogInterestListener::HandleInterestChange(interest_result->data());
46
47 socket_ = std::move(local);
48 client_end_ = log_sink.TakeClientEnd();
49}
50
51fidl::ClientEnd<::fuchsia_logger::LogSink> LogState::TakeClientEnd() {
52 std::lock_guard lock(mutex_);
53 return std::move(client_end_);
54}
55
56void LogState::SetTags(const std::initializer_list<std::string>& tags) {
57 std::atomic_store(&tags_,
58 std::make_shared<const std::vector<std::string>>(tags));
59}
60
62 static LogState* instance = new LogState();
63 return *instance;
64}
65
66} // namespace fml
static void HandleInterestChange(const fuchsia_diagnostics::Interest &interest)
void SetTags(const std::initializer_list< std::string > &tags)
Definition: log_state.cc:56
static LogState & Default()
Definition: log_state.cc:61
std::shared_ptr< const std::vector< std::string > > tags() const
Definition: log_state.h:31
fidl::ClientEnd<::fuchsia_logger::LogSink > TakeClientEnd()
Definition: log_state.cc:51
VkInstance instance
Definition: main.cc:48
GAsyncResult * result
Definition: ascii_trie.cc:9
int_closure create