1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
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
16 #include "dsched_continue_source_end_state.h"
17
18 #include "dsched_continue.h"
19 #include "dsched_continue_event.h"
20 #include "dtbschedmgr_log.h"
21
22 namespace OHOS {
23 namespace DistributedSchedule {
24 namespace {
25 const std::string TAG = "DSchedContinueEndState";
26 }
DSchedContinueEndState(std::shared_ptr<DSchedContinueStateMachine> stateMachine)27 DSchedContinueEndState::DSchedContinueEndState(std::shared_ptr<DSchedContinueStateMachine> stateMachine)
28 : stateMachine_(stateMachine)
29 {
30 memberFuncMap_[DSCHED_CONTINUE_END_EVENT] = &DSchedContinueEndState::DoContinueEndTask;
31 }
32
~DSchedContinueEndState()33 DSchedContinueEndState::~DSchedContinueEndState()
34 {
35 }
36
Execute(std::shared_ptr<DSchedContinue> dContinue,const AppExecFwk::InnerEvent::Pointer & event)37 int32_t DSchedContinueEndState::Execute(std::shared_ptr<DSchedContinue> dContinue,
38 const AppExecFwk::InnerEvent::Pointer &event)
39 {
40 if (event == nullptr) {
41 HILOGE("event is null");
42 return INVALID_PARAMETERS_ERR;
43 }
44 auto iterFunc = memberFuncMap_.find(event->GetInnerEventId());
45 if (iterFunc == memberFuncMap_.end()) {
46 HILOGI("DSchedContinueEndState execute %{public}d in wrong state", event->GetInnerEventId());
47 return CONTINUE_STATE_MACHINE_INVALID_STATE;
48 }
49
50 auto memberFunc = iterFunc->second;
51 int32_t ret = (this->*memberFunc)(dContinue, event);
52 if (ret != ERR_OK) {
53 HILOGI("DSchedContinueEndState execute %{public}d failed, ret: %{public}d", event->GetInnerEventId(), ret);
54 }
55 return ret;
56 }
57
GetStateType()58 DSchedContinueStateType DSchedContinueEndState::GetStateType()
59 {
60 return DSCHED_CONTINUE_SOURCE_END_STATE;
61 }
62
DoContinueEndTask(std::shared_ptr<DSchedContinue> dContinue,const AppExecFwk::InnerEvent::Pointer & event)63 int32_t DSchedContinueEndState::DoContinueEndTask(std::shared_ptr<DSchedContinue> dContinue,
64 const AppExecFwk::InnerEvent::Pointer &event)
65 {
66 if (dContinue == nullptr || event == nullptr) {
67 HILOGE("dContinue or event is null");
68 return INVALID_PARAMETERS_ERR;
69 }
70 auto syncContinueData = event->GetSharedObject<int32_t>();
71 int32_t ret = dContinue->ExecuteContinueEnd(*syncContinueData);
72 if (ret != ERR_OK) {
73 HILOGE("DSchedContinueSourceStartState ExecuteContinueEnd failed, ret: %{public}d", ret);
74 }
75 return ret;
76 }
77 } // namespace DistributedSchedule
78 } // namespace OHOS
79