1 // Copyright 2022 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 #pragma once 15 16 #include <cstring> 17 18 #include "pw_bytes/span.h" 19 #include "pw_containers/intrusive_list.h" 20 #include "pw_metric/metric.h" 21 #include "pw_metric_proto/metric_service.raw_rpc.pb.h" 22 #include "pw_rpc/raw/server_reader_writer.h" 23 #include "pw_span/span.h" 24 25 namespace pw::metric { 26 27 // The MetricService will send metrics when requested by Get(). For now, each 28 // Get() request results in a stream of responses, containing the metrics from 29 // the supplied list of groups and metrics. This includes recursive traversal 30 // of subgroups. In the future, filtering will be supported. 31 // 32 // An important limitation of the current implementation is that the Get() 33 // method is blocking, and sends all metrics at once (though batched). In the 34 // future, we may switch to offering an async version where the Get() method 35 // returns immediately, and someone else is responsible for pumping the queue. 36 class MetricService final 37 : public proto::pw_rpc::raw::MetricService::Service<MetricService> { 38 public: MetricService(const IntrusiveList<Metric> & metrics,const IntrusiveList<Group> & groups)39 MetricService(const IntrusiveList<Metric>& metrics, 40 const IntrusiveList<Group>& groups) 41 : metrics_(metrics), groups_(groups) {} 42 43 void Get(ConstByteSpan request, rpc::RawServerWriter& response); 44 45 private: 46 const IntrusiveList<Metric>& metrics_; 47 const IntrusiveList<Group>& groups_; 48 }; 49 50 } // namespace pw::metric 51