Hanumant Singh | 80d02f6 | 2019-12-27 17:44:17 -0800 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://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, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "RunnerComponent.h" |
| 16 | |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 17 | #include "ClientConfig.pb.h" |
Hanumant Singh | 80d02f6 | 2019-12-27 17:44:17 -0800 | [diff] [blame] | 18 | #include "types/Status.h" |
| 19 | |
| 20 | namespace android { |
| 21 | namespace automotive { |
| 22 | namespace computepipe { |
| 23 | namespace runner { |
| 24 | |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 25 | /* Is this a notification to enter the phase */ |
| 26 | bool RunnerEvent::isPhaseEntry() const { |
| 27 | return false; |
| 28 | } |
| 29 | /* Is this a notification that all components have transitioned to the phase */ |
| 30 | bool RunnerEvent::isTransitionComplete() const { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | bool RunnerEvent::isAborted() const { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * ClientConfig methods |
| 40 | */ |
| 41 | Status ClientConfig::dispatchToComponent(const std::shared_ptr<RunnerComponentInterface>& iface) { |
| 42 | return iface->handleConfigPhase(*this); |
| 43 | } |
| 44 | |
| 45 | std::string ClientConfig::getSerializedClientConfig() const { |
| 46 | proto::ClientConfig config; |
| 47 | std::string output; |
| 48 | |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 49 | config.set_input_config_id(mInputConfigId); |
| 50 | config.set_termination_id(mTerminationId); |
| 51 | config.set_offload_id(mOffloadId); |
Kathan Shukla | 3db9190 | 2020-04-15 13:11:24 -0700 | [diff] [blame] | 52 | config.set_profiling_type(mProfilingType); |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 53 | for (auto it : mOutputConfigs) { |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 54 | (*config.mutable_output_options())[it.first] = it.second; |
| 55 | } |
| 56 | if (!config.SerializeToString(&output)) { |
| 57 | return ""; |
| 58 | } |
| 59 | return output; |
| 60 | } |
| 61 | |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 62 | Status ClientConfig::getInputConfigId(int* outId) const { |
| 63 | if (mInputConfigId == kInvalidId) { |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 64 | return Status::ILLEGAL_STATE; |
| 65 | } |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 66 | *outId = mInputConfigId; |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 67 | return Status::SUCCESS; |
| 68 | } |
| 69 | |
| 70 | Status ClientConfig::getOffloadId(int* outId) const { |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 71 | if (mOffloadId == kInvalidId) { |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 72 | return Status::ILLEGAL_STATE; |
| 73 | } |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 74 | *outId = mOffloadId; |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 75 | return Status::SUCCESS; |
| 76 | } |
| 77 | |
| 78 | Status ClientConfig::getTerminationId(int* outId) const { |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 79 | if (mTerminationId == kInvalidId) { |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 80 | return Status::ILLEGAL_STATE; |
| 81 | } |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 82 | *outId = mTerminationId; |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 83 | return Status::SUCCESS; |
| 84 | } |
| 85 | |
| 86 | Status ClientConfig::getOutputStreamConfigs(std::map<int, int>& outputConfig) const { |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 87 | if (mOutputConfigs.empty()) { |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 88 | return Status::ILLEGAL_STATE; |
| 89 | } |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 90 | outputConfig = mOutputConfigs; |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 91 | return Status::SUCCESS; |
| 92 | } |
| 93 | |
| 94 | Status ClientConfig::getOptionalConfigs(std::string& outOptional) const { |
Yogeshwar Nagaraj | 8faf81a | 2020-01-13 13:50:32 -0800 | [diff] [blame] | 95 | outOptional = mOptionalConfigs; |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 96 | return Status::SUCCESS; |
| 97 | } |
| 98 | |
Kathan Shukla | bf7a01e | 2020-03-20 07:15:47 -0700 | [diff] [blame] | 99 | Status ClientConfig::getProfilingType(proto::ProfilingType* profilingType) const { |
| 100 | *profilingType = mProfilingType; |
| 101 | return Status::SUCCESS; |
| 102 | } |
| 103 | |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Methods for ComponentInterface |
| 106 | */ |
| 107 | |
Hanumant Singh | 80d02f6 | 2019-12-27 17:44:17 -0800 | [diff] [blame] | 108 | /* handle a ConfigPhase related event notification from Runner Engine */ |
Hanumant Singh | fb70cb0 | 2020-01-02 18:55:06 -0800 | [diff] [blame] | 109 | Status RunnerComponentInterface::handleConfigPhase(const ClientConfig& /* e*/) { |
Hanumant Singh | 80d02f6 | 2019-12-27 17:44:17 -0800 | [diff] [blame] | 110 | return Status::SUCCESS; |
| 111 | } |
| 112 | /* handle execution phase notification from Runner Engine */ |
| 113 | Status RunnerComponentInterface::handleExecutionPhase(const RunnerEvent& /* e*/) { |
| 114 | return SUCCESS; |
| 115 | } |
| 116 | /* handle a stop with flushing semantics phase notification from the engine */ |
| 117 | Status RunnerComponentInterface::handleStopWithFlushPhase(const RunnerEvent& /* e*/) { |
| 118 | return SUCCESS; |
| 119 | } |
| 120 | /* handle an immediate stop phase notification from the engine */ |
| 121 | Status RunnerComponentInterface::handleStopImmediatePhase(const RunnerEvent& /* e*/) { |
| 122 | return SUCCESS; |
| 123 | } |
| 124 | /* handle an engine notification to return to reset state */ |
| 125 | Status RunnerComponentInterface::handleResetPhase(const RunnerEvent& /* e*/) { |
| 126 | return SUCCESS; |
| 127 | } |
| 128 | |
| 129 | } // namespace runner |
| 130 | } // namespace computepipe |
| 131 | } // namespace automotive |
| 132 | } // namespace android |