1 // Copyright 2020 The Pigweed Authors 2 // 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 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 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 13 // the License. 14 15 #pragma once 16 17 #include "pw_log/log.h" 18 #include "pw_log_multisink/log_queue.h" 19 #include "pw_log_proto/log.raw_rpc.pb.h" 20 21 namespace pw::log_rpc { 22 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. 26 // 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> { 30 public: Logs(LogQueue & log_queue)31 Logs(LogQueue& log_queue) : log_queue_(log_queue), dropped_entries_(0) {} 32 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); 37 38 // Interface for the owner of the service instance to flush all existing 39 // logs to the writer, if one is attached. 40 Status Flush(); 41 42 // Interface for the owner of the service instance to close the RPC, if 43 // one is attached. Finish()44 void Finish() { response_writer_.Finish(); } 45 46 private: 47 LogQueue& log_queue_; 48 rpc::RawServerWriter response_writer_; 49 size_t dropped_entries_; 50 }; 51 52 } // namespace pw::log_rpc 53