1 // 2 // Copyright (C) 2019 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #include "host/commands/run_cvd/launch/launch.h" 17 18 #include <string> 19 #include <unordered_set> 20 #include <utility> 21 #include <vector> 22 23 #include <fruit/fruit.h> 24 25 #include "common/libs/utils/result.h" 26 #include "host/libs/config/command_source.h" 27 #include "host/libs/config/known_paths.h" 28 29 namespace cuttlefish { 30 namespace { 31 32 class MetricsService : public CommandSource { 33 public: INJECT(MetricsService (const CuttlefishConfig & config))34 INJECT(MetricsService(const CuttlefishConfig& config)) : config_(config) {} 35 36 // CommandSource Commands()37 Result<std::vector<MonitorCommand>> Commands() override { 38 Command command(MetricsBinary()); 39 std::vector<MonitorCommand> commands; 40 commands.emplace_back(std::move(command)); 41 return commands; 42 } 43 44 // SetupFeature Name() const45 std::string Name() const override { return "MetricsService"; } Enabled() const46 bool Enabled() const override { 47 return config_.enable_metrics() == CuttlefishConfig::kYes; 48 } 49 50 private: Dependencies() const51 std::unordered_set<SetupFeature*> Dependencies() const override { return {}; } Setup()52 bool Setup() override { return true; } 53 54 private: 55 const CuttlefishConfig& config_; 56 }; 57 58 } // namespace 59 60 fruit::Component<fruit::Required<const CuttlefishConfig>> MetricsServiceComponent()61MetricsServiceComponent() { 62 return fruit::createComponent() 63 .addMultibinding<CommandSource, MetricsService>() 64 .addMultibinding<SetupFeature, MetricsService>(); 65 } 66 67 } // namespace cuttlefish 68