1 /* 2 * Copyright (C) 2022 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 ACCESSIBILITY_OPERATOR_ASYNC_LOCK_H 17 #define ACCESSIBILITY_OPERATOR_ASYNC_LOCK_H 18 19 #include <cstdint> 20 #include <mutex> 21 22 namespace OHOS { 23 namespace Accessibility { 24 class AccessibilityElementAsyncOperatorMng { 25 public: 26 /** 27 * @brief construct function 28 * @param - 29 * @return - 30 */ AccessibilityElementAsyncOperatorMng()31 AccessibilityElementAsyncOperatorMng() {} 32 33 /** 34 * @brief function: Set the timer related with the requestion from AA to ACE. 35 * @param sequence The sequence value from AA, it is used to match with request and feedback. 36 * @return - 37 */ 38 bool SearchElementResultTimer(int sequence); 39 40 /** 41 * @brief function: Set the feedback searcg from ACE. 42 * @param feedbackSequence The response sequence value from ACE 43 * @return - 44 */ 45 void UpdateSearchFeedback(int feedbackSequence); 46 47 /** 48 * @brief Inner function: Set the status requested from AA to ACE. 49 * @param status true: The requestion is completed; otherwise is not. 50 * @return - 51 */ 52 void SetOperationStatus(bool status); 53 54 /** 55 * @brief Inner function: The status requested from AA to ACE. 56 * @param 57 * @return true: The requestion is completed; otherwise is not. 58 */ 59 bool GetOperationStatus(); 60 61 /** 62 * @brief Inner function: Count the unique value requested 63 * @param 64 * @return The sequence value from AA, it is used to match with request and response. 65 */ 66 int RecordSearchSequence(); 67 private: 68 static const uint32_t MAX_REQUEST = 0x7FFFFFFF; 69 static const uint32_t SECOND_TO_MILLIS = 1000000; 70 static const long TIMEOUT_OPERATOR_MILLIS = 500000; 71 static const long SLEEP_MILLIS = 5000; 72 int feedbackSequence_ = 0; 73 bool completed_ = false; 74 static std::recursive_mutex mutex_; 75 static int sequence_; // matched request with callback result 76 }; 77 } // namespace Accessibility 78 } // namespace OHOS 79 #endif