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