1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
17 #include "pw_log/log.h"
18 #include "pw_log_multisink/log_queue.h"
19 #include "pw_log_proto/log.raw_rpc.pb.h"
21 namespace pw::log_rpc {
23 // The Logs RPC service will send logs when requested by Get(). For now, Get()
24 // requests result in a stream of responses, containing all log entries from
25 // the attached log queue.
27 // The Get() method will return logs in the current queue immediately, but
28 // someone else is responsible for pumping the log queue using Flush().
29 class Logs final : public pw::log::generated::Logs<Logs> {
31 Logs(LogQueue& log_queue) : log_queue_(log_queue), dropped_entries_(0) {}
33 // RPC API for the Logs that produces a log stream. This method will
34 // return immediately, another class must call Flush() to push logs from
35 // the queue to this stream.
36 void Get(ServerContext&, ConstByteSpan, rpc::RawServerWriter& writer);
38 // Interface for the owner of the service instance to flush all existing
39 // logs to the writer, if one is attached.
42 // Interface for the owner of the service instance to close the RPC, if
44 void Finish() { response_writer_.Finish(); }
48 rpc::RawServerWriter response_writer_;
49 size_t dropped_entries_;
52 } // namespace pw::log_rpc