1 /* 2 * Copyright (C) 2024-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 #ifndef FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_H 17 #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_H 18 19 #include "actions/action.h" 20 21 #include <list> 22 #include <memory> 23 24 namespace OHOS { 25 namespace MiscServices { 26 27 enum SourceType : uint32_t { 28 SOURCE_TYPE_AMS = 0, 29 SOURCE_TYPE_IMA, 30 SOURCE_TYPE_IMSA, 31 SOURCE_TYPE_INNER, 32 }; 33 34 #define TASK_TYPE_OFFSET(src) ((src)*10000) 35 36 enum TaskType : uint32_t { 37 // Task from AMS 38 TASK_TYPE_AMS_BEGIN = TASK_TYPE_OFFSET(SOURCE_TYPE_AMS), 39 TASK_TYPE_AMS_INIT = TASK_TYPE_AMS_BEGIN, 40 TASK_TYPE_AMS_END = TASK_TYPE_AMS_INIT, 41 42 // Task from IMA 43 TASK_TYPE_IMA_BEGIN = TASK_TYPE_OFFSET(SOURCE_TYPE_IMA), 44 TASK_TYPE_IMA_SHOW_PANEL = TASK_TYPE_IMA_BEGIN, 45 TASK_TYPE_IMA_HIDE_PANEL, 46 TASK_TYPE_IMA_END = TASK_TYPE_IMA_HIDE_PANEL, 47 48 // Task from IMSA 49 TASK_TYPE_IMSA_BEGIN = TASK_TYPE_OFFSET(SOURCE_TYPE_IMSA), 50 TASK_TYPE_IMSA_START_INPUT = TASK_TYPE_IMSA_BEGIN, 51 TASK_TYPE_IMSA_STOP_INPUT, 52 TASK_TYPE_IMSA_SHOW_KEYBOARD, 53 TASK_TYPE_IMSA_HIDE_KEYBOARD, 54 TASK_TYPE_IMSA_CLIENT_INACTIVE, 55 TASK_TYPE_IMSA_INIT_INPUT_CTRL_CHANNEL, 56 TASK_TYPE_IMSA_CURSOR_UPDATE, 57 TASK_TYPE_IMSA_SEND_PRIVATE_COMMAND, 58 TASK_TYPE_IMSA_SELECTION_CHANGE, 59 TASK_TYPE_IMSA_ATTRIBUTE_CHANGE, 60 TASK_TYPE_IMSA_STOP_INPUT_SERVICE, 61 TASK_TYPE_IMSA_SET_SUBPROPERTY, 62 TASK_TYPE_IMSA_SET_CORE_AND_AGENT, 63 TASK_TYPE_IMSA_ADJUST_KEYBOARD, 64 TASK_TYPE_IMSA_END = TASK_TYPE_IMSA_ADJUST_KEYBOARD, 65 66 // Task from inner 67 TASK_TYPE_RESUME, 68 }; 69 70 class Task { 71 public: 72 explicit Task(TaskType t); 73 Task(TaskType t, uint64_t seqId); 74 virtual ~Task() = default; 75 76 RunningState Execute(); 77 RunningState Resume(uint64_t resumeId); 78 79 virtual RunningState OnTask(std::shared_ptr<Task> task); 80 81 int32_t Pend(std::shared_ptr<Task> task); 82 int32_t Pend(std::unique_ptr<Action> action); 83 84 TaskType GetType() const; 85 SourceType GetSourceType() const; 86 uint64_t GetSeqId() const; 87 RunningState GetState() const; 88 bool IsRunning() const; 89 const std::list<std::unique_ptr<Action>> &GetActions() const; 90 91 static uint64_t GetNextSeqId(); 92 93 private: 94 RunningState ExecuteInner(); 95 96 protected: 97 const TaskType type_; 98 RunningState state_ { RUNNING_STATE_IDLE }; 99 const uint64_t seqId_; 100 std::unique_ptr<Action> curAction_ { nullptr }; 101 std::list<std::unique_ptr<Action>> actions_; 102 std::list<std::unique_ptr<Action>> pendingActions_; 103 }; 104 105 } // namespace MiscServices 106 } // namespace OHOS 107 #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_H