1 // Copyright (C) 2020 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 "EventGenerator.h"
16 
17 #include "RunnerComponent.h"
18 
19 namespace android {
20 namespace automotive {
21 namespace computepipe {
22 namespace runner {
23 namespace generator {
24 
isPhaseEntry() const25 bool DefaultEvent::isPhaseEntry() const {
26     return mType == static_cast<int>(PhaseState::ENTRY);
27 }
isAborted() const28 bool DefaultEvent::isAborted() const {
29     return mType == static_cast<int>(PhaseState::ABORTED);
30 }
isTransitionComplete() const31 bool DefaultEvent::isTransitionComplete() const {
32     return mType == static_cast<int>(PhaseState::TRANSITION_COMPLETE);
33 }
34 
dispatchToComponent(const std::shared_ptr<RunnerComponentInterface> & iface)35 Status DefaultEvent::dispatchToComponent(const std::shared_ptr<RunnerComponentInterface>& iface) {
36     switch (mPhase) {
37         case RESET:
38             return iface->handleResetPhase(*this);
39         case RUN:
40             return iface->handleExecutionPhase(*this);
41         case STOP_WITH_FLUSH:
42             return iface->handleStopWithFlushPhase(*this);
43         case STOP_IMMEDIATE:
44             return iface->handleStopImmediatePhase(*this);
45     }
46     return Status::ILLEGAL_STATE;
47 }
48 
generateEntryEvent(Phase p)49 DefaultEvent DefaultEvent::generateEntryEvent(Phase p) {
50     return DefaultEvent(PhaseState::ENTRY, p);
51 }
generateAbortEvent(Phase p)52 DefaultEvent DefaultEvent::generateAbortEvent(Phase p) {
53     return DefaultEvent(PhaseState::ABORTED, p);
54 }
generateTransitionCompleteEvent(Phase p)55 DefaultEvent DefaultEvent::generateTransitionCompleteEvent(Phase p) {
56     return DefaultEvent(PhaseState::TRANSITION_COMPLETE, p);
57 }
58 
59 }  // namespace generator
60 }  // namespace runner
61 }  // namespace computepipe
62 }  // namespace automotive
63 }  // namespace android
64