1 // Copyright 2021 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 <span> 18 19 #include "pw_log_rpc/rpc_log_drain.h" 20 #include "pw_result/result.h" 21 #include "pw_status/status.h" 22 23 namespace pw::log_rpc { 24 25 // Holds an inmutable map of RPC channel ID to RpcLogDrain to fascilitate the 26 // maintenance of all RPC log streams. 27 class RpcLogDrainMap { 28 public: RpcLogDrainMap(std::span<RpcLogDrain> drains)29 explicit constexpr RpcLogDrainMap(std::span<RpcLogDrain> drains) 30 : drains_(drains) {} 31 32 // Not copyable nor movable. 33 RpcLogDrainMap(RpcLogDrainMap const&) = delete; 34 RpcLogDrainMap& operator=(RpcLogDrainMap const&) = delete; 35 RpcLogDrainMap(RpcLogDrainMap&&) = delete; 36 RpcLogDrainMap& operator=(RpcLogDrainMap&&) = delete; 37 GetDrainFromChannelId(uint32_t channel_id)38 Result<RpcLogDrain*> GetDrainFromChannelId(uint32_t channel_id) const { 39 for (auto& drain : drains_) { 40 if (drain.channel_id() == channel_id) { 41 return &drain; 42 } 43 } 44 return Status::NotFound(); 45 } 46 drains()47 const std::span<RpcLogDrain>& drains() const { return drains_; } 48 49 protected: 50 const std::span<RpcLogDrain> drains_; 51 }; 52 53 } // namespace pw::log_rpc 54