1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <cobalt-client/cpp/metric-options.h> 6 #include <cobalt-client/cpp/types-internal.h> 7 #include <fbl/string_printf.h> 8 9 namespace cobalt_client { 10 namespace internal { 11 From(const MetricOptions & options)12LocalMetricInfo LocalMetricInfo::From(const MetricOptions& options) { 13 LocalMetricInfo metric_info; 14 if (!options.name.empty()) { 15 metric_info.name = options.name; 16 return metric_info; 17 } 18 19 if (options.get_metric_name != nullptr) { 20 metric_info.name = options.get_metric_name(options.metric_id); 21 } else { 22 metric_info.name = fbl::StringPrintf("%u", options.metric_id); 23 } 24 25 if (!options.component.empty()) { 26 metric_info.name = 27 fbl::StringPrintf("%s.%s", metric_info.name.c_str(), options.component.c_str()); 28 } 29 30 if (options.get_event_name != nullptr) { 31 metric_info.name = fbl::StringPrintf("%s.%s", metric_info.name.c_str(), 32 options.get_event_name(options.event_code)); 33 } else { 34 metric_info.name = fbl::StringPrintf("%s.%u", metric_info.name.c_str(), options.event_code); 35 } 36 37 return metric_info; 38 } 39 operator ==(const LocalMetricInfo & rhs) const40bool LocalMetricInfo::operator==(const LocalMetricInfo& rhs) const { 41 return rhs.name == name; 42 } 43 operator !=(const LocalMetricInfo & rhs) const44bool LocalMetricInfo::operator!=(const LocalMetricInfo& rhs) const { 45 return !(*this == rhs); 46 } 47 From(const MetricOptions & options)48RemoteMetricInfo RemoteMetricInfo::From(const MetricOptions& options) { 49 RemoteMetricInfo metric_info; 50 metric_info.metric_id = options.metric_id; 51 metric_info.component = options.component; 52 metric_info.event_code = options.event_code; 53 return metric_info; 54 } 55 operator ==(const RemoteMetricInfo & rhs) const56bool RemoteMetricInfo::operator==(const RemoteMetricInfo& rhs) const { 57 return rhs.metric_id == metric_id && rhs.event_code == event_code && rhs.component == component; 58 } 59 operator !=(const RemoteMetricInfo & rhs) const60bool RemoteMetricInfo::operator!=(const RemoteMetricInfo& rhs) const { 61 return !(*this == rhs); 62 } 63 64 } // namespace internal 65 } // namespace cobalt_client 66