blob: d3d14828312e90a3fc079d05cda3fa413e862888 [file] [log] [blame]
Hanumant Singh80d02f62019-12-27 17:44:17 -08001// 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 Singhfb70cb02020-01-02 18:55:06 -080017#include "ClientConfig.pb.h"
Hanumant Singh80d02f62019-12-27 17:44:17 -080018#include "types/Status.h"
19
20namespace android {
21namespace automotive {
22namespace computepipe {
23namespace runner {
24
Hanumant Singhfb70cb02020-01-02 18:55:06 -080025/* Is this a notification to enter the phase */
26bool RunnerEvent::isPhaseEntry() const {
27 return false;
28}
29/* Is this a notification that all components have transitioned to the phase */
30bool RunnerEvent::isTransitionComplete() const {
31 return false;
32}
33
34bool RunnerEvent::isAborted() const {
35 return false;
36}
37
38/**
39 * ClientConfig methods
40 */
41Status ClientConfig::dispatchToComponent(const std::shared_ptr<RunnerComponentInterface>& iface) {
42 return iface->handleConfigPhase(*this);
43}
44
45std::string ClientConfig::getSerializedClientConfig() const {
46 proto::ClientConfig config;
47 std::string output;
48
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080049 config.set_input_config_id(mInputConfigId);
50 config.set_termination_id(mTerminationId);
51 config.set_offload_id(mOffloadId);
Kathan Shukla3db91902020-04-15 13:11:24 -070052 config.set_profiling_type(mProfilingType);
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080053 for (auto it : mOutputConfigs) {
Hanumant Singhfb70cb02020-01-02 18:55:06 -080054 (*config.mutable_output_options())[it.first] = it.second;
55 }
56 if (!config.SerializeToString(&output)) {
57 return "";
58 }
59 return output;
60}
61
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080062Status ClientConfig::getInputConfigId(int* outId) const {
63 if (mInputConfigId == kInvalidId) {
Hanumant Singhfb70cb02020-01-02 18:55:06 -080064 return Status::ILLEGAL_STATE;
65 }
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080066 *outId = mInputConfigId;
Hanumant Singhfb70cb02020-01-02 18:55:06 -080067 return Status::SUCCESS;
68}
69
70Status ClientConfig::getOffloadId(int* outId) const {
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080071 if (mOffloadId == kInvalidId) {
Hanumant Singhfb70cb02020-01-02 18:55:06 -080072 return Status::ILLEGAL_STATE;
73 }
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080074 *outId = mOffloadId;
Hanumant Singhfb70cb02020-01-02 18:55:06 -080075 return Status::SUCCESS;
76}
77
78Status ClientConfig::getTerminationId(int* outId) const {
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080079 if (mTerminationId == kInvalidId) {
Hanumant Singhfb70cb02020-01-02 18:55:06 -080080 return Status::ILLEGAL_STATE;
81 }
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080082 *outId = mTerminationId;
Hanumant Singhfb70cb02020-01-02 18:55:06 -080083 return Status::SUCCESS;
84}
85
86Status ClientConfig::getOutputStreamConfigs(std::map<int, int>& outputConfig) const {
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080087 if (mOutputConfigs.empty()) {
Hanumant Singhfb70cb02020-01-02 18:55:06 -080088 return Status::ILLEGAL_STATE;
89 }
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080090 outputConfig = mOutputConfigs;
Hanumant Singhfb70cb02020-01-02 18:55:06 -080091 return Status::SUCCESS;
92}
93
94Status ClientConfig::getOptionalConfigs(std::string& outOptional) const {
Yogeshwar Nagaraj8faf81a2020-01-13 13:50:32 -080095 outOptional = mOptionalConfigs;
Hanumant Singhfb70cb02020-01-02 18:55:06 -080096 return Status::SUCCESS;
97}
98
Kathan Shuklabf7a01e2020-03-20 07:15:47 -070099Status ClientConfig::getProfilingType(proto::ProfilingType* profilingType) const {
100 *profilingType = mProfilingType;
101 return Status::SUCCESS;
102}
103
Hanumant Singhfb70cb02020-01-02 18:55:06 -0800104/**
105 * Methods for ComponentInterface
106 */
107
Hanumant Singh80d02f62019-12-27 17:44:17 -0800108/* handle a ConfigPhase related event notification from Runner Engine */
Hanumant Singhfb70cb02020-01-02 18:55:06 -0800109Status RunnerComponentInterface::handleConfigPhase(const ClientConfig& /* e*/) {
Hanumant Singh80d02f62019-12-27 17:44:17 -0800110 return Status::SUCCESS;
111}
112/* handle execution phase notification from Runner Engine */
113Status RunnerComponentInterface::handleExecutionPhase(const RunnerEvent& /* e*/) {
114 return SUCCESS;
115}
116/* handle a stop with flushing semantics phase notification from the engine */
117Status RunnerComponentInterface::handleStopWithFlushPhase(const RunnerEvent& /* e*/) {
118 return SUCCESS;
119}
120/* handle an immediate stop phase notification from the engine */
121Status RunnerComponentInterface::handleStopImmediatePhase(const RunnerEvent& /* e*/) {
122 return SUCCESS;
123}
124/* handle an engine notification to return to reset state */
125Status RunnerComponentInterface::handleResetPhase(const RunnerEvent& /* e*/) {
126 return SUCCESS;
127}
128
129} // namespace runner
130} // namespace computepipe
131} // namespace automotive
132} // namespace android