blob: 71a56dcb5711862aac530368022d6b5ec1b8cb0f [file] [log] [blame]
// Copyright 2020 The Pigweed Authors
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#pragma once
#include "pw_log/log.h"
#include "pw_log/proto/log.raw_rpc.pb.h"
#include "pw_log_multisink/log_queue.h"
namespace pw::log_rpc {
// The Logs RPC service will send logs when requested by Get(). For now, Get()
// requests result in a stream of responses, containing all log entries from
// the attached log queue.
// The Get() method will return logs in the current queue immediately, but
// someone else is responsible for pumping the log queue using Flush().
class Logs final : public pw::log::generated::Logs<Logs> {
Logs(LogQueue& log_queue) : log_queue_(log_queue), dropped_entries_(0) {}
// RPC API for the Logs that produces a log stream. This method will
// return immediately, another class must call Flush() to push logs from
// the queue to this stream.
void Get(ServerContext&, ConstByteSpan, rpc::RawServerWriter& writer);
// Interface for the owner of the service instance to flush all existing
// logs to the writer, if one is attached.
Status Flush();
// Interface for the owner of the service instance to close the RPC, if
// one is attached.
void Finish() { response_writer_.Finish(); }
LogQueue& log_queue_;
rpc::RawServerWriter response_writer_;
size_t dropped_entries_;
} // namespace pw::log_rpc