blob: c700af49a80bf066df8247f4ec39ca236f3a881f [file] [log] [blame]
Carlos Chinchilla5e645b22021-08-02 20:48:33 -07001// 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
Carlos Chinchilla6ea8f212021-12-06 12:12:48 -080015// clang-format off
16#include "pw_log_rpc/internal/log_config.h" // PW_LOG_* macros must be first.
17
Carlos Chinchilla5e645b22021-08-02 20:48:33 -070018#include "pw_log_rpc/log_service.h"
Carlos Chinchilla6ea8f212021-12-06 12:12:48 -080019// clang-format on
Carlos Chinchilla5e645b22021-08-02 20:48:33 -070020
21#include "pw_log/log.h"
22#include "pw_log/proto/log.pwpb.h"
23
24namespace pw::log_rpc {
25
Wyatt Hepler8e756e32021-11-18 09:59:27 -080026void LogService::Listen(ConstByteSpan, rpc::RawServerWriter& writer) {
Wyatt Heplerebf33b72021-09-09 13:33:56 -070027 uint32_t channel_id = writer.channel_id();
Carlos Chinchilla5e645b22021-08-02 20:48:33 -070028 Result<RpcLogDrain*> drain = drains_.GetDrainFromChannelId(channel_id);
29 if (!drain.ok()) {
30 return;
31 }
32
33 if (const Status status = drain.value()->Open(writer); !status.ok()) {
Carlos Chinchilla6ea8f212021-12-06 12:12:48 -080034 PW_LOG_DEBUG("Could not start new log stream. %d",
Carlos Chinchilla5e645b22021-08-02 20:48:33 -070035 static_cast<int>(status.code()));
36 }
37}
38
Carlos Chinchilla5e645b22021-08-02 20:48:33 -070039} // namespace pw::log_rpc