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 17 #ifndef SRC_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 18 #define SRC_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "perfetto/base/task_runner.h" 24 #include "perfetto/ext/base/weak_ptr.h" 25 #include "perfetto/ext/tracing/core/producer.h" 26 #include "perfetto/ext/tracing/core/tracing_service.h" 27 #include "perfetto/tracing/core/forward_decls.h" 28 namespace perfetto { 29 30 // This is a producer that only sends the provided |triggers| to the service. It 31 // will never register any data sources. 32 class TriggerProducer : public Producer { 33 public: 34 TriggerProducer(base::TaskRunner* task_runner, 35 std::function<void(bool)> callback, 36 const std::vector<std::string>* const triggers); 37 ~TriggerProducer() override; 38 39 // We will call Trigger() on the |producer_endpoint_| and then 40 // immediately call |callback_|. 41 void OnConnect() override; 42 // We have no clean up to do OnDisconnect. 43 void OnDisconnect() override; 44 45 // Unimplemented methods are below this. 46 void OnTracingSetup() override; 47 void SetupDataSource(DataSourceInstanceID, const DataSourceConfig&) override; 48 void StartDataSource(DataSourceInstanceID, const DataSourceConfig&) override; 49 void StopDataSource(DataSourceInstanceID) override; 50 void Flush(FlushRequestID, const DataSourceInstanceID*, size_t) override; 51 void ClearIncrementalState(const DataSourceInstanceID* data_source_ids, 52 size_t num_data_sources) override; 53 54 private: 55 bool issued_callback_ = false; 56 base::TaskRunner* const task_runner_; 57 const std::function<void(bool)> callback_; 58 const std::vector<std::string>* const triggers_; 59 std::unique_ptr<TracingService::ProducerEndpoint> producer_endpoint_; 60 base::WeakPtrFactory<TriggerProducer> weak_factory_; 61 }; 62 63 } // namespace perfetto 64 65 #endif // SRC_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 66